Skip to content

Commit

Permalink
Merge branch 'develop' into feat/paymaster-row
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwalsh0 committed Jun 21, 2024
2 parents e06b707 + 533a483 commit a3f9eca
Show file tree
Hide file tree
Showing 93 changed files with 2,783 additions and 1,065 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ executors:
resource_class: small
playwright:
docker:
- image: mcr.microsoft.com/playwright:v1.42.1-focal
- image: mcr.microsoft.com/playwright:v1.44.1-focal
resource_class: medium

orbs:
Expand Down Expand Up @@ -776,11 +776,11 @@ jobs:
prep-build-test-mmi-playwright:
executor: node-browsers-medium-plus
steps:
- run: *shallow-git-clone
- run: sudo corepack enable
- attach_workspace:
at: .
- run: *check-mmi-optional
- run: *shallow-git-clone
- run: sudo corepack enable
- run:
name: Build MMI extension for Playwright e2e
command: |
Expand Down Expand Up @@ -1281,11 +1281,11 @@ jobs:
executor: playwright
parallelism: 2
steps:
- run: *shallow-git-clone
- run: corepack enable
- attach_workspace:
at: .
- run: *check-mmi-optional
- run: *shallow-git-clone
- run: corepack enable
- run:
name: Move test build to dist
command: mv ./dist-test-mmi-playwright ./dist
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ test-results/
# This file is used to authenticate with the GitHub Package registry, to
# enable the use of @metamask preview builds.
.npmrc
#yarn

# Yarn
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
**/.yarn/*
development/generate-attributions/.yarn/*

# MMI Playwright
public/playwright
Expand Down
4 changes: 4 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module.exports = {
'@storybook/addon-designs',
],
staticDirs: ['../app', './images'],
env: (config) => ({
...config,
ENABLE_CONFIRMATION_REDESIGN: true,
}),
// Uses babel.config.js settings and prevents "Missing class properties transform" error
babel: async (options) => ({
overrides: options.overrides,
Expand Down
12 changes: 12 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/images/icons/customize.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions app/scripts/controllers/swaps.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER,
FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
} from '../../../shared/constants/smartTransactions';
import { MINUTE } from '../../../shared/constants/time';

import type { SwapsControllerState } from './swaps.types';

// The MAX_GAS_LIMIT is a number that is higher than the maximum gas costs we have observed on any aggregator
export const MAX_GAS_LIMIT = 2500000;

// To ensure that our serves are not spammed if MetaMask is left idle, we limit the number of fetches for quotes that are made on timed intervals.
// 3 seems to be an appropriate balance of giving users the time they need when MetaMask is not left idle, and turning polling off when it is.
export const POLL_COUNT_LIMIT = 3;

// If for any reason the MetaSwap API fails to provide a refresh time,
// provide a reasonable fallback to avoid further errors
export const FALLBACK_QUOTE_REFRESH_TIME = MINUTE;

export const swapsControllerInitialState: { swapsState: SwapsControllerState } =
{
swapsState: {
quotes: {},
quotesPollingLimitEnabled: false,
fetchParams: null,
tokens: null,
tradeTxId: null,
approveTxId: null,
quotesLastFetched: null,
customMaxGas: '',
customGasPrice: null,
customMaxFeePerGas: null,
customMaxPriorityFeePerGas: null,
swapsUserFeeLevel: '',
selectedAggId: null,
customApproveTxData: '',
errorKey: '',
topAggId: null,
routeState: '',
swapsFeatureIsLive: true,
saveFetchedQuotes: false,
swapsQuoteRefreshTime: FALLBACK_QUOTE_REFRESH_TIME,
swapsQuotePrefetchingRefreshTime: FALLBACK_QUOTE_REFRESH_TIME,
swapsStxBatchStatusRefreshTime: FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
swapsStxGetTransactionsRefreshTime:
FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
swapsStxMaxFeeMultiplier: FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER,
swapsFeatureFlags: {},
},
};
29 changes: 14 additions & 15 deletions app/scripts/controllers/swaps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER,
} from '../../../shared/constants/smartTransactions';
import SwapsController, { utils } from './swaps';
import SwapsController from './swaps';
import { getMedianEthValueQuote } from './swaps.utils';

const MOCK_FETCH_PARAMS = {
slippage: 3,
Expand Down Expand Up @@ -179,7 +180,7 @@ describe('SwapsController', function () {
expect(swapsController.getBufferedGasLimit).toStrictEqual(
MOCK_GET_BUFFERED_GAS_LIMIT,
);
expect(swapsController.pollCount).toStrictEqual(0);
expect(swapsController._pollCount).toStrictEqual(0);
expect(swapsController.getProviderConfig).toStrictEqual(
MOCK_GET_PROVIDER_CONFIG,
);
Expand Down Expand Up @@ -716,7 +717,7 @@ describe('SwapsController', function () {

const timedoutGasReturnResult = { gasLimit: 1000000 };
const timedoutGasReturnSpy = jest
.spyOn(swapsController, 'timedoutGasReturn')
.spyOn(swapsController, '_timedoutGasReturn')
.mockReturnValue(timedoutGasReturnResult);

await swapsController.fetchAndSetQuotes(
Expand Down Expand Up @@ -820,7 +821,7 @@ describe('SwapsController', function () {

const _swapsController = getSwapsController();

const currentEthersInstance = _swapsController.ethersProvider;
const currentEthersInstance = _swapsController._ethersProvider;

// Make the network fetch error message disappear
jest
Expand All @@ -832,7 +833,7 @@ describe('SwapsController', function () {
chainId: CHAIN_IDS.GOERLI,
});

const newEthersInstance = _swapsController.ethersProvider;
const newEthersInstance = _swapsController._ethersProvider;
expect(currentEthersInstance).not.toStrictEqual(newEthersInstance);
});

Expand All @@ -845,7 +846,7 @@ describe('SwapsController', function () {
fetchTradesInfo: fetchTradesInfoStub,
getCurrentChainId: getCurrentChainIdStub,
});
const currentEthersInstance = _swapsController.ethersProvider;
const currentEthersInstance = _swapsController._ethersProvider;

// Make the network fetch error message disappear
jest.spyOn(swapsController, '_setSwapsNetworkConfig').mockReturnValue();
Expand All @@ -855,7 +856,7 @@ describe('SwapsController', function () {
chainId: CHAIN_IDS.MAINNET,
});

const newEthersInstance = _swapsController.ethersProvider;
const newEthersInstance = _swapsController._ethersProvider;
expect(currentEthersInstance).toStrictEqual(newEthersInstance);
});

Expand All @@ -870,7 +871,7 @@ describe('SwapsController', function () {
getLayer1GasFee: getLayer1GasFeeStub,
getNetworkClientId: getNetworkClientIdStub,
});
const firstEthersInstance = _swapsController.ethersProvider;
const firstEthersInstance = _swapsController._ethersProvider;
const firstEthersProviderChainId =
_swapsController._ethersProviderChainId;

Expand All @@ -884,7 +885,7 @@ describe('SwapsController', function () {
chainId: CHAIN_IDS.GOERLI,
});

const secondEthersInstance = _swapsController.ethersProvider;
const secondEthersInstance = _swapsController._ethersProvider;
const secondEthersProviderChainId =
_swapsController._ethersProviderChainId;

Expand All @@ -898,7 +899,7 @@ describe('SwapsController', function () {
chainId: CHAIN_IDS.LOCALHOST,
});

const thirdEthersInstance = _swapsController.ethersProvider;
const thirdEthersInstance = _swapsController._ethersProvider;
const thirdEthersProviderChainId =
_swapsController._ethersProviderChainId;

Expand Down Expand Up @@ -946,7 +947,7 @@ describe('SwapsController', function () {
});

it('clears polling timeout', function () {
swapsController.pollingTimeout = setTimeout(() => {
swapsController._pollingTimeout = setTimeout(() => {
throw new Error('Polling timeout not cleared');
}, POLLING_TIMEOUT);

Expand All @@ -960,7 +961,7 @@ describe('SwapsController', function () {

describe('stopPollingForQuotes', function () {
it('clears polling timeout', function () {
swapsController.pollingTimeout = setTimeout(() => {
swapsController._pollingTimeout = setTimeout(() => {
throw new Error('Polling timeout not cleared');
}, POLLING_TIMEOUT);

Expand All @@ -981,7 +982,7 @@ describe('SwapsController', function () {

describe('resetPostFetchState', function () {
it('clears polling timeout', function () {
swapsController.pollingTimeout = setTimeout(() => {
swapsController._pollingTimeout = setTimeout(() => {
throw new Error('Polling timeout not cleared');
}, POLLING_TIMEOUT);

Expand Down Expand Up @@ -1031,8 +1032,6 @@ describe('SwapsController', function () {

describe('utils', function () {
describe('getMedianEthValueQuote', function () {
const { getMedianEthValueQuote } = utils;

it('calculates median correctly with uneven sample', function () {
const expectedResult = {
ethFee: '10',
Expand Down
Loading

0 comments on commit a3f9eca

Please sign in to comment.