Skip to content

Commit

Permalink
feat(ramps): introduce dynamic support for rampable networks
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeweiler committed Apr 16, 2024
1 parent be3c4f2 commit 8bda667
Show file tree
Hide file tree
Showing 40 changed files with 666 additions and 189 deletions.
2 changes: 2 additions & 0 deletions builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ env:
# Enables the notifications feature within the build:
- NOTIFICATIONS: ''

- METAMASK_RAMP_API_BASE_URL: https://on-ramp-content.metaswap.codefi.network

###
# Meta variables
###
Expand Down
1 change: 1 addition & 0 deletions privacy-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"mainnet.infura.io",
"metamask.github.io",
"min-api.cryptocompare.com",
"on-ramp-content.metaswap.codefi.network",
"phishing-detection.metafi.codefi.network",
"portfolio.metamask.io",
"price-api.metafi.codefi.network",
Expand Down
110 changes: 0 additions & 110 deletions shared/constants/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,6 @@ export type RPCDefinition = {
rpcPrefs: RPCPreferences;
};

/**
* For each chain that we support fiat onramps for, we provide a set of
* configuration options that help for initializing the connectiong to the
* onramp providers.
*/
type BuyableChainSettings = {
/**
* The native currency for the given chain
*/
nativeCurrency: CurrencySymbol | TestNetworkCurrencySymbol;
/**
* The network name or identifier
*/
network: string;
};

/**
* Throughout the extension we set the current provider by referencing its
* "type", which can be any of the values in the below object. These values
Expand Down Expand Up @@ -861,100 +845,6 @@ export const UNSUPPORTED_RPC_METHODS = new Set([

export const IPFS_DEFAULT_GATEWAY_URL = 'dweb.link';

// The first item in transakCurrencies must be the
// default crypto currency for the network
const BUYABLE_CHAIN_ETHEREUM_NETWORK_NAME = 'ethereum';

export const BUYABLE_CHAINS_MAP: {
[K in Exclude<
ChainId,
| typeof CHAIN_IDS.LOCALHOST
| typeof CHAIN_IDS.OPTIMISM_TESTNET
| typeof CHAIN_IDS.OPTIMISM_GOERLI
| typeof CHAIN_IDS.BASE_TESTNET
| typeof CHAIN_IDS.OPBNB_TESTNET
| typeof CHAIN_IDS.OPBNB
| typeof CHAIN_IDS.BSC_TESTNET
| typeof CHAIN_IDS.POLYGON_TESTNET
| typeof CHAIN_IDS.AVALANCHE_TESTNET
| typeof CHAIN_IDS.FANTOM_TESTNET
| typeof CHAIN_IDS.MOONBEAM_TESTNET
| typeof CHAIN_IDS.LINEA_GOERLI
| typeof CHAIN_IDS.LINEA_SEPOLIA
| typeof CHAIN_IDS.GOERLI
| typeof CHAIN_IDS.SEPOLIA
| typeof CHAIN_IDS.GNOSIS
| typeof CHAIN_IDS.AURORA
| typeof CHAIN_IDS.ARBITRUM_GOERLI
| typeof CHAIN_IDS.BLAST
>]: BuyableChainSettings;
} = {
[CHAIN_IDS.MAINNET]: {
nativeCurrency: CURRENCY_SYMBOLS.ETH,
network: BUYABLE_CHAIN_ETHEREUM_NETWORK_NAME,
},
[CHAIN_IDS.BSC]: {
nativeCurrency: CURRENCY_SYMBOLS.BNB,
network: 'bsc',
},
[CHAIN_IDS.POLYGON]: {
nativeCurrency: CURRENCY_SYMBOLS.MATIC,
network: 'polygon',
},
[CHAIN_IDS.AVALANCHE]: {
nativeCurrency: CURRENCY_SYMBOLS.AVALANCHE,
network: 'avaxcchain',
},
[CHAIN_IDS.FANTOM]: {
nativeCurrency: CURRENCY_SYMBOLS.FANTOM,
network: 'fantom',
},
[CHAIN_IDS.CELO]: {
nativeCurrency: CURRENCY_SYMBOLS.CELO,
network: 'celo',
},
[CHAIN_IDS.OPTIMISM]: {
nativeCurrency: CURRENCY_SYMBOLS.ETH,
network: 'optimism',
},
[CHAIN_IDS.ARBITRUM]: {
nativeCurrency: CURRENCY_SYMBOLS.ARBITRUM,
network: 'arbitrum',
},
[CHAIN_IDS.CRONOS]: {
nativeCurrency: CURRENCY_SYMBOLS.CRONOS,
network: 'cronos',
},
[CHAIN_IDS.MOONBEAM]: {
nativeCurrency: CURRENCY_SYMBOLS.GLIMMER,
network: 'moonbeam',
},
[CHAIN_IDS.MOONRIVER]: {
nativeCurrency: CURRENCY_SYMBOLS.MOONRIVER,
network: 'moonriver',
},
[CHAIN_IDS.HARMONY]: {
nativeCurrency: CURRENCY_SYMBOLS.ONE,
network: 'harmony',
},
[CHAIN_IDS.PALM]: {
nativeCurrency: CURRENCY_SYMBOLS.PALM,
network: 'palm',
},
[CHAIN_IDS.LINEA_MAINNET]: {
nativeCurrency: CURRENCY_SYMBOLS.ETH,
network: 'linea',
},
[CHAIN_IDS.ZKSYNC_ERA]: {
nativeCurrency: CURRENCY_SYMBOLS.ETH,
network: 'zksync',
},
[CHAIN_IDS.BASE]: {
nativeCurrency: CURRENCY_SYMBOLS.ETH,
network: 'base',
},
};

export const FEATURED_RPCS: RPCDefinition[] = [
{
chainId: CHAIN_IDS.ARBITRUM,
Expand Down
82 changes: 82 additions & 0 deletions test/data/mock-send-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,88 @@
}
]
},
"ramps": {
"buyableChains": [
{
"active": true,
"chainId": 1,
"chainName": "Ethereum Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 10,
"chainName": "Optimism Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 25,
"chainName": "Cronos Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 56,
"chainName": "BNB Chain Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 137,
"chainName": "Polygon Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 250,
"chainName": "Fantom Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 1285,
"chainName": "Moonriver Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 42161,
"chainName": "Arbitrum Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 42220,
"chainName": "Celo Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 43114,
"chainName": "Avalanche C-Chain Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 1313161554,
"chainName": "Aurora Mainnet",
"nativeTokenSupported": false
},
{
"active": true,
"chainId": 1666600000,
"chainName": "Harmony Mainnet (Shard 0)",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 11297108109,
"chainName": "Palm",
"nativeTokenSupported": false
}
]
},
"send": {
"amountMode": "INPUT",
"currentTransactionUUID": "1-tx",
Expand Down
82 changes: 82 additions & 0 deletions test/data/mock-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,88 @@
}
}
},
"ramps": {
"buyableChains": [
{
"active": true,
"chainId": 1,
"chainName": "Ethereum Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 10,
"chainName": "Optimism Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 25,
"chainName": "Cronos Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 56,
"chainName": "BNB Chain Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 137,
"chainName": "Polygon Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 250,
"chainName": "Fantom Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 1285,
"chainName": "Moonriver Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 42161,
"chainName": "Arbitrum Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 42220,
"chainName": "Celo Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 43114,
"chainName": "Avalanche C-Chain Mainnet",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 1313161554,
"chainName": "Aurora Mainnet",
"nativeTokenSupported": false
},
{
"active": true,
"chainId": 1666600000,
"chainName": "Harmony Mainnet (Shard 0)",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 11297108109,
"chainName": "Palm",
"nativeTokenSupported": false
}
]
},
"send": {
"amountMode": "INPUT",
"currentTransactionUUID": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"showAccountBanner": true,
"trezorModel": null,
"hadAdvancedGasFeesSetPriorToMigration92_3": false,
"hasDismissedOpenSeaToBlockaidBanner": false,
"nftsDropdownState": {},
"termsOfUseLastAgreed": "number",
"qrHardware": {},
Expand Down Expand Up @@ -103,6 +102,7 @@
"dismissSeedBackUpReminder": true,
"disabledRpcMethodPreferences": { "eth_sign": false },
"useMultiAccountBalanceChecker": true,
"hasDismissedOpenSeaToBlockaidBanner": false,
"useSafeChainsListValidation": true,
"useTokenDetection": false,
"useNftDetection": false,
Expand Down Expand Up @@ -229,6 +229,7 @@
"storageMetadata": {},
"versionFileETag": "string"
},
"ramps": "object",
"send": "object",
"swaps": "object",
"unconnectedAccount": { "state": "CLOSED" }
Expand Down
1 change: 1 addition & 0 deletions ui/components/app/add-network/add-network.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import mockState from '../../../../test/data/mock-state.json';
import AddNetwork from './add-network';

jest.mock('../../../selectors', () => ({
...jest.requireActual('../../../selectors'),
getNetworkConfigurations: () => ({
networkConfigurationId: {
chainId: '0x539',
Expand Down
6 changes: 2 additions & 4 deletions ui/components/app/asset-list/asset-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import {
getDetectedTokensInCurrentNetwork,
getIstokenDetectionInactiveOnNonMainnetSupportedNetwork,
getShouldHideZeroBalanceTokens,
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
getIsBuyableChain,
///: END:ONLY_INCLUDE_IF
getCurrentNetwork,
getSelectedAccount,
getPreferences,
Expand Down Expand Up @@ -48,6 +45,7 @@ import {
RAMPS_CARD_VARIANT_TYPES,
RampsCard,
} from '../../multichain/ramps-card/ramps-card';
import { getIsNativeTokenBuyable } from '../../../ducks/ramps';
///: END:ONLY_INCLUDE_IF

const AssetList = ({ onClickAsset }) => {
Expand Down Expand Up @@ -107,7 +105,7 @@ const AssetList = ({ onClickAsset }) => {
});
const balanceIsZero = Number(totalFiatBalance) === 0;
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
const isBuyableChain = useSelector(getIsBuyableChain);
const isBuyableChain = useSelector(getIsNativeTokenBuyable);
const shouldShowBuy = isBuyableChain && balanceIsZero;
///: END:ONLY_INCLUDE_IF

Expand Down
Loading

0 comments on commit 8bda667

Please sign in to comment.