mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
add platforms to mascara + move buyEther window open to ui
This commit is contained in:
parent
5d967eeebb
commit
5a91adf7d8
@ -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',
|
||||
|
19
app/scripts/lib/buy-eth-url.js
Normal file
19
app/scripts/lib/buy-eth-url.js
Normal file
@ -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
|
||||
}
|
@ -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 })
|
||||
}
|
||||
|
||||
|
24
app/scripts/platforms/sw.js
Normal file
24
app/scripts/platforms/sw.js
Normal file
@ -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 '<unable to read version>'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = SwPlatform
|
22
app/scripts/platforms/window.js
Normal file
22
app/scripts/platforms/window.js
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
class WindowPlatform {
|
||||
|
||||
//
|
||||
// Public
|
||||
//
|
||||
|
||||
reload () {
|
||||
global.location.reload()
|
||||
}
|
||||
|
||||
openWindow ({ url }) {
|
||||
global.open(url, '_blank')
|
||||
}
|
||||
|
||||
getVersion () {
|
||||
return '<unable to read version>'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = WindowPlatform
|
@ -8,6 +8,7 @@ const PortStream = require('../../app/scripts/lib/port-stream.js')
|
||||
|
||||
const DbController = require('./lib/index-db-controller')
|
||||
|
||||
const SwPlatform = require('../../app/scripts/platforms/sw')
|
||||
const MetamaskController = require('../../app/scripts/metamask-controller')
|
||||
const extension = {} //require('../../app/scripts/lib/extension')
|
||||
|
||||
@ -17,7 +18,8 @@ const migrations = require('../../app/scripts/migrations/')
|
||||
const firstTimeState = require('../../app/scripts/first-time-state')
|
||||
|
||||
const STORAGE_KEY = 'metamask-config'
|
||||
const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG'
|
||||
// const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG'
|
||||
const METAMASK_DEBUG = true
|
||||
let popupIsOpen = false
|
||||
|
||||
const log = require('loglevel')
|
||||
@ -70,7 +72,11 @@ function setupController (initState, client) {
|
||||
// MetaMask Controller
|
||||
//
|
||||
|
||||
const platform = new SwPlatform()
|
||||
|
||||
const controller = new MetamaskController({
|
||||
// platform specific implementation
|
||||
platform,
|
||||
// User confirmation callbacks:
|
||||
showUnconfirmedMessage: noop,
|
||||
unlockAccountMessage: noop,
|
||||
|
@ -4,8 +4,13 @@ const SwStream = require('sw-stream/lib/sw-stream.js')
|
||||
const MetaMaskUiCss = require('../../ui/css')
|
||||
const setupIframe = require('./lib/setup-iframe.js')
|
||||
const MetamaskInpageProvider = require('../../app/scripts/lib/inpage-provider.js')
|
||||
const MetamascaraPlatform = require('../../app/scripts/platforms/window')
|
||||
const startPopup = require('../../app/scripts/popup-core')
|
||||
|
||||
// create platform global
|
||||
global.platform = new MetamascaraPlatform()
|
||||
|
||||
|
||||
var css = MetaMaskUiCss()
|
||||
injectCss(css)
|
||||
const container = document.getElementById('app-content')
|
||||
|
@ -1,3 +1,5 @@
|
||||
const getBuyEthUrl = require('../../app/scripts/lib/buy-eth-url')
|
||||
|
||||
var actions = {
|
||||
_setBackgroundConnection: _setBackgroundConnection,
|
||||
|
||||
@ -833,10 +835,10 @@ function showSendPage () {
|
||||
}
|
||||
}
|
||||
|
||||
function buyEth (address, amount) {
|
||||
function buyEth (opts) {
|
||||
return (dispatch) => {
|
||||
log.debug(`background.buyEth`)
|
||||
background.buyEth(address, amount)
|
||||
const url = getBuyEthUrl(opts)
|
||||
global.platform.openWindow({ url })
|
||||
dispatch({
|
||||
type: actions.BUY_ETH,
|
||||
})
|
||||
|
@ -104,7 +104,8 @@ BuyButtonSubview.prototype.render = function () {
|
||||
}
|
||||
|
||||
BuyButtonSubview.prototype.formVersionSubview = function () {
|
||||
if (this.props.network === '1') {
|
||||
const network = this.props.network
|
||||
if (network === '1') {
|
||||
if (this.props.buyView.formView.coinbase) {
|
||||
return h(CoinbaseForm, this.props)
|
||||
} else if (this.props.buyView.formView.shapeshift) {
|
||||
@ -123,15 +124,15 @@ BuyButtonSubview.prototype.formVersionSubview = function () {
|
||||
marginBottom: '15px',
|
||||
},
|
||||
}, 'In order to access this feature, please switch to the Main Network'),
|
||||
((this.props.network === '3') || (this.props.network === '42')) ? h('h3.text-transform-uppercase', 'or go to the') : null,
|
||||
(this.props.network === '3') ? h('button.text-transform-uppercase', {
|
||||
onClick: () => this.props.dispatch(actions.buyEth()),
|
||||
((network === '3') || (network === '42')) ? h('h3.text-transform-uppercase', 'or go to the') : null,
|
||||
(network === '3') ? h('button.text-transform-uppercase', {
|
||||
onClick: () => this.props.dispatch(actions.buyEth({ network })),
|
||||
style: {
|
||||
marginTop: '15px',
|
||||
},
|
||||
}, 'Ropsten Test Faucet') : null,
|
||||
(this.props.network === '42') ? h('button.text-transform-uppercase', {
|
||||
onClick: () => this.props.dispatch(actions.buyEth()),
|
||||
(network === '42') ? h('button.text-transform-uppercase', {
|
||||
onClick: () => this.props.dispatch(actions.buyEth({ network })),
|
||||
style: {
|
||||
marginTop: '15px',
|
||||
},
|
||||
|
@ -112,7 +112,7 @@ CoinbaseForm.prototype.toCoinbase = function () {
|
||||
var message
|
||||
|
||||
if (isValidAddress(address) && isValidAmountforCoinBase(amount).valid) {
|
||||
props.dispatch(actions.buyEth(address, props.buyView.amount))
|
||||
props.dispatch(actions.buyEth({ network: '1', address, amount: props.buyView.amount }))
|
||||
} else if (!isValidAmountforCoinBase(amount).valid) {
|
||||
message = isValidAmountforCoinBase(amount).message
|
||||
return props.dispatch(actions.displayWarning(message))
|
||||
|
Loading…
Reference in New Issue
Block a user