Remove fallback selected address (#8439)

The `getSelectedAddress` selector has a fallback of selecting the first
MetaMask account. This is not useful. The only time the
`selectedAddress` is not set is during onboarding, before any accounts
exist, so selecting the first account wouldn't be useful anyway.
Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>
feature/default_network_editable
Mark Stacey 5 years ago committed by GitHub
parent 46d72d17a9
commit 06ba0db840
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      test/unit/ui/app/selectors.spec.js
  2. 4
      ui/app/selectors/selectors.js

@ -9,27 +9,13 @@ const provider = createTestProviderTools({ scaffold: {} }).provider
describe('Selectors', function () {
describe('#getSelectedAddress', function () {
let state
beforeEach(function () {
state = {
metamask: {
accounts: {
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': {
'balance': '0x0',
'address': '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
},
},
cachedBalances: {},
},
}
})
it('returns first account if selectedAddress is undefined', function () {
assert.equal(selectors.getSelectedAddress(state), '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc')
it('returns undefined if selectedAddress is undefined', function () {
assert.equal(selectors.getSelectedAddress({ metamask: {} }), undefined)
})
it('returns selectedAddress', function () {
assert.equal(selectors.getSelectedAddress(mockState), '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc')
const selectedAddress = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'
assert.equal(selectors.getSelectedAddress({ metamask: { selectedAddress } }), selectedAddress)
})
})

@ -86,9 +86,7 @@ export const getMetaMaskAccounts = createSelector(
)
export function getSelectedAddress (state) {
const selectedAddress = state.metamask.selectedAddress || Object.keys(getMetaMaskAccounts(state))[0]
return selectedAddress
return state.metamask.selectedAddress
}
export function getSelectedIdentity (state) {

Loading…
Cancel
Save