@@ -15,6 +15,7 @@ import type { Chain } from "../../../../chains/types.js";
15
15
import type { ThirdwebClient } from "../../../../client/client.js" ;
16
16
import { getContract } from "../../../../contract/contract.js" ;
17
17
import { getLastAuthProvider } from "../../../../react/core/utils/storage.js" ;
18
+ import { shortenAddress } from "../../../../utils/address.js" ;
18
19
import { isContractDeployed } from "../../../../utils/bytecode/is-contract-deployed.js" ;
19
20
import { formatNumber } from "../../../../utils/formatNumber.js" ;
20
21
import { webLocalStorage } from "../../../../utils/storage/webStorage.js" ;
@@ -67,10 +68,7 @@ import type {
67
68
SupportedTokens ,
68
69
} from "../../../core/utils/defaultTokens.js" ;
69
70
import { hasSmartAccount } from "../../../core/utils/isSmartWallet.js" ;
70
- import {
71
- useConnectedWalletDetails ,
72
- useWalletInfo ,
73
- } from "../../../core/utils/wallet.js" ;
71
+ import { useWalletInfo } from "../../../core/utils/wallet.js" ;
74
72
import { WalletUIStatesProvider } from "../../providers/wallet-ui-states-provider.js" ;
75
73
import { ChainIcon } from "../components/ChainIcon.js" ;
76
74
import { CopyIcon } from "../components/CopyIcon.js" ;
@@ -86,8 +84,13 @@ import { Button, IconButton } from "../components/buttons.js";
86
84
import { Link , Text } from "../components/text.js" ;
87
85
import { fadeInAnimation } from "../design-system/animations.js" ;
88
86
import { StyledButton } from "../design-system/elements.js" ;
87
+ import { AccountAddress } from "../prebuilt/Account/address.js" ;
88
+ import { AccountAvatar } from "../prebuilt/Account/avatar.js" ;
89
+ import { AccountBalance } from "../prebuilt/Account/balance.js" ;
90
+ import { AccountBlobbie } from "../prebuilt/Account/blobbie.js" ;
91
+ import { AccountName } from "../prebuilt/Account/name.js" ;
92
+ import { AccountProvider } from "../prebuilt/Account/provider.js" ;
89
93
import type { LocaleId } from "../types.js" ;
90
- import { Blobbie } from "./Blobbie.js" ;
91
94
import { MenuButton , MenuLink } from "./MenuButton.js" ;
92
95
import { ScreenSetupContext , useSetupScreen } from "./Modal/screen.js" ;
93
96
import {
@@ -140,18 +143,10 @@ export const ConnectedWalletDetails: React.FC<{
140
143
connectOptions : DetailsModalConnectOptions | undefined ;
141
144
} > = ( props ) => {
142
145
const { connectLocale : locale , client } = props ;
143
-
144
146
const setRootEl = useContext ( SetRootElementContext ) ;
145
147
const activeAccount = useActiveAccount ( ) ;
146
148
const walletChain = useActiveWalletChain ( ) ;
147
149
148
- const { pfp, name, balanceQuery } = useConnectedWalletDetails (
149
- client ,
150
- walletChain ,
151
- activeAccount ,
152
- props . detailsButton ?. displayBalanceToken ,
153
- ) ;
154
-
155
150
function closeModal ( ) {
156
151
setRootEl ( null ) ;
157
152
}
@@ -199,8 +194,6 @@ export const ConnectedWalletDetails: React.FC<{
199
194
) ;
200
195
}
201
196
202
- const avatarSrc = props . detailsButton ?. connectedAccountAvatarUrl || pfp ;
203
-
204
197
const combinedClassName = `${ TW_CONNECTED_WALLET } ${ props . detailsButton ?. className || "" } ` ;
205
198
206
199
return (
@@ -219,18 +212,27 @@ export const ConnectedWalletDetails: React.FC<{
219
212
height : "35px" ,
220
213
} }
221
214
>
222
- { avatarSrc ? (
215
+ { props . detailsButton ?. connectedAccountAvatarUrl ? (
223
216
< img
224
217
alt = ""
225
- src = { avatarSrc }
218
+ src = { props . detailsButton . connectedAccountAvatarUrl }
226
219
style = { {
227
220
height : "100%" ,
228
221
width : "100%" ,
229
222
objectFit : "cover" ,
230
223
} }
231
224
/>
232
225
) : (
233
- activeAccount && < Blobbie address = { activeAccount . address } size = { 35 } />
226
+ activeAccount && (
227
+ < AccountAvatar
228
+ loadingComponent = { < AccountBlobbie size = { 35 } /> }
229
+ fallbackComponent = { < AccountBlobbie size = { 35 } /> }
230
+ queryOptions = { {
231
+ refetchOnWindowFocus : false ,
232
+ refetchOnMount : false ,
233
+ } }
234
+ />
235
+ )
234
236
) }
235
237
</ Container >
236
238
< Container
@@ -243,29 +245,47 @@ export const ConnectedWalletDetails: React.FC<{
243
245
} }
244
246
>
245
247
{ /* Address */ }
246
- < Text
247
- size = "xs"
248
- color = "primaryText"
249
- weight = { 500 }
250
- className = { `${ TW_CONNECTED_WALLET } __address` }
251
- >
252
- { props . detailsButton ?. connectedAccountName ?? name }
253
- </ Text >
254
-
255
- { /* Balance */ }
256
- { balanceQuery . data ? (
248
+ { props . detailsButton ?. connectedAccountName ? (
257
249
< Text
258
- className = { `${ TW_CONNECTED_WALLET } __balance` }
259
250
size = "xs"
260
- color = "secondaryText"
261
- weight = { 400 }
251
+ color = "primaryText"
252
+ weight = { 500 }
253
+ className = { `${ TW_CONNECTED_WALLET } __address` }
262
254
>
263
- { formatBalanceOnButton ( Number ( balanceQuery . data . displayValue ) ) } { " " }
264
- { balanceQuery . data . symbol }
255
+ { props . detailsButton . connectedAccountName }
265
256
</ Text >
266
257
) : (
267
- < Skeleton height = { fontSize . xs } width = "70px" />
258
+ < Text
259
+ size = "xs"
260
+ color = "primaryText"
261
+ weight = { 500 }
262
+ className = { `${ TW_CONNECTED_WALLET } __address` }
263
+ >
264
+ < AccountName
265
+ loadingComponent = { < AccountAddress formatFn = { shortenAddress } /> }
266
+ fallbackComponent = { < AccountAddress formatFn = { shortenAddress } /> }
267
+ />
268
+ </ Text >
268
269
) }
270
+
271
+ < Text
272
+ className = { `${ TW_CONNECTED_WALLET } __balance` }
273
+ size = "xs"
274
+ color = "secondaryText"
275
+ weight = { 400 }
276
+ >
277
+ < AccountBalance
278
+ chain = { walletChain }
279
+ loadingComponent = { < Skeleton height = { fontSize . xs } width = "70px" /> }
280
+ fallbackComponent = { < Skeleton height = { fontSize . xs } width = "70px" /> }
281
+ formatFn = { formatBalanceOnButton }
282
+ tokenAddress = {
283
+ props . detailsButton ?. displayBalanceToken ?. [
284
+ Number ( walletChain ?. id )
285
+ ]
286
+ }
287
+ />
288
+ </ Text >
269
289
</ Container >
270
290
</ WalletInfoButton >
271
291
) ;
@@ -295,12 +315,6 @@ function DetailsModal(props: {
295
315
const { client, locale } = props ;
296
316
const walletChain = useActiveWalletChain ( ) ;
297
317
const activeAccount = useActiveAccount ( ) ;
298
- const { pfp, name, balanceQuery } = useConnectedWalletDetails (
299
- client ,
300
- walletChain ,
301
- activeAccount ,
302
- props . displayBalanceToken ,
303
- ) ;
304
318
const theme = parseTheme ( props . theme ) ;
305
319
306
320
const activeWallet = useActiveWallet ( ) ;
@@ -363,12 +377,15 @@ function DetailsModal(props: {
363
377
< Text color = "primaryText" size = "md" multiline >
364
378
{ chainNameQuery . name || `Unknown chain #${ walletChain ?. id } ` }
365
379
< Text color = "secondaryText" size = "xs" >
366
- { balanceQuery . data ? (
367
- formatNumber ( Number ( balanceQuery . data . displayValue ) , 9 )
368
- ) : (
369
- < Skeleton height = "1em" width = "100px" />
370
- ) } { " " }
371
- { balanceQuery . data ?. symbol }
380
+ < AccountBalance
381
+ fallbackComponent = { < Skeleton height = "1em" width = "100px" /> }
382
+ loadingComponent = { < Skeleton height = "1em" width = "100px" /> }
383
+ formatFn = { ( num : number ) => formatNumber ( num , 9 ) }
384
+ chain = { walletChain }
385
+ tokenAddress = {
386
+ props . displayBalanceToken ?. [ Number ( walletChain ?. id ) ]
387
+ }
388
+ />
372
389
</ Text >
373
390
</ Text >
374
391
) }
@@ -384,8 +401,6 @@ function DetailsModal(props: {
384
401
</ MenuButton >
385
402
) ;
386
403
387
- const avatarSrc = props . detailsModal ?. connectedAccountAvatarUrl ?? pfp ;
388
-
389
404
const { hideSendFunds, hideReceiveFunds, hideBuyFunds } =
390
405
props . detailsModal || { } ;
391
406
@@ -407,9 +422,9 @@ function DetailsModal(props: {
407
422
overflow : "hidden" ,
408
423
} }
409
424
>
410
- { avatarSrc ? (
425
+ { props . detailsModal ?. connectedAccountAvatarUrl ? (
411
426
< img
412
- src = { avatarSrc }
427
+ src = { props . detailsModal . connectedAccountAvatarUrl }
413
428
style = { {
414
429
height : "100%" ,
415
430
width : "100%" ,
@@ -419,9 +434,9 @@ function DetailsModal(props: {
419
434
/>
420
435
) : (
421
436
activeAccount && (
422
- < Blobbie
423
- address = { activeAccount . address }
424
- size = { Number ( iconSize . xxl ) }
437
+ < AccountAvatar
438
+ loadingComponent = { < AccountBlobbie size = { Number ( iconSize . xxl ) } /> }
439
+ fallbackComponent = { < AccountBlobbie size = { Number ( iconSize . xxl ) } /> }
425
440
/>
426
441
)
427
442
) }
@@ -496,9 +511,22 @@ function DetailsModal(props: {
496
511
alignItems : "center" ,
497
512
} }
498
513
>
499
- < Text color = "primaryText" weight = { 500 } size = "md" >
500
- { props . detailsModal ?. connectedAccountName ?? name }
501
- </ Text >
514
+ { props . detailsModal ?. connectedAccountName ? (
515
+ < Text color = "primaryText" weight = { 500 } size = "md" >
516
+ { props . detailsModal . connectedAccountName }
517
+ </ Text >
518
+ ) : (
519
+ < Text color = "primaryText" weight = { 500 } size = "md" >
520
+ < AccountName
521
+ loadingComponent = {
522
+ < AccountAddress formatFn = { shortenAddress } />
523
+ }
524
+ fallbackComponent = {
525
+ < AccountAddress formatFn = { shortenAddress } />
526
+ }
527
+ />
528
+ </ Text >
529
+ ) }
502
530
< IconButton >
503
531
< CopyIcon
504
532
text = { activeAccount ?. address || "" }
@@ -964,7 +992,12 @@ function DetailsModal(props: {
964
992
}
965
993
} }
966
994
>
967
- { content }
995
+ < AccountProvider
996
+ address = { activeAccount ?. address || "" }
997
+ client = { client }
998
+ >
999
+ { content }
1000
+ </ AccountProvider >
968
1001
</ Modal >
969
1002
</ ScreenSetupContext . Provider >
970
1003
</ WalletUIStatesProvider >
0 commit comments