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" ;
@@ -21,6 +22,7 @@ interface TokenSelectionProps {
2122 destinationToken : Token ;
2223 destinationAmount : bigint ;
2324 feePayer ?: "sender" | "receiver" ;
25+ currency ?: SupportedFiatCurrency ;
2426}
2527
2628// Individual payment method token row component
@@ -31,19 +33,22 @@ interface PaymentMethodTokenRowProps {
3133 client : ThirdwebClient ;
3234 onPaymentMethodSelected : ( paymentMethod : PaymentMethod ) => void ;
3335 feePayer ?: "sender" | "receiver" ;
36+ currency ?: SupportedFiatCurrency ;
3437}
3538
3639function PaymentMethodTokenRow ( {
3740 paymentMethod,
3841 client,
3942 onPaymentMethodSelected,
43+ currency,
4044} : PaymentMethodTokenRowProps ) {
4145 const theme = useCustomTheme ( ) ;
4246
4347 const displayOriginAmount = paymentMethod . quote . originAmount ;
4448 const hasEnoughBalance = displayOriginAmount
4549 ? paymentMethod . balance >= displayOriginAmount
4650 : false ;
51+ const currencyPrice = paymentMethod . originToken . prices [ currency || "USD" ] ;
4752
4853 return (
4954 < Button
@@ -79,26 +84,34 @@ function PaymentMethodTokenRow({
7984 gap = "3xs"
8085 style = { { alignItems : "flex-end" , flex : 1 } }
8186 >
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:{ " " }
87+ { currencyPrice && (
88+ < Text
89+ color = "primaryText"
90+ size = "sm"
91+ style = { { fontWeight : 600 , textWrap : "nowrap" } }
92+ >
93+ { new Intl . NumberFormat ( navigator . language , {
94+ style : "currency" ,
95+ currency : currency ,
96+ minimumFractionDigits : 2 ,
97+ maximumFractionDigits : 2 ,
98+ } ) . format (
99+ Number (
100+ formatTokenAmount (
101+ paymentMethod . balance ,
102+ paymentMethod . originToken . decimals ,
103+ ) ,
104+ ) * currencyPrice ,
105+ ) }
96106 </ Text >
107+ ) }
108+ < Container flex = "row" gap = "3xs" >
97109 < Text color = { hasEnoughBalance ? "success" : "danger" } size = "xs" >
98110 { formatTokenAmount (
99111 paymentMethod . balance ,
100112 paymentMethod . originToken . decimals ,
101- ) }
113+ ) } { " " }
114+ { paymentMethod . originToken . symbol }
102115 </ Text >
103116 </ Container >
104117 </ Container >
@@ -116,6 +129,7 @@ export function TokenSelection({
116129 destinationToken,
117130 destinationAmount,
118131 feePayer,
132+ currency,
119133} : TokenSelectionProps ) {
120134 const theme = useCustomTheme ( ) ;
121135
@@ -210,7 +224,7 @@ export function TokenSelection({
210224 return (
211225 < >
212226 < Text color = "primaryText" size = "md" >
213- Select payment token
227+ Your token balances
214228 </ Text >
215229 < Spacer y = "sm" />
216230 < Container
@@ -233,6 +247,7 @@ export function TokenSelection({
233247 key = { `${ method . originToken . address } -${ method . originToken . chainId } ` }
234248 onPaymentMethodSelected = { onPaymentMethodSelected }
235249 paymentMethod = { method }
250+ currency = { currency }
236251 />
237252 ) ) }
238253 </ Container >
0 commit comments