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
|
2020-11-10 18:30:41 +01:00
|
|
|
* @param {string} opts.network - The network for which to return a url
|
|
|
|
* @param {string} opts.address - The address the bought ETH should be sent to. Only relevant if network === '1'.
|
|
|
|
* @returns {string|undefined} The url at which the user can access ETH, while in the given network. If the passed
|
2018-04-17 01:53:29 +02:00
|
|
|
* network does not match any of the specified cases, or if no network is given, returns undefined.
|
2018-04-16 19:08:04 +02:00
|
|
|
*
|
|
|
|
*/
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function getBuyEthUrl({ network, 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
|
2019-11-20 01:03:20 +01:00
|
|
|
service = getDefaultServiceForNetwork(network)
|
|
|
|
}
|
2019-03-29 03:03:35 +01:00
|
|
|
|
|
|
|
switch (service) {
|
2019-03-29 03:20:19 +01:00
|
|
|
case 'wyre':
|
2020-09-15 22:26:51 +02: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':
|
|
|
|
return 'https://faucet.metamask.io/'
|
|
|
|
case 'rinkeby-faucet':
|
|
|
|
return 'https://www.rinkeby.io/'
|
|
|
|
case 'kovan-faucet':
|
|
|
|
return 'https://github.com/kovan-testnet/faucet'
|
2019-04-17 19:34:49 +02:00
|
|
|
case 'goerli-faucet':
|
|
|
|
return 'https://goerli-faucet.slock.it/'
|
2019-11-27 17:08:35 +01:00
|
|
|
default:
|
|
|
|
throw new Error(`Unknown cryptocurrency exchange or faucet: "${service}"`)
|
2019-03-29 03:03:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function getDefaultServiceForNetwork(network) {
|
2017-04-05 03:23:46 +02:00
|
|
|
switch (network) {
|
|
|
|
case '1':
|
2019-03-29 03:20:19 +01:00
|
|
|
return 'wyre'
|
2017-04-05 03:23:46 +02:00
|
|
|
case '3':
|
2019-03-29 03:03:35 +01:00
|
|
|
return 'metamask-faucet'
|
2017-04-25 23:39:01 +02:00
|
|
|
case '4':
|
2019-03-29 03:03:35 +01:00
|
|
|
return 'rinkeby-faucet'
|
2017-04-05 03:23:46 +02:00
|
|
|
case '42':
|
2019-03-29 03:03:35 +01:00
|
|
|
return 'kovan-faucet'
|
2019-04-17 19:34:49 +02:00
|
|
|
case '5':
|
|
|
|
return 'goerli-faucet'
|
2019-11-27 17:08:35 +01:00
|
|
|
default:
|
2020-11-03 00:41:28 +01:00
|
|
|
throw new Error(
|
|
|
|
`No default cryptocurrency exchange or faucet for networkId: "${network}"`,
|
|
|
|
)
|
2017-04-05 03:23:46 +02:00
|
|
|
}
|
2017-04-25 23:39:01 +02:00
|
|
|
}
|