Skip to content

Commit 62c8e7c

Browse files
[SDK] show transfer amounts with fees (#6618)
1 parent f618c53 commit 62c8e7c

File tree

3 files changed

+57
-42
lines changed

3 files changed

+57
-42
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/pay-transactions/SwapDetailsScreen.tsx

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ export function SwapTxDetailsTable(
101101
) {
102102
let uiData: SwapTxDetailsData;
103103
let showStatusRow = true;
104-
let isTransfer = false;
105104
if (props.type === "status") {
106-
isTransfer = props.status.swapType === "TRANSFER";
107105
const status = props.status;
108106
if (props.hideStatusRow) {
109107
showStatusRow = false;
@@ -191,33 +189,6 @@ export function SwapTxDetailsTable(
191189
</>
192190
);
193191

194-
if (isTransfer) {
195-
return (
196-
<div>
197-
{/* source chain Tx hash link */}
198-
{fromChainExplorers.explorers?.[0]?.url && sourceTxHash && (
199-
<ButtonLink
200-
fullWidth
201-
variant="outline"
202-
href={formatExplorerTxUrl(
203-
fromChainExplorers.explorers[0]?.url,
204-
sourceTxHash,
205-
)}
206-
target="_blank"
207-
gap="xs"
208-
style={{
209-
fontSize: fontSize.sm,
210-
padding: spacing.sm,
211-
}}
212-
>
213-
View on {fromChainName.name} Explorer
214-
<ExternalLinkIcon width={iconSize.sm} height={iconSize.sm} />
215-
</ButtonLink>
216-
)}
217-
</div>
218-
);
219-
}
220-
221192
return (
222193
<div>
223194
{/* Pay */}

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

Lines changed: 52 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,48 @@ 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+
refetchInterval: 30 * 1000,
106+
});
107+
108+
if (transferQuery.isLoading) {
109+
return (
110+
<Container p="lg">
111+
<ModalHeader title={title} onBack={onBack} />
112+
<Container flex="column" center="both" style={{ minHeight: "300px" }}>
113+
<Spacer y="xl" />
114+
<Spinner size="xl" color="secondaryText" />
115+
<Spacer y="xl" />
116+
</Container>
117+
</Container>
118+
);
119+
}
120+
121+
const transferFromAmountWithFees =
122+
transferQuery.data?.paymentToken.amount || tokenAmount;
123+
81124
return (
82125
<Container p="lg">
83126
<ModalHeader title={title} onBack={onBack} />
@@ -109,7 +152,7 @@ export function TransferConfirmationScreen(
109152
fromChain={chain}
110153
toToken={token}
111154
toChain={chain}
112-
fromAmount={tokenAmount}
155+
fromAmount={transactionMode ? tokenAmount : transferFromAmountWithFees}
113156
toAmount={tokenAmount}
114157
/>
115158

@@ -230,7 +273,9 @@ export function TransferConfirmationScreen(
230273
token,
231274
chain,
232275
tokenMetadata,
233-
tokenAmount,
276+
tokenAmount: transactionMode
277+
? tokenAmount
278+
: transferFromAmountWithFees,
234279
fromAddress: payer.account.address,
235280
toAddress: receiverAddress,
236281
transaction: txResult,
@@ -240,17 +285,11 @@ export function TransferConfirmationScreen(
240285
setStep("execute");
241286
setStatus({ id: "idle" });
242287
} 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-
});
288+
const transferResponse = transferQuery.data;
289+
290+
if (!transferResponse) {
291+
throw new Error("Transfer data not found");
292+
}
254293

255294
if (transferResponse.approvalData) {
256295
// check allowance

0 commit comments

Comments
 (0)