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/wallet-view.js

247 lines
6.5 KiB
JavaScript
Raw Normal View History

const Component = require('react').Component
const PropTypes = require('prop-types')
const connect = require('react-redux').connect
const h = require('react-hyperscript')
const { withRouter } = require('react-router-dom')
const { compose } = require('recompose')
const inherits = require('util').inherits
const classnames = require('classnames')
const { checksumAddress } = require('../util')
import Identicon from './identicon'
2017-10-24 08:59:21 +02:00
// const AccountDropdowns = require('./dropdowns/index.js').AccountDropdowns
2018-09-09 01:06:19 +02:00
const Tooltip = require('./tooltip-v2.js').default
2017-10-24 08:59:21 +02:00
const copyToClipboard = require('copy-to-clipboard')
const actions = require('../actions')
import BalanceComponent from './balance'
2017-09-05 10:48:52 +02:00
const TokenList = require('./token-list')
const selectors = require('../selectors')
const { ADD_TOKEN_ROUTE } = require('../routes')
import AddTokenButton from './add-token-button'
module.exports = compose(
withRouter,
connect(mapStateToProps, mapDispatchToProps)
)(WalletView)
WalletView.contextTypes = {
t: PropTypes.func,
Metametrics (#6171) * Add metametrics provider and util. * Add backend api and state for participating in metametrics. * Add frontend action for participating in metametrics. * Add metametrics opt-in screen. * Add metametrics events to first time flow. * Add metametrics events for route changes * Add metametrics events for send and confirm screens * Add metametrics events to dropdowns, transactions, log in and out, settings, sig requests and main screen * Ensures each log in is measured as a new visit by metametrics. * Ensure metametrics is called with an empty string for dimensions params if specified * Adds opt in metametrics modal after unlock for existing users * Adds settings page toggle for opting in and out of MetaMetrics * Switch metametrics dimensions to page level scope * Lint, test and translation fixes for metametrics. * Update design for metametrics opt-in screen * Complete responsive styling of metametrics-opt-in modal * Use new chart image on metrics opt in screens * Incorporate the metametrics opt-in screen into the new onboarding flow * Update e2e tests to accomodate metametrics changes * Mock out metametrics network requests in integration tests * Fix tx-list integration test to support metametrics provider. * Send number of tokens and accounts data with every metametrics event. * Update metametrics event descriptor schema and add new events. * Fix import tos bug and send gas button bug due to metametrics changes. * Various small fixes on the metametrics branch. * Add origin custom variable type to metametrics.util * Fix names of onboarding complete actions (metametrics). * Fix names of Metrics Options actions (metametrics). * Clean up code related to metametrics. * Fix bad merge conflict resolution and improve promise handling in sendMetaMetrics event and confrim tx base * Don't send a second metrics event if user has gone back during first time flow. * Collect metametrics on going back from onboarding create/import. * Add missing custom variable constants for metametrics * Fix metametrics provider * Make height of opt-in modal responsive. * Adjust text content for opt-in modal. * Update metametrics event names and clean up code in opt-in-modal * Put phishing warning step next to last in onboarding flow * Link terms of service on create and import screens of first time flow * Add subtext to options on the onboarding select action screen. * Fix styling of bullet points on end of onboarding screen. * Combine phishing warning and congratulations screens. * Fix placement of users if unlocking after an incomplete onboarding import flow. * Fix capitalization in opt-in screen * Fix last onboarding screen translations * Add link to 'Learn More' on the last screen of onboarding * Code clean up: metametrics branch * Update e2e tests for phishing warning step removal * e2e tests passing on metametrics branch * Different tracking urls for metametrics on development and prod
2019-03-05 16:45:01 +01:00
metricsEvent: PropTypes.func,
}
WalletView.defaultProps = {
responsiveDisplayClassname: '',
}
function mapStateToProps (state) {
2017-08-10 08:48:05 +02:00
return {
network: state.metamask.network,
sidebarOpen: state.appState.sidebar.isOpen,
2017-08-07 06:54:42 +02:00
identities: state.metamask.identities,
accounts: selectors.getMetaMaskAccounts(state),
2017-10-24 08:59:21 +02:00
keyrings: state.metamask.keyrings,
selectedAddress: selectors.getSelectedAddress(state),
selectedAccount: selectors.getSelectedAccount(state),
2017-09-06 12:17:49 +02:00
selectedTokenAddress: state.metamask.selectedTokenAddress,
}
}
function mapDispatchToProps (dispatch) {
return {
2017-10-24 08:59:21 +02:00
showSendPage: () => dispatch(actions.showSendPage()),
hideSidebar: () => dispatch(actions.hideSidebar()),
2017-09-06 12:17:49 +02:00
unsetSelectedToken: () => dispatch(actions.setSelectedToken()),
2017-10-24 08:59:21 +02:00
showAccountDetailModal: () => {
dispatch(actions.showModal({ name: 'ACCOUNT_DETAILS' }))
},
2017-10-24 09:29:20 +02:00
showAddTokenPage: () => dispatch(actions.showAddTokenPage()),
}
}
inherits(WalletView, Component)
function WalletView () {
Component.call(this)
2017-10-25 05:04:29 +02:00
this.state = {
hasCopied: false,
copyToClipboardPressed: false,
2017-10-25 05:04:29 +02:00
}
}
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,
2017-09-28 13:55:04 +02:00
} = this.props
2017-10-24 08:59:21 +02:00
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, {
2017-10-19 21:47:44 +02:00
balanceValue: selectedAccount ? selectedAccount.balance : '',
2017-09-06 12:17:49 +02:00
style: {},
}),
]
),
])
2017-09-05 10:48:52 +02:00
}
WalletView.prototype.renderAddToken = function () {
const {
sidebarOpen,
hideSidebar,
history,
} = this.props
const { metricsEvent } = this.context
return h(AddTokenButton, {
onClick () {
history.push(ADD_TOKEN_ROUTE)
metricsEvent({
Metametrics (#6171) * Add metametrics provider and util. * Add backend api and state for participating in metametrics. * Add frontend action for participating in metametrics. * Add metametrics opt-in screen. * Add metametrics events to first time flow. * Add metametrics events for route changes * Add metametrics events for send and confirm screens * Add metametrics events to dropdowns, transactions, log in and out, settings, sig requests and main screen * Ensures each log in is measured as a new visit by metametrics. * Ensure metametrics is called with an empty string for dimensions params if specified * Adds opt in metametrics modal after unlock for existing users * Adds settings page toggle for opting in and out of MetaMetrics * Switch metametrics dimensions to page level scope * Lint, test and translation fixes for metametrics. * Update design for metametrics opt-in screen * Complete responsive styling of metametrics-opt-in modal * Use new chart image on metrics opt in screens * Incorporate the metametrics opt-in screen into the new onboarding flow * Update e2e tests to accomodate metametrics changes * Mock out metametrics network requests in integration tests * Fix tx-list integration test to support metametrics provider. * Send number of tokens and accounts data with every metametrics event. * Update metametrics event descriptor schema and add new events. * Fix import tos bug and send gas button bug due to metametrics changes. * Various small fixes on the metametrics branch. * Add origin custom variable type to metametrics.util * Fix names of onboarding complete actions (metametrics). * Fix names of Metrics Options actions (metametrics). * Clean up code related to metametrics. * Fix bad merge conflict resolution and improve promise handling in sendMetaMetrics event and confrim tx base * Don't send a second metrics event if user has gone back during first time flow. * Collect metametrics on going back from onboarding create/import. * Add missing custom variable constants for metametrics * Fix metametrics provider * Make height of opt-in modal responsive. * Adjust text content for opt-in modal. * Update metametrics event names and clean up code in opt-in-modal * Put phishing warning step next to last in onboarding flow * Link terms of service on create and import screens of first time flow * Add subtext to options on the onboarding select action screen. * Fix styling of bullet points on end of onboarding screen. * Combine phishing warning and congratulations screens. * Fix placement of users if unlocking after an incomplete onboarding import flow. * Fix capitalization in opt-in screen * Fix last onboarding screen translations * Add link to 'Learn More' on the last screen of onboarding * Code clean up: metametrics branch * Update e2e tests for phishing warning step removal * e2e tests passing on metametrics branch * Different tracking urls for metametrics on development and prod
2019-03-05 16:45:01 +01:00
eventOpts: {
category: 'Navigation',
action: 'Token Menu',
name: 'Clicked "Add Token"',
},
})
if (sidebarOpen) {
hideSidebar()
}
},
})
}
WalletView.prototype.render = function () {
2017-09-05 10:48:52 +02:00
const {
2017-10-24 08:59:21 +02:00
responsiveDisplayClassname,
selectedAddress,
keyrings,
showAccountDetailModal,
hideSidebar,
identities,
network,
2017-09-05 10:48:52 +02:00
} = this.props
// temporary logs + fake extra wallets
const checksummedAddress = checksumAddress(selectedAddress, network)
if (!selectedAddress) {
throw new Error('selectedAddress should not be ' + String(selectedAddress))
}
2017-10-24 08:59:21 +02:00
const keyring = keyrings.find((kr) => {
return kr.accounts.includes(selectedAddress)
2017-10-24 08:59:21 +02:00
})
2018-08-17 02:41:23 +02:00
let label = ''
let type
if (keyring) {
type = keyring.type
if (type !== 'HD Key Tree') {
if (type.toLowerCase().search('hardware') !== -1) {
label = this.context.t('hardware')
} else {
label = this.context.t('imported')
}
}
}
2017-10-24 08:59:21 +02:00
return h('div.wallet-view.flex-column', {
style: {},
className: responsiveDisplayClassname,
}, [
// TODO: Separate component: wallet account details
h('div.flex-column.wallet-view-account-details', {
2017-08-29 16:50:48 +02:00
style: {},
}, [
2017-10-24 08:59:21 +02:00
h('div.wallet-view__sidebar-close', {
onClick: hideSidebar,
}),
2018-08-17 02:41:23 +02:00
h('div.wallet-view__keyring-label.allcaps', label),
h('div.flex-column.flex-center.wallet-view__name-container', {
2017-10-24 08:59:21 +02:00
style: { margin: '0 auto' },
onClick: showAccountDetailModal,
}, [
h(Identicon, {
diameter: 54,
address: checksummedAddress,
}),
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
}, [
identities[selectedAddress].name,
2017-08-07 06:54:42 +02:00
]),
h('button.btn-clear.wallet-view__details-button.allcaps', this.context.t('details')),
]),
]),
h(Tooltip, {
position: 'bottom',
title: this.state.hasCopied ? this.context.t('copiedExclamation') : this.context.t('copyToClipboard'),
wrapperClassName: 'wallet-view__tooltip',
2017-10-25 05:04:29 +02:00
}, [
h('button.wallet-view__address', {
className: classnames({
'wallet-view__address__pressed': this.state.copyToClipboardPressed,
}),
onClick: () => {
copyToClipboard(checksummedAddress)
Metametrics (#6171) * Add metametrics provider and util. * Add backend api and state for participating in metametrics. * Add frontend action for participating in metametrics. * Add metametrics opt-in screen. * Add metametrics events to first time flow. * Add metametrics events for route changes * Add metametrics events for send and confirm screens * Add metametrics events to dropdowns, transactions, log in and out, settings, sig requests and main screen * Ensures each log in is measured as a new visit by metametrics. * Ensure metametrics is called with an empty string for dimensions params if specified * Adds opt in metametrics modal after unlock for existing users * Adds settings page toggle for opting in and out of MetaMetrics * Switch metametrics dimensions to page level scope * Lint, test and translation fixes for metametrics. * Update design for metametrics opt-in screen * Complete responsive styling of metametrics-opt-in modal * Use new chart image on metrics opt in screens * Incorporate the metametrics opt-in screen into the new onboarding flow * Update e2e tests to accomodate metametrics changes * Mock out metametrics network requests in integration tests * Fix tx-list integration test to support metametrics provider. * Send number of tokens and accounts data with every metametrics event. * Update metametrics event descriptor schema and add new events. * Fix import tos bug and send gas button bug due to metametrics changes. * Various small fixes on the metametrics branch. * Add origin custom variable type to metametrics.util * Fix names of onboarding complete actions (metametrics). * Fix names of Metrics Options actions (metametrics). * Clean up code related to metametrics. * Fix bad merge conflict resolution and improve promise handling in sendMetaMetrics event and confrim tx base * Don't send a second metrics event if user has gone back during first time flow. * Collect metametrics on going back from onboarding create/import. * Add missing custom variable constants for metametrics * Fix metametrics provider * Make height of opt-in modal responsive. * Adjust text content for opt-in modal. * Update metametrics event names and clean up code in opt-in-modal * Put phishing warning step next to last in onboarding flow * Link terms of service on create and import screens of first time flow * Add subtext to options on the onboarding select action screen. * Fix styling of bullet points on end of onboarding screen. * Combine phishing warning and congratulations screens. * Fix placement of users if unlocking after an incomplete onboarding import flow. * Fix capitalization in opt-in screen * Fix last onboarding screen translations * Add link to 'Learn More' on the last screen of onboarding * Code clean up: metametrics branch * Update e2e tests for phishing warning step removal * e2e tests passing on metametrics branch * Different tracking urls for metametrics on development and prod
2019-03-05 16:45:01 +01:00
this.context.metricsEvent({
eventOpts: {
category: 'Navigation',
action: 'Home',
name: 'Copied Address',
Metametrics (#6171) * Add metametrics provider and util. * Add backend api and state for participating in metametrics. * Add frontend action for participating in metametrics. * Add metametrics opt-in screen. * Add metametrics events to first time flow. * Add metametrics events for route changes * Add metametrics events for send and confirm screens * Add metametrics events to dropdowns, transactions, log in and out, settings, sig requests and main screen * Ensures each log in is measured as a new visit by metametrics. * Ensure metametrics is called with an empty string for dimensions params if specified * Adds opt in metametrics modal after unlock for existing users * Adds settings page toggle for opting in and out of MetaMetrics * Switch metametrics dimensions to page level scope * Lint, test and translation fixes for metametrics. * Update design for metametrics opt-in screen * Complete responsive styling of metametrics-opt-in modal * Use new chart image on metrics opt in screens * Incorporate the metametrics opt-in screen into the new onboarding flow * Update e2e tests to accomodate metametrics changes * Mock out metametrics network requests in integration tests * Fix tx-list integration test to support metametrics provider. * Send number of tokens and accounts data with every metametrics event. * Update metametrics event descriptor schema and add new events. * Fix import tos bug and send gas button bug due to metametrics changes. * Various small fixes on the metametrics branch. * Add origin custom variable type to metametrics.util * Fix names of onboarding complete actions (metametrics). * Fix names of Metrics Options actions (metametrics). * Clean up code related to metametrics. * Fix bad merge conflict resolution and improve promise handling in sendMetaMetrics event and confrim tx base * Don't send a second metrics event if user has gone back during first time flow. * Collect metametrics on going back from onboarding create/import. * Add missing custom variable constants for metametrics * Fix metametrics provider * Make height of opt-in modal responsive. * Adjust text content for opt-in modal. * Update metametrics event names and clean up code in opt-in-modal * Put phishing warning step next to last in onboarding flow * Link terms of service on create and import screens of first time flow * Add subtext to options on the onboarding select action screen. * Fix styling of bullet points on end of onboarding screen. * Combine phishing warning and congratulations screens. * Fix placement of users if unlocking after an incomplete onboarding import flow. * Fix capitalization in opt-in screen * Fix last onboarding screen translations * Add link to 'Learn More' on the last screen of onboarding * Code clean up: metametrics branch * Update e2e tests for phishing warning step removal * e2e tests passing on metametrics branch * Different tracking urls for metametrics on development and prod
2019-03-05 16:45:01 +01:00
},
})
this.setState({ hasCopied: true })
setTimeout(() => this.setState({ hasCopied: false }), 3000)
},
onMouseDown: () => {
this.setState({ copyToClipboardPressed: true })
},
onMouseUp: () => {
this.setState({ copyToClipboardPressed: false })
},
}, [
`${checksummedAddress.slice(0, 6)}...${checksummedAddress.slice(-4)}`,
h('i.fa.fa-clipboard', { style: { marginLeft: '8px' } }),
]),
2017-10-24 08:59:21 +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
this.renderAddToken(),
])
}
// 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: {},
// }),
// ]),
// ])