Improve transaction confirmation page performance (#16205)

* Reduce the amount of calls to insight snaps

* Add dep

* Update LavaMoat policies

* Fix selectors and revert changes to hook

* Remove dep

* Revert "Update LavaMoat policies"

This reverts commit 7469c94e0e7c52eb877766a96005cc559c9d8d20.
feature/default_network_editable
Frederik Bolding 2 years ago committed by GitHub
parent d452613f71
commit 012e9fab9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      ui/hooks/flask/useTransactionInsightSnap.js
  2. 23
      ui/pages/confirm-transaction-base/confirm-transaction-base.container.js
  3. 54
      ui/selectors/selectors.js

@ -18,7 +18,7 @@ export function useTransactionInsightSnap({ transaction, chainId, snapId }) {
async function fetchInsight() { async function fetchInsight() {
const d = await handleSnapRequest({ const d = await handleSnapRequest({
snapId, snapId,
origin: 'test', origin: '',
handler: 'onTransaction', handler: 'onTransaction',
request: { request: {
jsonrpc: '2.0', jsonrpc: '2.0',

@ -35,6 +35,8 @@ import {
getEIP1559V2Enabled, getEIP1559V2Enabled,
getIsBuyableChain, getIsBuyableChain,
getEnsResolutionByAddress, getEnsResolutionByAddress,
getUnapprovedTransaction,
getFullTxData,
///: BEGIN:ONLY_INCLUDE_IN(flask) ///: BEGIN:ONLY_INCLUDE_IN(flask)
getInsightSnaps, getInsightSnaps,
///: END:ONLY_INCLUDE_IN ///: END:ONLY_INCLUDE_IN
@ -98,10 +100,8 @@ const mapStateToProps = (state, ownProps) => {
} = metamask; } = metamask;
const { tokenData, txData, tokenProps, nonce } = confirmTransaction; const { tokenData, txData, tokenProps, nonce } = confirmTransaction;
const { txParams = {}, id: transactionId, type } = txData; const { txParams = {}, id: transactionId, type } = txData;
const transaction = const txId = transactionId || Number(paramsTransactionId);
Object.values(unapprovedTxs).find( const transaction = getUnapprovedTransaction(state, txId);
({ id }) => id === (transactionId || Number(paramsTransactionId)),
) || {};
const { const {
from: fromAddress, from: fromAddress,
to: txParamsToAddress, to: txParamsToAddress,
@ -148,10 +148,6 @@ const mapStateToProps = (state, ownProps) => {
gasEstimationObject, gasEstimationObject,
} = transactionFeeSelector(state, transaction); } = transactionFeeSelector(state, transaction);
if (transaction && transaction.simulationFails) {
txData.simulationFails = transaction.simulationFails;
}
const currentNetworkUnapprovedTxs = Object.keys(unapprovedTxs) const currentNetworkUnapprovedTxs = Object.keys(unapprovedTxs)
.filter((key) => .filter((key) =>
transactionMatchesNetwork(unapprovedTxs[key], chainId, network), transactionMatchesNetwork(unapprovedTxs[key], chainId, network),
@ -168,16 +164,7 @@ const mapStateToProps = (state, ownProps) => {
const methodData = getKnownMethodData(state, data) || {}; const methodData = getKnownMethodData(state, data) || {};
let fullTxData = { ...txData, ...transaction }; const fullTxData = getFullTxData(state, txId, customTxParamsData);
if (customTxParamsData) {
fullTxData = {
...fullTxData,
txParams: {
...fullTxData.txParams,
data: customTxParamsData,
},
};
}
const isCollectibleTransfer = Boolean( const isCollectibleTransfer = Boolean(
allCollectibleContracts?.[selectedAddress]?.[chainId]?.find((contract) => { allCollectibleContracts?.[selectedAddress]?.[chainId]?.find((contract) => {

@ -1,7 +1,14 @@
import { createSelector } from 'reselect'; import {
///: BEGIN:ONLY_INCLUDE_IN(flask) createSelector,
import { memoize } from 'lodash'; createSelectorCreator,
///: END:ONLY_INCLUDE_IN defaultMemoize,
} from 'reselect';
import {
///: BEGIN:ONLY_INCLUDE_IN(flask)
memoize,
///: END:ONLY_INCLUDE_IN
isEqual,
} from 'lodash';
import { addHexPrefix } from '../../app/scripts/lib/util'; import { addHexPrefix } from '../../app/scripts/lib/util';
import { import {
TEST_CHAINS, TEST_CHAINS,
@ -779,6 +786,45 @@ export function getShowWhatsNewPopup(state) {
return state.appState.showWhatsNewPopup; return state.appState.showWhatsNewPopup;
} }
const createDeepEqualSelector = createSelectorCreator(defaultMemoize, isEqual);
export const getUnapprovedTransactions = (state) =>
state.metamask.unapprovedTxs;
export const getTxData = (state) => state.confirmTransaction.txData;
export const getUnapprovedTransaction = createDeepEqualSelector(
getUnapprovedTransactions,
(_, transactionId) => transactionId,
(unapprovedTxs, transactionId) => {
return (
Object.values(unapprovedTxs).find(({ id }) => id === transactionId) || {}
);
},
);
export const getFullTxData = createDeepEqualSelector(
getTxData,
(state, transactionId) => getUnapprovedTransaction(state, transactionId),
(_state, _transactionId, customTxParamsData) => customTxParamsData,
(txData, transaction, customTxParamsData) => {
let fullTxData = { ...txData, ...transaction };
if (transaction && transaction.simulationFails) {
txData.simulationFails = transaction.simulationFails;
}
if (customTxParamsData) {
fullTxData = {
...fullTxData,
txParams: {
...fullTxData.txParams,
data: customTxParamsData,
},
};
}
return fullTxData;
},
);
///: BEGIN:ONLY_INCLUDE_IN(flask) ///: BEGIN:ONLY_INCLUDE_IN(flask)
export function getSnaps(state) { export function getSnaps(state) {
return state.metamask.snaps; return state.metamask.snaps;

Loading…
Cancel
Save