Skip to content

Commit 727171c

Browse files
committed
refactor: only show user balances in payment selection screens
1 parent a77e98a commit 727171c

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

.changeset/warm-ways-decide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Hide quote value in payment widgets

packages/thirdweb/src/react/web/ui/Bridge/payment-selection/FiatProviderSelection.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ export function FiatProviderSelection({
164164
size="sm"
165165
style={{ fontWeight: 500 }}
166166
>
167-
$
168-
{quote.currencyAmount.toLocaleString(undefined, {
169-
maximumFractionDigits: 2,
167+
{new Intl.NumberFormat(navigator.language, {
168+
style: "currency",
169+
currency: currency,
170170
minimumFractionDigits: 2,
171-
})}{" "}
172-
{quote.currency}
171+
maximumFractionDigits: 2,
172+
}).format(quote.currencyAmount)}
173173
</Text>
174174
<Text color="secondaryText" size="xs">
175175
{formatNumber(

packages/thirdweb/src/react/web/ui/Bridge/payment-selection/PaymentSelection.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ export function PaymentSelection({
292292
onPaymentMethodSelected={handlePaymentMethodSelected}
293293
paymentMethods={suitableTokenPaymentMethods}
294294
paymentMethodsLoading={paymentMethodsLoading}
295+
currency={currency}
295296
/>
296297
)}
297298

packages/thirdweb/src/react/web/ui/Bridge/payment-selection/TokenSelection.tsx

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22
import type { Token } from "../../../../../bridge/types/Token.js";
33
import type { ThirdwebClient } from "../../../../../client/client.js";
4+
import type { SupportedFiatCurrency } from "../../../../../pay/convert/type.js";
45
import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js";
56
import { radius, spacing } from "../../../../core/design-system/index.js";
67
import 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

3639
function 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

Comments
 (0)