Skip to content

Commit

Permalink
fixup! fixup! feat: extend reporting for 'canceled' event in sendform
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-sanderson committed Feb 10, 2025
1 parent 4acdabc commit a499e63
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 40 deletions.
36 changes: 19 additions & 17 deletions packages/suite-analytics/src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ export type SuiteAnalyticsEventSuiteReady = {
};
};

export type TransactionCreatedEvent = {
type: EventType.TransactionCreated;
payload: {
action: 'sent' | 'copied' | 'downloaded' | 'replaced' | 'canceled';
symbol: string;
tokens: string;
outputsCount: number;
broadcast: boolean;
bitcoinLockTime: boolean;
ethereumData: boolean;
ethereumNonce: boolean;
rippleDestinationTag: boolean;
selectedFee: string;
isCoinControlEnabled: boolean;
hasCoinControlBeenOpened: boolean;
};
};

export type SuiteAnalyticsEvent =
| SuiteAnalyticsEventSuiteReady
| {
Expand Down Expand Up @@ -198,23 +216,7 @@ export type SuiteAnalyticsEvent =
type: 'exchange' | 'buy' | 'sell';
};
}
| {
type: EventType.TransactionCreated;
payload: {
action: 'sent' | 'copied' | 'downloaded' | 'replaced' | 'canceled';
symbol: string;
tokens: string;
outputsCount: number;
broadcast: boolean;
bitcoinLockTime: boolean;
ethereumData: boolean;
ethereumNonce: boolean;
rippleDestinationTag: boolean;
selectedFee: string;
isCoinControlEnabled: boolean;
hasCoinControlBeenOpened: boolean;
};
}
| TransactionCreatedEvent
| {
type: EventType.SendRawTransaction;
payload: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import {
selectSendFormReviewButtonRequestsCount,
selectStakePrecomposedForm,
} from '@suite-common/wallet-core';
import { FormState, StakeFormState } from '@suite-common/wallet-types';
import { FormState, RbfTransactionType, StakeFormState } from '@suite-common/wallet-types';
import {
constructTransactionReviewOutputs,
getTxStakeNameByDataHex,
isRbfBumpFeeTransaction,
isRbfCancelTransaction,
isRbfTransaction,
} from '@suite-common/wallet-utils';
import { NewModal } from '@trezor/components';
import { copyToClipboard, download } from '@trezor/dom-utils';
import { ConfirmOnDevice } from '@trezor/product-components';
import { EventType, analytics } from '@trezor/suite-analytics';
import { EventType, TransactionCreatedEvent, analytics } from '@trezor/suite-analytics';
import { Deferred } from '@trezor/utils';

import * as modalActions from 'src/actions/suite/modalActions';
Expand All @@ -41,6 +42,14 @@ const isStakeState = (state: SendState | StakeState): state is StakeState => 'da
const isStakeForm = (form: FormState | StakeFormState): form is StakeFormState =>
'stakeType' in form;

const mapRbfTypeToReporting: Record<
RbfTransactionType,
TransactionCreatedEvent['payload']['action']
> = {
'bump-fee': 'replaced',
cancel: 'canceled',
};

type TransactionReviewModalContentProps = {
decision: Deferred<boolean, string | number | undefined> | undefined;
txInfoState: SendState | StakeState;
Expand Down Expand Up @@ -127,9 +136,7 @@ export const TransactionReviewModalContent = ({

const isBroadcastEnabled = options.includes('broadcast');

const reportTransactionCreatedEvent = (
action: 'sent' | 'copied' | 'downloaded' | 'replaced' | 'canceled',
) =>
const reportTransactionCreatedEvent = (action: TransactionCreatedEvent['payload']['action']) =>
analytics.report({
type: EventType.TransactionCreated,
payload: {
Expand Down Expand Up @@ -158,8 +165,9 @@ export const TransactionReviewModalContent = ({
if (decision) {
decision.resolve(true);
reportTransactionCreatedEvent(
// eslint-disable-next-line no-nested-ternary
isBumpFeeRbfAction ? 'replaced' : isCancelRbfAction ? 'canceled' : 'sent',
isRbfTransaction(precomposedTx)
? mapRbfTypeToReporting[precomposedTx.rbfType]
: 'sent',
);
}
};
Expand Down Expand Up @@ -234,12 +242,8 @@ export const TransactionReviewModalContent = ({
return <TransactionReviewDetails tx={precomposedTx} txHash={serializedTx?.tx} />;
}

if (isRbfConfirmedError) {
return (
<ReplaceByFeeFailedOriginalTxConfirmed
type={isCancelRbfAction ? 'cancel-transaction' : 'replace-by-fee'}
/>
);
if (isRbfConfirmedError && isRbfTransaction(precomposedTx)) {
return <ReplaceByFeeFailedOriginalTxConfirmed type={precomposedTx.rbfType} />;
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const CancelTransactionModal = ({
onBackClick={onBackClick}
>
{isTxConfirmed ? (
<ReplaceByFeeFailedOriginalTxConfirmed type="cancel-transaction" />
<ReplaceByFeeFailedOriginalTxConfirmed type="cancel" />
) : (
<Column gap={spacings.md}>
<CancelTransaction tx={tx} selectedAccount={selectedAccount} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const BumpFeeModal = ({
onBackClick={onBackClick}
>
{isTxConfirmed ? (
<ReplaceByFeeFailedOriginalTxConfirmed type="replace-by-fee" />
<ReplaceByFeeFailedOriginalTxConfirmed type="bump-fee" />
) : (
<ChangeFee tx={tx} chainedTxs={chainedTxs} showChained={onShowChained} />
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RbfTransactionType } from '@suite-common/wallet-types';
import { Box, Card, Column, IconCircle, Text } from '@trezor/components';
import { spacings } from '@trezor/theme';
import {
Expand All @@ -9,23 +10,23 @@ import {
import { Translation, TranslationKey } from '../../../../Translation';
import { TrezorLink } from '../../../../TrezorLink';

type ReplaceByFeeFailedOriginalTxConfirmedProps = {
type: 'replace-by-fee' | 'cancel-transaction';
export type ReplaceByFeeFailedOriginalTxConfirmedProps = {
type: RbfTransactionType;
};

const titleMap: Record<ReplaceByFeeFailedOriginalTxConfirmedProps['type'], TranslationKey> = {
'replace-by-fee': 'TR_REPLACE_BY_FEE_FAILED_ALREADY_MINED',
'cancel-transaction': 'TR_CANCEL_TX_FAILED_ALREADY_MINED',
'bump-fee': 'TR_REPLACE_BY_FEE_FAILED_ALREADY_MINED',
cancel: 'TR_CANCEL_TX_FAILED_ALREADY_MINED',
};

const descriptionMap: Record<ReplaceByFeeFailedOriginalTxConfirmedProps['type'], TranslationKey> = {
'replace-by-fee': 'TR_REPLACE_BY_FEE_FAILED_ALREADY_MINED_DESCRIPTION',
'cancel-transaction': 'TR_CANCEL_TX_FAILED_ALREADY_MINED_DESCRIPTION',
'bump-fee': 'TR_REPLACE_BY_FEE_FAILED_ALREADY_MINED_DESCRIPTION',
cancel: 'TR_CANCEL_TX_FAILED_ALREADY_MINED_DESCRIPTION',
};

const helpLink: Record<ReplaceByFeeFailedOriginalTxConfirmedProps['type'], Url> = {
'replace-by-fee': HELP_CENTER_REPLACE_BY_FEE_BITCOIN,
'cancel-transaction': HELP_CENTER_CANCEL_TRANSACTION,
'bump-fee': HELP_CENTER_REPLACE_BY_FEE_BITCOIN,
cancel: HELP_CENTER_CANCEL_TRANSACTION,
};

export const ReplaceByFeeFailedOriginalTxConfirmed = ({
Expand Down
2 changes: 2 additions & 0 deletions suite-common/wallet-types/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export type PrecomposedTransactionCardanoFinal =
token?: TokenInfo;
};

export type RbfTransactionType = 'bump-fee' | 'cancel';

export type PrecomposedTransactionFinalBumpFeeRbf = PrecomposedTransactionBase & {
rbfType: 'bump-fee';
prevTxid: string;
Expand Down

0 comments on commit a499e63

Please sign in to comment.