2017-04-05 03:23:46 +02:00
|
|
|
module.exports = getBuyEthUrl
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @param {object} opts Options required to determine the correct url
|
|
|
|
* @param {string} opts.network The network for which to return a url
|
|
|
|
* @param {string} opts.amount The amount of ETH to buy on coinbase. Only relevant if network === '1'.
|
2018-04-17 01:53:29 +02:00
|
|
|
* @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
|
|
|
|
* 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
|
|
|
*
|
|
|
|
*/
|
2019-03-29 03:53:46 +01:00
|
|
|
function getBuyEthUrl ({ network, amount, 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) {
|
|
|
|
service = getDefaultServiceForNetwork(network)
|
|
|
|
}
|
2019-03-29 03:03:35 +01:00
|
|
|
|
|
|
|
switch (service) {
|
2019-03-29 03:20:19 +01:00
|
|
|
case 'wyre':
|
2019-12-04 02:12:14 +01:00
|
|
|
return `https://dash.sendwyre.com/sign-up`
|
2019-03-29 03:03:35 +01:00
|
|
|
case 'coinswitch':
|
|
|
|
return `https://metamask.coinswitch.co/?address=${address}&to=eth`
|
|
|
|
case 'coinbase':
|
|
|
|
return `https://buy.coinbase.com/?code=9ec56d01-7e81-5017-930c-513daa27bb6a&amount=${amount}&address=${address}&crypto_currency=ETH`
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-29 03:37:16 +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:
|
|
|
|
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
|
|
|
}
|