2021-03-12 23:23:26 +01:00
|
|
|
import {
|
|
|
|
GOERLI_CHAIN_ID,
|
|
|
|
KOVAN_CHAIN_ID,
|
|
|
|
MAINNET_CHAIN_ID,
|
|
|
|
RINKEBY_CHAIN_ID,
|
|
|
|
ROPSTEN_CHAIN_ID,
|
|
|
|
} from '../../../shared/constants/network';
|
|
|
|
|
2018-04-16 19:08:04 +02:00
|
|
|
/**
|
|
|
|
* Gives the caller a url at which the user can acquire eth, depending on the network they are in
|
|
|
|
*
|
2020-01-13 19:36:36 +01:00
|
|
|
* @param {Object} opts - Options required to determine the correct url
|
2021-03-12 23:23:26 +01:00
|
|
|
* @param {string} opts.chainId - The chainId for which to return a url
|
|
|
|
* @param {string} opts.address - The address the bought ETH should be sent to. Only relevant if chainId === '0x1'.
|
|
|
|
* @returns {string|undefined} The url at which the user can access ETH, while in the given chain. If the passed
|
|
|
|
* chainId does not match any of the specified cases, or if no chainId is given, returns undefined.
|
2018-04-16 19:08:04 +02:00
|
|
|
*
|
|
|
|
*/
|
2021-03-12 23:23:26 +01:00
|
|
|
export default function getBuyEthUrl({ chainId, address, service }) {
|
2019-03-29 03:03:35 +01:00
|
|
|
// default service by network if not specified
|
2019-11-20 01:03:20 +01:00
|
|
|
if (!service) {
|
2020-08-15 13:58:11 +02:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
2021-03-12 23:23:26 +01:00
|
|
|
service = getDefaultServiceForChain(chainId);
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
2019-03-29 03:03:35 +01:00
|
|
|
|
|
|
|
switch (service) {
|
2019-03-29 03:20:19 +01:00
|
|
|
case 'wyre':
|
2021-02-04 19:15:23 +01:00
|
|
|
return `https://pay.sendwyre.com/purchase?dest=ethereum:${address}&destCurrency=ETH&accountId=AC-7AG3W4XH4N2&paymentMethod=debit-card`;
|
2019-03-29 03:03:35 +01:00
|
|
|
case 'metamask-faucet':
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'https://faucet.metamask.io/';
|
2019-03-29 03:03:35 +01:00
|
|
|
case 'rinkeby-faucet':
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'https://www.rinkeby.io/';
|
2019-03-29 03:03:35 +01:00
|
|
|
case 'kovan-faucet':
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'https://github.com/kovan-testnet/faucet';
|
2019-04-17 19:34:49 +02:00
|
|
|
case 'goerli-faucet':
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'https://goerli-faucet.slock.it/';
|
2019-11-27 17:08:35 +01:00
|
|
|
default:
|
2021-02-04 19:15:23 +01:00
|
|
|
throw new Error(
|
|
|
|
`Unknown cryptocurrency exchange or faucet: "${service}"`,
|
|
|
|
);
|
2019-03-29 03:03:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 23:23:26 +01:00
|
|
|
function getDefaultServiceForChain(chainId) {
|
|
|
|
switch (chainId) {
|
|
|
|
case MAINNET_CHAIN_ID:
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'wyre';
|
2021-03-12 23:23:26 +01:00
|
|
|
case ROPSTEN_CHAIN_ID:
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'metamask-faucet';
|
2021-03-12 23:23:26 +01:00
|
|
|
case RINKEBY_CHAIN_ID:
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'rinkeby-faucet';
|
2021-03-12 23:23:26 +01:00
|
|
|
case KOVAN_CHAIN_ID:
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'kovan-faucet';
|
2021-03-12 23:23:26 +01:00
|
|
|
case GOERLI_CHAIN_ID:
|
2021-02-04 19:15:23 +01:00
|
|
|
return 'goerli-faucet';
|
2019-11-27 17:08:35 +01:00
|
|
|
default:
|
2020-11-03 00:41:28 +01:00
|
|
|
throw new Error(
|
2021-03-12 23:23:26 +01:00
|
|
|
`No default cryptocurrency exchange or faucet for chainId: "${chainId}"`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2017-04-05 03:23:46 +02:00
|
|
|
}
|
2017-04-25 23:39:01 +02:00
|
|
|
}
|