Skip to content

Commit

Permalink
Use preview build
Browse files Browse the repository at this point in the history
Include network client ID in addTransaction calls.
Include network client ID in updateIncomingTransactions calls.
Include network client Id in getNetworkNonce calls.
Update calls to wipeTransactions.
Create global network utils.
Move getGlobalEthQuery to global network utils.
Add network client ID to test data.
  • Loading branch information
matthewwalsh0 committed Nov 17, 2024
1 parent 95fbed4 commit 33e2207
Show file tree
Hide file tree
Showing 34 changed files with 275 additions and 131 deletions.
8 changes: 5 additions & 3 deletions app/components/Nav/Main/RootRPCMethodsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import { updateSwapsTransaction } from '../../../util/swaps/swaps-transactions';

///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
import InstallSnapApproval from '../../Approvals/InstallSnapApproval';
import { getGlobalEthQuery } from '../../../util/networks/global-network';
///: END:ONLY_INCLUDE_IF

const hstInterface = new ethers.utils.Interface(abi);
Expand Down Expand Up @@ -157,7 +158,7 @@ const RootRPCMethodsUI = (props) => {
({ id }) => id === approvalTransactionMetaId,
);

const ethQuery = Engine.getGlobalEthQuery();
const ethQuery = getGlobalEthQuery();

const ethBalance = await query(ethQuery, 'getBalance', [
props.selectedAddress,
Expand Down Expand Up @@ -304,7 +305,7 @@ const RootRPCMethodsUI = (props) => {
transactionId: transactionMeta.id,
deviceId,
// eslint-disable-next-line no-empty-function
onConfirmationComplete: () => {},
onConfirmationComplete: () => { },
type: 'signTransaction',
}),
);
Expand Down Expand Up @@ -356,6 +357,7 @@ const RootRPCMethodsUI = (props) => {
autoSign(transactionMeta);
} else {
const {
networkClientId,
txParams: { value, gas, gasPrice, data },
} = transactionMeta;
const { AssetsContractController } = Engine.context;
Expand All @@ -367,7 +369,7 @@ const RootRPCMethodsUI = (props) => {
data &&
data !== '0x' &&
to &&
(await getMethodData(data)).name === TOKEN_METHOD_TRANSFER
(await getMethodData(data, networkClientId)).name === TOKEN_METHOD_TRANSFER
) {
let asset = props.tokens.find(({ address }) =>
toLowerCaseEquals(address, to),
Expand Down
13 changes: 10 additions & 3 deletions app/components/Nav/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { useMinimumVersions } from '../../hooks/MinimumVersions';
import navigateTermsOfUse from '../../../util/termsOfUse/termsOfUse';
import {
selectChainId,
selectNetworkClientId,
selectNetworkConfigurations,
selectProviderConfig,
selectProviderType,
Expand All @@ -82,6 +83,7 @@ import {
} from '../../../util/transaction-controller';
import isNetworkUiRedesignEnabled from '../../../util/networks/isNetworkUiRedesignEnabled';
import { useConnectionHandler } from '../../../util/navigation/useConnectionHandler';
import { getGlobalEthQuery } from '../../../util/networks/global-network';

const Stack = createStackNavigator();

Expand Down Expand Up @@ -137,7 +139,7 @@ const Main = (props) => {
const checkInfuraAvailability = useCallback(async () => {
if (props.providerType !== 'rpc') {
try {
const ethQuery = Engine.getGlobalEthQuery();
const ethQuery = getGlobalEthQuery();
await query(ethQuery, 'blockNumber', []);
props.setInfuraAvailabilityNotBlocked();
} catch (e) {
Expand Down Expand Up @@ -175,11 +177,11 @@ const Main = (props) => {
removeNotVisibleNotifications();

BackgroundTimer.runBackgroundTimer(async () => {
await updateIncomingTransactions();
await updateIncomingTransactions([props.networkClientId]);
}, AppConstants.TX_CHECK_BACKGROUND_FREQUENCY);
}
},
[backgroundMode, removeNotVisibleNotifications],
[backgroundMode, removeNotVisibleNotifications, props.networkClientId],
);

const initForceReload = () => {
Expand Down Expand Up @@ -447,13 +449,18 @@ Main.propTypes = {
* backup seed phrase modal visible
*/
backUpSeedphraseVisible: PropTypes.bool,
/**
* ID of the global network client
*/
networkClientId: PropTypes.string,
};

const mapStateToProps = (state) => ({
showIncomingTransactionsNetworks:
selectShowIncomingTransactionNetworks(state),
providerType: selectProviderType(state),
chainId: selectChainId(state),
networkClientId: selectNetworkClientId(state),
backUpSeedphraseVisible: state.user.backUpSeedphraseVisible,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { generateTransferData } from '../../../../../util/transactions';
import useAnalytics from '../../hooks/useAnalytics';
import { toHex } from '@metamask/controller-utils';
import { RAMPS_SEND } from '../../constants';
import { selectNetworkClientId } from '../../../../../selectors/networkController';

interface SendTransactionParams {
orderId?: string;
Expand All @@ -70,6 +71,7 @@ function SendTransaction() {
const order = useSelector((state: RootState) =>
getOrderById(state, params.orderId),
);
const networkClientId = useSelector(selectNetworkClientId);
const trackEvent = useAnalytics();

const [isConfirming, setIsConfirming] = useState(false);
Expand Down Expand Up @@ -165,10 +167,13 @@ function SendTransaction() {
// but RampTransaction type / interface expecting it to be a number
transactionAnalyticsPayload,
);

const response = await addTransaction(transactionParams, {
deviceConfirmedOn: WalletDevice.MM_MOBILE,
networkClientId,
origin: RAMPS_SEND,
});

const hash = await response.result;

if (order?.id) {
Expand Down Expand Up @@ -200,6 +205,7 @@ function SendTransaction() {
orderData,
trackEvent,
transactionAnalyticsPayload,
networkClientId,
]);

if (!order) {
Expand Down
7 changes: 7 additions & 0 deletions app/components/UI/Stake/hooks/usePoolStakedClaim/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isRequestClaimable,
transformAggregatedClaimableExitRequestToMulticallArgs,
} from './utils';
import { getGlobalNetworkClientId } from '../../../../../util/networks/global-network';

const attemptMultiCallClaimTransaction = async (
pooledStakesData: PooledStake,
Expand Down Expand Up @@ -42,8 +43,11 @@ const attemptMultiCallClaimTransaction = async (
gasLimit.toString(),
);

const networkClientId = getGlobalNetworkClientId();

return addTransaction(txParams, {
deviceConfirmedOn: WalletDevice.MM_MOBILE,
networkClientId,
origin: ORIGIN_METAMASK,
type: TransactionType.stakingClaim,
});
Expand Down Expand Up @@ -85,8 +89,11 @@ const attemptSingleClaimTransaction = async (
gasLimit.toString(),
);

const networkClientId = getGlobalNetworkClientId();

return addTransaction(txParams, {
deviceConfirmedOn: WalletDevice.MM_MOBILE,
networkClientId,
origin: ORIGIN_METAMASK,
type: TransactionType.stakingClaim,
});
Expand Down
5 changes: 4 additions & 1 deletion app/components/UI/Stake/hooks/usePoolStakedDeposit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { addTransaction } from '../../../../../util/transaction-controller';
import { formatEther } from 'ethers/lib/utils';
import { useStakeContext } from '../useStakeContext';
import trackErrorAsAnalytics from '../../../../../util/metrics/TrackError/trackErrorAsAnalytics';
import { getGlobalNetworkClientId } from '../../../../../util/networks/global-network';

const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

Expand Down Expand Up @@ -60,9 +61,11 @@ const attemptDepositTransaction =
chainId,
);

// TODO: Add Stake/Unstake/Claim TransactionType to display contract method in confirmation screen.
const networkClientId = getGlobalNetworkClientId();

return await addTransaction(txParams, {
deviceConfirmedOn: WalletDevice.MM_MOBILE,
networkClientId,
origin: ORIGIN_METAMASK,
type: TransactionType.stakingDeposit,
});
Expand Down
4 changes: 4 additions & 0 deletions app/components/UI/Stake/hooks/usePoolStakedUnstake/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { addTransaction } from '../../../../../util/transaction-controller';
import { ORIGIN_METAMASK } from '@metamask/controller-utils';
import trackErrorAsAnalytics from '../../../../../util/metrics/TrackError/trackErrorAsAnalytics';
import useBalance from '../useBalance';
import { getGlobalNetworkClientId } from '../../../../../util/networks/global-network';

const generateUnstakeTxParams = (
activeAccountAddress: string,
Expand Down Expand Up @@ -72,8 +73,11 @@ const attemptUnstakeTransaction =
chainId,
);

const networkClientId = getGlobalNetworkClientId();

return await addTransaction(txParams, {
deviceConfirmedOn: WalletDevice.MM_MOBILE,
networkClientId,
origin: ORIGIN_METAMASK,
type: TransactionType.stakingUnstake,
});
Expand Down
3 changes: 2 additions & 1 deletion app/components/UI/Swaps/QuotesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ import { selectGasFeeEstimates } from '../../../selectors/confirmTransaction';
import { selectShouldUseSmartTransaction } from '../../../selectors/smartTransactionsController';
import { selectGasFeeControllerEstimateType } from '../../../selectors/gasFeeController';
import { addSwapsTransaction } from '../../../util/swaps/swaps-transactions';
import { getGlobalEthQuery } from '../../../util/networks/global-network';

const LOG_PREFIX = 'Swaps';
const POLLING_INTERVAL = 30000;
Expand Down Expand Up @@ -794,7 +795,7 @@ function SwapsQuotesView({

const updateSwapsTransactions = useCallback(
async (transactionMeta, approvalTransactionMetaId) => {
const ethQuery = Engine.getGlobalEthQuery();
const ethQuery = getGlobalEthQuery();
const blockNumber = await query(ethQuery, 'blockNumber', []);
const currentBlock = await query(ethQuery, 'getBlockByNumber', [
blockNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
selectTransactions,
} from '../../../../selectors/transactionController';
import { swapsControllerTokens } from '../../../../reducers/swaps';
import { getGlobalEthQuery } from '../../../../util/networks/global-network';

const createStyles = (colors) =>
StyleSheet.create({
Expand Down Expand Up @@ -144,7 +145,7 @@ class TransactionDetails extends PureComponent {
};

fetchTxReceipt = async (transactionHash) => {
const ethQuery = Engine.getGlobalEthQuery();
const ethQuery = getGlobalEthQuery();
return await query(ethQuery, 'getTransactionReceipt', [transactionHash]);
};

Expand Down
16 changes: 12 additions & 4 deletions app/components/UI/Transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import NotificationManager from '../../../core/NotificationManager';
import { collectibleContractsSelector } from '../../../reducers/collectibles';
import {
selectChainId,
selectNetworkClientId,
selectNetworkConfigurations,
selectProviderConfig,
selectProviderType,
Expand Down Expand Up @@ -206,6 +207,10 @@ class Transactions extends PureComponent {
*/
onScrollThroughContent: PropTypes.func,
gasFeeEstimates: PropTypes.object,
/**
* ID of the global network client
*/
networkClientId: PropTypes.string,
};

static defaultProps = {
Expand Down Expand Up @@ -341,9 +346,11 @@ class Transactions extends PureComponent {
};

onRefresh = async () => {
const { networkClientId } = this.props;

this.setState({ refreshing: true });

await updateIncomingTransactions();
await updateIncomingTransactions([networkClientId]);

this.setState({ refreshing: false });
};
Expand Down Expand Up @@ -565,7 +572,7 @@ class Transactions extends PureComponent {
const onConfirmation = (isComplete) => {
if (isComplete) {
transaction.speedUpParams &&
transaction.speedUpParams?.type === 'SpeedUp'
transaction.speedUpParams?.type === 'SpeedUp'
? this.onSpeedUpCompleted()
: this.onCancelCompleted();
}
Expand Down Expand Up @@ -751,8 +758,8 @@ class Transactions extends PureComponent {
const transactions =
submittedTransactions && submittedTransactions.length
? submittedTransactions
.sort((a, b) => b.time - a.time)
.concat(confirmedTransactions)
.sort((a, b) => b.time - a.time)
.concat(confirmedTransactions)
: this.props.transactions;

const renderRetryGas = (rate) => {
Expand Down Expand Up @@ -900,6 +907,7 @@ class Transactions extends PureComponent {
const mapStateToProps = (state) => ({
accounts: selectAccounts(state),
chainId: selectChainId(state),
networkClientId: selectNetworkClientId(state),
collectibleContracts: collectibleContractsSelector(state),
contractExchangeRates: selectContractExchangeRates(state),
conversionRate: selectConversionRate(state),
Expand Down
10 changes: 9 additions & 1 deletion app/components/Views/Asset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '../../../reducers/swaps';
import {
selectChainId,
selectNetworkClientId,
selectNetworkConfigurations,
selectRpcUrl,
} from '../../../selectors/networkController';
Expand Down Expand Up @@ -157,6 +158,10 @@ class Asset extends PureComponent {
* Boolean that indicates if native token is supported to buy
*/
isNetworkBuyNativeTokenSupported: PropTypes.bool,
/**
* ID of the global network client
*/
networkClientId: PropTypes.string,
};

state = {
Expand Down Expand Up @@ -428,9 +433,11 @@ class Asset extends PureComponent {
};

onRefresh = async () => {
const { networkClientId } = this.props;

this.setState({ refreshing: true });

await updateIncomingTransactions();
await updateIncomingTransactions([networkClientId]);

this.setState({ refreshing: false });
};
Expand Down Expand Up @@ -521,6 +528,7 @@ const mapStateToProps = (state) => ({
selectChainId(state),
getRampNetworks(state),
),
networkClientId: selectNetworkClientId(state),
});

export default connect(mapStateToProps)(withMetricsAwareness(Asset));
2 changes: 1 addition & 1 deletion app/components/Views/NetworkSelector/NetworkSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ const NetworkSelector = () => {
AccountTrackerController.refresh();

setTimeout(async () => {
await updateIncomingTransactions();
await updateIncomingTransactions([clientId]);
}, 1000);
}

Expand Down
2 changes: 1 addition & 1 deletion app/components/Views/Settings/AdvancedSettings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class AdvancedSettings extends PureComponent {

resetAccount = () => {
const { navigation } = this.props;
wipeTransactions(true);
wipeTransactions();
navigation.navigate('WalletView');
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ export class NetworkSettings extends PureComponent {
NetworkController.setActiveNetwork(networkClientId);

setTimeout(async () => {
await updateIncomingTransactions();
await updateIncomingTransactions([networkClientId]);
}, 1000);
};

Expand Down
2 changes: 1 addition & 1 deletion app/components/Views/Settings/NetworksSettings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class NetworksSettings extends PureComponent {
NetworkController.setProviderType(MAINNET);

setTimeout(async () => {
await updateIncomingTransactions();
await updateIncomingTransactions([MAINNET]);
}, 1000);
};

Expand Down
Loading

0 comments on commit 33e2207

Please sign in to comment.