Skip to content

Commit

Permalink
fix(suite-native): improve DAC error handling and report check result
Browse files Browse the repository at this point in the history
yanascz committed Dec 3, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f7dd25b commit 8a4d68c
Showing 4 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions suite-native/analytics/src/constants.ts
Original file line number Diff line number Diff line change
@@ -49,4 +49,5 @@ export enum EventType {
SendTransactionDispatched = 'send/transaction_dispatched',
SendFlowExited = 'send/flow_exited',
DeviceSettingsPinProtectionChange = 'device_settings/pin_protection_change',
DeviceSettingsAuthenticityCheck = 'device_settings/authenticity_check',
}
8 changes: 7 additions & 1 deletion suite-native/analytics/src/events.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { FeeLevelLabel, TokenAddress, TokenSymbol } from '@suite-common/wallet-t
import { DeviceModelInternal, VersionArray } from '@trezor/connect';

import { EventType } from './constants';
import { AnalyticsSendFlowStep } from './types';
import { AnalyticsSendFlowStep, DeviceAuthenticityCheckResult } from './types';

export type SuiteNativeAnalyticsEvent =
| {
@@ -310,4 +310,10 @@ export type SuiteNativeAnalyticsEvent =
payload: {
action: 'enable' | 'change' | 'disable';
};
}
| {
type: EventType.DeviceSettingsAuthenticityCheck;
payload: {
result: DeviceAuthenticityCheckResult;
};
};
2 changes: 2 additions & 0 deletions suite-native/analytics/src/types.ts
Original file line number Diff line number Diff line change
@@ -4,3 +4,5 @@ export type AnalyticsSendFlowStep =
| 'address_review'
| 'outputs_review'
| 'destination_tag_review';

export type DeviceAuthenticityCheckResult = 'successful' | 'compromised' | 'cancelled' | 'failed';
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { useSelector } from 'react-redux';

import { useNavigation } from '@react-navigation/native';

import { analytics, DeviceAuthenticityCheckResult, EventType } from '@suite-native/analytics';
import { selectDevice } from '@suite-common/wallet-core';
import { requestPrioritizedDeviceAccess } from '@suite-native/device-mutex';
import { useAlert } from '@suite-native/alerts';
@@ -31,6 +32,15 @@ export const DeviceAuthenticityCard = () => {

const device = useSelector(selectDevice);

const reportCheckResult = useCallback(
(result: DeviceAuthenticityCheckResult) =>
analytics.report({
type: EventType.DeviceSettingsAuthenticityCheck,
payload: { result },
}),
[],
);

const checkAuthenticity = useCallback(async () => {
navigation.navigate(DeviceStackRoutes.DeviceAuthenticity);

@@ -48,13 +58,25 @@ export const DeviceAuthenticityCard = () => {

const { success, payload } = result.payload;
if (success) {
navigation.navigate(DeviceAuthenticityStackRoutes.AuthenticitySummary, {
checkResult: payload.valid ? 'successful' : 'compromised',
});
} else if (payload.code === 'Failure_ActionCancelled') {
navigation.goBack();
const checkResult = payload.valid ? 'successful' : 'compromised';
navigation.navigate(DeviceAuthenticityStackRoutes.AuthenticitySummary, { checkResult });
reportCheckResult(checkResult);
} else {
const errorCode = payload.code;
if (errorCode === 'Failure_ActionCancelled' || errorCode === 'Failure_PinCancelled') {
navigation.goBack();
reportCheckResult('cancelled');
} else if (errorCode === 'Method_Interrupted') {
// navigation.goBack() already called via the X button
reportCheckResult('cancelled');
} else {
navigation.navigate(DeviceAuthenticityStackRoutes.AuthenticitySummary, {
checkResult: 'compromised',
});
reportCheckResult('failed');
}
}
}, [navigation, device]);
}, [device, navigation, reportCheckResult]);

const showInfoAlert = useCallback(() => {
showAlert({

0 comments on commit 8a4d68c

Please sign in to comment.