1
1
"use client" ;
2
2
import type { Token } from "../../../../../bridge/types/Token.js" ;
3
3
import type { ThirdwebClient } from "../../../../../client/client.js" ;
4
+ import type { SupportedFiatCurrency } from "../../../../../pay/convert/type.js" ;
4
5
import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js" ;
5
6
import { radius , spacing } from "../../../../core/design-system/index.js" ;
6
7
import 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" ;
8
12
import { Container } from "../../components/basic.js" ;
9
13
import { Button } from "../../components/buttons.js" ;
10
14
import { Skeleton } from "../../components/Skeleton.js" ;
@@ -21,6 +25,7 @@ interface TokenSelectionProps {
21
25
destinationToken : Token ;
22
26
destinationAmount : bigint ;
23
27
feePayer ?: "sender" | "receiver" ;
28
+ currency ?: SupportedFiatCurrency ;
24
29
}
25
30
26
31
// Individual payment method token row component
@@ -31,19 +36,22 @@ interface PaymentMethodTokenRowProps {
31
36
client : ThirdwebClient ;
32
37
onPaymentMethodSelected : ( paymentMethod : PaymentMethod ) => void ;
33
38
feePayer ?: "sender" | "receiver" ;
39
+ currency ?: SupportedFiatCurrency ;
34
40
}
35
41
36
42
function PaymentMethodTokenRow ( {
37
43
paymentMethod,
38
44
client,
39
45
onPaymentMethodSelected,
46
+ currency,
40
47
} : PaymentMethodTokenRowProps ) {
41
48
const theme = useCustomTheme ( ) ;
42
49
43
50
const displayOriginAmount = paymentMethod . quote . originAmount ;
44
51
const hasEnoughBalance = displayOriginAmount
45
52
? paymentMethod . balance >= displayOriginAmount
46
53
: false ;
54
+ const currencyPrice = paymentMethod . originToken . prices [ currency || "USD" ] ;
47
55
48
56
return (
49
57
< Button
@@ -79,26 +87,30 @@ function PaymentMethodTokenRow({
79
87
gap = "3xs"
80
88
style = { { alignItems : "flex-end" , flex : 1 } }
81
89
>
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
+ ) }
96
105
</ Text >
106
+ ) }
107
+ < Container flex = "row" gap = "3xs" >
97
108
< Text color = { hasEnoughBalance ? "success" : "danger" } size = "xs" >
98
109
{ formatTokenAmount (
99
110
paymentMethod . balance ,
100
111
paymentMethod . originToken . decimals ,
101
- ) }
112
+ ) } { " " }
113
+ { paymentMethod . originToken . symbol }
102
114
</ Text >
103
115
</ Container >
104
116
</ Container >
@@ -116,6 +128,7 @@ export function TokenSelection({
116
128
destinationToken,
117
129
destinationAmount,
118
130
feePayer,
131
+ currency,
119
132
} : TokenSelectionProps ) {
120
133
const theme = useCustomTheme ( ) ;
121
134
@@ -210,7 +223,7 @@ export function TokenSelection({
210
223
return (
211
224
< >
212
225
< Text color = "primaryText" size = "md" >
213
- Select payment token
226
+ Your token balances
214
227
</ Text >
215
228
< Spacer y = "sm" />
216
229
< Container
@@ -233,6 +246,7 @@ export function TokenSelection({
233
246
key = { `${ method . originToken . address } -${ method . originToken . chainId } ` }
234
247
onPaymentMethodSelected = { onPaymentMethodSelected }
235
248
paymentMethod = { method }
249
+ currency = { currency }
236
250
/>
237
251
) ) }
238
252
</ Container >
0 commit comments