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

148 lines
4.1 KiB
JavaScript
Raw Normal View History

2016-08-10 13:43:01 -07: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')
const extension = require('../../../app/scripts/lib/extension')
const Loading = require('./loading')
const TabBar = require('./tab-bar')
2016-08-10 13:43:01 -07:00
module.exports = connect(mapStateToProps)(BuyButtonSubview)
function mapStateToProps (state) {
return {
warning: state.appState.warning,
buyView: state.appState.buyView,
2016-08-10 13:43:01 -07:00
network: state.metamask.network,
provider: state.metamask.provider,
context: state.appState.currentView.context,
isSubLoading: state.appState.isSubLoading,
2016-08-10 13:43:01 -07:00
}
}
inherits(BuyButtonSubview, Component)
function BuyButtonSubview () {
Component.call(this)
}
BuyButtonSubview.prototype.render = function () {
const props = this.props
const isLoading = props.isSubLoading
2016-08-10 13:43:01 -07:00
return (
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: this.backButtonContext.bind(this),
style: {
position: 'absolute',
left: '10px',
},
}),
h('h2.page-subtitle', 'Buy Eth'),
]),
h(Loading, { isLoading }),
h(TabBar, {
tabs: [
{
content: [
'Coinbase',
h('a', {
onClick: (event) => this.navigateTo('https://github.com/MetaMask/faq/blob/master/COINBASE.md'),
}, [
h('i.fa.fa-question-circle', {
style: {
margin: '0px 5px',
},
}),
]),
],
2016-11-04 12:31:03 -07:00
key: 'coinbase',
},
{
content: [
'Shapeshift',
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: {
margin: '0px 5px',
},
}),
2016-11-04 12:31:03 -07:00
]),
],
2016-11-04 12:31:03 -07:00
key: 'shapeshift',
},
],
defaultTab: 'coinbase',
tabSelected: (key) => {
switch (key) {
case 'coinbase':
props.dispatch(actions.coinBaseSubview())
break
case 'shapeshift':
props.dispatch(actions.shapeShiftSubview(props.provider.type))
break
}
2016-08-10 13:43:01 -07:00
},
}),
2016-08-10 13:43:01 -07:00
this.formVersionSubview(),
])
)
}
BuyButtonSubview.prototype.formVersionSubview = function () {
if (this.props.network === '1') {
if (this.props.buyView.formView.coinbase) {
2016-08-10 13:43:01 -07:00
return h(CoinbaseForm, this.props)
} else if (this.props.buyView.formView.shapeshift) {
2016-08-10 13:43:01 -07: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-11-22 10:13:57 -08:00
}, 'In order to access this feature, please switch to the Main Network'),
(this.props.network === '3') ? h('h3.text-transform-uppercase', 'or:') : null,
(this.props.network === '3') ? h('button.text-transform-uppercase', {
2016-08-12 15:59:12 -07:00
onClick: () => this.props.dispatch(actions.buyEth()),
style: {
marginTop: '15px',
},
2016-08-12 15:59:12 -07:00
}, 'Go To Test Faucet') : null,
2016-08-10 13:43:01 -07:00
])
}
}
BuyButtonSubview.prototype.navigateTo = function (url) {
extension.tabs.create({ url })
}
BuyButtonSubview.prototype.backButtonContext = function () {
if (this.props.context === 'confTx') {
this.props.dispatch(actions.showConfTxPage(false))
} else {
this.props.dispatch(actions.goHome())
}
}