diff --git a/app/images/matic-token.png b/app/images/matic-token.png new file mode 100644 index 000000000..b154c46ea Binary files /dev/null and b/app/images/matic-token.png differ diff --git a/shared/constants/network.js b/shared/constants/network.js index 66bd1e949..1d22b5271 100644 --- a/shared/constants/network.js +++ b/shared/constants/network.js @@ -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]; diff --git a/shared/constants/swaps.js b/shared/constants/swaps.js index 00512c0cc..dba447b2c 100644 --- a/shared/constants/swaps.js +++ b/shared/constants/swaps.js @@ -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'; diff --git a/ui/pages/swaps/swaps.util.js b/ui/pages/swaps/swaps.util.js index 068c3f870..160cded10 100644 --- a/ui/pages/swaps/swaps.util.js +++ b/ui/pages/swaps/swaps.util.js @@ -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?`;