Skip to content

Commit

Permalink
fix: fix update vs revoke tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
rkalis committed Jan 15, 2025
1 parent 3e001c0 commit 6b7629e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/utils/allowances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export const updateErc20Allowance = async (
// Note that tracking happens in the wrapRevoke function already so we only need to track if the allowance is not being revoked
// TODO: Merge tracking with wrapRevoke
if (newAmount !== '0') {
trackRevokeTransaction(allowance, hash, newAmount);
trackRevokeTransaction(allowance, newAmount);
}

const waitForConfirmation = async () => {
Expand Down Expand Up @@ -512,25 +512,25 @@ export const prepareUpdateErc20Allowance = async (
}
};

export const trackRevokeTransaction = (allowance: TokenAllowanceData, hash: string, newAmount?: string) => {
if (!hash) return;

export const trackRevokeTransaction = (allowance: TokenAllowanceData, newAmount?: string) => {
if (isErc721Contract(allowance.contract)) {
track('Revoked ERC721 allowance', {
chainId: allowance.chainId,
account: allowance.owner,
spender: allowance.payload?.spender,
token: allowance.contract.address,
tokenId: (allowance.payload as any).tokenId,
tokenId: allowance.payload?.type === AllowanceType.ERC721_SINGLE ? allowance.payload.tokenId : undefined,
});
}

track(newAmount === '0' ? 'Revoked ERC20 allowance' : 'Updated ERC20 allowance', {
const isRevoke = !newAmount || newAmount === '0';

track(isRevoke ? 'Revoked ERC20 allowance' : 'Updated ERC20 allowance', {
chainId: allowance.chainId,
account: allowance.owner,
spender: allowance.payload?.spender,
token: allowance.contract.address,
amount: newAmount === '0' ? undefined : newAmount,
amount: isRevoke ? undefined : newAmount,
permit2: allowance.payload?.type === AllowanceType.PERMIT2,
});
};
Expand All @@ -553,7 +553,7 @@ export const wrapRevoke = (

updateTransaction(allowance, { status: 'pending', transactionHash: transactionSubmitted.hash });

trackRevokeTransaction(allowance, transactionSubmitted.hash);
trackRevokeTransaction(allowance);

// We don't await this, since we want to return after submitting all transactions, even if they're still pending
transactionSubmitted.confirmation.then(() => {
Expand Down

0 comments on commit 6b7629e

Please sign in to comment.