11import { Menu } from '@headlessui/react' ;
2- import { useMemo , useState } from 'react' ;
2+ import { useMemo } from 'react' ;
33import { CheckCircleIcon , ChevronDownIcon } from '@heroicons/react/solid' ;
44import styled from '@emotion/styled' ;
55import useWalletStore from '../stores/useWalletStore' ;
66import {
77 getWalletProviderByUrl ,
88 WALLET_PROVIDERS ,
99} from '../utils/wallet-adapters' ;
10- import {
11- AddressImage ,
12- DisplayAddress ,
13- useAddressName ,
14- useWalletIdentity ,
15- } from '@cardinal/namespaces-components' ;
16- import { BackspaceIcon } from '@heroicons/react/solid' ;
17- import { UserCircleIcon } from '@heroicons/react/outline' ;
18- import { abbreviateAddress } from '@utils/formatting' ;
19- import { useRouter } from 'next/router' ;
20- import TwitterIcon from './TwitterIcon' ;
21- import Switch from './Switch' ;
2210
2311const StyledWalletProviderLabel = styled . p `
2412 font-size: 0.65rem;
@@ -30,25 +18,13 @@ const ConnectWalletButton = (props) => {
3018 connected,
3119 current,
3220 providerUrl,
33- connection,
3421 set : setWalletStore ,
3522 } = useWalletStore ( ( s ) => s ) ;
3623
3724 const provider = useMemo ( ( ) => getWalletProviderByUrl ( providerUrl ) , [
3825 providerUrl ,
3926 ] ) ;
4027
41- const [ useDevnet , setUseDevnet ] = useState ( false ) ;
42- const router = useRouter ( ) ;
43- const handleToggleDevnet = ( ) => {
44- setUseDevnet ( ! useDevnet ) ;
45- if ( useDevnet ) {
46- router . push ( `${ window . location . pathname } ` ) ;
47- } else {
48- router . push ( `${ window . location . href } ?cluster=devnet` ) ;
49- }
50- } ;
51-
5228 const handleConnectDisconnect = async ( ) => {
5329 try {
5430 if ( connected ) {
@@ -61,70 +37,27 @@ const ConnectWalletButton = (props) => {
6137 }
6238 } ;
6339
64- const { show } = useWalletIdentity ( ) ;
65-
66- const { displayName } = useAddressName (
67- connection . current ,
68- current ?. publicKey || undefined ,
69- ) ;
70-
71- const walletAddressFormatted = current ?. publicKey
72- ? abbreviateAddress ( current ?. publicKey )
73- : '' ;
40+ if ( ! provider ) {
41+ return null ;
42+ }
7443
7544 return (
7645 < div className = "flex" >
7746 < button
78- disabled = { connected }
79- className = { `bg-transparent border border-fgd-4 border-r-0 default-transition flex h-12 items-center pl-1 pr-2 rounded-l-full rounded-r-none ${
80- connected ? 'cursor-default' : 'hover:bg-bkg-3 focus:outline-none'
81- } `}
47+ className = "bg-transparent border border-fgd-3 border-r-0 default-transition flex h-12 items-center pl-3 pr-4 rounded-l-full rounded-r-none w-36 hover:bg-bkg-3 focus:outline-none"
8248 onClick = { handleConnectDisconnect }
8349 { ...props }
8450 >
85- < div className = "flex font-bold items-center text-fgd-1 text-left text-sm relative" >
86- { connected && current ?. publicKey ? (
87- < div className = "w-12 pr-2" >
88- < AddressImage
89- dark = { true }
90- connection = { connection . current }
91- address = { current ?. publicKey }
92- height = "40px"
93- width = "40px"
94- placeholder = {
95- < div className = "bg-bkg-4 flex flex-shrink-0 items-center justify-center h-10 rounded-full w-10 mr-2" >
96- < UserCircleIcon className = "h-9 text-fgd-3 w-9" />
97- </ div >
98- }
99- />
100- </ div >
101- ) : (
102- < div className = "pr-2 pl-2" >
103- < img src = { provider ?. icon } className = "h-5 w-5" />
104- </ div >
105- ) }
51+ < div className = "flex font-bold items-center text-fgd-1 text-left text-sm" >
52+ < div className = "pr-2" >
53+ < img src = { provider . icon } className = "h-5 w-5" />
54+ </ div >
55+
10656 < div >
107- { connected && current ?. publicKey ? (
108- < >
109- < DisplayAddress
110- connection = { connection . current }
111- address = { current ?. publicKey }
112- width = "100px"
113- height = "20px"
114- dark = { true }
115- />
116- < StyledWalletProviderLabel className = "font-normal text-fgd-3" >
117- { walletAddressFormatted }
118- </ StyledWalletProviderLabel >
119- </ >
120- ) : (
121- < >
122- Connect
123- < StyledWalletProviderLabel className = "font-normal text-fgd-3" >
124- { provider ?. name }
125- </ StyledWalletProviderLabel >
126- </ >
127- ) }
57+ { connected ? 'Disconnect' : 'Connect' }
58+ < StyledWalletProviderLabel className = "font-normal text-fgd-3" >
59+ { provider . name }
60+ </ StyledWalletProviderLabel >
12861 </ div >
12962 </ div >
13063 </ button >
@@ -133,88 +66,32 @@ const ConnectWalletButton = (props) => {
13366 < Menu >
13467 { ( { open } ) => (
13568 < >
136- < Menu . Button
137- className = { `border border-fgd-4 cursor-pointer default-transition h-12 w-12 py-2 px-2 rounded-r-full hover:bg-bkg-3 focus:outline-none` }
138- >
69+ < Menu . Button className = "border border-fgd-3 cursor-pointer default-transition h-12 w-12 py-2 px-2 rounded-r-full hover:bg-bkg-3 focus:outline-none" >
13970 < ChevronDownIcon
14071 className = { `${
14172 open ? 'transform rotate-180' : 'transform rotate-360'
14273 } default-transition h-5 m-auto ml-1 text-primary-light w-5`}
14374 />
14475 </ Menu . Button >
14576 < Menu . Items className = "absolute bg-bkg-1 border border-fgd-4 p-2 right-0 top-14 shadow-md outline-none rounded-md w-48 z-20" >
146- < >
147- { WALLET_PROVIDERS . map ( ( { name, url, icon } ) => (
148- < Menu . Item key = { name } >
149- < button
150- className = "flex default-transition h-9 items-center p-2 w-full hover:bg-bkg-3 hover:cursor-pointer hover:rounded font-normal focus:outline-none"
151- onClick = { ( ) =>
152- setWalletStore ( ( s ) => {
153- s . providerUrl = url ;
154- } )
155- }
156- >
157- < img src = { icon } className = "h-4 w-4 mr-2" />
158- < span className = "text-sm" > { name } </ span >
159-
160- { provider ?. url === url ? (
161- < CheckCircleIcon className = "h-5 ml-2 text-green w-5" />
162- ) : null }
163- </ button >
164- </ Menu . Item >
165- ) ) }
166-
167- { current && current . publicKey && (
168- < >
169- < hr
170- className = { `border border-fgd-3 opacity-50 mt-2 mb-2` }
171- > </ hr >
172- < Menu . Item
173- key = { 'twitter' }
174- onClick = { ( ) =>
175- show (
176- // @ts -ignore
177- current ,
178- connection . current ,
179- connection . cluster ,
180- )
181- }
182- >
183- < button className = "flex default-transition h-9 items-center p-2 w-full hover:bg-bkg-3 hover:cursor-pointer hover:rounded font-normal focus:outline-none" >
184- < TwitterIcon className = "h-4 w-4 mr-2" />
185- < span className = "text-sm" >
186- { displayName ? 'Edit Twitter' : 'Link Twitter' }
187- </ span >
188- </ button >
189- </ Menu . Item >
190- < Menu . Item
191- key = { 'disconnect' }
192- onClick = { handleConnectDisconnect }
193- >
194- < button className = "flex default-transition h-9 items-center p-2 w-full hover:bg-bkg-3 hover:cursor-pointer hover:rounded font-normal focus:outline-none" >
195- < BackspaceIcon className = "h-4 w-4 mr-2" />
196- < span className = "text-sm" > Disconnect</ span >
197- </ button >
198- </ Menu . Item >
199- < Menu . Item
200- key = { 'devnet' }
201- onClick = { ( ) => {
202- handleToggleDevnet ( ) ;
203- } }
204- >
205- < button className = "flex default-transition h-9 items-center p-2 w-full hover:bg-bkg-3 hover:cursor-pointer hover:rounded font-normal focus:outline-none" >
206- < span className = "text-sm" > Devnet</ span >
207- < Switch
208- checked = { useDevnet }
209- onChange = { ( ) => {
210- handleToggleDevnet ( ) ;
211- } }
212- />
213- </ button >
214- </ Menu . Item >
215- </ >
216- ) }
217- </ >
77+ { WALLET_PROVIDERS . map ( ( { name, url, icon } ) => (
78+ < Menu . Item key = { name } >
79+ < button
80+ className = "flex default-transition h-9 items-center p-2 w-full hover:bg-bkg-3 hover:cursor-pointer hover:rounded font-normal focus:outline-none"
81+ onClick = { ( ) =>
82+ setWalletStore ( ( s ) => {
83+ s . providerUrl = url ;
84+ } )
85+ }
86+ >
87+ < img src = { icon } className = "h-4 w-4 mr-2" />
88+ < span className = "text-sm" > { name } </ span >
89+ { provider . url === url ? (
90+ < CheckCircleIcon className = "h-5 ml-2 text-green w-5" />
91+ ) : null }
92+ </ button >
93+ </ Menu . Item >
94+ ) ) }
21895 </ Menu . Items >
21996 </ >
22097 ) }
0 commit comments