mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Streamlined some transition logic
Fixes #122 Had used multiple actions for some transitions, which would lead to brief intermediary states. Now making a few actions much more explicit about what they route to, so there is less intermediary logic, and we can transition confidently to the correct view.
This commit is contained in:
parent
f2676d1241
commit
041b5493dc
@ -105,14 +105,14 @@ IdentityStore.prototype.getSelectedAddress = function(){
|
|||||||
return configManager.getSelectedAccount()
|
return configManager.getSelectedAccount()
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.setSelectedAddress = function(address){
|
IdentityStore.prototype.setSelectedAddress = function(address, cb){
|
||||||
if (!address) {
|
if (!address) {
|
||||||
var addresses = this._getAddresses()
|
var addresses = this._getAddresses()
|
||||||
address = addresses[0]
|
address = addresses[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
configManager.setSelectedAccount(address)
|
configManager.setSelectedAccount(address)
|
||||||
this._didUpdate()
|
if (cb) return cb(null, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.getNetwork = function(tries) {
|
IdentityStore.prototype.getNetwork = function(tries) {
|
||||||
|
@ -21,7 +21,13 @@ describe('#recoverFromSeed(password, seed)', function() {
|
|||||||
|
|
||||||
// stub out account manager
|
// stub out account manager
|
||||||
actions._setAccountManager({
|
actions._setAccountManager({
|
||||||
recoverFromSeed(pw, seed, cb) { cb(null, [{}, {}]) },
|
recoverFromSeed(pw, seed, cb) {
|
||||||
|
cb(null, {
|
||||||
|
identities: {
|
||||||
|
foo: 'bar'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sets metamask.isUnlocked to true', function() {
|
it('sets metamask.isUnlocked to true', function() {
|
||||||
|
@ -26,3 +26,24 @@ describe('SET_SELECTED_ACCOUNT', function() {
|
|||||||
assert.equal(resultingState.appState.activeAddress, action.value)
|
assert.equal(resultingState.appState.activeAddress, action.value)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('SHOW_ACCOUNT_DETAIL', function() {
|
||||||
|
it('updates metamask state', function() {
|
||||||
|
var initialState = {
|
||||||
|
metamask: {
|
||||||
|
selectedAccount: 'foo'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
freeze(initialState)
|
||||||
|
|
||||||
|
const action = {
|
||||||
|
type: actions.SHOW_ACCOUNT_DETAIL,
|
||||||
|
value: 'bar',
|
||||||
|
}
|
||||||
|
freeze(action)
|
||||||
|
|
||||||
|
var resultingState = reducers(initialState, action)
|
||||||
|
assert.equal(resultingState.metamask.selectedAccount, action.value)
|
||||||
|
assert.equal(resultingState.metamask.selectedAddress, action.value)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
@ -62,7 +62,7 @@ AccountDetailScreen.prototype.render = function() {
|
|||||||
h('.identicon-wrapper.flex-column.flex-center.select-none', [
|
h('.identicon-wrapper.flex-column.flex-center.select-none', [
|
||||||
h(Identicon, {
|
h(Identicon, {
|
||||||
diameter: 62,
|
diameter: 62,
|
||||||
address: account.address
|
address: selected,
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ AccountDetailScreen.prototype.render = function() {
|
|||||||
style: {
|
style: {
|
||||||
'line-height': 16,
|
'line-height': 16,
|
||||||
},
|
},
|
||||||
}, addressSummary(account.address)),
|
}, addressSummary(selected)),
|
||||||
|
|
||||||
h('i.fa.fa-download.fa-md.cursor-pointer.color-orange', {
|
h('i.fa.fa-download.fa-md.cursor-pointer.color-orange', {
|
||||||
onClick: () => this.requestAccountExport(account.address),
|
onClick: () => this.requestAccountExport(account.address),
|
||||||
|
@ -114,7 +114,7 @@ function tryUnlockMetamask(password) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
dispatch(this.unlockFailed())
|
dispatch(this.unlockFailed())
|
||||||
} else {
|
} else {
|
||||||
dispatch(this.unlockMetamask())
|
dispatch(this.unlockMetamask(selectedAccount))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -133,12 +133,12 @@ function recoverFromSeed(password, seed) {
|
|||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
// dispatch(this.createNewVaultInProgress())
|
// dispatch(this.createNewVaultInProgress())
|
||||||
dispatch(this.showLoadingIndication())
|
dispatch(this.showLoadingIndication())
|
||||||
_accountManager.recoverFromSeed(password, seed, (err, selectedAccount) => {
|
_accountManager.recoverFromSeed(password, seed, (err, metamaskState) => {
|
||||||
dispatch(this.hideLoadingIndication())
|
dispatch(this.hideLoadingIndication())
|
||||||
if (err) return dispatch(this.displayWarning(err.message))
|
if (err) return dispatch(this.displayWarning(err.message))
|
||||||
|
|
||||||
dispatch(this.goHome())
|
var account = Object.keys(metamaskState.identities)[0]
|
||||||
dispatch(this.unlockMetamask())
|
dispatch(this.unlockMetamask(account))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,9 +271,10 @@ function unlockFailed() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function unlockMetamask() {
|
function unlockMetamask(account) {
|
||||||
return {
|
return {
|
||||||
type: this.UNLOCK_METAMASK,
|
type: this.UNLOCK_METAMASK,
|
||||||
|
value: account,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,11 +298,13 @@ function lockMetamask() {
|
|||||||
|
|
||||||
function showAccountDetail(address) {
|
function showAccountDetail(address) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
_accountManager.setSelectedAddress(address)
|
dispatch(this.showLoadingIndication())
|
||||||
|
_accountManager.setSelectedAddress(address, (err, address) => {
|
||||||
dispatch({
|
dispatch(this.hideLoadingIndication())
|
||||||
type: this.SHOW_ACCOUNT_DETAIL,
|
dispatch({
|
||||||
value: address,
|
type: this.SHOW_ACCOUNT_DETAIL,
|
||||||
|
value: address,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -323,7 +326,6 @@ function confirmSeedWords() {
|
|||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(this.showLoadingIndication())
|
dispatch(this.showLoadingIndication())
|
||||||
_accountManager.clearSeedWordCache((err, account) => {
|
_accountManager.clearSeedWordCache((err, account) => {
|
||||||
dispatch(this.clearSeedWordCache(account))
|
|
||||||
console.log('Seed word cache cleared. ' + account)
|
console.log('Seed word cache cleared. ' + account)
|
||||||
dispatch(this.showAccountDetail(account))
|
dispatch(this.showAccountDetail(account))
|
||||||
})
|
})
|
||||||
|
@ -29,6 +29,7 @@ function reduceMetamask(state, action) {
|
|||||||
return extend(metamaskState, {
|
return extend(metamaskState, {
|
||||||
isUnlocked: true,
|
isUnlocked: true,
|
||||||
isInitialized: true,
|
isInitialized: true,
|
||||||
|
selectedAccount: action.value,
|
||||||
})
|
})
|
||||||
|
|
||||||
case actions.LOCK_METAMASK:
|
case actions.LOCK_METAMASK:
|
||||||
@ -85,9 +86,14 @@ function reduceMetamask(state, action) {
|
|||||||
return newState
|
return newState
|
||||||
|
|
||||||
case actions.SHOW_ACCOUNT_DETAIL:
|
case actions.SHOW_ACCOUNT_DETAIL:
|
||||||
return extend(metamaskState, {
|
const newState = extend(metamaskState, {
|
||||||
|
isUnlocked: true,
|
||||||
|
isInitialized: true,
|
||||||
selectedAccount: action.value,
|
selectedAccount: action.value,
|
||||||
|
selectedAddress: action.value,
|
||||||
})
|
})
|
||||||
|
delete newState.seedWords
|
||||||
|
return newState
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return metamaskState
|
return metamaskState
|
||||||
|
Loading…
Reference in New Issue
Block a user