nifty-wallet/old-ui/app/components/buy-button-subview.js

277 lines
7.4 KiB
JavaScript
Raw Normal View History

2017-11-14 08:04:23 -08:00
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const connect = require('react-redux').connect
2017-11-15 09:35:18 -08:00
const actions = require('../../../ui/app/actions')
2017-11-14 08:04:23 -08:00
const CoinbaseForm = require('./coinbase-form')
const ShapeshiftForm = require('./shapeshift-form')
const Loading = require('./loading')
const AccountPanel = require('./account-panel')
const RadioList = require('./custom-radio-list')
2018-04-12 14:17:36 -07:00
const { getNetworkDisplayName } = require('../../../app/scripts/controllers/network/util')
2017-11-14 08:04:23 -08:00
module.exports = connect(mapStateToProps)(BuyButtonSubview)
function mapStateToProps (state) {
return {
identity: state.appState.identity,
account: state.metamask.accounts[state.appState.buyView.buyAddress],
warning: state.appState.warning,
buyView: state.appState.buyView,
network: state.metamask.network,
provider: state.metamask.provider,
context: state.appState.currentView.context,
isSubLoading: state.appState.isSubLoading,
}
}
inherits(BuyButtonSubview, Component)
function BuyButtonSubview () {
Component.call(this)
}
BuyButtonSubview.prototype.render = function () {
return (
h('div', {
style: {
width: '100%',
},
}, [
this.headerSubview(),
this.primarySubview(),
])
)
}
BuyButtonSubview.prototype.headerSubview = function () {
const props = this.props
2018-07-19 04:12:21 -07:00
const { network } = props
2017-11-14 08:04:23 -08:00
const isLoading = props.isSubLoading
2018-07-19 04:12:21 -07:00
const isSokol = parseInt(network) === 77
2018-07-19 13:34:22 -07:00
const isPOA = parseInt(network) === 99
const coinName = isPOA ? 'POA' : isSokol ? 'SPOA' : 'ETH'
2017-11-14 08:04:23 -08:00
return (
h('.flex-column', {
2017-11-14 08:04:23 -08:00
style: {
alignItems: 'center',
},
}, [
// loading indication
h('div', {
style: {
position: 'absolute',
top: '57vh',
left: '49vw',
},
}, [
h(Loading, { isLoading }),
]),
// account panel
h('div', {
style: {
2018-07-26 11:15:51 -07:00
width: '100%',
2017-11-14 08:04:23 -08:00
},
}, [
h(AccountPanel, {
showFullAddress: true,
identity: props.identity,
account: props.account,
2018-07-19 04:12:21 -07:00
network: props.network,
2017-11-14 08:04:23 -08:00
}),
]),
2018-08-07 14:28:23 -07:00
// header bar (back button, label)
h('.flex-row.section-title', {
2017-11-14 08:04:23 -08:00
style: {
alignItems: 'center',
justifyContent: 'center',
},
}, [
2018-08-07 14:28:23 -07:00
h('i.fa.fa-arrow-left.fa-lg.cursor-pointer', {
onClick: this.backButtonContext.bind(this),
style: {
position: 'absolute',
left: '30px',
},
}),
h('h2.flex-center', {
2017-11-14 08:04:23 -08:00
style: {
width: '100vw',
2018-07-26 11:15:51 -07:00
background: '#ffffff',
color: '#333333',
2018-08-07 14:28:23 -07:00
paddingTop: '4px',
2017-11-14 08:04:23 -08:00
paddingBottom: '4px',
},
2018-08-07 14:28:23 -07:00
}, `Buy ${coinName}`),
]),
h('.flex-row', {
style: {
alignItems: 'center',
width: '100%',
},
}, [
h('h3.flex-center', {
style: {
width: '100%',
background: '#ffffff',
color: '#333333',
paddingLeft: '30px',
justifyContent: 'left',
fontFamily: 'Nunito Semibold',
2018-08-07 14:28:23 -07:00
},
2017-11-14 08:04:23 -08:00
}, 'Select Service'),
]),
])
)
}
BuyButtonSubview.prototype.primarySubview = function () {
const props = this.props
const network = props.network
switch (network) {
case 'loading':
return
case '1':
return this.mainnetSubview()
// Ropsten, Rinkeby, Kovan, Sokol, POA
2017-11-14 08:04:23 -08:00
case '3':
case '4':
case '42':
2018-07-18 10:41:53 -07:00
case '77':
2018-07-18 08:18:44 -07:00
case '99':
2018-04-12 14:17:36 -07:00
const networkName = getNetworkDisplayName(network)
2018-07-23 04:26:43 -07:00
const label = `${networkName} Test Faucet`
2017-11-14 08:04:23 -08:00
return (
h('div.flex-column', {
style: {
margin: '20px 30px',
2017-11-14 08:04:23 -08:00
},
}, [
network !== '99' ? h('p.cursor-pointer', {
style: {marginBottom: '10px'},
2017-11-14 08:04:23 -08:00
onClick: () => this.props.dispatch(actions.buyEth({ network })),
},
[h('span', {style: {marginRight: '10px', color: '#6729a8'}}, label), h('i.arrow-right')]) : null,
network === '99' ? h('p.cursor-pointer', {
style: {marginBottom: '10px'},
2018-07-23 04:26:43 -07:00
onClick: () => this.props.dispatch(actions.buyEth({ network, exchange: 'binance' })),
}, [h('span', {style: {marginRight: '10px', color: '#6729a8'}}, 'Binance'), h('i.arrow-right')]) : null,
network === '99' ? h('p.cursor-pointer', {
style: {marginBottom: '10px'},
2018-07-23 04:26:43 -07:00
onClick: () => this.props.dispatch(actions.buyEth({ network, exchange: 'bibox' })),
}, [h('span', {style: {marginRight: '10px', color: '#6729a8'}}, 'BiBox'), h('i.arrow-right')]) : null,
network === '99' ? h('p.cursor-pointer', {
style: {marginBottom: '10px'},
2018-07-23 04:26:43 -07:00
onClick: () => this.props.dispatch(actions.buyEth({ network, exchange: 'cex.plus' })),
}, [h('span', {style: {marginRight: '10px', color: '#6729a8'}}, 'CEX Plus'), h('i.arrow-right')]) : null,
2017-11-14 08:04:23 -08:00
// Kovan only: Dharma loans beta
network === '42' ? (
h('p.cursor-pointer', {
style: {marginBottom: '10px'},
2017-11-14 08:04:23 -08:00
onClick: () => this.navigateTo('https://borrow.dharma.io/'),
}, [h('span', {style: {marginRight: '10px', color: '#6729a8'}}, 'Borrow With Dharma (Beta)'), h('i.arrow-right')])
2017-11-14 08:04:23 -08:00
) : null,
])
)
default:
return (
h('div', {
style: {
padding: '20px 30px',
}},
h('h2.error', 'Unknown network ID')
)
2017-11-14 08:04:23 -08:00
)
}
}
BuyButtonSubview.prototype.mainnetSubview = function () {
const props = this.props
return (
2018-08-07 14:28:23 -07:00
h('.flex-column', [
2017-11-14 08:04:23 -08:00
h('.flex-row.selected-exchange', {
style: {
position: 'relative',
2018-08-07 14:28:23 -07:00
marginLeft: '30px',
2017-11-14 08:04:23 -08:00
marginTop: '20px',
marginBottom: '20px',
},
}, [
h(RadioList, {
defaultFocus: props.buyView.subview,
labels: [
'Coinbase',
'ShapeShift',
],
subtext: {
'Coinbase': 'Crypto/FIAT (USA only)',
'ShapeShift': 'Crypto',
},
onClick: this.radioHandler.bind(this),
}),
]),
2018-07-26 11:15:51 -07:00
h('h3', {
2017-11-14 08:04:23 -08:00
style: {
padding: '20px 30px',
fontFamily: 'Nunito Semibold',
color: '#333333',
paddingTop: '20px',
paddingBottom: '20px',
borderTop: '1px solid #e2e2e2',
2017-11-14 08:04:23 -08:00
},
}, props.buyView.subview),
this.formVersionSubview(),
])
)
}
BuyButtonSubview.prototype.formVersionSubview = function () {
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) {
return h(ShapeshiftForm, this.props)
}
}
}
BuyButtonSubview.prototype.navigateTo = function (url) {
global.platform.openWindow({ url })
}
BuyButtonSubview.prototype.backButtonContext = function () {
if (this.props.context === 'confTx') {
this.props.dispatch(actions.showConfTxPage(false))
} else {
this.props.dispatch(actions.goHome())
}
}
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))
}
}