Skip to content

Commit 57a9981

Browse files
authored
feat: Use chainId when checking if it's a smart transaction (#14890)
## **Description** We should be using a chainId param from a transaction (if available) to better support multichain efforts. This PR also disables unused STX networks in the dev environment and is similar to the PR in the extension: MetaMask/metamask-extension#32201 ## **Related issues** Fixes: ## **Manual testing steps** 1. Make sure that smart transactions still work (Send, Swap, dapp transactions) ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
1 parent ca72707 commit 57a9981

28 files changed

Lines changed: 191 additions & 57 deletions

File tree

app/components/Nav/Main/RootRPCMethodsUI.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,10 @@ const mapStateToProps = (state) => ({
588588
chainId: selectEvmChainId(state),
589589
tokens: selectTokens(state),
590590
providerType: selectProviderType(state),
591-
shouldUseSmartTransaction: selectShouldUseSmartTransaction(state),
591+
shouldUseSmartTransaction: selectShouldUseSmartTransaction(
592+
state,
593+
selectEvmChainId(state),
594+
),
592595
});
593596

594597
const mapDispatchToProps = (dispatch) => ({

app/components/UI/Swaps/QuotesView.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2650,7 +2650,10 @@ const mapStateToProps = (state) => ({
26502650
usedCustomGas: selectSwapsUsedCustomGas(state),
26512651
primaryCurrency: state.settings.primaryCurrency,
26522652
swapsTokens: swapsTokensSelector(state),
2653-
shouldUseSmartTransaction: selectShouldUseSmartTransaction(state),
2653+
shouldUseSmartTransaction: selectShouldUseSmartTransaction(
2654+
state,
2655+
selectEvmChainId(state),
2656+
),
26542657
isEIP1559Network: selectIsEIP1559Network(state),
26552658
});
26562659

app/components/UI/Swaps/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,10 @@ const mapStateToProps = (state) => ({
10401040
selectedNetworkClientId: selectSelectedNetworkClientId(state),
10411041
tokensWithBalance: swapsTokensWithBalanceSelector(state),
10421042
tokensTopAssets: swapsTopAssetsSelector(state),
1043-
shouldUseSmartTransaction: selectShouldUseSmartTransaction(state),
1043+
shouldUseSmartTransaction: selectShouldUseSmartTransaction(
1044+
state,
1045+
selectEvmChainId(state),
1046+
),
10441047
});
10451048

10461049
const mapDispatchToProps = (dispatch) => ({

app/components/UI/TransactionElement/TransactionDetails/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ class TransactionDetails extends PureComponent {
509509
};
510510
}
511511

512-
const mapStateToProps = (state) => ({
512+
const mapStateToProps = (state, ownProps) => ({
513513
chainId: selectChainId(state),
514514
networkConfigurations: selectNetworkConfigurations(state),
515515
selectedAddress: selectSelectedInternalAccountFormattedAddress(state),
@@ -522,7 +522,10 @@ const mapStateToProps = (state) => ({
522522
primaryCurrency: selectPrimaryCurrency(state),
523523
swapsTransactions: selectSwapsTransactions(state),
524524
swapsTokens: swapsControllerTokens(state),
525-
shouldUseSmartTransaction: selectShouldUseSmartTransaction(state),
525+
shouldUseSmartTransaction: selectShouldUseSmartTransaction(
526+
state,
527+
ownProps.transactionObject.chainId,
528+
),
526529
});
527530

528531
TransactionDetails.contextType = ThemeContext;

app/components/UI/TransactionElement/TransactionDetails/index.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ const renderComponent = ({
102102
<Stack.Screen name="Amount" options={{}}>
103103
{() => (
104104
<TransactionDetails
105-
// @ts-expect-error - TransactionDetails needs to be converted to typescript
106105
transactionObject={{
107106
networkID: '1',
108107
status,
@@ -112,7 +111,6 @@ const renderComponent = ({
112111
chainId: networkId,
113112
...(txParams ? { txParams } : {}),
114113
}}
115-
//@ts-expect-error - TransactionDetails needs to be converted to typescript
116114
transactionDetails={{
117115
renderFrom: '0x0',
118116
renderTo: networkId,
@@ -126,9 +124,7 @@ const renderComponent = ({
126124
hash: '0x3',
127125
...(hash ? { hash } : {}),
128126
}}
129-
//@ts-expect-error - navigation is not typed
130127
navigation={navigationMock}
131-
// @ts-expect-error - chainId is not typed
132128
chainId={networkId}
133129
/>
134130
)}

app/components/Views/Settings/AdvancedSettings/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,10 @@ const mapStateToProps = (state) => ({
515515
isTokenDetectionEnabled: selectUseTokenDetection(state),
516516
chainId: selectChainId(state),
517517
smartTransactionsOptInStatus: selectSmartTransactionsOptInStatus(state),
518-
smartTransactionsEnabled: selectSmartTransactionsEnabled(state),
518+
smartTransactionsEnabled: selectSmartTransactionsEnabled(
519+
state,
520+
selectChainId(state),
521+
),
519522
});
520523

521524
const mapDispatchToProps = (dispatch) => ({

app/components/Views/confirmations/hooks/useConfirmActions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useSignatureMetrics } from './signatures/useSignatureMetrics';
1212
import { useTransactionMetadataRequest } from './transactions/useTransactionMetadataRequest';
1313
import { selectShouldUseSmartTransaction } from '../../../../selectors/smartTransactionsController';
1414
import { useSelector } from 'react-redux';
15+
import { RootState } from '../../../../reducers';
1516

1617
export const useConfirmActions = () => {
1718
const {
@@ -29,7 +30,7 @@ export const useConfirmActions = () => {
2930
const navigation = useNavigation();
3031
const transactionMetadata = useTransactionMetadataRequest();
3132
const shouldUseSmartTransaction = useSelector(
32-
selectShouldUseSmartTransaction,
33+
(state: RootState) => selectShouldUseSmartTransaction(state, transactionMetadata?.chainId)
3334
);
3435
const isOneOfTheStakingConfirmations = isStakingConfirmation(
3536
transactionMetadata?.type as string,

app/components/Views/confirmations/legacy/Approval/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ const mapStateToProps = (state) => {
763763
showCustomNonce: selectShowCustomNonce(state),
764764
chainId,
765765
activeTabUrl: getActiveTabUrl(state),
766-
shouldUseSmartTransaction: selectShouldUseSmartTransaction(state),
766+
shouldUseSmartTransaction: selectShouldUseSmartTransaction(state, chainId),
767767
confirmationMetricsById: selectConfirmationMetrics(state),
768768
securityAlertResponse: selectCurrentTransactionSecurityAlertResponse(state),
769769
};

app/components/Views/confirmations/legacy/Approve/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ const mapStateToProps = (state) => {
983983
providerType: selectProviderTypeByChainId(state, chainId),
984984
providerRpcTarget: selectRpcUrlByChainId(state, chainId),
985985
networkConfigurations: selectEvmNetworkConfigurationsByChainId(state),
986-
shouldUseSmartTransaction: selectShouldUseSmartTransaction(state),
986+
shouldUseSmartTransaction: selectShouldUseSmartTransaction(state, chainId),
987987
simulationData: selectCurrentTransactionMetadata(state)?.simulationData,
988988
};
989989
};

app/components/Views/confirmations/legacy/ApproveView/Approve/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ const mapStateToProps = (state) => {
984984
providerType: selectProviderTypeByChainId(state, chainId),
985985
providerRpcTarget: selectRpcUrlByChainId(state, chainId),
986986
networkConfigurations: selectEvmNetworkConfigurationsByChainId(state),
987-
shouldUseSmartTransaction: selectShouldUseSmartTransaction(state),
987+
shouldUseSmartTransaction: selectShouldUseSmartTransaction(state, chainId),
988988
simulationData: selectCurrentTransactionMetadata(state)?.simulationData,
989989
};
990990
};

0 commit comments

Comments
 (0)