@@ -14,10 +14,10 @@ import { trackPayEvent } from "../../../../analytics/track/pay.js";
1414import type { Chain } from "../../../../chains/types.js" ;
1515import type { ThirdwebClient } from "../../../../client/client.js" ;
1616import { getContract } from "../../../../contract/contract.js" ;
17+ import type { SupportedFiatCurrency } from "../../../../pay/convert/type.js" ;
1718import { getLastAuthProvider } from "../../../../react/core/utils/storage.js" ;
1819import { shortenAddress } from "../../../../utils/address.js" ;
1920import { isContractDeployed } from "../../../../utils/bytecode/is-contract-deployed.js" ;
20- import { formatNumber } from "../../../../utils/formatNumber.js" ;
2121import { webLocalStorage } from "../../../../utils/storage/webStorage.js" ;
2222import { isEcosystemWallet } from "../../../../wallets/ecosystem/is-ecosystem-wallet.js" ;
2323import type { Ecosystem } from "../../../../wallets/in-app/core/wallet/types.js" ;
@@ -86,7 +86,12 @@ import { fadeInAnimation } from "../design-system/animations.js";
8686import { StyledButton } from "../design-system/elements.js" ;
8787import { AccountAddress } from "../prebuilt/Account/address.js" ;
8888import { AccountAvatar } from "../prebuilt/Account/avatar.js" ;
89- import { AccountBalance } from "../prebuilt/Account/balance.js" ;
89+ import {
90+ AccountBalance ,
91+ type AccountBalanceInfo ,
92+ formatAccountFiatBalance ,
93+ formatAccountTokenBalance ,
94+ } from "../prebuilt/Account/balance.js" ;
9095import { AccountBlobbie } from "../prebuilt/Account/blobbie.js" ;
9196import { AccountName } from "../prebuilt/Account/name.js" ;
9297import { AccountProvider } from "../prebuilt/Account/provider.js" ;
@@ -231,6 +236,11 @@ export const ConnectedWalletDetails: React.FC<{
231236 refetchOnWindowFocus : false ,
232237 refetchOnMount : false ,
233238 } }
239+ style = { {
240+ height : "100%" ,
241+ width : "100%" ,
242+ objectFit : "cover" ,
243+ } }
234244 />
235245 )
236246 ) }
@@ -273,18 +283,59 @@ export const ConnectedWalletDetails: React.FC<{
273283 size = "xs"
274284 color = "secondaryText"
275285 weight = { 400 }
286+ style = { {
287+ display : "flex" ,
288+ gap : "2px" ,
289+ alignItems : "center" ,
290+ } }
276291 >
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- />
292+ { props . detailsButton ?. showBalanceInFiat ? (
293+ < >
294+ < AccountBalance
295+ chain = { walletChain }
296+ loadingComponent = {
297+ < Skeleton height = { fontSize . xs } width = "50px" />
298+ }
299+ fallbackComponent = {
300+ < Skeleton height = { fontSize . xs } width = "50px" />
301+ }
302+ tokenAddress = {
303+ props . detailsButton ?. displayBalanceToken ?. [
304+ Number ( walletChain ?. id )
305+ ]
306+ }
307+ />
308+ < AccountBalance
309+ chain = { walletChain }
310+ tokenAddress = {
311+ props . detailsButton ?. displayBalanceToken ?. [
312+ Number ( walletChain ?. id )
313+ ]
314+ }
315+ showBalanceInFiat = "USD"
316+ formatFn = { ( props : AccountBalanceInfo ) =>
317+ ` (${ formatAccountFiatBalance ( { ...props , decimals : 0 } ) } )`
318+ }
319+ loadingComponent = {
320+ < Skeleton height = { fontSize . xs } width = "20px" />
321+ }
322+ />
323+ </ >
324+ ) : (
325+ < AccountBalance
326+ chain = { walletChain }
327+ loadingComponent = { < Skeleton height = { fontSize . xs } width = "70px" /> }
328+ fallbackComponent = { < Skeleton height = { fontSize . xs } width = "70px" /> }
329+ formatFn = { ( props : AccountBalanceInfo ) =>
330+ `${ formatAccountTokenBalance ( { ...props , decimals : props . balance < 1 ? 5 : 4 } ) } `
331+ }
332+ tokenAddress = {
333+ props . detailsButton ?. displayBalanceToken ?. [
334+ Number ( walletChain ?. id )
335+ ]
336+ }
337+ />
338+ ) }
288339 </ Text >
289340 </ Container >
290341 </ WalletInfoButton >
@@ -307,6 +358,7 @@ function DetailsModal(props: {
307358 displayBalanceToken ?: Record < number , string > ;
308359 connectOptions : DetailsModalConnectOptions | undefined ;
309360 assetTabs ?: AssetTabs [ ] ;
361+ showBalanceInFiat ?: SupportedFiatCurrency ;
310362} ) {
311363 const [ screen , setScreen ] = useState < WalletDetailsModalScreen > ( "main" ) ;
312364 const { disconnect } = useDisconnect ( ) ;
@@ -377,15 +429,44 @@ function DetailsModal(props: {
377429 < Text color = "primaryText" size = "md" multiline >
378430 { chainNameQuery . name || `Unknown chain #${ walletChain ?. id } ` }
379431 < Text color = "secondaryText" size = "xs" >
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- />
432+ { props . showBalanceInFiat ? (
433+ < >
434+ < AccountBalance
435+ fallbackComponent = { < Skeleton height = "1em" width = "70px" /> }
436+ loadingComponent = { < Skeleton height = "1em" width = "70px" /> }
437+ chain = { walletChain }
438+ tokenAddress = {
439+ props . displayBalanceToken ?. [ Number ( walletChain ?. id ) ]
440+ }
441+ formatFn = { ( props : AccountBalanceInfo ) =>
442+ formatAccountTokenBalance ( { ...props , decimals : 7 } )
443+ }
444+ /> { " " }
445+ < AccountBalance
446+ loadingComponent = { < Skeleton height = "1em" width = "30px" /> }
447+ chain = { walletChain }
448+ tokenAddress = {
449+ props . displayBalanceToken ?. [ Number ( walletChain ?. id ) ]
450+ }
451+ formatFn = { ( props : AccountBalanceInfo ) =>
452+ ` (${ formatAccountFiatBalance ( { ...props , decimals : 3 } ) } )`
453+ }
454+ showBalanceInFiat = "USD"
455+ />
456+ </ >
457+ ) : (
458+ < AccountBalance
459+ fallbackComponent = { < Skeleton height = "1em" width = "100px" /> }
460+ loadingComponent = { < Skeleton height = "1em" width = "100px" /> }
461+ formatFn = { ( props : AccountBalanceInfo ) =>
462+ formatAccountTokenBalance ( { ...props , decimals : 7 } )
463+ }
464+ chain = { walletChain }
465+ tokenAddress = {
466+ props . displayBalanceToken ?. [ Number ( walletChain ?. id ) ]
467+ }
468+ />
469+ ) }
389470 </ Text >
390471 </ Text >
391472 ) }
@@ -437,6 +518,11 @@ function DetailsModal(props: {
437518 < AccountAvatar
438519 loadingComponent = { < AccountBlobbie size = { Number ( iconSize . xxl ) } /> }
439520 fallbackComponent = { < AccountBlobbie size = { Number ( iconSize . xxl ) } /> }
521+ style = { {
522+ height : "100%" ,
523+ width : "100%" ,
524+ objectFit : "cover" ,
525+ } }
440526 />
441527 )
442528 ) }
@@ -1006,10 +1092,6 @@ function DetailsModal(props: {
10061092 ) ;
10071093}
10081094
1009- function formatBalanceOnButton ( num : number ) {
1010- return formatNumber ( num , num < 1 ? 5 : 4 ) ;
1011- }
1012-
10131095const WalletInfoButton = /* @__PURE__ */ StyledButton ( ( _ ) => {
10141096 const theme = useCustomTheme ( ) ;
10151097 return {
@@ -1507,6 +1589,12 @@ export type UseWalletDetailsModalOptions = {
15071589 * Note: If an empty array is passed, the [View Funds] button will be hidden
15081590 */
15091591 assetTabs ?: AssetTabs [ ] ;
1592+
1593+ /**
1594+ * Show the token balance's value in fiat.
1595+ * Note: Not all tokens are resolvable to a fiat value. In that case, nothing will be shown.
1596+ */
1597+ showBalanceInFiat ?: SupportedFiatCurrency ;
15101598} ;
15111599
15121600/**
0 commit comments