1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Persist selected account tab

Also improve error handling with token balances.
This commit is contained in:
Dan Finlay 2017-06-14 14:21:50 -07:00
parent 3df2f2b2d4
commit b7b9e0c1ac
6 changed files with 52 additions and 14 deletions

View File

@ -7,6 +7,7 @@ class PreferencesController {
constructor (opts = {}) { constructor (opts = {}) {
const initState = extend({ const initState = extend({
frequentRpcList: [], frequentRpcList: [],
currentAccountTab: 'history',
}, opts.initState) }, opts.initState)
this.store = new ObservableStore(initState) this.store = new ObservableStore(initState)
} }
@ -35,6 +36,13 @@ class PreferencesController {
}) })
} }
setCurrentAccountTab (currentAccountTab) {
return new Promise((resolve, reject) => {
this.store.updateState({ currentAccountTab })
resolve()
})
}
addToFrequentRpcList (_url) { addToFrequentRpcList (_url) {
const rpcList = this.getFrequentRpcList() const rpcList = this.getFrequentRpcList()
const index = rpcList.findIndex((element) => { return element === _url }) const index = rpcList.findIndex((element) => { return element === _url })

View File

@ -275,6 +275,7 @@ module.exports = class MetamaskController extends EventEmitter {
// PreferencesController // PreferencesController
setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController), setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController),
setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab).bind(preferencesController),
setDefaultRpc: nodeify(this.setDefaultRpc).bind(this), setDefaultRpc: nodeify(this.setDefaultRpc).bind(this),
setCustomRpc: nodeify(this.setCustomRpc).bind(this), setCustomRpc: nodeify(this.setCustomRpc).bind(this),

View File

@ -62,12 +62,12 @@
"end-of-stream": "^1.1.0", "end-of-stream": "^1.1.0",
"ensnare": "^1.0.0", "ensnare": "^1.0.0",
"eth-bin-to-ops": "^1.0.1", "eth-bin-to-ops": "^1.0.1",
"eth-contract-metadata": "^1.1.0", "eth-contract-metadata": "^1.1.1",
"eth-hd-keyring": "^1.1.1", "eth-hd-keyring": "^1.1.1",
"eth-query": "^2.1.1", "eth-query": "^2.1.1",
"eth-sig-util": "^1.1.1", "eth-sig-util": "^1.1.1",
"eth-simple-keyring": "^1.1.1", "eth-simple-keyring": "^1.1.1",
"eth-token-tracker": "^1.0.4", "eth-token-tracker": "^1.0.6",
"ethereumjs-tx": "^1.3.0", "ethereumjs-tx": "^1.3.0",
"ethereumjs-util": "ethereumjs/ethereumjs-util#ac5d0908536b447083ea422b435da27f26615de9", "ethereumjs-util": "ethereumjs/ethereumjs-util#ac5d0908536b447083ea422b435da27f26615de9",
"ethereumjs-wallet": "^0.6.0", "ethereumjs-wallet": "^0.6.0",

View File

@ -34,12 +34,12 @@ function mapStateToProps (state) {
transactions: state.metamask.selectedAddressTxList || [], transactions: state.metamask.selectedAddressTxList || [],
conversionRate: state.metamask.conversionRate, conversionRate: state.metamask.conversionRate,
currentCurrency: state.metamask.currentCurrency, currentCurrency: state.metamask.currentCurrency,
currentAccountTab: state.metamask.currentAccountTab,
} }
} }
inherits(AccountDetailScreen, Component) inherits(AccountDetailScreen, Component)
function AccountDetailScreen () { function AccountDetailScreen () {
this.state = { tabSelection: 'history' }
Component.call(this) Component.call(this)
} }
@ -251,7 +251,8 @@ AccountDetailScreen.prototype.subview = function () {
} }
AccountDetailScreen.prototype.tabSections = function () { AccountDetailScreen.prototype.tabSections = function () {
const tabSelection = this.state.tabSelection const { currentAccountTab } = this.props
return h('section.tabSection', [ return h('section.tabSection', [
h(TabBar, { h(TabBar, {
@ -259,9 +260,9 @@ AccountDetailScreen.prototype.tabSections = function () {
{ content: 'Sent', key: 'history' }, { content: 'Sent', key: 'history' },
{ content: 'Tokens', key: 'tokens' }, { content: 'Tokens', key: 'tokens' },
], ],
defaultTab: tabSelection || 'history', defaultTab: currentAccountTab || 'history',
tabSelected: (key) => { tabSelected: (key) => {
this.setState({ tabSelection: key }) this.props.dispatch(actions.setCurrentAccountTab(key))
}, },
}), }),
@ -272,9 +273,9 @@ AccountDetailScreen.prototype.tabSections = function () {
AccountDetailScreen.prototype.tabSwitchView = function () { AccountDetailScreen.prototype.tabSwitchView = function () {
const props = this.props const props = this.props
const { address, network } = props const { address, network } = props
const tabSelection = this.state.tabSelection || 'history' const { currentAccountTab } = this.props
switch (tabSelection) { switch (currentAccountTab) {
case 'tokens': case 'tokens':
return h(TokenList, { userAddress: address, network }) return h(TokenList, { userAddress: address, network })
default: default:

View File

@ -74,6 +74,7 @@ var actions = {
SHOW_CONF_MSG_PAGE: 'SHOW_CONF_MSG_PAGE', SHOW_CONF_MSG_PAGE: 'SHOW_CONF_MSG_PAGE',
SET_CURRENT_FIAT: 'SET_CURRENT_FIAT', SET_CURRENT_FIAT: 'SET_CURRENT_FIAT',
setCurrentCurrency: setCurrentCurrency, setCurrentCurrency: setCurrentCurrency,
setCurrentAccountTab,
// account detail screen // account detail screen
SHOW_SEND_PAGE: 'SHOW_SEND_PAGE', SHOW_SEND_PAGE: 'SHOW_SEND_PAGE',
showSendPage: showSendPage, showSendPage: showSendPage,
@ -218,7 +219,7 @@ function confirmSeedWords () {
return dispatch(actions.displayWarning(err.message)) return dispatch(actions.displayWarning(err.message))
} }
console.log('Seed word cache cleared. ' + account) log.info('Seed word cache cleared. ' + account)
dispatch(actions.showAccountDetail(account)) dispatch(actions.showAccountDetail(account))
}) })
} }
@ -338,7 +339,7 @@ function setCurrentCurrency (currencyCode) {
background.setCurrentCurrency(currencyCode, (err, data) => { background.setCurrentCurrency(currencyCode, (err, data) => {
dispatch(this.hideLoadingIndication()) dispatch(this.hideLoadingIndication())
if (err) { if (err) {
console.error(err.stack) log.error(err.stack)
return dispatch(actions.displayWarning(err.message)) return dispatch(actions.displayWarning(err.message))
} }
dispatch({ dispatch({
@ -409,7 +410,7 @@ function sendTx (txData) {
background.approveTransaction(txData.id, (err) => { background.approveTransaction(txData.id, (err) => {
if (err) { if (err) {
dispatch(actions.txError(err)) dispatch(actions.txError(err))
return console.error(err.message) return log.error(err.message)
} }
dispatch(actions.completedTx(txData.id)) dispatch(actions.completedTx(txData.id))
}) })
@ -424,7 +425,7 @@ function updateAndApproveTx (txData) {
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) { if (err) {
dispatch(actions.txError(err)) dispatch(actions.txError(err))
return console.error(err.message) return log.error(err.message)
} }
dispatch(actions.completedTx(txData.id)) dispatch(actions.completedTx(txData.id))
}) })
@ -558,6 +559,11 @@ function lockMetamask () {
return callBackgroundThenUpdate(background.setLocked) return callBackgroundThenUpdate(background.setLocked)
} }
function setCurrentAccountTab (newTabName) {
log.debug(`background.setCurrentAccountTab: ${newTabName}`)
return callBackgroundThenUpdateNoSpinner(background.setCurrentAccountTab, newTabName)
}
function showAccountDetail (address) { function showAccountDetail (address) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())
@ -965,6 +971,17 @@ function shapeShiftRequest (query, options, cb) {
// We hide loading indication. // We hide loading indication.
// If it errored, we show a warning. // If it errored, we show a warning.
// If it didn't, we update the state. // If it didn't, we update the state.
function callBackgroundThenUpdateNoSpinner (method, ...args) {
return (dispatch) => {
method.call(background, ...args, (err) => {
if (err) {
return dispatch(actions.displayWarning(err.message))
}
forceUpdateMetamaskState(dispatch)
})
}
}
function callBackgroundThenUpdate (method, ...args) { function callBackgroundThenUpdate (method, ...args) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())

View File

@ -80,10 +80,21 @@ TokenList.prototype.componentDidMount = function () {
this.setState({ tokens: this.tracker.serialize() }) this.setState({ tokens: this.tracker.serialize() })
this.tracker.on('update', (tokenData) => { this.tracker.on('update', (tokenData) => {
const heldTokens = tokenData.filter(token => token.balance !== '0' && token.string !== '0.000') this.updateBalances(tokenData)
this.setState({ tokens: heldTokens, isLoading: false })
}) })
this.tracker.updateBalances() this.tracker.updateBalances()
.then(() => {
this.updateBalances(this.tracker.serialize())
})
.catch((reason) => {
log.error(`Problem updating balances`, reason)
this.setState({ isLoading: false })
})
}
TokenList.prototype.updateBalances = function (tokenData) {
const heldTokens = tokenData.filter(token => token.balance !== '0' && token.string !== '0.000')
this.setState({ tokens: heldTokens, isLoading: false })
} }
TokenList.prototype.componentWillUnmount = function () { TokenList.prototype.componentWillUnmount = function () {