Skip to content

Commit 3ebca18

Browse files
[SDK] Add error tracking for payment execution failures (#8486)
1 parent 4c5696e commit 3ebca18

File tree

7 files changed

+68
-1
lines changed

7 files changed

+68
-1
lines changed

.changeset/fifty-moons-punch.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+
Fix getWalletBalance with native token address

packages/thirdweb/src/react/core/hooks/useStepExecutor.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2+
import { trackPayEvent } from "../../../analytics/track/pay.js";
23
import type { status as OnrampStatus } from "../../../bridge/OnrampStatus.js";
34
import { ApiError } from "../../../bridge/types/Errors.js";
45
import type {
@@ -9,6 +10,7 @@ import type { Status } from "../../../bridge/types/Status.js";
910
import { getCachedChain } from "../../../chains/utils.js";
1011
import type { ThirdwebClient } from "../../../client/client.js";
1112
import { waitForReceipt } from "../../../transaction/actions/wait-for-tx-receipt.js";
13+
import { stringify } from "../../../utils/json.js";
1214
import { waitForCallsReceipt } from "../../../wallets/eip5792/wait-for-calls-receipt.js";
1315
import type { Account, Wallet } from "../../../wallets/interfaces/wallet.js";
1416
import type { WindowAdapter } from "../adapters/WindowAdapter.js";
@@ -481,6 +483,22 @@ export function useStepExecutor(
481483
return;
482484
}
483485

486+
trackPayEvent({
487+
client,
488+
event: `ub:ui:execution:start`,
489+
toChainId:
490+
preparedQuote.steps[preparedQuote.steps.length - 1]?.destinationToken
491+
.chainId,
492+
toToken:
493+
preparedQuote.steps[preparedQuote.steps.length - 1]?.destinationToken
494+
.address,
495+
fromToken: preparedQuote.steps[0]?.originToken.address,
496+
chainId: preparedQuote.steps[0]?.destinationToken.chainId,
497+
amountWei: preparedQuote.steps[0]?.originAmount?.toString(),
498+
walletAddress: wallet?.getAccount()?.address,
499+
walletType: wallet?.id,
500+
});
501+
484502
setExecutionState("executing");
485503
setError(undefined);
486504
const completedStatusResults: CompletedStatusResult[] = [];
@@ -625,9 +643,41 @@ export function useStepExecutor(
625643
if (onComplete) {
626644
onComplete(completedStatusResults);
627645
}
646+
647+
trackPayEvent({
648+
client,
649+
event: `ub:ui:execution:success`,
650+
toChainId:
651+
preparedQuote.steps[preparedQuote.steps.length - 1]
652+
?.destinationToken.chainId,
653+
toToken:
654+
preparedQuote.steps[preparedQuote.steps.length - 1]
655+
?.destinationToken.address,
656+
fromToken: preparedQuote.steps[0]?.originToken.address,
657+
chainId: preparedQuote.steps[0]?.destinationToken.chainId,
658+
amountWei: preparedQuote.steps[0]?.originAmount?.toString(),
659+
walletAddress: wallet?.getAccount()?.address,
660+
walletType: wallet?.id,
661+
});
628662
}
629663
} catch (err) {
630664
console.error("Error executing payment", err);
665+
trackPayEvent({
666+
client,
667+
error: err instanceof Error ? err.message : stringify(err),
668+
event: `ub:ui:execution:error`,
669+
toChainId:
670+
preparedQuote.steps[preparedQuote.steps.length - 1]?.destinationToken
671+
.chainId,
672+
toToken:
673+
preparedQuote.steps[preparedQuote.steps.length - 1]?.destinationToken
674+
.address,
675+
fromToken: preparedQuote.steps[0]?.originToken.address,
676+
chainId: preparedQuote.steps[0]?.destinationToken.chainId,
677+
amountWei: preparedQuote.steps[0]?.originAmount?.toString(),
678+
walletAddress: wallet?.getAccount()?.address,
679+
walletType: wallet?.id,
680+
});
631681
if (err instanceof ApiError) {
632682
setError(err);
633683
} else {
@@ -655,6 +705,7 @@ export function useStepExecutor(
655705
executeOnramp,
656706
onComplete,
657707
preparedQuote,
708+
client,
658709
]);
659710

660711
// Start execution

packages/thirdweb/src/react/web/ui/Bridge/QuoteLoader.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export function QuoteLoader({
122122
: undefined,
123123
toChainId: destinationToken.chainId,
124124
toToken: destinationToken.address,
125+
walletAddress: sender,
125126
});
126127
return true;
127128
},

packages/thirdweb/src/react/web/ui/Bridge/payment-details/PaymentDetails.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ export function PaymentDetails({
108108
preparedQuote.type === "transfer"
109109
? preparedQuote.intent.tokenAddress
110110
: preparedQuote.intent.destinationTokenAddress,
111+
walletAddress: paymentMethod.payerWallet?.getAccount()?.address,
112+
walletType: paymentMethod.payerWallet?.id,
111113
});
112114
}
113115
return true;

packages/thirdweb/src/react/web/ui/Bridge/payment-selection/PaymentSelection.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ export function PaymentSelection({
136136
event: "payment_selection",
137137
toChainId: destinationToken.chainId,
138138
toToken: destinationToken.address,
139+
walletAddress: payerWallet?.getAccount()?.address,
140+
walletType: payerWallet?.id,
139141
});
140142
return true;
141143
},

packages/thirdweb/src/react/web/ui/Bridge/payment-success/SuccessScreen.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export function SuccessScreen({
7373
fromToken: preparedQuote.intent.originTokenAddress,
7474
toChainId: preparedQuote.intent.destinationChainId,
7575
toToken: preparedQuote.intent.destinationTokenAddress,
76+
walletAddress: preparedQuote.intent.sender,
7677
});
7778
}
7879
if (preparedQuote.type === "transfer") {
@@ -83,6 +84,7 @@ export function SuccessScreen({
8384
fromToken: preparedQuote.intent.tokenAddress,
8485
toChainId: preparedQuote.intent.chainId,
8586
toToken: preparedQuote.intent.tokenAddress,
87+
walletAddress: preparedQuote.intent.sender,
8688
});
8789
}
8890
queryClient.invalidateQueries({

packages/thirdweb/src/wallets/utils/getWalletBalance.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getContract } from "../../contract/contract.js";
1010
import type { GetBalanceResult } from "../../extensions/erc20/read/getBalance.js";
1111
import { eth_getBalance } from "../../rpc/actions/eth_getBalance.js";
1212
import { getRpcClient } from "../../rpc/rpc.js";
13+
import { getAddress } from "../../utils/address.js";
1314
import { toTokens } from "../../utils/units.js";
1415

1516
export type GetWalletBalanceOptions = {
@@ -44,7 +45,10 @@ export async function getWalletBalance(
4445
): Promise<GetBalanceResult> {
4546
const { address, client, chain, tokenAddress } = options;
4647
// erc20 case
47-
if (tokenAddress && tokenAddress !== NATIVE_TOKEN_ADDRESS) {
48+
if (
49+
tokenAddress &&
50+
getAddress(tokenAddress) !== getAddress(NATIVE_TOKEN_ADDRESS)
51+
) {
4852
// load balanceOf dynamically to avoid circular dependency
4953
const { getBalance } = await import(
5054
"../../extensions/erc20/read/getBalance.js"

0 commit comments

Comments
 (0)