Ensure simple send gas estimation happens after the recipient is iden… (#11485)

* Ensure simple send gas estimation happens after the recipient is identified

* Update ui/ducks/send/send.test.js

Co-authored-by: Alex Donesky <adonesky@gmail.com>

* Improve test name

* Lint fix

Co-authored-by: Alex Donesky <adonesky@gmail.com>
feature/default_network_editable
Dan J Miller 3 years ago committed by Dan Miller
parent bff17c6873
commit 3ab5419dec
  1. 8
      ui/ducks/send/send.js
  2. 68
      ui/ducks/send/send.test.js

@ -407,7 +407,8 @@ export const initializeSendState = createAsyncThunk(
: GAS_LIMITS.SIMPLE;
if (
basicEstimateStatus === BASIC_ESTIMATE_STATES.READY &&
stage !== SEND_STAGES.EDIT
stage !== SEND_STAGES.EDIT &&
recipient.address
) {
// Run our estimateGasLimit logic to get a more accurate estimation of
// required gas. If this value isn't nullish, set it as the new gasLimit
@ -1201,12 +1202,9 @@ export function useMyAccountsForRecipientSearch() {
* @returns {void}
*/
export function updateRecipient({ address, nickname }) {
return async (dispatch, getState) => {
return async (dispatch) => {
await dispatch(actions.updateRecipient({ address, nickname }));
const state = getState();
if (state.send.asset.type === ASSET_TYPES.TOKEN) {
await dispatch(computeEstimatedGasLimit());
}
};
}

@ -1347,12 +1347,36 @@ describe('Send Slice', () => {
nickname: '',
};
it('should create an action to update recipient', async () => {
it('should create actions to update recipient and recalculate gas limit if the asset type is not set', async () => {
global.eth = {
getCode: sinon.stub(),
};
const updateRecipientState = {
metamask: {
provider: {
chainId: '0x1',
},
},
send: {
account: {
balance: '',
},
asset: {
type: '',
},
gas: {
gasPrice: '',
},
recipient: {
address: '',
},
amount: {
value: '',
},
draftTransaction: {
userInputHexData: '',
},
},
};
@ -1362,18 +1386,20 @@ describe('Send Slice', () => {
const actionResult = store.getActions();
const expectedActionResult = [
{
type: 'send/updateRecipient',
payload: recipient,
},
];
expect(actionResult).toHaveLength(1);
expect(actionResult).toStrictEqual(expectedActionResult);
expect(actionResult).toHaveLength(4);
expect(actionResult[0].type).toStrictEqual('send/updateRecipient');
expect(actionResult[1].type).toStrictEqual(
'send/computeEstimatedGasLimit/pending',
);
expect(actionResult[2].type).toStrictEqual(
'metamask/gas/SET_CUSTOM_GAS_LIMIT',
);
expect(actionResult[3].type).toStrictEqual(
'send/computeEstimatedGasLimit/fulfilled',
);
});
it('should create actions to update recipient and recalculate gas limit if the asset is a token', async () => {
it('should create actions to reset recipient input and ens, calculate gas and then validate input', async () => {
const tokenState = {
metamask: {
blockGasLimit: '',
@ -1442,6 +1468,13 @@ describe('Send Slice', () => {
address: 'Address',
nickname: 'NickName',
},
gas: {
gasPrice: '0x1',
},
amount: {
value: '0x1',
},
draftTransaction: {},
},
};
@ -1450,14 +1483,23 @@ describe('Send Slice', () => {
await store.dispatch(resetRecipientInput());
const actionResult = store.getActions();
expect(actionResult).toHaveLength(4);
expect(actionResult).toHaveLength(7);
expect(actionResult[0].type).toStrictEqual(
'send/updateRecipientUserInput',
);
expect(actionResult[0].payload).toStrictEqual('');
expect(actionResult[1].type).toStrictEqual('send/updateRecipient');
expect(actionResult[2].type).toStrictEqual('ENS/resetEnsResolution');
expect(actionResult[2].type).toStrictEqual(
'send/computeEstimatedGasLimit/pending',
);
expect(actionResult[3].type).toStrictEqual(
'metamask/gas/SET_CUSTOM_GAS_LIMIT',
);
expect(actionResult[4].type).toStrictEqual(
'send/computeEstimatedGasLimit/fulfilled',
);
expect(actionResult[5].type).toStrictEqual('ENS/resetEnsResolution');
expect(actionResult[6].type).toStrictEqual(
'send/validateRecipientUserInput',
);
});

Loading…
Cancel
Save