From 06ba0db8409ab7db32c27fca792f3dc7cb8cbd04 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Tue, 28 Apr 2020 12:36:25 -0300 Subject: [PATCH] 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> --- test/unit/ui/app/selectors.spec.js | 22 ++++------------------ ui/app/selectors/selectors.js | 4 +--- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/test/unit/ui/app/selectors.spec.js b/test/unit/ui/app/selectors.spec.js index 17214a90a..9b3b2c01d 100644 --- a/test/unit/ui/app/selectors.spec.js +++ b/test/unit/ui/app/selectors.spec.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) }) }) diff --git a/ui/app/selectors/selectors.js b/ui/app/selectors/selectors.js index 2ea4405a3..af28a5f61 100644 --- a/ui/app/selectors/selectors.js +++ b/ui/app/selectors/selectors.js @@ -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) {