1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

add safegaurd for missing account in action (#15450)

* add safegaurd for missing account in action

* add test to cover case
This commit is contained in:
Brad Decker 2022-08-03 13:14:23 -05:00 committed by GitHub
parent 71cc3397bf
commit cfe5f3a99a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 5 deletions

View File

@ -1571,11 +1571,11 @@ const slice = createSlice({
slice.caseReducers.validateSendState(state);
})
.addCase(SELECTED_ACCOUNT_CHANGED, (state, action) => {
// If we are on the edit flow the account we are keyed into will be the
// original 'from' account, which may differ from the selected account
if (state.stage !== SEND_STAGES.EDIT) {
// This event occurs when the user selects a new account from the
// account menu, or the currently active account's balance updates.
// We only care about new transactions, not edits, here, because we use
// the fromAccount and ACCOUNT_CHANGED action for that.
if (state.stage !== SEND_STAGES.EDIT && action.payload.account) {
state.selectedAccount.balance = action.payload.account.balance;
state.selectedAccount.address = action.payload.account.address;
const draftTransaction =

View File

@ -1139,6 +1139,28 @@ describe('Send Slice', () => {
action.payload.account.address,
);
});
it('should gracefully handle missing account in payload', () => {
const olderState = {
...INITIAL_SEND_STATE_FOR_EXISTING_DRAFT,
selectedAccount: {
balance: '0x0',
address: '0xAddress',
},
};
const action = {
type: 'SELECTED_ACCOUNT_CHANGED',
payload: {
account: undefined,
},
};
const result = sendReducer(olderState, action);
expect(result.selectedAccount.balance).toStrictEqual('0x0');
expect(result.selectedAccount.address).toStrictEqual('0xAddress');
});
});
describe('Account Changed', () => {