Skip to content

Commit dfbd33e

Browse files
committed
fix: requested changes
1 parent 91d4ddf commit dfbd33e

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

packages/thirdweb/src/react/core/hooks/useTransactionDetails.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ export function useTransactionDetails({
7878
encode(transaction).catch(() => "0x"),
7979
]);
8080

81-
const account = wallet?.getAccount();
82-
if (!account) {
83-
throw new Error("No active account");
84-
}
85-
8681
const [tokenInfo, gasCostWei] = await Promise.all([
8782
getToken(
8883
client,
@@ -158,7 +153,7 @@ export function useTransactionDetails({
158153

159154
const totalCostWei =
160155
erc20Value &&
161-
erc20Value.tokenAddress.toLowerCase() !== NATIVE_TOKEN_ADDRESS
156+
erc20Value.tokenAddress.toLowerCase() !== NATIVE_TOKEN_ADDRESS
162157
? erc20Value.amountWei
163158
: (value || 0n) + (gasCostWei || 0n);
164159
const totalCost = toTokens(totalCostWei, decimal);

packages/thirdweb/src/react/web/ui/Bridge/TransactionPayment.tsx

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
"use client";
2+
import { useQuery } from "@tanstack/react-query";
23
import type { Token } from "../../../../bridge/index.js";
34
import type { ThirdwebClient } from "../../../../client/client.js";
5+
import { NATIVE_TOKEN_ADDRESS } from "../../../../constants/addresses.js";
46
import {
57
type Address,
68
getAddress,
79
shortenAddress,
810
} from "../../../../utils/address.js";
11+
import { resolvePromisedValue } from "../../../../utils/promise/resolve-promised-value.js";
12+
import { getWalletBalance } from "../../../../wallets/utils/getWalletBalance.js";
913
import { useCustomTheme } from "../../../core/design-system/CustomThemeProvider.js";
1014
import {
1115
fontSize,
@@ -27,13 +31,6 @@ import type { PayEmbedConnectOptions } from "../PayEmbed.js";
2731
import type { UIOptions } from "./BridgeOrchestrator.js";
2832
import { ChainIcon } from "./common/TokenAndChain.js";
2933
import { WithHeader } from "./common/WithHeader.js";
30-
import { useQuery } from "@tanstack/react-query";
31-
import { getWalletBalance } from "../../../../wallets/utils/getWalletBalance.js";
32-
import { resolvePromisedValue } from "../../../../utils/promise/resolve-promised-value.js";
33-
import { decimals } from "../../../../extensions/erc20/read/decimals.js";
34-
import { getContract } from "../../../../contract/contract.js";
35-
import { NATIVE_TOKEN_ADDRESS } from "../../../../constants/addresses.js";
36-
import { toTokens } from "../../../../utils/units.js";
3734

3835
export interface TransactionPaymentProps {
3936
/**
@@ -91,26 +88,22 @@ export function TransactionPayment({
9188
if (!activeAccount?.address) {
9289
return "0";
9390
}
94-
const erc20Value = await resolvePromisedValue(uiOptions.transaction.erc20Value);
95-
const tokenDecimals = erc20Value?.tokenAddress.toLowerCase() !== NATIVE_TOKEN_ADDRESS && erc20Value
96-
? await decimals({
97-
contract: getContract({
98-
address: erc20Value.tokenAddress,
99-
chain: uiOptions.transaction.chain,
100-
client,
101-
}),
102-
})
103-
: 18;
91+
const erc20Value = await resolvePromisedValue(
92+
uiOptions.transaction.erc20Value,
93+
);
10494
const walletBalance = await getWalletBalance({
10595
address: activeAccount?.address,
10696
chain: uiOptions.transaction.chain,
107-
tokenAddress: erc20Value?.tokenAddress.toLowerCase() !== NATIVE_TOKEN_ADDRESS ? erc20Value?.tokenAddress : undefined,
97+
tokenAddress:
98+
erc20Value?.tokenAddress.toLowerCase() !== NATIVE_TOKEN_ADDRESS
99+
? erc20Value?.tokenAddress
100+
: undefined,
108101
client,
109102
});
110103

111-
return toTokens(walletBalance.value, tokenDecimals);
104+
return walletBalance.displayValue;
112105
},
113-
queryKey: ["active-account-address"],
106+
queryKey: ["user-balance", activeAccount?.address],
114107
});
115108

116109
const contractName =
@@ -366,7 +359,7 @@ export function TransactionPayment({
366359
Math.max(
367360
0,
368361
Number(transactionDataQuery.data.totalCost) -
369-
Number(userBalance ?? "0"),
362+
Number(userBalance ?? "0"),
370363
).toString(),
371364
transactionDataQuery.data.tokenInfo,
372365
getAddress(activeAccount.address),

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useMemo } from "react";
33
import type { ThirdwebClient } from "../../../../../client/client.js";
44
import type { SupportedFiatCurrency } from "../../../../../pay/convert/type.js";
55
import { checksumAddress } from "../../../../../utils/address.js";
6+
import { formatNumber } from "../../../../../utils/formatNumber.js";
67
import { toTokens } from "../../../../../utils/units.js";
78
import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js";
89
import {
@@ -171,9 +172,14 @@ export function FiatProviderSelection({
171172
{quote.currency}
172173
</Text>
173174
<Text color="secondaryText" size="xs">
174-
{toTokens(
175-
quote.destinationAmount,
176-
quote.destinationToken.decimals,
175+
{formatNumber(
176+
Number(
177+
toTokens(
178+
quote.destinationAmount,
179+
quote.destinationToken.decimals,
180+
),
181+
),
182+
4,
177183
)}{" "}
178184
{quote.destinationToken.symbol}
179185
</Text>

0 commit comments

Comments
 (0)