55 ArrowsRightLeftIcon ,
66 XCircleIcon ,
77 ChevronDownIcon ,
8- TableCellsIcon ,
98 BanknotesIcon ,
109 ChevronRightIcon ,
1110 CheckIcon ,
@@ -19,7 +18,6 @@ import {
1918 type ComponentProps ,
2019 type ReactNode ,
2120 useCallback ,
22- useState ,
2321 useMemo ,
2422 type ReactElement ,
2523} from "react" ;
@@ -42,10 +40,8 @@ import {
4240import { StateType as DataStateType , useData } from "../../hooks/use-data" ;
4341import { useLogger } from "../../hooks/use-logger" ;
4442import { usePrimaryDomain } from "../../hooks/use-primary-domain" ;
45- import { AccountHistory } from "../AccountHistory" ;
4643import { Button } from "../Button" ;
4744import { Menu , MenuItem , Section , Separator } from "../Menu" ;
48- import { ModalDialog } from "../ModalDialog" ;
4945import { TruncatedKey } from "../TruncatedKey" ;
5046
5147const ONE_SECOND_IN_MS = 1000 ;
@@ -103,10 +99,6 @@ const ConnectedButton = ({
10399 api,
104100 ...props
105101} : ConnectedButtonProps ) => {
106- const [ accountHistoryOpen , setAccountHistoryOpen ] = useState ( false ) ;
107- const openAccountHistory = useCallback ( ( ) => {
108- setAccountHistoryOpen ( true ) ;
109- } , [ setAccountHistoryOpen ] ) ;
110102 const modal = useWalletModal ( ) ;
111103 const showModal = useCallback ( ( ) => {
112104 modal . setVisible ( true ) ;
@@ -120,61 +112,39 @@ const ConnectedButton = ({
120112 } , [ wallet , logger ] ) ;
121113
122114 return (
123- < >
124- < MenuTrigger >
125- < ButtonComponent
126- className = { clsx (
127- "group data-[pressed]:bg-pythpurple-600/60" ,
128- className ,
129- ) }
130- { ...props }
131- >
132- < span className = "truncate" >
133- < ButtonContent />
134- </ span >
135- < ChevronDownIcon className = "size-4 flex-none opacity-60 transition duration-300 group-data-[pressed]:-rotate-180" />
136- </ ButtonComponent >
137- < Menu className = "min-w-[var(--trigger-width)]" >
138- { api . type === ApiStateType . Loaded && (
139- < >
140- < Section >
141- < StakeAccountSelector api = { api } >
142- < MenuItem
143- icon = { BanknotesIcon }
144- textValue = "Select stake account"
145- >
146- < span > Select stake account</ span >
147- < ChevronRightIcon className = "size-4" />
148- </ MenuItem >
149- </ StakeAccountSelector >
150- < MenuItem onAction = { openAccountHistory } icon = { TableCellsIcon } >
151- Account history
115+ < MenuTrigger >
116+ < ButtonComponent
117+ className = { clsx ( "group data-[pressed]:bg-pythpurple-600/60" , className ) }
118+ { ...props }
119+ >
120+ < span className = "truncate" >
121+ < ButtonContent />
122+ </ span >
123+ < ChevronDownIcon className = "size-4 flex-none opacity-60 transition duration-300 group-data-[pressed]:-rotate-180" />
124+ </ ButtonComponent >
125+ < Menu className = "min-w-[var(--trigger-width)]" >
126+ { api . type === ApiStateType . Loaded && (
127+ < >
128+ < Section >
129+ < StakeAccountSelector api = { api } >
130+ < MenuItem icon = { BanknotesIcon } textValue = "Select stake account" >
131+ < span > Select stake account</ span >
132+ < ChevronRightIcon className = "size-4" />
152133 </ MenuItem >
153- </ Section >
154- < Separator />
155- </ >
156- ) }
157- < Section >
158- < MenuItem onAction = { showModal } icon = { ArrowsRightLeftIcon } >
159- Change wallet
160- </ MenuItem >
161- < MenuItem onAction = { disconnectWallet } icon = { XCircleIcon } >
162- Disconnect
163- </ MenuItem >
164- </ Section >
165- </ Menu >
166- </ MenuTrigger >
167- { api . type === ApiStateType . Loaded && (
168- < ModalDialog
169- isOpen = { accountHistoryOpen }
170- onOpenChange = { setAccountHistoryOpen }
171- title = "Account history"
172- description = "A history of events that have affected your account balances"
173- >
174- < AccountHistory api = { api } />
175- </ ModalDialog >
176- ) }
177- </ >
134+ </ StakeAccountSelector >
135+ </ Section >
136+ </ >
137+ ) }
138+ < Section >
139+ < MenuItem onAction = { showModal } icon = { ArrowsRightLeftIcon } >
140+ Change wallet
141+ </ MenuItem >
142+ < MenuItem onAction = { disconnectWallet } icon = { XCircleIcon } >
143+ Disconnect
144+ </ MenuItem >
145+ </ Section >
146+ </ Menu >
147+ </ MenuTrigger >
178148 ) ;
179149} ;
180150
@@ -206,47 +176,47 @@ const StakeAccountSelector = ({ children, api }: StakeAccountSelectorProps) => {
206176 }
207177 } , [ data , api ] ) ;
208178
209- if ( accounts === undefined ) {
179+ return accounts === undefined ||
210180 // eslint-disable-next-line unicorn/no-null
211- return null ;
212- } else if ( accounts . main === undefined ) {
213- return accounts . other . length > 1 ? (
214- < SubmenuTrigger >
215- { children }
216- < Menu items = { accounts . other } className = "-mr-20 xs:mr-0" >
217- { ( { account } ) => < AccountMenuItem account = { account } api = { api } /> }
218- </ Menu >
219- </ SubmenuTrigger >
220- ) : // eslint-disable-next-line unicorn/no-null
221- null ;
222- } else {
223- return (
224- < SubmenuTrigger >
225- { children }
226- < Menu className = "-mr-20 xs:mr-0" >
227- < Section >
228- < Header className = "mx-4 text-sm font-semibold" > Main Account </ Header >
229- < AccountMenuItem account = { accounts . main } api = { api } />
230- </ Section >
231- { accounts . other . length > 0 && (
232- < >
233- < Separator / >
234- < Section >
235- < Header className = "mx-4 text-sm font-semibold" >
236- Other Accounts
237- </ Header >
238- < Collection items = { accounts . other } >
239- { ( { account } ) => (
240- < AccountMenuItem account = { account } api = { api } />
241- ) }
242- </ Collection >
243- </ Section >
244- </ >
245- ) }
246- </ Menu >
247- </ SubmenuTrigger >
248- ) ;
249- }
181+ ( accounts . main === undefined && accounts . other . length === 1 ) ? null : (
182+ < >
183+ < Section >
184+ < SubmenuTrigger >
185+ { children }
186+ < Menu items = { accounts . other } className = "-mr-20 xs:mr-0" >
187+ { accounts . main === undefined ? (
188+ ( { account } ) => < AccountMenuItem account = { account } api = { api } / >
189+ ) : (
190+ < >
191+ < Section >
192+ < Header className = "mx-4 text-sm font-semibold" >
193+ Main Account
194+ </ Header >
195+ < AccountMenuItem account = { accounts . main } api = { api } />
196+ </ Section >
197+ { accounts . other . length > 0 && (
198+ < >
199+ < Separator />
200+ < Section >
201+ < Header className = "mx-4 text-sm font-semibold" >
202+ Other Accounts
203+ </ Header >
204+ < Collection items = { accounts . other } >
205+ { ( { account } ) => (
206+ < AccountMenuItem account = { account } api = { api } />
207+ ) }
208+ </ Collection >
209+ </ Section >
210+ < />
211+ ) }
212+ </ >
213+ ) }
214+ </ Menu >
215+ </ SubmenuTrigger >
216+ </ Section >
217+ < Separator / >
218+ </ >
219+ ) ;
250220} ;
251221
252222type AccountMenuItemProps = {
0 commit comments