5
5
ArrowsRightLeftIcon ,
6
6
XCircleIcon ,
7
7
ChevronDownIcon ,
8
- TableCellsIcon ,
9
8
BanknotesIcon ,
10
9
ChevronRightIcon ,
11
10
CheckIcon ,
@@ -19,7 +18,6 @@ import {
19
18
type ComponentProps ,
20
19
type ReactNode ,
21
20
useCallback ,
22
- useState ,
23
21
useMemo ,
24
22
type ReactElement ,
25
23
} from "react" ;
@@ -42,10 +40,8 @@ import {
42
40
import { StateType as DataStateType , useData } from "../../hooks/use-data" ;
43
41
import { useLogger } from "../../hooks/use-logger" ;
44
42
import { usePrimaryDomain } from "../../hooks/use-primary-domain" ;
45
- import { AccountHistory } from "../AccountHistory" ;
46
43
import { Button } from "../Button" ;
47
44
import { Menu , MenuItem , Section , Separator } from "../Menu" ;
48
- import { ModalDialog } from "../ModalDialog" ;
49
45
import { TruncatedKey } from "../TruncatedKey" ;
50
46
51
47
const ONE_SECOND_IN_MS = 1000 ;
@@ -103,10 +99,6 @@ const ConnectedButton = ({
103
99
api,
104
100
...props
105
101
} : ConnectedButtonProps ) => {
106
- const [ accountHistoryOpen , setAccountHistoryOpen ] = useState ( false ) ;
107
- const openAccountHistory = useCallback ( ( ) => {
108
- setAccountHistoryOpen ( true ) ;
109
- } , [ setAccountHistoryOpen ] ) ;
110
102
const modal = useWalletModal ( ) ;
111
103
const showModal = useCallback ( ( ) => {
112
104
modal . setVisible ( true ) ;
@@ -120,61 +112,39 @@ const ConnectedButton = ({
120
112
} , [ wallet , logger ] ) ;
121
113
122
114
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" />
152
133
</ 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 >
178
148
) ;
179
149
} ;
180
150
@@ -206,47 +176,47 @@ const StakeAccountSelector = ({ children, api }: StakeAccountSelectorProps) => {
206
176
}
207
177
} , [ data , api ] ) ;
208
178
209
- if ( accounts === undefined ) {
179
+ return accounts === undefined ||
210
180
// 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
+ ) ;
250
220
} ;
251
221
252
222
type AccountMenuItemProps = {
0 commit comments