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-09-16 05:51:41 +02:00
|
|
|
const Loading = require('./loading')
|
2017-04-18 18:21:24 +02:00
|
|
|
const AccountPanel = require('./account-panel')
|
|
|
|
const RadioList = require('./custom-radio-list')
|
2016-08-10 22:43:01 +02:00
|
|
|
|
|
|
|
module.exports = connect(mapStateToProps)(BuyButtonSubview)
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
2017-04-18 18:21:24 +02:00
|
|
|
identity: state.appState.identity,
|
|
|
|
account: state.metamask.accounts[state.appState.buyView.buyAddress],
|
2016-08-10 22:43:01 +02:00
|
|
|
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,
|
2016-09-15 19:24:05 +02:00
|
|
|
context: state.appState.currentView.context,
|
2016-09-16 05:51:41 +02:00
|
|
|
isSubLoading: state.appState.isSubLoading,
|
2016-08-10 22:43:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(BuyButtonSubview, Component)
|
|
|
|
function BuyButtonSubview () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
BuyButtonSubview.prototype.render = function () {
|
|
|
|
const props = this.props
|
2016-09-16 05:51:41 +02:00
|
|
|
const isLoading = props.isSubLoading
|
2016-08-10 22:43:01 +02:00
|
|
|
|
|
|
|
return (
|
2017-04-18 18:21:24 +02:00
|
|
|
h('.buy-eth-section.flex-column', {
|
|
|
|
style: {
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
|
|
|
}, [
|
2016-08-13 00:41:59 +02:00
|
|
|
// back button
|
|
|
|
h('.flex-row', {
|
|
|
|
style: {
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h('i.fa.fa-arrow-left.fa-lg.cursor-pointer.color-orange', {
|
2016-09-15 19:24:05 +02:00
|
|
|
onClick: this.backButtonContext.bind(this),
|
2016-08-13 00:41:59 +02:00
|
|
|
style: {
|
|
|
|
position: 'absolute',
|
|
|
|
left: '10px',
|
|
|
|
},
|
|
|
|
}),
|
2017-04-18 18:21:24 +02:00
|
|
|
h('h2.text-transform-uppercase.flex-center', {
|
|
|
|
style: {
|
|
|
|
width: '100vw',
|
|
|
|
background: 'rgb(235, 235, 235)',
|
|
|
|
color: 'rgb(174, 174, 174)',
|
|
|
|
paddingTop: '4px',
|
|
|
|
paddingBottom: '4px',
|
2016-11-04 20:02:00 +01:00
|
|
|
},
|
2017-04-18 18:21:24 +02:00
|
|
|
}, 'Buy Eth'),
|
|
|
|
]),
|
|
|
|
h('div', {
|
|
|
|
style: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: '57vh',
|
|
|
|
left: '49vw',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h(Loading, {isLoading}),
|
|
|
|
]),
|
|
|
|
h('div', {
|
|
|
|
style: {
|
|
|
|
width: '80%',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h(AccountPanel, {
|
|
|
|
showFullAddress: true,
|
|
|
|
identity: props.identity,
|
|
|
|
account: props.account,
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
h('h3.text-transform-uppercase', {
|
|
|
|
style: {
|
|
|
|
paddingLeft: '15px',
|
|
|
|
fontFamily: 'Montserrat Light',
|
|
|
|
width: '100vw',
|
|
|
|
background: 'rgb(235, 235, 235)',
|
|
|
|
color: 'rgb(174, 174, 174)',
|
|
|
|
paddingTop: '4px',
|
|
|
|
paddingBottom: '4px',
|
|
|
|
},
|
|
|
|
}, 'Select Service'),
|
|
|
|
h('.flex-row.selected-exchange', {
|
|
|
|
style: {
|
|
|
|
position: 'relative',
|
|
|
|
right: '35px',
|
|
|
|
marginTop: '20px',
|
|
|
|
marginBottom: '20px',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h(RadioList, {
|
|
|
|
defaultFocus: props.buyView.subview,
|
2017-04-24 20:56:31 +02:00
|
|
|
labels: [
|
2017-04-18 18:21:24 +02:00
|
|
|
'Coinbase',
|
|
|
|
'ShapeShift',
|
|
|
|
],
|
|
|
|
subtext: {
|
|
|
|
'Coinbase': 'Crypto/FIAT (USA only)',
|
|
|
|
'ShapeShift': 'Crypto',
|
2016-11-04 20:02:00 +01:00
|
|
|
},
|
2017-04-18 18:21:24 +02:00
|
|
|
onClick: this.radioHandler.bind(this),
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
h('h3.text-transform-uppercase', {
|
|
|
|
style: {
|
|
|
|
paddingLeft: '15px',
|
|
|
|
fontFamily: 'Montserrat Light',
|
|
|
|
width: '100vw',
|
|
|
|
background: 'rgb(235, 235, 235)',
|
|
|
|
color: 'rgb(174, 174, 174)',
|
|
|
|
paddingTop: '4px',
|
|
|
|
paddingBottom: '4px',
|
2016-08-10 22:43:01 +02:00
|
|
|
},
|
2017-04-18 18:21:24 +02:00
|
|
|
}, props.buyView.subview),
|
2016-08-10 22:43:01 +02:00
|
|
|
this.formVersionSubview(),
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
BuyButtonSubview.prototype.formVersionSubview = function () {
|
2017-04-05 03:23:46 +02:00
|
|
|
const network = this.props.network
|
|
|
|
if (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',
|
2017-08-09 00:17:24 +02:00
|
|
|
margin: '20px 50px',
|
2016-08-10 22:43:01 +02:00
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h('h3.text-transform-uppercase', {
|
|
|
|
style: {
|
|
|
|
width: '225px',
|
2017-03-27 22:05:21 +02:00
|
|
|
marginBottom: '15px',
|
2016-08-10 22:43:01 +02:00
|
|
|
},
|
2016-11-22 19:13:57 +01:00
|
|
|
}, 'In order to access this feature, please switch to the Main Network'),
|
2017-04-25 23:39:01 +02:00
|
|
|
((network === '3') || (network === '4') || (network === '42')) ? h('h3.text-transform-uppercase', 'or go to the') : null,
|
2017-04-05 03:23:46 +02:00
|
|
|
(network === '3') ? h('button.text-transform-uppercase', {
|
|
|
|
onClick: () => this.props.dispatch(actions.buyEth({ network })),
|
2016-08-15 06:41:08 +02:00
|
|
|
style: {
|
|
|
|
marginTop: '15px',
|
|
|
|
},
|
2017-03-27 22:05:21 +02:00
|
|
|
}, 'Ropsten Test Faucet') : null,
|
2017-04-25 23:39:01 +02:00
|
|
|
(network === '4') ? h('button.text-transform-uppercase', {
|
|
|
|
onClick: () => this.props.dispatch(actions.buyEth({ network })),
|
|
|
|
style: {
|
|
|
|
marginTop: '15px',
|
|
|
|
},
|
|
|
|
}, 'Rinkeby Test Faucet') : null,
|
2017-04-05 03:23:46 +02:00
|
|
|
(network === '42') ? h('button.text-transform-uppercase', {
|
|
|
|
onClick: () => this.props.dispatch(actions.buyEth({ network })),
|
2017-03-27 22:05:21 +02:00
|
|
|
style: {
|
|
|
|
marginTop: '15px',
|
|
|
|
},
|
|
|
|
}, 'Kovan Test Faucet') : null,
|
2016-08-10 22:43:01 +02:00
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-13 00:41:59 +02:00
|
|
|
BuyButtonSubview.prototype.navigateTo = function (url) {
|
2017-04-01 03:04:13 +02:00
|
|
|
global.platform.openWindow({ url })
|
2016-08-13 00:41:59 +02:00
|
|
|
}
|
2016-09-15 19:24:05 +02:00
|
|
|
|
|
|
|
BuyButtonSubview.prototype.backButtonContext = function () {
|
|
|
|
if (this.props.context === 'confTx') {
|
|
|
|
this.props.dispatch(actions.showConfTxPage(false))
|
|
|
|
} else {
|
|
|
|
this.props.dispatch(actions.goHome())
|
|
|
|
}
|
|
|
|
}
|
2017-04-18 18:21:24 +02:00
|
|
|
|
|
|
|
BuyButtonSubview.prototype.radioHandler = function (event) {
|
|
|
|
switch (event.target.title) {
|
|
|
|
case 'Coinbase':
|
|
|
|
return this.props.dispatch(actions.coinBaseSubview())
|
|
|
|
case 'ShapeShift':
|
|
|
|
return this.props.dispatch(actions.shapeShiftSubview(this.props.provider.type))
|
|
|
|
}
|
|
|
|
}
|