Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ import {
TokenStandard,
SIGNING_METHODS,
} from '../../shared/constants/transaction';
import {
GAS_API_BASE_URL,
GAS_DEV_API_BASE_URL,
SWAPS_CLIENT_ID,
} from '../../shared/constants/swaps';
import { SWAPS_CLIENT_ID } from '../../shared/constants/swaps';
import {
CHAIN_IDS,
NETWORK_TYPES,
Expand Down Expand Up @@ -715,10 +711,6 @@ export default class MetamaskController extends EventEmitter {
allowedEvents: ['NetworkController:stateChange'],
});

const gasApiBaseUrl = process.env.SWAPS_USE_DEV_APIS
? GAS_DEV_API_BASE_URL
: GAS_API_BASE_URL;

this.gasFeeController = new GasFeeController({
state: initState.GasFeeController,
interval: 10000,
Expand All @@ -738,13 +730,12 @@ export default class MetamaskController extends EventEmitter {
),
getCurrentAccountEIP1559Compatibility:
this.getCurrentAccountEIP1559Compatibility.bind(this),
legacyAPIEndpoint: `${gasApiBaseUrl}/networks/<chain_id>/gasPrices`,
EIP1559APIEndpoint: `${gasApiBaseUrl}/networks/<chain_id>/suggestedGasFees`,
getCurrentNetworkLegacyGasAPICompatibility: () => {
const { chainId } = this.networkController.state.providerConfig;
return chainId === CHAIN_IDS.BSC;
},
getChainId: () => this.networkController.state.providerConfig.chainId,
infuraAPIKey: opts.infuraProjectId,
});

this.appStateController = new AppStateController({
Expand Down
1 change: 1 addition & 0 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,7 @@
"@metamask/ethjs>@metamask/ethjs-unit": true,
"@metamask/gas-fee-controller>@metamask/polling-controller": true,
"bn.js": true,
"browserify>buffer": true,
"uuid": true
}
},
Expand Down
1 change: 1 addition & 0 deletions lavamoat/browserify/desktop/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,7 @@
"@metamask/ethjs>@metamask/ethjs-unit": true,
"@metamask/gas-fee-controller>@metamask/polling-controller": true,
"bn.js": true,
"browserify>buffer": true,
"uuid": true
}
},
Expand Down
1 change: 1 addition & 0 deletions lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,7 @@
"@metamask/ethjs>@metamask/ethjs-unit": true,
"@metamask/gas-fee-controller>@metamask/polling-controller": true,
"bn.js": true,
"browserify>buffer": true,
"uuid": true
}
},
Expand Down
1 change: 1 addition & 0 deletions lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,7 @@
"@metamask/ethjs>@metamask/ethjs-unit": true,
"@metamask/gas-fee-controller>@metamask/polling-controller": true,
"bn.js": true,
"browserify>buffer": true,
"uuid": true
}
},
Expand Down
1 change: 1 addition & 0 deletions lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,7 @@
"@metamask/ethjs>@metamask/ethjs-unit": true,
"@metamask/gas-fee-controller>@metamask/polling-controller": true,
"bn.js": true,
"browserify>buffer": true,
"uuid": true
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
"@metamask/ethjs": "^0.6.0",
"@metamask/ethjs-contract": "^0.4.1",
"@metamask/ethjs-query": "^0.7.1",
"@metamask/gas-fee-controller": "^14.0.0",
"@metamask/gas-fee-controller": "^15.0.0",
"@metamask/jazzicon": "^2.0.0",
"@metamask/keyring-api": "^3.0.0",
"@metamask/keyring-controller": "^13.0.0",
Expand Down
2 changes: 1 addition & 1 deletion privacy-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"etherscan.io",
"execution.metamask.io",
"fonts.gstatic.com",
"gas.api.cx.metamask.io",
"gas.api.infura.io",
"github.com",
"goerli.infura.io",
"localhost:8000",
Expand Down
2 changes: 1 addition & 1 deletion shared/constants/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const SWAPS_TESTNET_CHAIN_ID = '0x539';

export const SWAPS_API_V2_BASE_URL = 'https://swap.metaswap.codefi.network';
export const SWAPS_DEV_API_V2_BASE_URL = 'https://swap.dev-api.cx.metamask.io';
export const GAS_API_BASE_URL = 'https://gas.api.cx.metamask.io';
export const GAS_API_BASE_URL = 'https://gas.api.infura.io';
export const GAS_DEV_API_BASE_URL = 'https://gas.uat-api.cx.metamask.io';

const BSC_DEFAULT_BLOCK_EXPLORER_URL = 'https://bscscan.com/';
Expand Down
3 changes: 1 addition & 2 deletions shared/lib/swaps-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import log from 'loglevel';
import { CHAIN_IDS } from '../constants/network';
import {
GAS_API_BASE_URL,
GAS_DEV_API_BASE_URL,
SWAPS_API_V2_BASE_URL,
SWAPS_CHAINID_DEFAULT_TOKEN_MAP,
SWAPS_CLIENT_ID,
Expand Down Expand Up @@ -130,7 +129,7 @@ const getBaseUrlForNewSwapsApi = (type, chainId) => {
const v2ApiBaseUrl = useDevApis
? SWAPS_DEV_API_V2_BASE_URL
: SWAPS_API_V2_BASE_URL;
const gasApiBaseUrl = useDevApis ? GAS_DEV_API_BASE_URL : GAS_API_BASE_URL;
const gasApiBaseUrl = GAS_API_BASE_URL;
const noNetworkSpecificTypes = ['refreshTime']; // These types don't need network info in the URL.
if (noNetworkSpecificTypes.includes(type)) {
return v2ApiBaseUrl;
Expand Down
48 changes: 48 additions & 0 deletions test/e2e/mock-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,54 @@ async function setupMocking(server, testSpecificMock, { chainId }) {
};
});

// Both are added to support swaps e2e tests
Copy link
Member Author

@OGPoyraz OGPoyraz Mar 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gas prices are fetch within swaps UI

I am not sure why chainId is override in the tests

Basically if we don't put these mocks then swaps e2e tests will fail, because it's not being caught by XHR mocks and auth modal will appear (as expected in the screenshot)

This is a quick fix but just patching the current implementation, fyi

Screenshot 2024-03-28 at 17 47 19

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, are you saying you believe this wasn't being mocked previously and was hitting the real endpoint?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this issue went unnoticed previously because the former endpoint shared the same domain, allowing it to bypass the privacy snapshot. However, the new endpoint is protected by authentication, which explains why it is prompting for credentials, as in the screenshot.

await server
.forGet(`${GAS_API_BASE_URL}/networks/1/gasPrices`)
.thenCallback(() => {
return {
statusCode: 200,
json: {
SafeGasPrice: '1',
ProposeGasPrice: '2',
FastGasPrice: '3',
},
};
});
await server
.forGet(`${GAS_API_BASE_URL}/networks/1/suggestedGasFees`)
.thenCallback(() => {
return {
statusCode: 200,
json: {
low: {
suggestedMaxPriorityFeePerGas: '1',
suggestedMaxFeePerGas: '20.44436136',
minWaitTimeEstimate: 15000,
maxWaitTimeEstimate: 30000,
},
medium: {
suggestedMaxPriorityFeePerGas: '1.5',
suggestedMaxFeePerGas: '25.80554517',
minWaitTimeEstimate: 15000,
maxWaitTimeEstimate: 45000,
},
high: {
suggestedMaxPriorityFeePerGas: '2',
suggestedMaxFeePerGas: '27.277766977',
minWaitTimeEstimate: 15000,
maxWaitTimeEstimate: 60000,
},
estimatedBaseFee: '19.444436136',
networkCongestion: 0.14685,
latestPriorityFeeRange: ['0.378818859', '6.555563864'],
historicalPriorityFeeRange: ['0.1', '248.262969261'],
historicalBaseFeeRange: ['14.146999781', '28.825256275'],
priorityFeeTrend: 'down',
baseFeeTrend: 'up',
},
};
});

await server
.forGet('https://swap.metaswap.codefi.network/networks/1/token')
.withQuery({ address: '0x72c9Fb7ED19D3ce51cea5C56B3e023cd918baaDf' })
Expand Down
2 changes: 1 addition & 1 deletion test/jest/constants.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const METASWAP_BASE_URL = 'https://swap.metaswap.codefi.network';
export const GAS_API_URL = 'https://gas.api.cx.metamask.io';
export const GAS_API_URL = 'https://gas.api.infura.io';
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4617,7 +4617,7 @@ __metadata:
languageName: node
linkType: hard

"@metamask/gas-fee-controller@npm:^14.0.0, @metamask/gas-fee-controller@npm:^14.0.1":
"@metamask/gas-fee-controller@npm:^14.0.1":
version: 14.0.1
resolution: "@metamask/gas-fee-controller@npm:14.0.1"
dependencies:
Expand Down Expand Up @@ -24826,7 +24826,7 @@ __metadata:
"@metamask/ethjs-contract": "npm:^0.4.1"
"@metamask/ethjs-query": "npm:^0.7.1"
"@metamask/forwarder": "npm:^1.1.0"
"@metamask/gas-fee-controller": "npm:^14.0.0"
"@metamask/gas-fee-controller": "npm:^15.0.0"
"@metamask/jazzicon": "npm:^2.0.0"
"@metamask/keyring-api": "npm:^3.0.0"
"@metamask/keyring-controller": "npm:^13.0.0"
Expand Down