getBuyEthUrl - getDefaultServiceForNetwork then switch on service

feature/default_network_editable
kumavis 6 years ago committed by GitHub
parent ab5fe4d659
commit 0ae68d1a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 42
      app/scripts/lib/buy-eth-url.js

@ -12,28 +12,34 @@ module.exports = getBuyEthUrl
* *
*/ */
function getBuyEthUrl({ network, amount, address, service }) { function getBuyEthUrl({ network, amount, address, service }) {
let url // default service by network if not specified
if (typeof network !== 'undefined') { if (!service) service = getDefaultServiceForNetwork(network)
switch (service) {
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'
}
throw new Error(`Unknown cryptocurrency exchange or faucet: "${service}"`)
}
function getDefaultServiceForNetwork (networkId) {
switch (network) { switch (network) {
case '1': case '1':
url = `https://buy.coinbase.com/?code=9ec56d01-7e81-5017-930c-513daa27bb6a&amount=${amount}&address=${address}&crypto_currency=ETH` return 'coinbase'
break
case '3': case '3':
url = 'https://faucet.metamask.io/' return 'metamask-faucet'
break
case '4': case '4':
url = 'https://www.rinkeby.io/' return 'rinkeby-faucet'
break
case '42': case '42':
url = 'https://github.com/kovan-testnet/faucet' return 'kovan-faucet'
break
}
} else {
switch (service) {
case 'coinswitch':
url = `https://metamask.coinswitch.co/?address=${address}&to=eth`
break
}
} }
return url throw new Error(`No default cryptocurrency exchange or faucet for networkId: "${networkId}"`)
} }

Loading…
Cancel
Save