Skip to content

Commit 6fea818

Browse files
UI polish + auto refresh
1 parent 87a01f4 commit 6fea818

File tree

6 files changed

+243
-61
lines changed

6 files changed

+243
-61
lines changed

packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,10 @@ export function useSendTransactionCore(args: {
234234
return null;
235235
});
236236

237-
if (!supportedDestinations) {
237+
if (
238+
!supportedDestinations ||
239+
supportedDestinations.length === 0
240+
) {
238241
// not a supported detination -> show deposit screen
239242
trackPayEvent({
240243
client: tx.client,

packages/thirdweb/src/react/web/ui/ConnectWallet/locale/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const connectLocaleEn: ConnectLocale = {
6868
},
6969
receiveFundsScreen: {
7070
title: "Receive Funds",
71-
instruction: "Copy the wallet address to send funds to this wallet",
71+
instruction: "Copy the address to send funds to this wallet",
7272
},
7373
sendFundsScreen: {
7474
title: "Send Funds",

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ChainMetadata } from "../../../../../../../chains/types.js";
12
import type { BuyWithCryptoQuote } from "../../../../../../../pay/buyWithCrypto/getQuote.js";
23
import type { BuyWithFiatQuote } from "../../../../../../../pay/buyWithFiat/getQuote.js";
34
import type { GetWalletBalanceResult } from "../../../../../../../wallets/utils/getWalletBalance.js";
@@ -9,6 +10,7 @@ export type TransactionCostAndData = {
910
walletBalance: GetWalletBalanceResult;
1011
transactionValueWei: bigint;
1112
gasCostWei: bigint;
13+
chainMetadata: ChainMetadata;
1214
};
1315

1416
export type SelectedScreen =

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function useTransactionCostAndData(args: {
1818
transaction: PreparedTransaction;
1919
account: Account | undefined;
2020
supportedDestinations: SupportedChainAndTokens;
21+
refetchIntervalMs?: number;
2122
}) {
2223
const { transaction, account, supportedDestinations } = args;
2324
// Compute query key of the transaction first
@@ -62,22 +63,24 @@ export function useTransactionCostAndData(args: {
6263

6364
const erc20Value = await resolvePromisedValue(transaction.erc20Value);
6465
if (erc20Value) {
65-
const [tokenBalance, tokenMeta, gasCostWei] = await Promise.all([
66-
getWalletBalance({
67-
address: account.address,
68-
chain: transaction.chain,
69-
client: transaction.client,
70-
tokenAddress: erc20Value.tokenAddress,
71-
}),
72-
getCurrencyMetadata({
73-
contract: getContract({
74-
address: erc20Value.tokenAddress,
66+
const [tokenBalance, tokenMeta, gasCostWei, chainMetadata] =
67+
await Promise.all([
68+
getWalletBalance({
69+
address: account.address,
7570
chain: transaction.chain,
7671
client: transaction.client,
72+
tokenAddress: erc20Value.tokenAddress,
7773
}),
78-
}),
79-
getTransactionGasCost(transaction, account?.address),
80-
]);
74+
getCurrencyMetadata({
75+
contract: getContract({
76+
address: erc20Value.tokenAddress,
77+
chain: transaction.chain,
78+
client: transaction.client,
79+
}),
80+
}),
81+
getTransactionGasCost(transaction, account?.address),
82+
getChainMetadata(transaction.chain),
83+
]);
8184
const transactionValueWei = erc20Value.amountWei;
8285
const walletBalance = tokenBalance;
8386
const currency = {
@@ -95,6 +98,7 @@ export function useTransactionCostAndData(args: {
9598
return {
9699
token: currency,
97100
decimals: tokenMeta.decimals,
101+
chainMetadata,
98102
walletBalance,
99103
gasCostWei,
100104
transactionValueWei,
@@ -121,19 +125,14 @@ export function useTransactionCostAndData(args: {
121125
symbol: chainMetadata.nativeCurrency.symbol,
122126
icon: chainMetadata.icon?.url,
123127
},
128+
chainMetadata,
124129
decimals: 18,
125130
walletBalance,
126131
gasCostWei,
127132
transactionValueWei,
128133
} satisfies TransactionCostAndData;
129134
},
130135
enabled: !!transaction && !!txQueryKey,
131-
refetchInterval: () => {
132-
if (transaction.erc20Value) {
133-
// if erc20 value is set, we don't need to poll
134-
return undefined;
135-
}
136-
return 30_000;
137-
},
136+
refetchInterval: args.refetchIntervalMs || 30_000,
138137
});
139138
}

0 commit comments

Comments
 (0)