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:
parent
3df2f2b2d4
commit
b7b9e0c1ac
@ -7,6 +7,7 @@ class PreferencesController {
|
||||
constructor (opts = {}) {
|
||||
const initState = extend({
|
||||
frequentRpcList: [],
|
||||
currentAccountTab: 'history',
|
||||
}, opts.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) {
|
||||
const rpcList = this.getFrequentRpcList()
|
||||
const index = rpcList.findIndex((element) => { return element === _url })
|
||||
|
@ -275,6 +275,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
|
||||
// PreferencesController
|
||||
setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController),
|
||||
setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab).bind(preferencesController),
|
||||
setDefaultRpc: nodeify(this.setDefaultRpc).bind(this),
|
||||
setCustomRpc: nodeify(this.setCustomRpc).bind(this),
|
||||
|
||||
|
@ -62,12 +62,12 @@
|
||||
"end-of-stream": "^1.1.0",
|
||||
"ensnare": "^1.0.0",
|
||||
"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-query": "^2.1.1",
|
||||
"eth-sig-util": "^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-util": "ethereumjs/ethereumjs-util#ac5d0908536b447083ea422b435da27f26615de9",
|
||||
"ethereumjs-wallet": "^0.6.0",
|
||||
|
@ -34,12 +34,12 @@ function mapStateToProps (state) {
|
||||
transactions: state.metamask.selectedAddressTxList || [],
|
||||
conversionRate: state.metamask.conversionRate,
|
||||
currentCurrency: state.metamask.currentCurrency,
|
||||
currentAccountTab: state.metamask.currentAccountTab,
|
||||
}
|
||||
}
|
||||
|
||||
inherits(AccountDetailScreen, Component)
|
||||
function AccountDetailScreen () {
|
||||
this.state = { tabSelection: 'history' }
|
||||
Component.call(this)
|
||||
}
|
||||
|
||||
@ -251,7 +251,8 @@ AccountDetailScreen.prototype.subview = function () {
|
||||
}
|
||||
|
||||
AccountDetailScreen.prototype.tabSections = function () {
|
||||
const tabSelection = this.state.tabSelection
|
||||
const { currentAccountTab } = this.props
|
||||
|
||||
return h('section.tabSection', [
|
||||
|
||||
h(TabBar, {
|
||||
@ -259,9 +260,9 @@ AccountDetailScreen.prototype.tabSections = function () {
|
||||
{ content: 'Sent', key: 'history' },
|
||||
{ content: 'Tokens', key: 'tokens' },
|
||||
],
|
||||
defaultTab: tabSelection || 'history',
|
||||
defaultTab: currentAccountTab || 'history',
|
||||
tabSelected: (key) => {
|
||||
this.setState({ tabSelection: key })
|
||||
this.props.dispatch(actions.setCurrentAccountTab(key))
|
||||
},
|
||||
}),
|
||||
|
||||
@ -272,9 +273,9 @@ AccountDetailScreen.prototype.tabSections = function () {
|
||||
AccountDetailScreen.prototype.tabSwitchView = function () {
|
||||
const props = this.props
|
||||
const { address, network } = props
|
||||
const tabSelection = this.state.tabSelection || 'history'
|
||||
const { currentAccountTab } = this.props
|
||||
|
||||
switch (tabSelection) {
|
||||
switch (currentAccountTab) {
|
||||
case 'tokens':
|
||||
return h(TokenList, { userAddress: address, network })
|
||||
default:
|
||||
|
@ -74,6 +74,7 @@ var actions = {
|
||||
SHOW_CONF_MSG_PAGE: 'SHOW_CONF_MSG_PAGE',
|
||||
SET_CURRENT_FIAT: 'SET_CURRENT_FIAT',
|
||||
setCurrentCurrency: setCurrentCurrency,
|
||||
setCurrentAccountTab,
|
||||
// account detail screen
|
||||
SHOW_SEND_PAGE: 'SHOW_SEND_PAGE',
|
||||
showSendPage: showSendPage,
|
||||
@ -218,7 +219,7 @@ function confirmSeedWords () {
|
||||
return dispatch(actions.displayWarning(err.message))
|
||||
}
|
||||
|
||||
console.log('Seed word cache cleared. ' + account)
|
||||
log.info('Seed word cache cleared. ' + account)
|
||||
dispatch(actions.showAccountDetail(account))
|
||||
})
|
||||
}
|
||||
@ -338,7 +339,7 @@ function setCurrentCurrency (currencyCode) {
|
||||
background.setCurrentCurrency(currencyCode, (err, data) => {
|
||||
dispatch(this.hideLoadingIndication())
|
||||
if (err) {
|
||||
console.error(err.stack)
|
||||
log.error(err.stack)
|
||||
return dispatch(actions.displayWarning(err.message))
|
||||
}
|
||||
dispatch({
|
||||
@ -409,7 +410,7 @@ function sendTx (txData) {
|
||||
background.approveTransaction(txData.id, (err) => {
|
||||
if (err) {
|
||||
dispatch(actions.txError(err))
|
||||
return console.error(err.message)
|
||||
return log.error(err.message)
|
||||
}
|
||||
dispatch(actions.completedTx(txData.id))
|
||||
})
|
||||
@ -424,7 +425,7 @@ function updateAndApproveTx (txData) {
|
||||
dispatch(actions.hideLoadingIndication())
|
||||
if (err) {
|
||||
dispatch(actions.txError(err))
|
||||
return console.error(err.message)
|
||||
return log.error(err.message)
|
||||
}
|
||||
dispatch(actions.completedTx(txData.id))
|
||||
})
|
||||
@ -558,6 +559,11 @@ function lockMetamask () {
|
||||
return callBackgroundThenUpdate(background.setLocked)
|
||||
}
|
||||
|
||||
function setCurrentAccountTab (newTabName) {
|
||||
log.debug(`background.setCurrentAccountTab: ${newTabName}`)
|
||||
return callBackgroundThenUpdateNoSpinner(background.setCurrentAccountTab, newTabName)
|
||||
}
|
||||
|
||||
function showAccountDetail (address) {
|
||||
return (dispatch) => {
|
||||
dispatch(actions.showLoadingIndication())
|
||||
@ -965,6 +971,17 @@ function shapeShiftRequest (query, options, cb) {
|
||||
// We hide loading indication.
|
||||
// If it errored, we show a warning.
|
||||
// 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) {
|
||||
return (dispatch) => {
|
||||
dispatch(actions.showLoadingIndication())
|
||||
|
@ -80,10 +80,21 @@ TokenList.prototype.componentDidMount = function () {
|
||||
|
||||
this.setState({ tokens: this.tracker.serialize() })
|
||||
this.tracker.on('update', (tokenData) => {
|
||||
const heldTokens = tokenData.filter(token => token.balance !== '0' && token.string !== '0.000')
|
||||
this.setState({ tokens: heldTokens, isLoading: false })
|
||||
this.updateBalances(tokenData)
|
||||
})
|
||||
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 () {
|
||||
|
Loading…
Reference in New Issue
Block a user