1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 11:46:13 +02:00
metamask-extension/ui/app/components/modals/deposit-ether-modal.js

201 lines
5.6 KiB
JavaScript
Raw Normal View History

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 networkNames = require('../../../../app/scripts/config.js').networkNames
const ShapeshiftForm = require('../shapeshift-form')
const t = require('../../../i18n')
const DIRECT_DEPOSIT_ROW_TITLE = t('directDepositEther')
const DIRECT_DEPOSIT_ROW_TEXT = t('directDepositEtherExplainer')
const COINBASE_ROW_TITLE = t('buyCoinbase')
const COINBASE_ROW_TEXT = t('buyCoinbaseExplainer')
const SHAPESHIFT_ROW_TITLE = t('depositShapeShift')
const SHAPESHIFT_ROW_TEXT = t('depositShapeShiftExplainer')
const FAUCET_ROW_TITLE = t('testFaucet')
2018-01-29 21:29:01 +01:00
const facuetRowText = (networkName) => {
return t('getEtherFromFaucet', [networkName])
}
function mapStateToProps (state) {
return {
network: state.metamask.network,
address: state.metamask.selectedAddress,
}
}
function mapDispatchToProps (dispatch) {
return {
toCoinbase: (address) => {
dispatch(actions.buyEth({ network: '1', address, amount: 0 }))
},
hideModal: () => {
dispatch(actions.hideModal())
},
hideWarning: () => {
dispatch(actions.hideWarning())
},
showAccountDetailModal: () => {
dispatch(actions.showModal({ name: 'ACCOUNT_DETAILS' }))
},
toFaucet: network => dispatch(actions.buyEth({ network })),
}
}
inherits(DepositEtherModal, Component)
function DepositEtherModal () {
Component.call(this)
this.state = {
buyingWithShapeshift: false,
}
}
module.exports = connect(mapStateToProps, mapDispatchToProps)(DepositEtherModal)
DepositEtherModal.prototype.renderRow = function ({
logo,
title,
text,
buttonLabel,
onButtonClick,
hide,
className,
hideButton,
hideTitle,
onBackClick,
showBackButton,
}) {
if (hide) {
return null
}
return h('div', {
className: className || 'deposit-ether-modal__buy-row',
}, [
onBackClick && showBackButton && h('div.deposit-ether-modal__buy-row__back', {
onClick: onBackClick,
}, [
h('i.fa.fa-arrow-left.cursor-pointer'),
]),
2018-03-12 19:25:12 +01:00
h('div.deposit-ether-modal__buy-row__logo-container', [logo]),
h('div.deposit-ether-modal__buy-row__description', [
!hideTitle && h('div.deposit-ether-modal__buy-row__description__title', [title]),
h('div.deposit-ether-modal__buy-row__description__text', [text]),
]),
!hideButton && h('div.deposit-ether-modal__buy-row__button', [
h('button.deposit-ether-modal__deposit-button', {
onClick: onButtonClick,
}, [buttonLabel]),
]),
])
}
DepositEtherModal.prototype.render = function () {
const { network, toCoinbase, address, toFaucet } = this.props
const { buyingWithShapeshift } = this.state
const isTestNetwork = ['3', '4', '42'].find(n => n === network)
const networkName = networkNames[network]
2018-03-16 21:09:49 +01:00
return h('div.page-container.page-container--full-width.page-container--full-height', {}, [
2018-03-12 19:25:12 +01:00
h('div.page-container__header', [
2018-03-13 18:21:03 +01:00
h('div.page-container__title', [t('depositEther')]),
h('div.page-container__subtitle', [
t('needEtherInWallet'),
]),
2018-03-12 19:25:12 +01:00
h('div.page-container__header-close', {
onClick: () => {
this.setState({ buyingWithShapeshift: false })
this.props.hideWarning()
this.props.hideModal()
},
}),
]),
2018-03-15 17:20:22 +01:00
2018-03-12 19:25:12 +01:00
h('.page-container__content', {}, [
2018-03-15 17:20:22 +01:00
2018-03-12 19:25:12 +01:00
h('div.deposit-ether-modal__buy-rows', [
this.renderRow({
2018-03-15 17:20:22 +01:00
logo: h('img.deposit-ether-modal__logo', {
src: '../../../images/deposit-eth.svg',
}),
2018-03-12 19:25:12 +01:00
title: DIRECT_DEPOSIT_ROW_TITLE,
text: DIRECT_DEPOSIT_ROW_TEXT,
2018-03-13 18:21:03 +01:00
buttonLabel: t('viewAccount'),
2018-03-12 19:25:12 +01:00
onButtonClick: () => this.goToAccountDetailsModal(),
hide: buyingWithShapeshift,
}),
2018-03-12 19:25:12 +01:00
this.renderRow({
2018-03-13 18:21:03 +01:00
logo: h('i.fa.fa-tint.fa-2x'),
2018-03-12 19:25:12 +01:00
title: FAUCET_ROW_TITLE,
2018-03-13 18:21:03 +01:00
text: facuetRowText(networkName),
buttonLabel: t('getEther'),
2018-03-12 19:25:12 +01:00
onButtonClick: () => toFaucet(network),
hide: !isTestNetwork || buyingWithShapeshift,
}),
2018-03-12 19:25:12 +01:00
this.renderRow({
logo: h('div.deposit-ether-modal__logo', {
style: {
backgroundImage: 'url(\'../../../images/coinbase logo.png\')',
height: '40px',
},
}),
title: COINBASE_ROW_TITLE,
text: COINBASE_ROW_TEXT,
2018-03-13 18:21:03 +01:00
buttonLabel: t('continueToCoinbase'),
2018-03-12 19:25:12 +01:00
onButtonClick: () => toCoinbase(address),
hide: isTestNetwork || buyingWithShapeshift,
}),
2018-03-15 17:20:22 +01:00
2018-03-12 19:25:12 +01:00
this.renderRow({
logo: h('div.deposit-ether-modal__logo', {
style: {
backgroundImage: 'url(\'../../../images/shapeshift logo.png\')',
},
}),
title: SHAPESHIFT_ROW_TITLE,
text: SHAPESHIFT_ROW_TEXT,
2018-03-13 18:21:03 +01:00
buttonLabel: t('shapeshiftBuy'),
2018-03-12 19:25:12 +01:00
onButtonClick: () => this.setState({ buyingWithShapeshift: true }),
hide: isTestNetwork,
hideButton: buyingWithShapeshift,
hideTitle: buyingWithShapeshift,
onBackClick: () => this.setState({ buyingWithShapeshift: false }),
showBackButton: this.state.buyingWithShapeshift,
className: buyingWithShapeshift && 'deposit-ether-modal__buy-row__shapeshift-buy',
}),
2018-03-12 19:25:12 +01:00
buyingWithShapeshift && h(ShapeshiftForm),
]),
]),
])
}
DepositEtherModal.prototype.goToAccountDetailsModal = function () {
this.props.hideWarning()
this.props.hideModal()
this.props.showAccountDetailModal()
}