Skip to content

track walletconnect failed requests #6304

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

Merged
8 changes: 8 additions & 0 deletions src/analytics/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export const event = {
wcNewSessionApproved: 'Approved new WalletConnect session',
wcShowingSigningRequest: 'Showing Walletconnect signing request',

wcRequestFailed: 'wc.failed_request',

nftOffersOpenedOffersSheet: 'Opened NFT Offers Sheet',
nftOffersOpenedSingleOfferSheet: 'Opened NFT Single Offer Sheet',
nftOffersViewedExternalOffer: 'Viewed external NFT Offer',
Expand Down Expand Up @@ -375,6 +377,12 @@ export type EventProperties = {
dappName: string;
dappUrl: string;
};
[event.wcRequestFailed]: {
type: 'session_proposal' | 'session_request' | 'read only wallet' | 'method not supported' | 'invalid namespaces' | 'dapp browser';
reason: string;
method?: string;
};

[event.nftOffersOpenedOffersSheet]: {
entryPoint: string;
};
Expand Down
10 changes: 9 additions & 1 deletion src/screens/NoNeedWCSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as lang from '@/languages';
import React, { useCallback } from 'react';
import React, { useCallback, useEffect } from 'react';
import { Centered } from '../components/layout';
import { Sheet, SheetActionButton } from '../components/sheet';
import { Text } from '../components/text';
Expand All @@ -9,6 +9,7 @@ import { useTheme } from '@/theme';
import { Colors } from '../styles/colors';
import { Box } from '@/design-system';
import { useRoute } from '@react-navigation/native';
import { analyticsV2 } from '@/analytics';

const BodyText = styled(Text).attrs(({ theme: { colors } }: { theme: { colors: Colors } }) => ({
align: 'center',
Expand All @@ -25,6 +26,13 @@ const WalletConnectRedirectSheet = () => {
const { goBack } = useNavigation();
const { params } = useRoute();

useEffect(() => {
analyticsV2.track(analyticsV2.event.wcRequestFailed, {
type: 'dapp browser',
reason: 'tried to connect with WalletConnect in the dapp browser',
});
}, []);

const handleOnPress = useCallback(() => {
(params as { cb?: () => void })?.cb?.();
goBack();
Expand Down
22 changes: 21 additions & 1 deletion src/walletConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { toUtf8String } from '@ethersproject/strings';
import { logger, RainbowError } from '@/logger';
import Navigation, { getActiveRoute } from '@/navigation/Navigation';
import Routes from '@/navigation/routesNames';
import { analyticsV2 as analytics } from '@/analytics';
import { analyticsV2 as analytics, analyticsV2 } from '@/analytics';
import { maybeSignUri } from '@/handlers/imgix';
import Alert from '@/components/alerts/Alert';
import * as lang from '@/languages';
Expand Down Expand Up @@ -541,6 +541,8 @@ export async function onSessionProposal(proposal: WalletKitTypes.SessionProposal
reason: 'INVALID_SESSION_SETTLE_REQUEST',
});

analyticsV2.track(analyticsV2.event.wcRequestFailed, { type: `invalid namespaces`, reason: namespaces.error.message });

showErrorSheet({
title: lang.t(T.errors.generic_title),
body: `${lang.t(T.errors.namespaces_invalid)} \n \n ${namespaces.error.message}`,
Expand Down Expand Up @@ -650,6 +652,11 @@ export async function onSessionRequest(event: SignClientTypes.EventArguments['se
message,
});

analyticsV2.track(analyticsV2.event.wcRequestFailed, {
type: 'session_request',
reason: 'session_request exited, signing request had no address and/or messsage',
});

await client.respondSessionRequest({
topic,
response: formatJsonRpcError(id, `Invalid RPC params`),
Expand Down Expand Up @@ -680,6 +687,11 @@ export async function onSessionRequest(event: SignClientTypes.EventArguments['se

const errorMessageBody = isReadOnly ? lang.t(T.errors.read_only_wallet_on_signing_method) : lang.t(T.errors.generic_error);

analyticsV2.track(analyticsV2.event.wcRequestFailed, {
type: 'read only wallet',
reason: 'session_request exited, selectedWallet was falsy or read only',
});

await client.respondSessionRequest({
topic,
response: formatJsonRpcError(id, `Wallet is read-only`),
Expand All @@ -703,6 +715,8 @@ export async function onSessionRequest(event: SignClientTypes.EventArguments['se
if (!session) {
logger.error(new RainbowError(`[walletConnect]: session_request topic was not found`));

analyticsV2.track(analyticsV2.event.wcRequestFailed, { type: 'session_request', reason: 'session_request topic was not found' });

await client.respondSessionRequest({
topic,
response: formatJsonRpcError(id, `Session not found`),
Expand Down Expand Up @@ -768,6 +782,12 @@ export async function onSessionRequest(event: SignClientTypes.EventArguments['se
method,
});

analyticsV2.track(analyticsV2.event.wcRequestFailed, {
type: `method not supported`,
reason: 'received unsupported session_request RPC method',
method: method,
});

try {
await client.respondSessionRequest({
topic,
Expand Down
Loading