Skip to content

Commit

Permalink
feat(suite-native): report send review app exit to analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
PeKne committed Oct 11, 2024
1 parent 5080309 commit c51e1f5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions suite-native/analytics/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export type SuiteNativeAnalyticsEvent =
symbol: NetworkSymbol;
outputsCount: number;
selectedFee: FeeLevelLabel;
wasAppLeftDuringReview: boolean;
tokenSymbols?: TokenSymbol[];
tokenAddresses?: TokenAddress[];
hasEthereumData?: boolean;
Expand Down
1 change: 1 addition & 0 deletions suite-native/module-send/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@trezor/transport": "workspace:*",
"@trezor/utils": "workspace:*",
"expo-linear-gradient": "13.0.2",
"jotai": "1.9.1",
"react": "18.2.0",
"react-hook-form": "^7.53.0",
"react-native": "0.75.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { atom } from 'jotai';

export const wasAppLeftDuringReviewAtom = atom<boolean>(false);
25 changes: 22 additions & 3 deletions suite-native/module-send/src/components/AddressReviewStepList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useCallback, useEffect, useState } from 'react';
import { LayoutChangeEvent, View, AppState } from 'react-native';
import { useDispatch, useSelector } from 'react-redux';
import { useEffect, useState } from 'react';
import { LayoutChangeEvent, View } from 'react-native';

import { useSetAtom } from 'jotai';
import { isRejected } from '@reduxjs/toolkit';
import { useNavigation, useRoute } from '@react-navigation/native';
import { useNavigation, useRoute, useFocusEffect } from '@react-navigation/native';

import {
RootStackParamList,
Expand All @@ -27,6 +28,7 @@ import { AddressReviewStep } from '../components/AddressReviewStep';
import { CompareAddressHelpButton } from '../components/CompareAddressHelpButton';
import { AddressOriginHelpButton } from '../components/AddressOriginHelpButton';
import { useHandleSendReviewFailure } from '../hooks/useHandleSendReviewFailure';
import { wasAppLeftDuringReviewAtom } from '../atoms/wasAppLeftDuringReviewAtom';

const NUMBER_OF_STEPS = 3;
const OVERLAY_INITIAL_POSITION = 75;
Expand All @@ -48,6 +50,23 @@ export const AddressReviewStepList = () => {
const [childHeights, setChildHeights] = useState<number[]>([]);
const [stepIndex, setStepIndex] = useState(0);
const handleSendReviewFailure = useHandleSendReviewFailure({ accountKey, transaction });
const setWasAppLeftDuringReview = useSetAtom(wasAppLeftDuringReviewAtom);

useFocusEffect(
useCallback(() => {
setWasAppLeftDuringReview(false);

const subscription = AppState.addEventListener('change', nextAppState => {
if (nextAppState === 'background') {
setWasAppLeftDuringReview(true);
}
});

return () => {
subscription.remove();
};
}, [setWasAppLeftDuringReview]),
);

const areAllStepsDone = stepIndex === NUMBER_OF_STEPS - 1;
const isLayoutReady = childHeights.length === NUMBER_OF_STEPS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import Animated, { SlideInDown } from 'react-native-reanimated';
import { useState } from 'react';

import { useAtomValue } from 'jotai';
import { CommonActions, useNavigation } from '@react-navigation/native';
import { isFulfilled } from '@reduxjs/toolkit';

Expand All @@ -21,6 +22,7 @@ import { analytics, EventType } from '@suite-native/analytics';

import { SendConfirmOnDeviceImage } from '../components/SendConfirmOnDeviceImage';
import { sendTransactionAndCleanupSendFormThunk } from '../sendFormThunks';
import { wasAppLeftDuringReviewAtom } from '../atoms/wasAppLeftDuringReviewAtom';

const navigateToAccountDetail = ({
accountKey,
Expand Down Expand Up @@ -64,6 +66,7 @@ export const OutputsReviewFooter = ({ accountKey }: { accountKey: AccountKey })
const navigation = useNavigation();
const { applyStyle } = useNativeStyles();
const [isSendInProgress, setIsSendInProgress] = useState(false);
const wasAppLeftDuringReview = useAtomValue(wasAppLeftDuringReviewAtom);

const account = useSelector((state: AccountsRootState) =>
selectAccountByKey(state, accountKey),
Expand Down Expand Up @@ -94,6 +97,7 @@ export const OutputsReviewFooter = ({ accountKey }: { accountKey: AccountKey })
symbol: account.symbol,
outputsCount: formValues.outputs.length,
selectedFee: formValues.selectedFee ?? 'normal',
wasAppLeftDuringReview,
},
});
}
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10368,6 +10368,7 @@ __metadata:
"@trezor/transport": "workspace:*"
"@trezor/utils": "workspace:*"
expo-linear-gradient: "npm:13.0.2"
jotai: "npm:1.9.1"
react: "npm:18.2.0"
react-hook-form: "npm:^7.53.0"
react-native: "npm:0.75.2"
Expand Down

0 comments on commit c51e1f5

Please sign in to comment.