aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2019-03-29 10:03:35 +0800
committerGitHub <noreply@github.com>2019-03-29 10:03:35 +0800
commit0ae68d1a612ec3999ded2ba6887c0f3b73ef27cd (patch)
treeda5aea93dea279ebbfe8f6c695ddb302ef16c72c
parentab5fe4d65994ce66ed6b796197eda349fbe5d145 (diff)
downloadtangerine-wallet-browser-0ae68d1a612ec3999ded2ba6887c0f3b73ef27cd.tar
tangerine-wallet-browser-0ae68d1a612ec3999ded2ba6887c0f3b73ef27cd.tar.gz
tangerine-wallet-browser-0ae68d1a612ec3999ded2ba6887c0f3b73ef27cd.tar.bz2
tangerine-wallet-browser-0ae68d1a612ec3999ded2ba6887c0f3b73ef27cd.tar.lz
tangerine-wallet-browser-0ae68d1a612ec3999ded2ba6887c0f3b73ef27cd.tar.xz
tangerine-wallet-browser-0ae68d1a612ec3999ded2ba6887c0f3b73ef27cd.tar.zst
tangerine-wallet-browser-0ae68d1a612ec3999ded2ba6887c0f3b73ef27cd.zip
getBuyEthUrl - getDefaultServiceForNetwork then switch on service
-rw-r--r--app/scripts/lib/buy-eth-url.js52
1 files changed, 29 insertions, 23 deletions
diff --git a/app/scripts/lib/buy-eth-url.js b/app/scripts/lib/buy-eth-url.js
index d434473ee..46710a16f 100644
--- a/app/scripts/lib/buy-eth-url.js
+++ b/app/scripts/lib/buy-eth-url.js
@@ -12,28 +12,34 @@ module.exports = getBuyEthUrl
*
*/
function getBuyEthUrl({ network, amount, address, service }) {
- let url
- if (typeof network !== 'undefined') {
- switch (network) {
- case '1':
- url = `https://buy.coinbase.com/?code=9ec56d01-7e81-5017-930c-513daa27bb6a&amount=${amount}&address=${address}&crypto_currency=ETH`
- break
- case '3':
- url = 'https://faucet.metamask.io/'
- break
- case '4':
- url = 'https://www.rinkeby.io/'
- break
- case '42':
- url = 'https://github.com/kovan-testnet/faucet'
- break
- }
- } else {
- switch (service) {
- case 'coinswitch':
- url = `https://metamask.coinswitch.co/?address=${address}&to=eth`
- break
- }
+ // default service by network if not specified
+ 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) {
+ case '1':
+ return 'coinbase'
+ case '3':
+ return 'metamask-faucet'
+ case '4':
+ return 'rinkeby-faucet'
+ case '42':
+ return 'kovan-faucet'
}
- return url
+ throw new Error(`No default cryptocurrency exchange or faucet for networkId: "${networkId}"`)
}