2016-08-10 22:43:01 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
|
|
|
const connect = require('react-redux').connect
|
|
|
|
const actions = require('../actions')
|
|
|
|
const CoinbaseForm = require('./coinbase-form')
|
|
|
|
const ShapeshiftForm = require('./shapeshift-form')
|
2016-08-13 00:41:59 +02:00
|
|
|
const extension = require('../../../app/scripts/lib/extension')
|
2016-08-10 22:43:01 +02:00
|
|
|
|
|
|
|
module.exports = connect(mapStateToProps)(BuyButtonSubview)
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
|
|
|
selectedAccount: state.selectedAccount,
|
|
|
|
warning: state.appState.warning,
|
2016-08-13 00:41:59 +02:00
|
|
|
buyView: state.appState.buyView,
|
2016-08-10 22:43:01 +02:00
|
|
|
network: state.metamask.network,
|
|
|
|
provider: state.metamask.provider,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(BuyButtonSubview, Component)
|
|
|
|
function BuyButtonSubview () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
BuyButtonSubview.prototype.render = function () {
|
|
|
|
const props = this.props
|
2016-08-13 00:41:59 +02:00
|
|
|
const currentForm = props.buyView.formView
|
2016-08-10 22:43:01 +02:00
|
|
|
|
|
|
|
return (
|
2016-08-13 00:41:59 +02:00
|
|
|
h('.buy-eth-section', [
|
|
|
|
// back button
|
|
|
|
h('.flex-row', {
|
|
|
|
style: {
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h('i.fa.fa-arrow-left.fa-lg.cursor-pointer.color-orange', {
|
|
|
|
onClick: () => props.dispatch(actions.backToAccountDetail(props.selectedAccount)),
|
|
|
|
style: {
|
|
|
|
position: 'absolute',
|
|
|
|
left: '10px',
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
h('h2.page-subtitle', 'Buy Eth'),
|
|
|
|
]),
|
2016-08-10 22:43:01 +02:00
|
|
|
h('h3.flex-row.text-transform-uppercase', {
|
|
|
|
style: {
|
|
|
|
background: '#EBEBEB',
|
|
|
|
color: '#AEAEAE',
|
|
|
|
paddingTop: '4px',
|
|
|
|
justifyContent: 'space-around',
|
|
|
|
},
|
|
|
|
}, [
|
2016-08-19 00:20:26 +02:00
|
|
|
h(currentForm.coinbase ? '.activeForm' : '.inactiveForm.pointer', {
|
2016-08-10 22:43:01 +02:00
|
|
|
onClick: () => props.dispatch(actions.coinBaseSubview()),
|
|
|
|
}, 'Coinbase'),
|
2016-08-13 00:41:59 +02:00
|
|
|
h('a', {
|
|
|
|
onClick: (event) => this.navigateTo('https://github.com/MetaMask/faq/blob/master/COINBASE.md'),
|
|
|
|
}, [
|
|
|
|
h('i.fa.fa-question-circle', {
|
|
|
|
style: {
|
|
|
|
position: 'relative',
|
|
|
|
right: '33px',
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
]),
|
2016-08-19 00:20:26 +02:00
|
|
|
h(currentForm.shapeshift ? '.activeForm' : '.inactiveForm.pointer', {
|
2016-08-10 22:43:01 +02:00
|
|
|
onClick: () => props.dispatch(actions.shapeShiftSubview(props.provider.type)),
|
|
|
|
}, 'Shapeshift'),
|
2016-08-13 00:41:59 +02:00
|
|
|
|
|
|
|
h('a', {
|
|
|
|
href: 'https://github.com/MetaMask/faq/blob/master/COINBASE.md',
|
|
|
|
onClick: (event) => this.navigateTo('https://info.shapeshift.io/about'),
|
|
|
|
}, [
|
|
|
|
h('i.fa.fa-question-circle', {
|
|
|
|
style: {
|
|
|
|
position: 'relative',
|
|
|
|
right: '28px',
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
]),
|
2016-08-10 22:43:01 +02:00
|
|
|
]),
|
|
|
|
this.formVersionSubview(),
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
BuyButtonSubview.prototype.formVersionSubview = function () {
|
|
|
|
if (this.props.network === '1') {
|
2016-08-13 00:41:59 +02:00
|
|
|
if (this.props.buyView.formView.coinbase) {
|
2016-08-10 22:43:01 +02:00
|
|
|
return h(CoinbaseForm, this.props)
|
2016-08-13 00:41:59 +02:00
|
|
|
} else if (this.props.buyView.formView.shapeshift) {
|
2016-08-10 22:43:01 +02:00
|
|
|
return h(ShapeshiftForm, this.props)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return h('div.flex-column', {
|
|
|
|
style: {
|
|
|
|
alignItems: 'center',
|
|
|
|
margin: '50px',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h('h3.text-transform-uppercase', {
|
|
|
|
style: {
|
|
|
|
width: '225px',
|
|
|
|
},
|
2016-09-06 19:03:10 +02:00
|
|
|
}, 'In order to access this feature please switch to the Main Network'),
|
2016-08-13 00:59:12 +02:00
|
|
|
h('h3.text-transform-uppercase', 'or:'),
|
|
|
|
this.props.network === '2' ? h('button.text-transform-uppercase', {
|
|
|
|
onClick: () => this.props.dispatch(actions.buyEth()),
|
2016-08-15 06:41:08 +02:00
|
|
|
style: {
|
|
|
|
marginTop: '15px',
|
|
|
|
},
|
2016-08-13 00:59:12 +02:00
|
|
|
}, 'Go To Test Faucet') : null,
|
2016-08-10 22:43:01 +02:00
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-13 00:41:59 +02:00
|
|
|
BuyButtonSubview.prototype.navigateTo = function (url) {
|
|
|
|
extension.tabs.create({ url })
|
|
|
|
}
|