@@ -1454,28 +1454,30 @@ const slice = createSlice({
14541454 extraReducers : ( builder ) => {
14551455 builder
14561456 . addCase ( ACCOUNT_CHANGED , ( state , action ) => {
1457- // If we are on the edit flow then we need to watch for changes to the
1458- // current account.address in state and keep balance updated
1459- // appropriately
1460- if (
1461- state . stage === SEND_STAGES . EDIT &&
1462- action . payload . account . address === state . selectedAccount . address
1463- ) {
1464- // This event occurs when the user's account details update due to
1465- // background state changes. If the account that is being updated is
1466- // the current from account on the edit flow we need to update
1467- // the balance for the account and revalidate the send state.
1468- state . selectedAccount . balance = action . payload . account . balance ;
1469- // We need to update the asset balance if the asset is the native
1470- // network asset. Once we update the balance we recompute error state.
1457+ // This event occurs when the user's account details update due to
1458+ // background state changes. If the account that is being updated is
1459+ // the current from account on the edit flow we need to update
1460+ // the balance for the account and revalidate the send state.
1461+ if ( state . stage === SEND_STAGES . EDIT && action . payload . account ) {
14711462 const draftTransaction =
14721463 state . draftTransactions [ state . currentTransactionUUID ] ;
1473- if ( draftTransaction ?. asset . type === ASSET_TYPES . NATIVE ) {
1474- draftTransaction . asset . balance = action . payload . account . balance ;
1464+ if (
1465+ draftTransaction &&
1466+ draftTransaction . fromAccount &&
1467+ draftTransaction . fromAccount . address ===
1468+ action . payload . account . address
1469+ ) {
1470+ draftTransaction . fromAccount . balance =
1471+ action . payload . account . balance ;
1472+ // We need to update the asset balance if the asset is the native
1473+ // network asset. Once we update the balance we recompute error state.
1474+ if ( draftTransaction . asset . type === ASSET_TYPES . NATIVE ) {
1475+ draftTransaction . asset . balance = action . payload . account . balance ;
1476+ }
1477+ slice . caseReducers . validateAmountField ( state ) ;
1478+ slice . caseReducers . validateGasField ( state ) ;
1479+ slice . caseReducers . validateSendState ( state ) ;
14751480 }
1476- slice . caseReducers . validateAmountField ( state ) ;
1477- slice . caseReducers . validateGasField ( state ) ;
1478- slice . caseReducers . validateSendState ( state ) ;
14791481 }
14801482 } )
14811483 . addCase ( ADDRESS_BOOK_UPDATED , ( state , action ) => {
0 commit comments