Skip to content

Commit 90f36bc

Browse files
authored
[SDK] Refactor: Only show user balances in payment selection screens (#7827)
1 parent a77e98a commit 90f36bc

File tree

4 files changed

+42
-23
lines changed

4 files changed

+42
-23
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
spacing,
1313
} from "../../../../core/design-system/index.js";
1414
import { useBuyWithFiatQuotesForProviders } from "../../../../core/hooks/pay/useBuyWithFiatQuotesForProviders.js";
15+
import { formatCurrencyAmount } from "../../ConnectWallet/screens/formatTokenBalance.js";
1516
import { Container } from "../../components/basic.js";
1617
import { Button } from "../../components/buttons.js";
1718
import { Img } from "../../components/Img.js";
@@ -164,12 +165,10 @@ export function FiatProviderSelection({
164165
size="sm"
165166
style={{ fontWeight: 500 }}
166167
>
167-
$
168-
{quote.currencyAmount.toLocaleString(undefined, {
169-
maximumFractionDigits: 2,
170-
minimumFractionDigits: 2,
171-
})}{" "}
172-
{quote.currency}
168+
{formatCurrencyAmount(
169+
currency || "US",
170+
quote.currencyAmount,
171+
)}
173172
</Text>
174173
<Text color="secondaryText" size="xs">
175174
{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 & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
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";
7-
import { formatTokenAmount } from "../../ConnectWallet/screens/formatTokenBalance.js";
8+
import {
9+
formatCurrencyAmount,
10+
formatTokenAmount,
11+
} from "../../ConnectWallet/screens/formatTokenBalance.js";
812
import { Container } from "../../components/basic.js";
913
import { Button } from "../../components/buttons.js";
1014
import { 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

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

Comments
 (0)