1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 11:01:41 +01:00
metamask-extension/ui/app/components/wallet-view.js

180 lines
4.6 KiB
JavaScript
Raw Normal View History

const Component = require('react').Component
const connect = require('react-redux').connect
const h = require('react-hyperscript')
const inherits = require('util').inherits
const Identicon = require('./identicon')
const AccountDropdowns = require('./dropdowns/index.js').AccountDropdowns
const actions = require('../actions')
2017-08-11 09:31:06 +02:00
const BalanceComponent = require('./balance-component')
2017-09-05 10:48:52 +02:00
const TokenList = require('./token-list')
const selectors = require('../selectors')
module.exports = connect(mapStateToProps, mapDispatchToProps)(WalletView)
function mapStateToProps (state) {
2017-08-10 08:48:05 +02:00
return {
network: state.metamask.network,
sidebarOpen: state.appState.sidebarOpen,
2017-08-07 06:54:42 +02:00
identities: state.metamask.identities,
accounts: state.metamask.accounts,
2017-09-05 10:48:52 +02:00
tokens: state.metamask.tokens,
selectedAddress: selectors.getSelectedAddress(state),
selectedIdentity: selectors.getSelectedIdentity(state),
selectedAccount: selectors.getSelectedAccount(state),
2017-09-06 12:17:49 +02:00
selectedTokenAddress: state.metamask.selectedTokenAddress,
}
}
function mapDispatchToProps (dispatch) {
return {
2017-08-29 16:50:48 +02:00
showSendPage: () => { dispatch(actions.showSendPage()) },
hideSidebar: () => { dispatch(actions.hideSidebar()) },
2017-09-06 12:17:49 +02:00
unsetSelectedToken: () => dispatch(actions.setSelectedToken()),
}
}
inherits(WalletView, Component)
function WalletView () {
Component.call(this)
}
2017-09-06 12:17:49 +02:00
WalletView.prototype.renderWalletBalance = function () {
2017-09-28 13:55:04 +02:00
const {
selectedTokenAddress,
selectedAccount,
unsetSelectedToken,
hideSidebar,
sidebarOpen
} = this.props
2017-09-06 12:17:49 +02:00
const selectedClass = selectedTokenAddress
? ''
: 'wallet-balance-wrapper--active'
const className = `flex-column wallet-balance-wrapper ${selectedClass}`
return h('div', { className }, [
h('div.wallet-balance',
{
2017-09-28 13:55:04 +02:00
onClick: () => {
unsetSelectedToken()
selectedTokenAddress && sidebarOpen && hideSidebar()
},
2017-09-06 12:17:49 +02:00
},
[
h(BalanceComponent, {
balanceValue: selectedAccount.balance,
style: {},
}),
]
),
])
2017-09-05 10:48:52 +02:00
}
WalletView.prototype.render = function () {
2017-09-05 10:48:52 +02:00
const {
network, responsiveDisplayClassname, identities,
selectedAddress, accounts,
2017-09-05 10:48:52 +02:00
selectedIdentity,
} = this.props
// temporary logs + fake extra wallets
// console.log('walletview, selectedAccount:', selectedAccount)
2017-08-02 22:03:36 +02:00
return h('div.wallet-view.flex-column' + (responsiveDisplayClassname || ''), {
style: {},
}, [
// TODO: Separate component: wallet account details
h('div.flex-column.wallet-view-account-details', {
2017-08-29 16:50:48 +02:00
style: {},
}, [
2017-08-07 06:54:42 +02:00
h('div.flex-row.account-options-menu', {
style: {
position: 'relative',
},
2017-08-07 06:54:42 +02:00
}, [
h(AccountDropdowns, {
selected: selectedAddress,
network,
identities,
useCssTransition: true,
2017-08-07 06:54:42 +02:00
enableAccountOptions: true,
dropdownWrapperStyle: {
padding: '1px 15px',
marginLeft: '-25px',
position: 'absolute',
2017-08-29 16:50:48 +02:00
width: '122%', // TODO, refactor all of this component out into media queries
},
menuItemStyles: {
padding: '0px 0px',
margin: '22px 0px',
2017-08-29 16:50:48 +02:00
},
2017-08-07 06:54:42 +02:00
}, []),
]),
2017-08-07 06:54:42 +02:00
h('div.flex-column.flex-center', {
}, [
h('div', {
2017-08-07 06:54:42 +02:00
style: {
position: 'relative',
2017-08-29 16:50:48 +02:00
},
2017-08-07 06:54:42 +02:00
}, [
h(AccountDropdowns, {
accounts,
style: {
position: 'absolute',
left: 'calc(50% + 28px + 5.5px)',
top: '14px',
},
innerStyle: {
2017-08-31 13:08:11 +02:00
padding: '10px 16px',
},
useCssTransition: true,
selected: selectedAddress,
network,
identities,
enableAccountsSelector: true,
}, []),
2017-08-07 06:54:42 +02:00
]),
h(Identicon, {
diameter: 54,
address: selectedAddress,
}),
2017-08-07 06:54:42 +02:00
h('span.account-name', {
2017-08-29 16:50:48 +02:00
style: {},
2017-08-07 06:54:42 +02:00
}, [
2017-08-29 16:50:48 +02:00
selectedIdentity.name,
2017-08-07 06:54:42 +02:00
]),
]),
]),
2017-08-29 16:50:48 +02:00
// 'Wallet' - Title
2017-08-11 09:31:06 +02:00
// Not visible on mobile
h('div.flex-column.wallet-view-title-wrapper', {}, [
h('span.wallet-view-title', {}, [
'Wallet',
2017-08-29 16:50:48 +02:00
]),
2017-08-11 09:31:06 +02:00
]),
2017-09-06 12:17:49 +02:00
this.renderWalletBalance(),
2017-08-11 09:31:06 +02:00
2017-09-06 12:17:49 +02:00
h(TokenList),
2017-09-05 10:48:52 +02:00
])
}
// TODO: Extra wallets, for dev testing. Remove when PRing to master.
// const extraWallet = h('div.flex-column.wallet-balance-wrapper', {}, [
// h('div.wallet-balance', {}, [
// h(BalanceComponent, {
// balanceValue: selectedAccount.balance,
// style: {},
// }),
// ]),
// ])