Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Claimables analytics #6195

Merged
merged 1 commit into from
Oct 15, 2024
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
39 changes: 39 additions & 0 deletions src/analytics/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ export const event = {
addFavoriteToken: 'add_favorite_token',
watchWallet: 'watch_wallet',
watchedWalletCohort: 'watched_wallet_cohort',

// claimables
claimClaimableSucceeded: 'claim_claimable.succeeded',
claimClaimableFailed: 'claim_claimable.failed',
claimablePanelOpened: 'claimable_panel.opened',
} as const;

type SwapEventParameters<T extends 'swap' | 'crosschainSwap'> = {
Expand Down Expand Up @@ -595,4 +600,38 @@ export type EventProperties = {
numWatchedWallets: number;
watchedWalletsAddresses: string[];
};

[event.claimClaimableSucceeded]: {
claimableId: string;
claimableType: 'transaction' | 'sponsored';
chainId: ChainId;
asset: {
symbol: string;
address: string;
};
amount: string;
};

[event.claimClaimableFailed]: {
claimableId: string;
claimableType: 'transaction' | 'sponsored';
chainId: ChainId;
asset: {
symbol: string;
address: string;
};
amount: string;
errorMessage: string;
};

[event.claimablePanelOpened]: {
claimableId: string;
claimableType: 'transaction' | 'sponsored';
chainId: ChainId;
asset: {
symbol: string;
address: string;
};
amount: string;
};
};
12 changes: 11 additions & 1 deletion src/components/asset-list/RecyclerAssetList2/Claimable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { deviceUtils } from '@/utils';
import Routes from '@/navigation/routesNames';
import { ExtendedState } from './core/RawRecyclerList';
import { convertAmountToNativeDisplayWorklet } from '@/__swaps__/utils/numbers';
import { analyticsV2 } from '@/analytics';

export const Claimable = React.memo(function Claimable({ uniqueId, extendedState }: { uniqueId: string; extendedState: ExtendedState }) {
const { accountAddress, nativeCurrency } = useAccountSettings();
Expand All @@ -32,7 +33,16 @@ export const Claimable = React.memo(function Claimable({ uniqueId, extendedState
return (
<Box
as={ButtonPressAnimation}
onPress={() => navigate(Routes.CLAIM_CLAIMABLE_PANEL, { claimable })}
onPress={() => {
analyticsV2.track(analyticsV2.event.claimablePanelOpened, {
claimableType: claimable.type,
claimableId: claimable.uniqueId,
chainId: claimable.chainId,
asset: { symbol: claimable.asset.symbol, address: claimable.asset.address },
amount: claimable.value.claimAsset.amount,
});
navigate(Routes.CLAIM_CLAIMABLE_PANEL, { claimable });
}}
scaleTo={0.96}
paddingHorizontal="20px"
justifyContent="space-between"
Expand Down
68 changes: 61 additions & 7 deletions src/screens/claimables/ClaimingSponsoredClaimable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import { useMutation } from '@tanstack/react-query';
import { getProvider } from '@/handlers/web3';
import { useAccountSettings } from '@/hooks';
import { haptics } from '@/utils';
import { analyticsV2 } from '@/analytics';

enum ErrorMessages {
CLAIM_API_CALL_FAILED = 'Failed to execute sponsored claim api call',
CLAIM_API_UNSUCCESSFUL_RESPONSE = 'Sponsored claim api call returned unsuccessful response',
UNHANDLED_ERROR = 'Failed to claim claimable due to unhandled error',
UNREACHABLE_CLAIM_STATE = 'Claim function completed but never resolved status to success or error state',
}

export const ClaimingSponsoredClaimable = ({ claimable }: { claimable: SponsoredClaimable }) => {
const { accountAddress, nativeCurrency } = useAccountSettings();
Expand Down Expand Up @@ -42,7 +50,15 @@ export const ClaimingSponsoredClaimable = ({ claimable }: { claimable: Sponsored
} catch (e) {
haptics.notificationError();
setClaimStatus('error');
logger.error(new RainbowError('[ClaimSponsoredClaimable]: failed to execute sponsored claim api call'));
analyticsV2.track(analyticsV2.event.claimClaimableFailed, {
claimableType: 'sponsored',
claimableId: claimable.uniqueId,
chainId: claimable.chainId,
asset: { symbol: claimable.asset.symbol, address: claimable.asset.address },
amount: claimable.value.claimAsset.amount,
errorMessage: ErrorMessages.CLAIM_API_CALL_FAILED,
});
logger.error(new RainbowError(`[ClaimSponsoredClaimable]: ${ErrorMessages.CLAIM_API_CALL_FAILED}`));
return;
}
} else {
Expand All @@ -51,15 +67,31 @@ export const ClaimingSponsoredClaimable = ({ claimable }: { claimable: Sponsored
} catch (e) {
haptics.notificationError();
setClaimStatus('error');
logger.error(new RainbowError('[ClaimSponsoredClaimable]: failed to execute sponsored claim api call'));
analyticsV2.track(analyticsV2.event.claimClaimableFailed, {
claimableType: 'sponsored',
claimableId: claimable.uniqueId,
chainId: claimable.chainId,
asset: { symbol: claimable.asset.symbol, address: claimable.asset.address },
amount: claimable.value.claimAsset.amount,
errorMessage: ErrorMessages.CLAIM_API_CALL_FAILED,
});
logger.error(new RainbowError(`[ClaimSponsoredClaimable]: ${ErrorMessages.CLAIM_API_CALL_FAILED}`));
return;
}
}

if (!response.data.payload.success) {
haptics.notificationError();
setClaimStatus('error');
logger.error(new RainbowError('[ClaimSponsoredClaimable]: sponsored claim api call returned unsuccessful response'));
analyticsV2.track(analyticsV2.event.claimClaimableFailed, {
claimableType: 'sponsored',
claimableId: claimable.uniqueId,
chainId: claimable.chainId,
asset: { symbol: claimable.asset.symbol, address: claimable.asset.address },
amount: claimable.value.claimAsset.amount,
errorMessage: ErrorMessages.CLAIM_API_UNSUCCESSFUL_RESPONSE,
});
logger.error(new RainbowError(`[ClaimSponsoredClaimable]: ${ErrorMessages.CLAIM_API_UNSUCCESSFUL_RESPONSE}`));
} else {
haptics.notificationSuccess();

Expand All @@ -69,24 +101,46 @@ export const ClaimingSponsoredClaimable = ({ claimable }: { claimable: Sponsored
setClaimStatus('pending');
}

analyticsV2.track(analyticsV2.event.claimClaimableSucceeded, {
claimableType: 'sponsored',
claimableId: claimable.uniqueId,
chainId: claimable.chainId,
asset: { symbol: claimable.asset.symbol, address: claimable.asset.address },
amount: claimable.value.claimAsset.amount,
});

// Immediately remove the claimable from cached data
queryClient.setQueryData(queryKey, (oldData: Claimable[] | undefined) => oldData?.filter(c => c.uniqueId !== claimable.uniqueId));
}
},
onError: e => {
haptics.notificationError();
setClaimStatus('error');
logger.error(new RainbowError('[ClaimingSponsoredClaimable]: Failed to claim claimable due to unhandled error'), {
analyticsV2.track(analyticsV2.event.claimClaimableFailed, {
claimableType: 'sponsored',
claimableId: claimable.uniqueId,
chainId: claimable.chainId,
asset: { symbol: claimable.asset.symbol, address: claimable.asset.address },
amount: claimable.value.claimAsset.amount,
errorMessage: ErrorMessages.UNHANDLED_ERROR,
});
logger.error(new RainbowError(`[ClaimSponsoredClaimable]: ${ErrorMessages.UNHANDLED_ERROR}`), {
message: (e as Error)?.message,
});
},
onSuccess: () => {
if (claimStatus === 'claiming') {
haptics.notificationError();
setClaimStatus('error');
logger.error(
new RainbowError('[ClaimingSponsoredClaimable]: claim function completed but never resolved status to success or error state')
);
analyticsV2.track(analyticsV2.event.claimClaimableFailed, {
claimableType: 'sponsored',
claimableId: claimable.uniqueId,
chainId: claimable.chainId,
asset: { symbol: claimable.asset.symbol, address: claimable.asset.address },
amount: claimable.value.claimAsset.amount,
errorMessage: ErrorMessages.UNREACHABLE_CLAIM_STATE,
});
logger.error(new RainbowError(`[ClaimSponsoredClaimable]: ${ErrorMessages.UNREACHABLE_CLAIM_STATE}`));
}
},
onSettled: () => {
Expand Down
69 changes: 59 additions & 10 deletions src/screens/claimables/ClaimingTransactionClaimable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ import { loadWallet } from '@/model/wallet';
import { walletExecuteRap } from '@/rapsV2/execute';
import { claimablesQueryKey } from '@/resources/addys/claimables/query';
import { queryClient } from '@/react-query';
import { analyticsV2 } from '@/analytics';

enum ErrorMessages {
NO_TX_PAYLOAD = 'Failed to claim claimable due to missing tx payload',
GAS_ESTIMATION_FAILURE = 'Failed to estimate gas limit',
L1_SECURITY_FEE_ESTIMATION_FAILURE = 'Failed to calculate L1 security fee',
RAP_ERROR = 'Failed to claim claimable due to rap error',
UNHANDLED_ERROR = 'Failed to claim claimable due to unhandled error',
UNREACHABLE_CLAIM_STATE = 'Claim function completed but never resolved status to success or error state',
UNREACHABLE_GAS_ESTIMATION_STATE = 'Attempted to estimate gas without a tx payload',
}

// supports legacy and new gas types
export type TransactionClaimableTxPayload = TransactionRequest &
Expand Down Expand Up @@ -82,7 +93,7 @@ export const ClaimingTransactionClaimable = ({ claimable }: { claimable: Transac

const estimateGas = useCallback(async () => {
if (!baseTxPayload) {
logger.error(new RainbowError('[ClaimingTransactionClaimable]: attempted to estimate gas without a tx payload'));
logger.error(new RainbowError(`[ClaimingTransactionClaimable]: ${ErrorMessages.UNREACHABLE_GAS_ESTIMATION_STATE}`));
return;
}

Expand All @@ -93,7 +104,7 @@ export const ClaimingTransactionClaimable = ({ claimable }: { claimable: Transac

if (!gasLimit) {
updateTxFee(null, null);
logger.error(new RainbowError('[ClaimingTransactionClaimable]: Failed to estimate gas limit'));
logger.warn(`[ClaimingTransactionClaimable]: ${ErrorMessages.GAS_ESTIMATION_FAILURE}`);
return;
}

Expand All @@ -110,7 +121,7 @@ export const ClaimingTransactionClaimable = ({ claimable }: { claimable: Transac

if (!l1SecurityFee) {
updateTxFee(null, null);
logger.error(new RainbowError('[ClaimingTransactionClaimable]: Failed to calculate L1 security fee'));
logger.error(new RainbowError(`[ClaimingTransactionClaimable]: ${ErrorMessages.L1_SECURITY_FEE_ESTIMATION_FAILURE}`));
return;
}

Expand All @@ -127,7 +138,7 @@ export const ClaimingTransactionClaimable = ({ claimable }: { claimable: Transac
try {
estimateGas();
} catch (e) {
logger.warn('[ClaimingTransactionClaimable]: Failed to estimate gas', { error: e });
logger.warn(`[ClaimingTransactionClaimable]: ${ErrorMessages.GAS_ESTIMATION_FAILURE}`, { error: e });
}
}
}, [baseTxPayload, estimateGas, selectedGasFee]);
Expand All @@ -145,7 +156,15 @@ export const ClaimingTransactionClaimable = ({ claimable }: { claimable: Transac
if (!txPayload) {
haptics.notificationError();
setClaimStatus('error');
logger.error(new RainbowError('[ClaimingTransactionClaimable]: Failed to claim claimable due to missing tx payload'));
analyticsV2.track(analyticsV2.event.claimClaimableFailed, {
claimableType: 'transaction',
claimableId: claimable.uniqueId,
chainId: claimable.chainId,
asset: { symbol: claimable.asset.symbol, address: claimable.asset.address },
amount: claimable.value.claimAsset.amount,
errorMessage: ErrorMessages.NO_TX_PAYLOAD,
});
logger.error(new RainbowError(`[ClaimingTransactionClaimable]: ${ErrorMessages.NO_TX_PAYLOAD}`));
return;
}

Expand All @@ -170,7 +189,15 @@ export const ClaimingTransactionClaimable = ({ claimable }: { claimable: Transac
if (errorMessage) {
haptics.notificationError();
setClaimStatus('error');
logger.error(new RainbowError('[ClaimingTransactionClaimable]: Failed to claim claimable due to rap error'), {
analyticsV2.track(analyticsV2.event.claimClaimableFailed, {
claimableType: 'transaction',
claimableId: claimable.uniqueId,
chainId: claimable.chainId,
asset: { symbol: claimable.asset.symbol, address: claimable.asset.address },
amount: claimable.value.claimAsset.amount,
errorMessage: ErrorMessages.RAP_ERROR,
});
logger.error(new RainbowError(`[ClaimingTransactionClaimable]: ${ErrorMessages.RAP_ERROR}`), {
message: errorMessage,
});
} else {
Expand All @@ -179,22 +206,44 @@ export const ClaimingTransactionClaimable = ({ claimable }: { claimable: Transac

// Immediately remove the claimable from cached data
queryClient.setQueryData(queryKey, (oldData: Claimable[] | undefined) => oldData?.filter(c => c.uniqueId !== claimable.uniqueId));

analyticsV2.track(analyticsV2.event.claimClaimableSucceeded, {
claimableType: 'transaction',
claimableId: claimable.uniqueId,
chainId: claimable.chainId,
asset: { symbol: claimable.asset.symbol, address: claimable.asset.address },
amount: claimable.value.claimAsset.amount,
});
}
},
onError: e => {
haptics.notificationError();
setClaimStatus('error');
logger.error(new RainbowError('[ClaimingTransactionClaimable]: Failed to claim claimable due to unhandled error'), {
analyticsV2.track(analyticsV2.event.claimClaimableFailed, {
claimableType: 'transaction',
claimableId: claimable.uniqueId,
chainId: claimable.chainId,
asset: { symbol: claimable.asset.symbol, address: claimable.asset.address },
amount: claimable.value.claimAsset.amount,
errorMessage: ErrorMessages.UNHANDLED_ERROR,
});
logger.error(new RainbowError(`[ClaimingTransactionClaimable]: ${ErrorMessages.UNHANDLED_ERROR}`), {
message: (e as Error)?.message,
});
},
onSuccess: () => {
if (claimStatus === 'claiming') {
haptics.notificationError();
setClaimStatus('error');
logger.error(
new RainbowError('[ClaimingTransactionClaimable]: claim function completed but never resolved status to success or error state')
);
analyticsV2.track(analyticsV2.event.claimClaimableFailed, {
claimableType: 'transaction',
claimableId: claimable.uniqueId,
chainId: claimable.chainId,
asset: { symbol: claimable.asset.symbol, address: claimable.asset.address },
amount: claimable.value.claimAsset.amount,
errorMessage: ErrorMessages.UNREACHABLE_CLAIM_STATE,
});
logger.error(new RainbowError(`[ClaimingTransactionClaimable]: ${ErrorMessages.UNREACHABLE_CLAIM_STATE}`));
}
},
onSettled: () => {
Expand Down
Loading