Skip to content

Commit 6366ccc

Browse files
show transfer amounts with fees
1 parent 04943d7 commit 6366ccc

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CheckCircledIcon } from "@radix-ui/react-icons";
2+
import { useQuery } from "@tanstack/react-query";
23
import { useState } from "react";
34
import type { Chain } from "../../../../../../../chains/types.js";
45
import { getCachedChain } from "../../../../../../../chains/utils.js";
@@ -78,6 +79,43 @@ export function TransferConfirmationScreen(
7879
| { id: "done" }
7980
>({ id: "idle" });
8081

82+
const transferQuery = useQuery({
83+
queryKey: [
84+
"transfer",
85+
isNativeToken(token) ? NATIVE_TOKEN_ADDRESS : token.address,
86+
tokenAmount,
87+
receiverAddress,
88+
],
89+
queryFn: async () => {
90+
const transferResponse = await getBuyWithCryptoTransfer({
91+
client,
92+
fromAddress: payer.account.address,
93+
toAddress: receiverAddress,
94+
chainId: chain.id,
95+
tokenAddress: isNativeToken(token)
96+
? NATIVE_TOKEN_ADDRESS
97+
: token.address,
98+
amount: tokenAmount,
99+
purchaseData: payOptions?.purchaseData,
100+
});
101+
return transferResponse;
102+
},
103+
});
104+
105+
if (transferQuery.isLoading) {
106+
return (
107+
<Container p="lg">
108+
<ModalHeader title={title} onBack={onBack} />
109+
<Spacer y="xl" />
110+
<Spinner size="lg" color="accentButtonText" />
111+
<Spacer y="xl" />
112+
</Container>
113+
);
114+
}
115+
116+
const transferFromAmountWithFees =
117+
transferQuery.data?.paymentToken.amount || tokenAmount;
118+
81119
return (
82120
<Container p="lg">
83121
<ModalHeader title={title} onBack={onBack} />
@@ -109,7 +147,7 @@ export function TransferConfirmationScreen(
109147
fromChain={chain}
110148
toToken={token}
111149
toChain={chain}
112-
fromAmount={tokenAmount}
150+
fromAmount={transactionMode ? tokenAmount : transferFromAmountWithFees}
113151
toAmount={tokenAmount}
114152
/>
115153

@@ -230,7 +268,9 @@ export function TransferConfirmationScreen(
230268
token,
231269
chain,
232270
tokenMetadata,
233-
tokenAmount,
271+
tokenAmount: transactionMode
272+
? tokenAmount
273+
: transferFromAmountWithFees,
234274
fromAddress: payer.account.address,
235275
toAddress: receiverAddress,
236276
transaction: txResult,
@@ -240,17 +280,11 @@ export function TransferConfirmationScreen(
240280
setStep("execute");
241281
setStatus({ id: "idle" });
242282
} else {
243-
const transferResponse = await getBuyWithCryptoTransfer({
244-
client,
245-
fromAddress: payer.account.address,
246-
toAddress: receiverAddress,
247-
chainId: chain.id,
248-
tokenAddress: isNativeToken(token)
249-
? NATIVE_TOKEN_ADDRESS
250-
: token.address,
251-
amount: tokenAmount,
252-
purchaseData: payOptions?.purchaseData,
253-
});
283+
const transferResponse = transferQuery.data;
284+
285+
if (!transferResponse) {
286+
throw new Error("Transfer data not found");
287+
}
254288

255289
if (transferResponse.approvalData) {
256290
// check allowance

0 commit comments

Comments
 (0)