Skip to content

Commit

Permalink
Merge branch 'develop' into caip-multichain
Browse files Browse the repository at this point in the history
  • Loading branch information
jiexi committed Oct 7, 2024
2 parents a392615 + 93500d2 commit a213b7e
Show file tree
Hide file tree
Showing 106 changed files with 1,822 additions and 1,207 deletions.
4 changes: 4 additions & 0 deletions .metamaskrc.dist
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ BLOCKAID_PUBLIC_KEY=
; Enable/disable why did you render debug tool: https://github.com/welldone-software/why-did-you-render
; This should NEVER be enabled in production since it slows down react
; ENABLE_WHY_DID_YOU_RENDER=false

; API key used in Etherscan requests to prevent rate limiting.
; Only applies to Mainnet and Sepolia.
; ETHERSCAN_API_KEY=
2 changes: 2 additions & 0 deletions app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export const SENTRY_BACKGROUND_STATE = {
},
destTokens: {},
destTopAssets: [],
srcTokens: {},
srcTopAssets: [],
},
},
CronjobController: {
Expand Down
24 changes: 24 additions & 0 deletions app/scripts/controllers/bridge/bridge-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,28 @@ describe('BridgeController', function () {
{ address: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', symbol: 'ABC' },
]);
});

it('selectSrcNetwork should set the bridge src tokens and top assets', async function () {
await bridgeController.selectSrcNetwork('0xa');
expect(bridgeController.state.bridgeState.srcTokens).toStrictEqual({
'0x0000000000000000000000000000000000000000': {
address: '0x0000000000000000000000000000000000000000',
decimals: 18,
iconUrl: './images/eth_logo.svg',
name: 'Ether',
symbol: 'ETH',
},
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984': {
address: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
symbol: 'ABC',
decimals: 16,
},
});
expect(bridgeController.state.bridgeState.srcTopAssets).toStrictEqual([
{
address: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
symbol: 'ABC',
},
]);
});
});
9 changes: 9 additions & 0 deletions app/scripts/controllers/bridge/bridge-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export default class BridgeController extends BaseController<
`${BRIDGE_CONTROLLER_NAME}:setBridgeFeatureFlags`,
this.setBridgeFeatureFlags.bind(this),
);
this.messagingSystem.registerActionHandler(
`${BRIDGE_CONTROLLER_NAME}:selectSrcNetwork`,
this.selectSrcNetwork.bind(this),
);
this.messagingSystem.registerActionHandler(
`${BRIDGE_CONTROLLER_NAME}:selectDestNetwork`,
this.selectDestNetwork.bind(this),
Expand All @@ -61,6 +65,11 @@ export default class BridgeController extends BaseController<
});
};

selectSrcNetwork = async (chainId: Hex) => {
await this.#setTopAssets(chainId, 'srcTopAssets');
await this.#setTokens(chainId, 'srcTokens');
};

selectDestNetwork = async (chainId: Hex) => {
await this.#setTopAssets(chainId, 'destTopAssets');
await this.#setTokens(chainId, 'destTokens');
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/controllers/bridge/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const DEFAULT_BRIDGE_CONTROLLER_STATE: BridgeControllerState = {
[BridgeFeatureFlagsKey.NETWORK_SRC_ALLOWLIST]: [],
[BridgeFeatureFlagsKey.NETWORK_DEST_ALLOWLIST]: [],
},
srcTokens: {},
srcTopAssets: [],
destTokens: {},
destTopAssets: [],
};
4 changes: 4 additions & 0 deletions app/scripts/controllers/bridge/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ export type BridgeFeatureFlags = {

export type BridgeControllerState = {
bridgeFeatureFlags: BridgeFeatureFlags;
srcTokens: Record<string, SwapsTokenObject>;
srcTopAssets: { address: string }[];
destTokens: Record<string, SwapsTokenObject>;
destTopAssets: { address: string }[];
};

export enum BridgeUserAction {
SELECT_SRC_NETWORK = 'selectSrcNetwork',
SELECT_DEST_NETWORK = 'selectDestNetwork',
}
export enum BridgeBackgroundAction {
Expand All @@ -40,6 +43,7 @@ type BridgeControllerAction<FunctionName extends keyof BridgeController> = {
// Maps to BridgeController function names
type BridgeControllerActions =
| BridgeControllerAction<BridgeBackgroundAction.SET_FEATURE_FLAGS>
| BridgeControllerAction<BridgeUserAction.SELECT_SRC_NETWORK>
| BridgeControllerAction<BridgeUserAction.SELECT_DEST_NETWORK>;

type BridgeControllerEvents = ControllerStateChangeEvent<
Expand Down
10 changes: 9 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,10 @@ export default class MetamaskController extends EventEmitter {
getCurrentChainId({ metamask: this.networkController.state })
],
incomingTransactions: {
etherscanApiKeysByChainId: {
[CHAIN_IDS.MAINNET]: process.env.ETHERSCAN_API_KEY,
[CHAIN_IDS.SEPOLIA]: process.env.ETHERSCAN_API_KEY,
},
includeTokenTransfers: false,
isEnabled: () =>
Boolean(
Expand Down Expand Up @@ -3949,6 +3953,10 @@ export default class MetamaskController extends EventEmitter {
this.controllerMessenger,
`${BRIDGE_CONTROLLER_NAME}:${BridgeBackgroundAction.SET_FEATURE_FLAGS}`,
),
[BridgeUserAction.SELECT_SRC_NETWORK]: this.controllerMessenger.call.bind(
this.controllerMessenger,
`${BRIDGE_CONTROLLER_NAME}:${BridgeUserAction.SELECT_SRC_NETWORK}`,
),
[BridgeUserAction.SELECT_DEST_NETWORK]:
this.controllerMessenger.call.bind(
this.controllerMessenger,
Expand Down Expand Up @@ -4182,7 +4190,7 @@ export default class MetamaskController extends EventEmitter {
const { tokens } = this.tokensController.state;

const staticTokenListDetails =
STATIC_MAINNET_TOKEN_LIST[address.toLowerCase()] || {};
STATIC_MAINNET_TOKEN_LIST[address?.toLowerCase()] || {};
const tokenListDetails = tokenList[address.toLowerCase()] || {};
const userDefinedTokenDetails =
tokens.find(({ address: _address }) =>
Expand Down
5 changes: 4 additions & 1 deletion builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,10 @@ env:
- SECURITY_ALERTS_API_ENABLED: ''
# URL of security alerts API used to validate dApp requests
- SECURITY_ALERTS_API_URL: 'http://localhost:3000'
# API key to authenticate Etherscan requests to avoid rate limiting
- ETHERSCAN_API_KEY: ''

# Enables the notifications feature within the build:
# Enables the notifications feature within the build:
- NOTIFICATIONS: ''

- METAMASK_RAMP_API_CONTENT_BASE_URL: https://on-ramp-content.api.cx.metamask.io
Expand All @@ -291,6 +293,7 @@ env:
###

- EIP_4337_ENTRYPOINT: null

###
# Enable/disable why did you render debug tool: https://github.com/welldone-software/why-did-you-render
# This should NEVER be enabled in production since it slows down react
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@
"@metamask-institutional/transaction-update": "^0.2.5",
"@metamask-institutional/types": "^1.1.0",
"@metamask/abi-utils": "^2.0.2",
"@metamask/account-watcher": "^4.1.0",
"@metamask/accounts-controller": "^18.2.1",
"@metamask/account-watcher": "^4.1.1",
"@metamask/accounts-controller": "^18.2.2",
"@metamask/address-book-controller": "^6.0.0",
"@metamask/announcement-controller": "^7.0.0",
"@metamask/api-specs": "^0.10.12",
"@metamask/approval-controller": "^7.0.0",
"@metamask/assets-controllers": "^37.0.0",
"@metamask/base-controller": "^7.0.0",
"@metamask/bitcoin-wallet-snap": "^0.6.0",
"@metamask/bitcoin-wallet-snap": "^0.6.1",
"@metamask/browser-passworder": "^4.3.0",
"@metamask/contract-metadata": "^2.5.0",
"@metamask/controller-utils": "^11.2.0",
Expand All @@ -323,17 +323,17 @@
"@metamask/eth-ledger-bridge-keyring": "^3.0.1",
"@metamask/eth-query": "^4.0.0",
"@metamask/eth-sig-util": "^7.0.1",
"@metamask/eth-snap-keyring": "^4.3.3",
"@metamask/eth-snap-keyring": "^4.3.6",
"@metamask/eth-token-tracker": "^8.0.0",
"@metamask/eth-trezor-keyring": "^3.1.0",
"@metamask/eth-trezor-keyring": "^3.1.3",
"@metamask/etherscan-link": "^3.0.0",
"@metamask/ethjs": "^0.6.0",
"@metamask/ethjs-contract": "^0.4.1",
"@metamask/ethjs-query": "^0.7.1",
"@metamask/gas-fee-controller": "^18.0.0",
"@metamask/jazzicon": "^2.0.0",
"@metamask/keyring-api": "^8.1.0",
"@metamask/keyring-controller": "^17.2.1",
"@metamask/keyring-api": "^8.1.3",
"@metamask/keyring-controller": "^17.2.2",
"@metamask/logging-controller": "^6.0.0",
"@metamask/logo": "^3.1.2",
"@metamask/message-manager": "^10.1.0",
Expand Down Expand Up @@ -366,7 +366,7 @@
"@metamask/snaps-rpc-methods": "^11.1.1",
"@metamask/snaps-sdk": "^6.5.1",
"@metamask/snaps-utils": "^8.1.1",
"@metamask/transaction-controller": "^37.0.0",
"@metamask/transaction-controller": "^37.2.0",
"@metamask/user-operation-controller": "^13.0.0",
"@metamask/utils": "^9.2.0",
"@ngraveio/bc-ur": "^1.1.12",
Expand Down
4 changes: 2 additions & 2 deletions test/data/mock-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,8 @@
"developer": "Metamask",
"website": "https://www.consensys.io/",
"auditUrls": ["auditUrl1", "auditUrl2"],
"version": "1.0.0",
"lastUpdated": "April 20, 2023"
"version": "1.1.6",
"lastUpdated": "September 26, 2024"
}
},
"notifications": {
Expand Down
94 changes: 0 additions & 94 deletions test/e2e/accounts/remove-account-snap.spec.ts

This file was deleted.

4 changes: 2 additions & 2 deletions test/e2e/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const BUNDLER_URL = 'http://localhost:3000/rpc';

/* URL of the 4337 account snap site. */
export const ERC_4337_ACCOUNT_SNAP_URL =
'https://metamask.github.io/snap-account-abstraction-keyring/0.4.1/';
'https://metamask.github.io/snap-account-abstraction-keyring/0.4.2/';

/* Salt used to generate the 4337 account. */
export const ERC_4337_ACCOUNT_SALT = '0x1';
Expand All @@ -31,7 +31,7 @@ export const SIMPLE_ACCOUNT_FACTORY =

/* URL of the Snap Simple Keyring site. */
export const TEST_SNAPS_SIMPLE_KEYRING_WEBSITE_URL =
'https://metamask.github.io/snap-simple-keyring/1.1.2/';
'https://metamask.github.io/snap-simple-keyring/1.1.6/';

/* Address of the VerifyingPaymaster smart contract deployed to Ganache. */
export const VERIFYING_PAYMASTER = '0xbdbDEc38ed168331b1F7004cc9e5392A2272C1D7';
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/default-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ function defaultFixture(inputChainId = CHAIN_IDS.LOCALHOST) {
},
destTokens: {},
destTopAssets: [],
srcTokens: {},
srcTopAssets: [],
},
},
CurrencyController: {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ class FixtureBuilder {
},
destTokens: {},
destTopAssets: [],
srcTokens: {},
srcTopAssets: [],
},
};
return this;
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/page-objects/flows/snap-simple-keyring.flow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Driver } from '../../webdriver/driver';
import SnapSimpleKeyringPage from '../pages/snap-simple-keyring-page';
import { TEST_SNAPS_SIMPLE_KEYRING_WEBSITE_URL } from '../../constants';

/**
* Go to the Snap Simple Keyring page and install the snap.
*
* @param driver - The WebDriver instance used to interact with the browser.
* @param isSyncFlow - Indicates whether to toggle on the use synchronous approval option on the snap. Defaults to true.
*/
export async function installSnapSimpleKeyring(
driver: Driver,
isSyncFlow: boolean = true,
) {
await driver.openNewPage(TEST_SNAPS_SIMPLE_KEYRING_WEBSITE_URL);

const snapSimpleKeyringPage = new SnapSimpleKeyringPage(driver);
await snapSimpleKeyringPage.check_pageIsLoaded();
await snapSimpleKeyringPage.installSnap();
if (isSyncFlow) {
await snapSimpleKeyringPage.toggleUseSyncApproval();
}
}
Loading

0 comments on commit a213b7e

Please sign in to comment.