Skip to content

Commit

Permalink
fix clearing recipient action
Browse files Browse the repository at this point in the history
  • Loading branch information
brad-decker committed Jun 7, 2021
1 parent 2b640c7 commit 9cc49b5
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions ui/ducks/send/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ const computeEstimatedGasLimit = createAsyncThunk(
blockGasLimit: metamask.blockGasLimit,
selectedAddress: metamask.selectedAddress,
sendToken: send.asset.details,
to: send.recipient.address.toLowerCase(),
to: send.recipient.address?.toLowerCase(),
value: send.amount.value,
data: send.draftTransaction.userInputHexData,
});
Expand Down Expand Up @@ -637,14 +637,24 @@ const slice = createSlice({
slice.caseReducers.updateDraftTransaction(state);
},
updateRecipient: (state, action) => {
state.recipient.address = action.payload.address;
state.recipient.address = action.payload.address ?? '';
state.recipient.nickname = action.payload.nickname ?? '';
// if an id exists on the draft transaction, we progress to the edit
// stage, otherwise we progress to the draft stage.
state.stage =
state.draftTransaction.id === null
? SEND_STAGES.DRAFT
: SEND_STAGES.EDIT;

if (state.recipient.address === '') {
// If address is null we are clearing the recipient and must return
// to the ADD_RECIPIENT stage.
state.stage = SEND_STAGES.ADD_RECIPIENT;
} else {
// if and address is provided and an id exists on the draft transaction,
// we progress to the EDIT stage, otherwise we progress to the DRAFT
// stage. We also reset the search mode for recipient search.
state.stage =
state.draftTransaction.id === null
? SEND_STAGES.DRAFT
: SEND_STAGES.EDIT;
state.recipient.mode = RECIPIENT_SEARCH_MODES.CONTACT_LIST;
}

// validate send state
slice.caseReducers.validateSendState(state);
// update the draft transaction
Expand Down Expand Up @@ -1104,6 +1114,7 @@ export function updateRecipient({ address, nickname }) {
export function resetRecipientInput() {
return async (dispatch) => {
await dispatch(updateRecipientUserInput(''));
await dispatch(updateRecipient({ address: null, nickname: null }));
await dispatch(resetResolution());
await dispatch(validateRecipientUserInput());
};
Expand Down

0 comments on commit 9cc49b5

Please sign in to comment.