From 5a91adf7d802097805938e3d54fe7256b19724d1 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 4 Apr 2017 18:23:46 -0700 Subject: add platforms to mascara + move buyEther window open to ui --- app/scripts/lib/auto-faucet.js | 8 +++++--- app/scripts/lib/buy-eth-url.js | 19 +++++++++++++++++++ app/scripts/metamask-controller.js | 19 ++----------------- app/scripts/platforms/sw.js | 24 ++++++++++++++++++++++++ app/scripts/platforms/window.js | 22 ++++++++++++++++++++++ 5 files changed, 72 insertions(+), 20 deletions(-) create mode 100644 app/scripts/lib/buy-eth-url.js create mode 100644 app/scripts/platforms/sw.js create mode 100644 app/scripts/platforms/window.js (limited to 'app/scripts') diff --git a/app/scripts/lib/auto-faucet.js b/app/scripts/lib/auto-faucet.js index 73b73dfe6..1e059cf73 100644 --- a/app/scripts/lib/auto-faucet.js +++ b/app/scripts/lib/auto-faucet.js @@ -3,9 +3,11 @@ const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG' const env = process.env.METAMASK_ENV module.exports = function (address) { - if (METAMASK_DEBUG || env === 'test') return // Don't faucet in development or test - let data = address - let headers = new Headers() + // Don't faucet in development or test + if (METAMASK_DEBUG || env === 'test') return + global.log.info('auto-fauceting:', address) + const data = address + const headers = new Headers() headers.append('Content-type', 'application/rawdata') fetch(uri, { method: 'POST', diff --git a/app/scripts/lib/buy-eth-url.js b/app/scripts/lib/buy-eth-url.js new file mode 100644 index 000000000..91a1ec322 --- /dev/null +++ b/app/scripts/lib/buy-eth-url.js @@ -0,0 +1,19 @@ +module.exports = getBuyEthUrl + +function getBuyEthUrl({ network, amount, address }){ + let url + 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 '42': + url = 'https://github.com/kovan-testnet/faucet' + break + } + return url +} \ No newline at end of file diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index edb9bbbd9..2b8fc9cb8 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -23,6 +23,7 @@ const ConfigManager = require('./lib/config-manager') const autoFaucet = require('./lib/auto-faucet') const nodeify = require('./lib/nodeify') const accountImporter = require('./account-import-strategies') +const getBuyEthUrl = require('./lib/buy-eth-url') const version = require('../manifest.json').version @@ -614,24 +615,8 @@ module.exports = class MetamaskController extends EventEmitter { buyEth (address, amount) { if (!amount) amount = '5' - const network = this.getNetworkState() - let url - - 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 '42': - url = 'https://github.com/kovan-testnet/faucet' - break - } - + const url = getBuyEthUrl({ network, address, amount }) if (url) this.platform.openWindow({ url }) } diff --git a/app/scripts/platforms/sw.js b/app/scripts/platforms/sw.js new file mode 100644 index 000000000..007d8dc5b --- /dev/null +++ b/app/scripts/platforms/sw.js @@ -0,0 +1,24 @@ + +class SwPlatform { + + // + // Public + // + + reload () { + // you cant actually do this + global.location.reload() + } + + openWindow ({ url }) { + // this doesnt actually work + global.open(url, '_blank') + } + + getVersion () { + return '' + } + +} + +module.exports = SwPlatform diff --git a/app/scripts/platforms/window.js b/app/scripts/platforms/window.js new file mode 100644 index 000000000..1527c008b --- /dev/null +++ b/app/scripts/platforms/window.js @@ -0,0 +1,22 @@ + +class WindowPlatform { + + // + // Public + // + + reload () { + global.location.reload() + } + + openWindow ({ url }) { + global.open(url, '_blank') + } + + getVersion () { + return '' + } + +} + +module.exports = WindowPlatform -- cgit v1.2.3