mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add support for Polygon (#11545)
* Fix a check for EIP presense * Add support for Polygon * Update default Polygon URL * Trigger Build * Use a more user-friendly error message for disabled Swaps API calls
This commit is contained in:
parent
b7ee6f47f8
commit
eb3b9e213b
BIN
app/images/matic-token.png
Normal file
BIN
app/images/matic-token.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
@ -49,10 +49,12 @@ export const ETH_SYMBOL = 'ETH';
|
||||
export const WETH_SYMBOL = 'WETH';
|
||||
export const TEST_ETH_SYMBOL = 'TESTETH';
|
||||
export const BNB_SYMBOL = 'BNB';
|
||||
export const MATIC_SYMBOL = 'MATIC';
|
||||
|
||||
export const ETH_TOKEN_IMAGE_URL = './images/eth_logo.svg';
|
||||
export const TEST_ETH_TOKEN_IMAGE_URL = './images/black-eth-logo.svg';
|
||||
export const BNB_TOKEN_IMAGE_URL = './images/bnb.png';
|
||||
export const MATIC_TOKEN_IMAGE_URL = './images/matic-token.png';
|
||||
|
||||
export const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET, GOERLI];
|
||||
|
||||
|
@ -6,6 +6,9 @@ import {
|
||||
TEST_ETH_TOKEN_IMAGE_URL,
|
||||
BNB_TOKEN_IMAGE_URL,
|
||||
BSC_CHAIN_ID,
|
||||
POLYGON_CHAIN_ID,
|
||||
MATIC_SYMBOL,
|
||||
MATIC_TOKEN_IMAGE_URL,
|
||||
} from './network';
|
||||
|
||||
export const QUOTES_EXPIRED_ERROR = 'quotes-expired';
|
||||
@ -35,6 +38,14 @@ export const BNB_SWAPS_TOKEN_OBJECT = {
|
||||
iconUrl: BNB_TOKEN_IMAGE_URL,
|
||||
};
|
||||
|
||||
export const MATIC_SWAPS_TOKEN_OBJECT = {
|
||||
symbol: MATIC_SYMBOL,
|
||||
name: 'Matic',
|
||||
address: DEFAULT_TOKEN_ADDRESS,
|
||||
decimals: 18,
|
||||
iconUrl: MATIC_TOKEN_IMAGE_URL,
|
||||
};
|
||||
|
||||
export const TEST_ETH_SWAPS_TOKEN_OBJECT = {
|
||||
symbol: TEST_ETH_SYMBOL,
|
||||
name: 'Test Ether',
|
||||
@ -52,6 +63,9 @@ const TESTNET_CONTRACT_ADDRESS = '0x881d40237659c251811cec9c364ef91dc08d300c';
|
||||
|
||||
const BSC_CONTRACT_ADDRESS = '0x1a1ec25dc08e98e5e93f1104b5e5cdd298707d31';
|
||||
|
||||
// It's the same as we use for BSC.
|
||||
const POLYGON_CONTRACT_ADDRESS = '0x1a1ec25dc08e98e5e93f1104b5e5cdd298707d31';
|
||||
|
||||
export const ETH_WETH_CONTRACT_ADDRESS =
|
||||
'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
|
||||
|
||||
@ -64,13 +78,16 @@ const SWAPS_TESTNET_HOST = 'https://metaswap-api.airswap-dev.codefi.network';
|
||||
|
||||
const BSC_DEFAULT_BLOCK_EXPLORER_URL = 'https://bscscan.com/';
|
||||
const MAINNET_DEFAULT_BLOCK_EXPLORER_URL = 'https://etherscan.io/';
|
||||
const POLYGON_DEFAULT_BLOCK_EXPLORER_URL = 'https://polygonscan.com/';
|
||||
|
||||
export const ALLOWED_SWAPS_CHAIN_IDS = {
|
||||
[MAINNET_CHAIN_ID]: true,
|
||||
[SWAPS_TESTNET_CHAIN_ID]: true,
|
||||
[BSC_CHAIN_ID]: true,
|
||||
[POLYGON_CHAIN_ID]: true,
|
||||
};
|
||||
|
||||
// This is mapping for v1 URLs and will be removed once we migrate to v2.
|
||||
export const METASWAP_CHAINID_API_HOST_MAP = {
|
||||
[MAINNET_CHAIN_ID]: METASWAP_ETH_API_HOST,
|
||||
[SWAPS_TESTNET_CHAIN_ID]: SWAPS_TESTNET_HOST,
|
||||
@ -81,17 +98,20 @@ export const SWAPS_CHAINID_CONTRACT_ADDRESS_MAP = {
|
||||
[MAINNET_CHAIN_ID]: MAINNET_CONTRACT_ADDRESS,
|
||||
[SWAPS_TESTNET_CHAIN_ID]: TESTNET_CONTRACT_ADDRESS,
|
||||
[BSC_CHAIN_ID]: BSC_CONTRACT_ADDRESS,
|
||||
[POLYGON_CHAIN_ID]: POLYGON_CONTRACT_ADDRESS,
|
||||
};
|
||||
|
||||
export const SWAPS_CHAINID_DEFAULT_TOKEN_MAP = {
|
||||
[MAINNET_CHAIN_ID]: ETH_SWAPS_TOKEN_OBJECT,
|
||||
[SWAPS_TESTNET_CHAIN_ID]: TEST_ETH_SWAPS_TOKEN_OBJECT,
|
||||
[BSC_CHAIN_ID]: BNB_SWAPS_TOKEN_OBJECT,
|
||||
[POLYGON_CHAIN_ID]: MATIC_SWAPS_TOKEN_OBJECT,
|
||||
};
|
||||
|
||||
export const SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP = {
|
||||
[BSC_CHAIN_ID]: BSC_DEFAULT_BLOCK_EXPLORER_URL,
|
||||
[MAINNET_CHAIN_ID]: MAINNET_DEFAULT_BLOCK_EXPLORER_URL,
|
||||
[POLYGON_CHAIN_ID]: POLYGON_DEFAULT_BLOCK_EXPLORER_URL,
|
||||
};
|
||||
|
||||
export const ETHEREUM = 'ethereum';
|
||||
|
@ -77,6 +77,9 @@ const getBaseApi = function (
|
||||
const baseUrl = useNewSwapsApi
|
||||
? getBaseUrlForNewSwapsApi(type, chainId)
|
||||
: METASWAP_CHAINID_API_HOST_MAP[chainId];
|
||||
if (!baseUrl) {
|
||||
throw new Error(`Swaps API calls are disabled for chainId: ${chainId}`);
|
||||
}
|
||||
switch (type) {
|
||||
case 'trade':
|
||||
return `${baseUrl}/trades?`;
|
||||
|
Loading…
Reference in New Issue
Block a user