1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 12:56:01 +01:00
metamask-extension/ui/app/components/coinbase-form.js

160 lines
3.9 KiB
JavaScript
Raw Normal View History

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 isValidAddress = require('../util').isValidAddress
module.exports = connect(mapStateToProps)(CoinbaseForm)
2016-11-11 19:26:12 +01:00
function mapStateToProps (state) {
2016-08-10 22:43:01 +02:00
return {
warning: state.appState.warning,
}
}
inherits(CoinbaseForm, Component)
2016-11-11 19:26:12 +01:00
function CoinbaseForm () {
2016-08-10 22:43:01 +02:00
Component.call(this)
}
CoinbaseForm.prototype.render = function () {
var props = this.props
var amount = props.buyView.amount
var address = props.buyView.buyAddress
2016-08-10 22:43:01 +02:00
return h('.flex-column', {
style: {
// margin: '10px',
padding: '25px',
2016-08-10 22:43:01 +02:00
},
}, [
h('.flex-column', {
style: {
alignItems: 'flex-start',
},
}, [
h('.flex-row', [
2016-08-10 22:43:01 +02:00
h('div', 'Address:'),
h('.ellip-address', address),
2016-08-10 22:43:01 +02:00
]),
h('.flex-row', [
h('div', 'Amount: $'),
h('.input-container', [
h('input.buy-inputs', {
style: {
width: '3em',
boxSizing: 'border-box',
},
defaultValue: amount,
onChange: this.handleAmount.bind(this),
}),
h('i.fa.fa-pencil-square-o.edit-text', {
style: {
fontSize: '12px',
color: '#F7861C',
position: 'relative',
bottom: '5px',
right: '11px',
},
}),
]),
]),
]),
h('.info-gray', {
style: {
fontSize: '10px',
fontFamily: 'Montserrat Light',
margin: '15px',
lineHeight: '13px',
},
},
2017-01-10 21:18:39 +01:00
`there is a USD$ 15 a day max and a USD$ 50
2016-08-10 22:43:01 +02:00
dollar limit per the life time of an account without a
coinbase account. A fee of 3.75% will be aplied to debit/credit cards.`),
!props.warning ? h('div', {
style: {
width: '340px',
height: '22px',
},
}) : props.warning && h('span.error.flex-center', props.warning),
h('.flex-row', {
style: {
justifyContent: 'space-around',
margin: '33px',
},
}, [
h('button', {
onClick: this.toCoinbase.bind(this),
}, 'Continue to Coinbase'),
h('button', {
onClick: () => props.dispatch(actions.backTobuyView(props.accounts.address)),
2016-08-10 22:43:01 +02:00
}, 'Cancel'),
]),
])
}
CoinbaseForm.prototype.handleAmount = function (event) {
this.props.dispatch(actions.updateCoinBaseAmount(event.target.value))
}
CoinbaseForm.prototype.handleAddress = function (event) {
this.props.dispatch(actions.updateBuyAddress(event.target.value))
}
CoinbaseForm.prototype.toCoinbase = function () {
var props = this.props
var amount = props.buyView.amount
var address = props.buyView.buyAddress
2016-08-10 22:43:01 +02:00
var message
if (isValidAddress(address) && isValidAmountforCoinBase(amount).valid) {
props.dispatch(actions.buyEth(address, props.buyView.amount))
2016-08-10 22:43:01 +02:00
} else if (!isValidAmountforCoinBase(amount).valid) {
message = isValidAmountforCoinBase(amount).message
2016-11-08 01:02:02 +01:00
return props.dispatch(actions.displayWarning(message))
2016-08-10 22:43:01 +02:00
} else {
message = 'Receiving address is invalid.'
2016-11-08 01:02:02 +01:00
return props.dispatch(actions.displayWarning(message))
2016-08-10 22:43:01 +02:00
}
}
CoinbaseForm.prototype.renderLoading = function () {
return h('img', {
style: {
width: '27px',
marginRight: '-27px',
},
src: 'images/loading.svg',
})
}
2016-11-11 19:26:12 +01:00
function isValidAmountforCoinBase (amount) {
2016-08-10 22:43:01 +02:00
amount = parseFloat(amount)
if (amount) {
2017-01-10 21:18:39 +01:00
if (amount <= 15 && amount > 0) {
2016-08-10 22:43:01 +02:00
return {
valid: true,
}
2017-01-10 21:18:39 +01:00
} else if (amount > 15) {
2016-08-10 22:43:01 +02:00
return {
valid: false,
2017-01-10 21:18:39 +01:00
message: 'The amount can not be greater then $15',
2016-08-10 22:43:01 +02:00
}
} else {
return {
valid: false,
message: 'Can not buy amounts less then $0',
}
}
} else {
return {
valid: false,
message: 'The amount entered is not a number',
}
}
}