1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00
metamask-extension/app/scripts/lib/buy-eth-url.js
Mark Stacey ac01c5c89a
Consistent jsdoc syntax (#7755)
* Specify type before parameter name

Various JSDoc `@param` entries were specified as `name {type}` rather
than `{type} name`.

A couple of `@return` entries have been given types as well.

* Use JSDoc optional syntax rather than Closure syntax

* Use @returns rather than @return

* Use consistent built-in type capitalization

Primitive types are lower-case, and Object is upper-case.

* Separate param/return description with a dash
2020-01-13 14:36:36 -04:00

56 lines
2.0 KiB
JavaScript

export default getBuyEthUrl
/**
* 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'.
* @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.
*
*/
function getBuyEthUrl ({ network, amount, address, service }) {
// default service by network if not specified
if (!service) {
service = getDefaultServiceForNetwork(network)
}
switch (service) {
case 'wyre':
return `https://dash.sendwyre.com/sign-up`
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'
case 'goerli-faucet':
return 'https://goerli-faucet.slock.it/'
default:
throw new Error(`Unknown cryptocurrency exchange or faucet: "${service}"`)
}
}
function getDefaultServiceForNetwork (network) {
switch (network) {
case '1':
return 'wyre'
case '3':
return 'metamask-faucet'
case '4':
return 'rinkeby-faucet'
case '42':
return 'kovan-faucet'
case '5':
return 'goerli-faucet'
default:
throw new Error(`No default cryptocurrency exchange or faucet for networkId: "${network}"`)
}
}