Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/purple-rice-bet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Show correct transfer from amount for transfer flow in PayEmbed
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ export function SwapTxDetailsTable(
) {
let uiData: SwapTxDetailsData;
let showStatusRow = true;
let isTransfer = false;
if (props.type === "status") {
isTransfer = props.status.swapType === "TRANSFER";
const status = props.status;
if (props.hideStatusRow) {
showStatusRow = false;
Expand Down Expand Up @@ -191,33 +189,6 @@ export function SwapTxDetailsTable(
</>
);

if (isTransfer) {
return (
<div>
{/* source chain Tx hash link */}
{fromChainExplorers.explorers?.[0]?.url && sourceTxHash && (
<ButtonLink
fullWidth
variant="outline"
href={formatExplorerTxUrl(
fromChainExplorers.explorers[0]?.url,
sourceTxHash,
)}
target="_blank"
gap="xs"
style={{
fontSize: fontSize.sm,
padding: spacing.sm,
}}
>
View on {fromChainName.name} Explorer
<ExternalLinkIcon width={iconSize.sm} height={iconSize.sm} />
</ButtonLink>
)}
</div>
);
}

return (
<div>
{/* Pay */}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CheckCircledIcon } from "@radix-ui/react-icons";
import { useQuery } from "@tanstack/react-query";
import { useState } from "react";
import type { Chain } from "../../../../../../../chains/types.js";
import { getCachedChain } from "../../../../../../../chains/utils.js";
Expand Down Expand Up @@ -78,6 +79,48 @@
| { id: "done" }
>({ id: "idle" });

const transferQuery = useQuery({
queryKey: [
"transfer",
isNativeToken(token) ? NATIVE_TOKEN_ADDRESS : token.address,
tokenAmount,
receiverAddress,
payer.account.address,
payOptions?.purchaseData,
],
queryFn: async () => {
const transferResponse = await getBuyWithCryptoTransfer({
client,
fromAddress: payer.account.address,
toAddress: receiverAddress,
chainId: chain.id,
tokenAddress: isNativeToken(token)
? NATIVE_TOKEN_ADDRESS
: token.address,
amount: tokenAmount,
purchaseData: payOptions?.purchaseData,
});
return transferResponse;
},
refetchInterval: 30 * 1000,
});

Check warning on line 106 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx#L82-L106

Added lines #L82 - L106 were not covered by tests

if (transferQuery.isLoading) {
return (
<Container p="lg">
<ModalHeader title={title} onBack={onBack} />
<Container flex="column" center="both" style={{ minHeight: "300px" }}>
<Spacer y="xl" />
<Spinner size="xl" color="secondaryText" />
<Spacer y="xl" />
</Container>
</Container>

Check warning on line 117 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx#L108-L117

Added lines #L108 - L117 were not covered by tests
);
}

Check warning on line 119 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L119 was not covered by tests

const transferFromAmountWithFees =
transferQuery.data?.paymentToken.amount || tokenAmount;

Check warning on line 122 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx#L121-L122

Added lines #L121 - L122 were not covered by tests

return (
<Container p="lg">
<ModalHeader title={title} onBack={onBack} />
Expand Down Expand Up @@ -109,7 +152,7 @@
fromChain={chain}
toToken={token}
toChain={chain}
fromAmount={tokenAmount}
fromAmount={transactionMode ? tokenAmount : transferFromAmountWithFees}

Check warning on line 155 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L155 was not covered by tests
toAmount={tokenAmount}
/>

Expand Down Expand Up @@ -230,7 +273,9 @@
token,
chain,
tokenMetadata,
tokenAmount,
tokenAmount: transactionMode
? tokenAmount
: transferFromAmountWithFees,

Check warning on line 278 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx#L276-L278

Added lines #L276 - L278 were not covered by tests
fromAddress: payer.account.address,
toAddress: receiverAddress,
transaction: txResult,
Expand All @@ -240,17 +285,11 @@
setStep("execute");
setStatus({ id: "idle" });
} else {
const transferResponse = await getBuyWithCryptoTransfer({
client,
fromAddress: payer.account.address,
toAddress: receiverAddress,
chainId: chain.id,
tokenAddress: isNativeToken(token)
? NATIVE_TOKEN_ADDRESS
: token.address,
amount: tokenAmount,
purchaseData: payOptions?.purchaseData,
});
const transferResponse = transferQuery.data;

Check warning on line 288 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L288 was not covered by tests

if (!transferResponse) {
throw new Error("Transfer data not found");
}

Check warning on line 292 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx#L290-L292

Added lines #L290 - L292 were not covered by tests

if (transferResponse.approvalData) {
// check allowance
Expand Down