Skip to content

Commit 4850a02

Browse files
show transfer amounts with fees
1 parent 04943d7 commit 4850a02

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

.changeset/purple-rice-bet.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+
Show correct transfer from amount for transfer flow in PayEmbed

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

Lines changed: 49 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,45 @@ 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+
payer.account.address,
89+
payOptions?.purchaseData,
90+
],
91+
queryFn: async () => {
92+
const transferResponse = await getBuyWithCryptoTransfer({
93+
client,
94+
fromAddress: payer.account.address,
95+
toAddress: receiverAddress,
96+
chainId: chain.id,
97+
tokenAddress: isNativeToken(token)
98+
? NATIVE_TOKEN_ADDRESS
99+
: token.address,
100+
amount: tokenAmount,
101+
purchaseData: payOptions?.purchaseData,
102+
});
103+
return transferResponse;
104+
},
105+
});
106+
107+
if (transferQuery.isLoading) {
108+
return (
109+
<Container p="lg">
110+
<ModalHeader title={title} onBack={onBack} />
111+
<Spacer y="xl" />
112+
<Spinner size="lg" color="accentButtonText" />
113+
<Spacer y="xl" />
114+
</Container>
115+
);
116+
}
117+
118+
const transferFromAmountWithFees =
119+
transferQuery.data?.paymentToken.amount || tokenAmount;
120+
81121
return (
82122
<Container p="lg">
83123
<ModalHeader title={title} onBack={onBack} />
@@ -109,7 +149,7 @@ export function TransferConfirmationScreen(
109149
fromChain={chain}
110150
toToken={token}
111151
toChain={chain}
112-
fromAmount={tokenAmount}
152+
fromAmount={transactionMode ? tokenAmount : transferFromAmountWithFees}
113153
toAmount={tokenAmount}
114154
/>
115155

@@ -230,7 +270,9 @@ export function TransferConfirmationScreen(
230270
token,
231271
chain,
232272
tokenMetadata,
233-
tokenAmount,
273+
tokenAmount: transactionMode
274+
? tokenAmount
275+
: transferFromAmountWithFees,
234276
fromAddress: payer.account.address,
235277
toAddress: receiverAddress,
236278
transaction: txResult,
@@ -240,17 +282,11 @@ export function TransferConfirmationScreen(
240282
setStep("execute");
241283
setStatus({ id: "idle" });
242284
} 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-
});
285+
const transferResponse = transferQuery.data;
286+
287+
if (!transferResponse) {
288+
throw new Error("Transfer data not found");
289+
}
254290

255291
if (transferResponse.approvalData) {
256292
// check allowance

0 commit comments

Comments
 (0)