Enable Avalanche for Swaps (#13653)

feature/default_network_editable
Daniel 3 years ago committed by GitHub
parent b1b4e64ad0
commit 120603e6df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/_locales/en/messages.json
  2. BIN
      app/images/avax-token.png
  3. 2
      shared/constants/network.js
  4. 28
      shared/constants/swaps.js
  5. 3
      ui/pages/swaps/fee-card/fee-card.js
  6. 4
      ui/pages/swaps/swaps.util.js
  7. 6
      ui/pages/swaps/swaps.util.test.js

@ -1857,6 +1857,9 @@
"networkName": {
"message": "Network Name"
},
"networkNameAvalanche": {
"message": "Avalanche"
},
"networkNameBSC": {
"message": "BSC"
},

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

@ -64,6 +64,7 @@ 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 AVAX_TOKEN_IMAGE_URL = './images/avax-token.png';
export const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET, GOERLI];
@ -138,6 +139,7 @@ export const NATIVE_CURRENCY_TOKEN_IMAGE_MAP = {
[TEST_ETH_SYMBOL]: TEST_ETH_TOKEN_IMAGE_URL,
[BNB_SYMBOL]: BNB_TOKEN_IMAGE_URL,
[MATIC_SYMBOL]: MATIC_TOKEN_IMAGE_URL,
[AVALANCHE_SYMBOL]: AVAX_TOKEN_IMAGE_URL,
};
export const INFURA_BLOCKED_KEY = 'countryBlocked';

@ -10,6 +10,9 @@ import {
MATIC_SYMBOL,
MATIC_TOKEN_IMAGE_URL,
RINKEBY_CHAIN_ID,
AVALANCHE_CHAIN_ID,
AVALANCHE_SYMBOL,
AVAX_TOKEN_IMAGE_URL,
} from './network';
export const QUOTES_EXPIRED_ERROR = 'quotes-expired';
@ -47,6 +50,14 @@ export const MATIC_SWAPS_TOKEN_OBJECT = {
iconUrl: MATIC_TOKEN_IMAGE_URL,
};
export const AVAX_SWAPS_TOKEN_OBJECT = {
symbol: AVALANCHE_SYMBOL,
name: 'Avalanche',
address: DEFAULT_TOKEN_ADDRESS,
decimals: 18,
iconUrl: AVAX_TOKEN_IMAGE_URL,
};
export const TEST_ETH_SWAPS_TOKEN_OBJECT = {
symbol: TEST_ETH_SYMBOL,
name: 'Test Ether',
@ -75,6 +86,8 @@ const BSC_CONTRACT_ADDRESS = '0x1a1ec25dc08e98e5e93f1104b5e5cdd298707d31';
// It's the same as we use for BSC.
const POLYGON_CONTRACT_ADDRESS = '0x1a1ec25dc08e98e5e93f1104b5e5cdd298707d31';
const AVALANCHE_CONTRACT_ADDRESS = '0x1a1ec25dc08e98e5e93f1104b5e5cdd298707d31';
export const WETH_CONTRACT_ADDRESS =
'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
export const WETH_RINKEBY_CONTRACT_ADDRESS =
@ -83,12 +96,14 @@ export const WBNB_CONTRACT_ADDRESS =
'0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c';
export const WMATIC_CONTRACT_ADDRESS =
'0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270';
export const WAVAX_CONTRACT_ADDRESS =
'0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7';
const SWAPS_TESTNET_CHAIN_ID = '0x539';
export const SWAPS_API_V2_BASE_URL = 'https://api2.metaswap.codefi.network';
export const SWAPS_DEV_API_V2_BASE_URL =
'https://api2.metaswap-dev.codefi.network';
'https://swap.metaswap-dev.codefi.network';
export const GAS_API_BASE_URL = 'https://gas-api.metaswap.codefi.network';
export const GAS_DEV_API_BASE_URL =
'https://gas-api.metaswap-dev.codefi.network';
@ -97,6 +112,7 @@ const BSC_DEFAULT_BLOCK_EXPLORER_URL = 'https://bscscan.com/';
const MAINNET_DEFAULT_BLOCK_EXPLORER_URL = 'https://etherscan.io/';
const RINKEBY_DEFAULT_BLOCK_EXPLORER_URL = 'https://rinkeby.etherscan.io/';
const POLYGON_DEFAULT_BLOCK_EXPLORER_URL = 'https://polygonscan.com/';
const AVALANCHE_DEFAULT_BLOCK_EXPLORER_URL = 'https://snowtrace.io/';
export const ALLOWED_SWAPS_CHAIN_IDS = {
[MAINNET_CHAIN_ID]: true,
@ -104,6 +120,7 @@ export const ALLOWED_SWAPS_CHAIN_IDS = {
[BSC_CHAIN_ID]: true,
[POLYGON_CHAIN_ID]: true,
[RINKEBY_CHAIN_ID]: true,
[AVALANCHE_CHAIN_ID]: true,
};
export const SWAPS_CHAINID_CONTRACT_ADDRESS_MAP = {
@ -112,6 +129,7 @@ export const SWAPS_CHAINID_CONTRACT_ADDRESS_MAP = {
[BSC_CHAIN_ID]: BSC_CONTRACT_ADDRESS,
[POLYGON_CHAIN_ID]: POLYGON_CONTRACT_ADDRESS,
[RINKEBY_CHAIN_ID]: TESTNET_CONTRACT_ADDRESS,
[AVALANCHE_CHAIN_ID]: AVALANCHE_CONTRACT_ADDRESS,
};
export const SWAPS_WRAPPED_TOKENS_ADDRESSES = {
@ -120,6 +138,7 @@ export const SWAPS_WRAPPED_TOKENS_ADDRESSES = {
[BSC_CHAIN_ID]: WBNB_CONTRACT_ADDRESS,
[POLYGON_CHAIN_ID]: WMATIC_CONTRACT_ADDRESS,
[RINKEBY_CHAIN_ID]: WETH_RINKEBY_CONTRACT_ADDRESS,
[AVALANCHE_CHAIN_ID]: WAVAX_CONTRACT_ADDRESS,
};
export const ALLOWED_CONTRACT_ADDRESSES = {
@ -143,6 +162,10 @@ export const ALLOWED_CONTRACT_ADDRESSES = {
SWAPS_CHAINID_CONTRACT_ADDRESS_MAP[POLYGON_CHAIN_ID],
SWAPS_WRAPPED_TOKENS_ADDRESSES[POLYGON_CHAIN_ID],
],
[AVALANCHE_CHAIN_ID]: [
SWAPS_CHAINID_CONTRACT_ADDRESS_MAP[AVALANCHE_CHAIN_ID],
SWAPS_WRAPPED_TOKENS_ADDRESSES[AVALANCHE_CHAIN_ID],
],
};
export const SWAPS_CHAINID_DEFAULT_TOKEN_MAP = {
@ -151,6 +174,7 @@ export const SWAPS_CHAINID_DEFAULT_TOKEN_MAP = {
[BSC_CHAIN_ID]: BNB_SWAPS_TOKEN_OBJECT,
[POLYGON_CHAIN_ID]: MATIC_SWAPS_TOKEN_OBJECT,
[RINKEBY_CHAIN_ID]: RINKEBY_SWAPS_TOKEN_OBJECT,
[AVALANCHE_CHAIN_ID]: AVAX_SWAPS_TOKEN_OBJECT,
};
export const SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP = {
@ -158,11 +182,13 @@ export const SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP = {
[MAINNET_CHAIN_ID]: MAINNET_DEFAULT_BLOCK_EXPLORER_URL,
[POLYGON_CHAIN_ID]: POLYGON_DEFAULT_BLOCK_EXPLORER_URL,
[RINKEBY_CHAIN_ID]: RINKEBY_DEFAULT_BLOCK_EXPLORER_URL,
[AVALANCHE_CHAIN_ID]: AVALANCHE_DEFAULT_BLOCK_EXPLORER_URL,
};
export const ETHEREUM = 'ethereum';
export const POLYGON = 'polygon';
export const BSC = 'bsc';
export const RINKEBY = 'rinkeby';
export const AVALANCHE = 'avalanche';
export const SWAPS_CLIENT_ID = 'extension';

@ -9,6 +9,7 @@ import {
LOCALHOST_CHAIN_ID,
POLYGON_CHAIN_ID,
RINKEBY_CHAIN_ID,
AVALANCHE_CHAIN_ID,
} from '../../../../shared/constants/network';
import TransactionDetail from '../../../components/app/transaction-detail/transaction-detail.component';
import TransactionDetailItem from '../../../components/app/transaction-detail-item/transaction-detail-item.component';
@ -51,6 +52,8 @@ export default function FeeCard({
return t('networkNameTestnet');
case RINKEBY_CHAIN_ID:
return t('networkNameRinkeby');
case AVALANCHE_CHAIN_ID:
return t('networkNameAvalanche');
default:
throw new Error('This network is not supported for token swaps');
}

@ -9,6 +9,7 @@ import {
POLYGON,
BSC,
RINKEBY,
AVALANCHE,
SWAPS_API_V2_BASE_URL,
SWAPS_DEV_API_V2_BASE_URL,
GAS_API_BASE_URL,
@ -26,6 +27,7 @@ import {
POLYGON_CHAIN_ID,
LOCALHOST_CHAIN_ID,
RINKEBY_CHAIN_ID,
AVALANCHE_CHAIN_ID,
} from '../../../shared/constants/network';
import { SECOND } from '../../../shared/constants/time';
import {
@ -793,6 +795,8 @@ export const getNetworkNameByChainId = (chainId) => {
return POLYGON;
case RINKEBY_CHAIN_ID:
return RINKEBY;
case AVALANCHE_CHAIN_ID:
return AVALANCHE;
default:
return '';
}

@ -7,6 +7,7 @@ import {
LOCALHOST_CHAIN_ID,
RINKEBY_CHAIN_ID,
KOVAN_CHAIN_ID,
AVALANCHE_CHAIN_ID,
} from '../../../shared/constants/network';
import {
SWAPS_CHAINID_CONTRACT_ADDRESS_MAP,
@ -18,6 +19,7 @@ import {
POLYGON,
BSC,
RINKEBY,
AVALANCHE,
} from '../../../shared/constants/swaps';
import {
TOKENS,
@ -318,6 +320,10 @@ describe('Swaps Util', () => {
expect(getNetworkNameByChainId(RINKEBY_CHAIN_ID)).toBe(RINKEBY);
});
it('returns "avalanche" for Avalanche chain ID', () => {
expect(getNetworkNameByChainId(AVALANCHE_CHAIN_ID)).toBe(AVALANCHE);
});
it('returns an empty string for an unsupported network', () => {
expect(getNetworkNameByChainId(KOVAN_CHAIN_ID)).toBe('');
});

Loading…
Cancel
Save