Skip to content

Commit d9f11d1

Browse files
committed
feat(metametrics): add events during snap account transaction loading screen
1 parent 538139b commit d9f11d1

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

shared/constants/metametrics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ export enum MetaMetricsEventName {
682682
AddSnapAccountCancelled = 'Add Snap Account Cancelled',
683683
AddSnapAccountSuccessViewed = 'Add Snap Account Success Viewed',
684684
AddSnapAccountSuccessClicked = 'Add Snap Account Success Clicked',
685+
SnapAccountTransactionLoadingViewed = 'Snap Account Transaction Loading Viewed',
685686
SnapAccountTransactionFinalizeViewed = 'Snap Account Transaction Finalize Viewed',
686687
SnapAccountTransactionFinalizeRedirectGoToSiteClicked = 'Snap Account Transaction Finalize Redirect "Go To Site" Clicked',
687688
SnapAccountTransactionFinalizeRedirectSnapUrlClicked = 'Snap Account Transaction Finalize Redirect "Snap URL" Clicked',

ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import { ConfirmGasDisplay } from '../components/confirm-gas-display';
5858
import updateTxData from '../../../../shared/modules/updateTxData';
5959
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
6060
import { KeyringType } from '../../../../shared/constants/keyring';
61+
import SnapAccountTransactionLoadingScreen from '../../snap-account-transaction-loading-screen/snap-account-transaction-loading-screen';
6162
///: END:ONLY_INCLUDE_IF
6263
import { isHardwareKeyring } from '../../../helpers/utils/hardware';
6364
import FeeDetailsComponent from '../components/fee-details-component/fee-details-component';
@@ -102,6 +103,9 @@ export default class ConfirmTransactionBase extends Component {
102103
unapprovedTxCount: PropTypes.number,
103104
customGas: PropTypes.object,
104105
addToAddressBookIfNew: PropTypes.func,
106+
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
107+
fromInternalAccount: PropTypes.object,
108+
///: END:ONLY_INCLUDE_IF
105109
keyringForAccount: PropTypes.object,
106110
// Component props
107111
actionKey: PropTypes.string,
@@ -671,14 +675,21 @@ export default class ConfirmTransactionBase extends Component {
671675
toAccounts,
672676
toAddress,
673677
keyringForAccount,
678+
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
679+
fromInternalAccount,
680+
///: END:ONLY_INCLUDE_IF
674681
} = this.props;
675682

676683
let loadingIndicatorMessage;
677684

678685
switch (keyringForAccount?.type) {
679686
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
680687
case KeyringType.snap:
681-
loadingIndicatorMessage = this.context.t('loadingScreenSnapMessage');
688+
loadingIndicatorMessage = (
689+
<SnapAccountTransactionLoadingScreen
690+
internalAccount={fromInternalAccount}
691+
></SnapAccountTransactionLoadingScreen>
692+
);
682693
break;
683694
///: END:ONLY_INCLUDE_IF
684695
default:

ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.container.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ const mapStateToProps = (state, ownProps) => {
159159
const tokenToAddress = getTokenAddressParam(transactionData);
160160

161161
const { balance } = accounts[fromAddress];
162-
const fromName = getInternalAccountByAddress(state, fromAddress)?.metadata
163-
.name;
162+
const fromInternalAccount = getInternalAccountByAddress(state, fromAddress);
163+
const fromName = fromInternalAccount?.metadata.name;
164164
const keyring = findKeyringForAddress(state, fromAddress);
165165

166166
const isSendingAmount =
@@ -315,6 +315,9 @@ const mapStateToProps = (state, ownProps) => {
315315
isBuyableChain,
316316
useCurrencyRateCheck: getUseCurrencyRateCheck(state),
317317
keyringForAccount: keyring,
318+
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
319+
fromInternalAccount,
320+
///: END:ONLY_INCLUDE_IF
318321
isUsingPaymaster,
319322
isSigningOrSubmitting,
320323
isUserOpContractDeployError,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as SnapAccountTransactionLoadingScreen } from './snap-account-transaction-loading-screen';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, { useContext, useEffect } from 'react';
2+
import { InternalAccount } from '@metamask/keyring-api';
3+
import { useI18nContext } from '../../hooks/useI18nContext';
4+
import { MetaMetricsContext } from '../../contexts/metametrics';
5+
import {
6+
MetaMetricsEventCategory,
7+
MetaMetricsEventName,
8+
MetaMetricsEventAccountType,
9+
} from '../../../shared/constants/metametrics';
10+
11+
const SnapAccountTransactionLoadingScreen = ({
12+
internalAccount,
13+
}: {
14+
internalAccount: InternalAccount;
15+
}) => {
16+
const t = useI18nContext();
17+
const trackEvent = useContext(MetaMetricsContext);
18+
19+
useEffect(() => {
20+
trackEvent({
21+
event: MetaMetricsEventName.SnapAccountTransactionLoadingViewed,
22+
category: MetaMetricsEventCategory.Transactions,
23+
properties: {
24+
snap_id: internalAccount?.metadata.snap?.id,
25+
snap_name: internalAccount?.metadata.snap?.name,
26+
account_type: MetaMetricsEventAccountType.Snap,
27+
},
28+
});
29+
}, []);
30+
31+
return <span>{t('loadingScreenSnapMessage')}</span>;
32+
};
33+
34+
export default SnapAccountTransactionLoadingScreen;

0 commit comments

Comments
 (0)