11"use client" ;
22import type { Token } from "../../../../../bridge/types/Token.js" ;
33import type { ThirdwebClient } from "../../../../../client/client.js" ;
4+ import type { SupportedFiatCurrency } from "../../../../../pay/convert/type.js" ;
45import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js" ;
56import { radius , spacing } from "../../../../core/design-system/index.js" ;
67import type { PaymentMethod } from "../../../../core/machines/paymentMachine.js" ;
7- import { formatTokenAmount } from "../../ConnectWallet/screens/formatTokenBalance.js" ;
8+ import {
9+ formatCurrencyAmount ,
10+ formatTokenAmount ,
11+ } from "../../ConnectWallet/screens/formatTokenBalance.js" ;
812import { Container } from "../../components/basic.js" ;
913import { Button } from "../../components/buttons.js" ;
1014import { Skeleton } from "../../components/Skeleton.js" ;
@@ -21,6 +25,7 @@ interface TokenSelectionProps {
2125 destinationToken : Token ;
2226 destinationAmount : bigint ;
2327 feePayer ?: "sender" | "receiver" ;
28+ currency ?: SupportedFiatCurrency ;
2429}
2530
2631// Individual payment method token row component
@@ -31,19 +36,22 @@ interface PaymentMethodTokenRowProps {
3136 client : ThirdwebClient ;
3237 onPaymentMethodSelected : ( paymentMethod : PaymentMethod ) => void ;
3338 feePayer ?: "sender" | "receiver" ;
39+ currency ?: SupportedFiatCurrency ;
3440}
3541
3642function PaymentMethodTokenRow ( {
3743 paymentMethod,
3844 client,
3945 onPaymentMethodSelected,
46+ currency,
4047} : PaymentMethodTokenRowProps ) {
4148 const theme = useCustomTheme ( ) ;
4249
4350 const displayOriginAmount = paymentMethod . quote . originAmount ;
4451 const hasEnoughBalance = displayOriginAmount
4552 ? paymentMethod . balance >= displayOriginAmount
4653 : false ;
54+ const currencyPrice = paymentMethod . originToken . prices [ currency || "USD" ] ;
4755
4856 return (
4957 < Button
@@ -79,26 +87,30 @@ function PaymentMethodTokenRow({
7987 gap = "3xs"
8088 style = { { alignItems : "flex-end" , flex : 1 } }
8189 >
82- < Text
83- color = "primaryText"
84- size = "sm"
85- style = { { fontWeight : 600 , textWrap : "nowrap" } }
86- >
87- { formatTokenAmount (
88- displayOriginAmount ,
89- paymentMethod . originToken . decimals ,
90- ) } { " " }
91- { paymentMethod . originToken . symbol }
92- </ Text >
93- < Container flex = "row" gap = "3xs" >
94- < Text color = "secondaryText" size = "xs" >
95- Balance:{ " " }
90+ { currencyPrice && (
91+ < Text
92+ color = "primaryText"
93+ size = "sm"
94+ style = { { fontWeight : 600 , textWrap : "nowrap" } }
95+ >
96+ { formatCurrencyAmount (
97+ currency || "USD" ,
98+ Number (
99+ formatTokenAmount (
100+ paymentMethod . balance ,
101+ paymentMethod . originToken . decimals ,
102+ ) ,
103+ ) * currencyPrice ,
104+ ) }
96105 </ Text >
106+ ) }
107+ < Container flex = "row" gap = "3xs" >
97108 < Text color = { hasEnoughBalance ? "success" : "danger" } size = "xs" >
98109 { formatTokenAmount (
99110 paymentMethod . balance ,
100111 paymentMethod . originToken . decimals ,
101- ) }
112+ ) } { " " }
113+ { paymentMethod . originToken . symbol }
102114 </ Text >
103115 </ Container >
104116 </ Container >
@@ -116,6 +128,7 @@ export function TokenSelection({
116128 destinationToken,
117129 destinationAmount,
118130 feePayer,
131+ currency,
119132} : TokenSelectionProps ) {
120133 const theme = useCustomTheme ( ) ;
121134
@@ -210,7 +223,7 @@ export function TokenSelection({
210223 return (
211224 < >
212225 < Text color = "primaryText" size = "md" >
213- Select payment token
226+ Your token balances
214227 </ Text >
215228 < Spacer y = "sm" />
216229 < Container
@@ -233,6 +246,7 @@ export function TokenSelection({
233246 key = { `${ method . originToken . address } -${ method . originToken . chainId } ` }
234247 onPaymentMethodSelected = { onPaymentMethodSelected }
235248 paymentMethod = { method }
249+ currency = { currency }
236250 />
237251 ) ) }
238252 </ Container >
0 commit comments