1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-28 05:12:18 +01:00
metamask-extension/ui/app/components/tx-view.js

149 lines
3.6 KiB
JavaScript
Raw Normal View History

const Component = require('react').Component
const connect = require('react-redux').connect
const h = require('react-hyperscript')
const ethUtil = require('ethereumjs-util')
const inherits = require('util').inherits
2017-08-02 22:32:02 +02:00
const actions = require('../actions')
2017-09-06 12:17:49 +02:00
const selectors = require('../selectors')
2017-08-02 22:32:02 +02:00
const BalanceComponent = require('./balance-component')
2017-08-09 12:10:51 +02:00
const TxList = require('./tx-list')
const Identicon = require('./identicon')
2017-08-02 22:32:02 +02:00
module.exports = connect(mapStateToProps, mapDispatchToProps)(TxView)
function mapStateToProps (state) {
const sidebarOpen = state.appState.sidebarOpen
const identities = state.metamask.identities
const accounts = state.metamask.accounts
2017-09-07 08:03:23 +02:00
const network = state.metamask.network
2017-09-06 12:17:49 +02:00
const selectedTokenAddress = state.metamask.selectedTokenAddress
const selectedAddress = state.metamask.selectedAddress || Object.keys(accounts)[0]
const checksumAddress = selectedAddress && ethUtil.toChecksumAddress(selectedAddress)
const identity = identities[selectedAddress]
2017-08-02 22:32:02 +02:00
return {
sidebarOpen,
selectedAddress,
checksumAddress,
2017-09-06 12:17:49 +02:00
selectedTokenAddress,
selectedToken: selectors.getSelectedToken(state),
identity,
2017-09-07 08:03:23 +02:00
network,
2017-08-02 22:32:02 +02:00
}
}
2017-08-02 22:32:02 +02:00
function mapDispatchToProps (dispatch) {
return {
showSidebar: () => { dispatch(actions.showSidebar()) },
hideSidebar: () => { dispatch(actions.hideSidebar()) },
showModal: (payload) => { dispatch(actions.showModal(payload)) },
showSendPage: () => { dispatch(actions.showSendPage()) },
2017-09-07 13:24:03 +02:00
showSendTokenPage: () => { dispatch(actions.showSendTokenPage()) },
2017-08-02 22:32:02 +02:00
}
}
2017-08-01 06:34:37 +02:00
inherits(TxView, Component)
function TxView () {
Component.call(this)
}
2017-09-06 12:17:49 +02:00
TxView.prototype.renderHeroBalance = function () {
2017-09-07 08:03:23 +02:00
const { selectedToken } = this.props
2017-09-06 12:17:49 +02:00
return h('div.hero-balance', {}, [
2017-09-07 08:03:23 +02:00
h(BalanceComponent, { token: selectedToken }),
2017-09-06 12:17:49 +02:00
2017-09-07 08:03:23 +02:00
this.renderButtons(),
2017-09-06 12:17:49 +02:00
])
}
2017-09-07 08:03:23 +02:00
TxView.prototype.renderButtons = function () {
2017-09-07 13:24:03 +02:00
const {selectedToken, showModal, showSendPage, showSendTokenPage } = this.props
2017-09-07 08:03:23 +02:00
return !selectedToken
? (
h('div.flex-row.flex-center.hero-balance-buttons', [
h('button.btn-clear', {
style: {
textAlign: 'center',
},
onClick: () => showModal({
name: 'BUY',
}),
}, 'BUY'),
h('button.btn-clear', {
style: {
textAlign: 'center',
marginLeft: '0.8em',
},
onClick: showSendPage,
}, 'SEND'),
])
)
: (
h('div.flex-row.flex-center.hero-balance-buttons', [
h('button.btn-clear', {
style: {
textAlign: 'center',
marginLeft: '0.8em',
},
2017-09-07 13:24:03 +02:00
onClick: showSendTokenPage,
2017-09-07 08:03:23 +02:00
}, 'SEND'),
])
)
}
2017-09-07 08:03:23 +02:00
TxView.prototype.render = function () {
const { selectedAddress, identity, network } = this.props
return h('div.tx-view.flex-column', {
style: {},
}, [
h('div.flex-row.phone-visible', {
style: {
margin: '1em 0.9em',
alignItems: 'center',
},
onClick: () => {
this.props.sidebarOpen ? this.props.hideSidebar() : this.props.showSidebar()
},
}, [
2017-08-11 04:35:10 +02:00
h('div.fa.fa-bars', {
style: {
fontSize: '1.3em',
},
}, []),
h('.identicon-wrapper.select-none', {
style: {
marginLeft: '0.9em',
},
}, [
h(Identicon, {
diameter: 24,
address: selectedAddress,
2017-09-07 08:03:23 +02:00
network,
}),
]),
h('span.account-name', {
style: {},
}, [
identity.name,
]),
]),
2017-09-06 12:17:49 +02:00
this.renderHeroBalance(),
2017-08-03 09:43:24 +02:00
2017-09-07 20:38:21 +02:00
h(TxList),
2017-08-01 07:00:18 +02:00
])
}