Skip to content

Commit 812b70b

Browse files
committed
[DDW-1007] Keep minimum fee when token is removed
1 parent f41548a commit 812b70b

File tree

2 files changed

+62
-25
lines changed

2 files changed

+62
-25
lines changed

source/renderer/app/components/wallet/WalletSendForm.spec.tsx

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,32 +174,50 @@ describe('wallet/Wallet Send Form', () => {
174174
return mock;
175175
}
176176

177+
const MINIMUM_AMOUNT_UPDATED_MESSAGE_TEST_ID =
178+
'WalletSendForm::minimumAmountNotice::updated';
179+
180+
function assertMinimumAmountNoticeMessage(minimumAda: number) {
181+
expect(
182+
screen.getByTestId(MINIMUM_AMOUNT_UPDATED_MESSAGE_TEST_ID)
183+
).toHaveTextContent(
184+
`Note: the ada field was automatically updated because this transaction requires a minimum of ${minimumAda} ADA.`
185+
);
186+
}
187+
177188
test('should update Ada input field to minimum required and restore to original value when tokens are removed', async () => {
178189
expect.assertions(4);
190+
179191
const minimumAda = 2;
180-
const calculateTransactionFeeMock = createTransactionFeeMock(2, minimumAda);
192+
const calculateTransactionFeeMock = createTransactionFeeMock(1, minimumAda);
193+
181194
render(
182195
<SetupWallet calculateTransactionFee={calculateTransactionFeeMock} />
183196
);
197+
184198
enterReceiverAddress();
199+
185200
const removeToken1 = await addToken();
201+
186202
await waitForMinimumAdaRequiredMsg();
187203
assertAdaInput(minimumAda);
204+
188205
const minimumAmountNoticeTestId =
189206
'WalletSendForm::minimumAmountNotice::updated';
207+
190208
expect(screen.getByTestId(minimumAmountNoticeTestId)).toHaveTextContent(
191209
`Note: the ada field was automatically updated because this transaction requires a minimum of ${minimumAda} ADA.`
192210
);
211+
193212
await removeToken1();
194-
const minimumAdaRequiredMsg = screen.getByTestId('minimumAdaRequiredMsg');
195-
await within(minimumAdaRequiredMsg).findByText(
196-
`to the minimum of 1 ADA required`
197-
);
198-
assertAdaInput(0);
199-
expect(
200-
screen.queryByTestId(minimumAmountNoticeTestId)
201-
).not.toBeInTheDocument();
213+
214+
await waitForMinimumAdaRequiredMsg(1);
215+
216+
assertAdaInput(1);
217+
218+
expect(screen.queryByTestId(minimumAmountNoticeTestId)).toBeInTheDocument();
202219
});
220+
203221
test('should display an update button when Ada input field is less than minimum required', async () => {
204222
expect.assertions(3);
205223
const minimumAda = 2;
@@ -227,6 +245,7 @@ describe('wallet/Wallet Send Form', () => {
227245
await waitForElementToBeRemoved(updateButton);
228246
assertAdaInput(minimumAda);
229247
});
248+
230249
test('should favour user Ada input instead of minimum required when the value is greater than the minimum one', async () => {
231250
expect.assertions(2);
232251
const minimumAda = 2.5;
@@ -253,6 +272,7 @@ describe('wallet/Wallet Send Form', () => {
253272
`Note: the ada field was automatically updated to ${userAdaAmount} ADA because now it fulfills the minimum amount of 1 ADA for the transaction.`
254273
);
255274
});
275+
256276
test('should remove message when user entry is higher than minimum amount', async () => {
257277
expect.assertions(3);
258278
const minimumAda = 2.5;
@@ -287,6 +307,7 @@ describe('wallet/Wallet Send Form', () => {
287307
screen.queryByTestId(minimumAmountNoticeTestId)
288308
).not.toBeInTheDocument();
289309
});
310+
290311
test('should not display any minimum amount notice message when ada input is greater than minimum amount', async () => {
291312
expect.assertions(2);
292313
const calculateTransactionFeeMock = jest.fn().mockResolvedValue({
@@ -311,6 +332,7 @@ describe('wallet/Wallet Send Form', () => {
311332
screen.findByTestId('WalletSendForm::minimumAmountNotice::restored')
312333
).rejects.toBeTruthy();
313334
});
335+
314336
test('should apply minimum fee to ada field when user has removed the previous update', async () => {
315337
expect.assertions(3);
316338
const minimumAda = 2;
@@ -334,6 +356,7 @@ describe('wallet/Wallet Send Form', () => {
334356
await waitForMinimumAdaRequiredMsg();
335357
assertAdaInput(minimumAda);
336358
});
359+
337360
test('should format ada input field using numeric format profile', async () => {
338361
expect.assertions(1);
339362
const minimumAda = 2;
@@ -350,6 +373,7 @@ describe('wallet/Wallet Send Form', () => {
350373
const adaInput = getInput('Ada');
351374
expect(adaInput).toHaveValue(`${minimumAda},000000`);
352375
});
376+
353377
test('should calculate transaction fee even when one of the assets are empty', async () => {
354378
expect.assertions(2);
355379
const minimumAda = 2;
@@ -365,4 +389,30 @@ describe('wallet/Wallet Send Form', () => {
365389
await waitForMinimumAdaRequiredMsg();
366390
assertAdaInput(minimumAda);
367391
});
392+
393+
test('should keep transaction fee when assets are removed and ada field is untouched', async () => {
394+
expect.assertions(3);
395+
396+
const fee = 2;
397+
const minimumAda = 1;
398+
const calculateTransactionFeeMock = createTransactionFeeMock(1, fee);
399+
400+
render(
401+
<SetupWallet calculateTransactionFee={calculateTransactionFeeMock} />
402+
);
403+
404+
enterReceiverAddress();
405+
406+
const removeToken = await addToken();
407+
await waitForMinimumAdaRequiredMsg();
408+
409+
assertAdaInput(fee);
410+
411+
await removeToken();
412+
413+
await waitForMinimumAdaRequiredMsg(minimumAda);
414+
415+
assertAdaInput(minimumAda);
416+
assertMinimumAmountNoticeMessage(minimumAda);
417+
});
368418
});

source/renderer/app/components/wallet/WalletSendForm.tsx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,7 @@ class WalletSendForm extends Component<Props, State> {
512512
};
513513

514514
if (shouldUpdateMinimumAdaAmount) {
515-
const adaInputState = await this.checkAdaInputState(
516-
adaAmountValue,
517-
minimumAdaValue
518-
);
515+
const adaInputState = await this.checkAdaInputState(minimumAdaValue);
519516
nextState.adaInputState = adaInputState;
520517
this.trySetMinimumAdaAmount(adaInputState, minimumAdaValue);
521518
}
@@ -553,9 +550,7 @@ class WalletSendForm extends Component<Props, State> {
553550

554551
if (shouldUpdateMinimumAdaAmount) {
555552
const minimumAdaValue = new BigNumber(minimumAda);
556-
const adaAmountValue = new BigNumber(adaAmountField.value || 0);
557553
const adaInputState = await this.checkAdaInputState(
558-
adaAmountValue,
559554
minimumAdaValue
560555
);
561556
this.trySetMinimumAdaAmount(adaInputState, minimumAdaValue);
@@ -590,7 +585,6 @@ class WalletSendForm extends Component<Props, State> {
590585
}
591586
};
592587
checkAdaInputState = async (
593-
adaAmount: BigNumber,
594588
minimumAda: BigNumber
595589
): Promise<AdaInputState> => {
596590
const {
@@ -600,16 +594,13 @@ class WalletSendForm extends Component<Props, State> {
600594
} = this.state;
601595

602596
if (
603-
adaAmountInputTrack.gt(minimumAda) &&
597+
adaAmountInputTrack.gte(minimumAda) &&
604598
adaInputState === AdaInputStateType.Updated
605599
) {
606600
return AdaInputStateType.Restored;
607601
}
608602

609-
if (
610-
adaAmountInputTrack.lt(minimumAda) &&
611-
!isEmpty(selectedAssetUniqueIds)
612-
) {
603+
if (adaAmountInputTrack.lt(minimumAda)) {
613604
const isValid = await this.props.validateAmount(
614605
formattedAmountToNaturalUnits(minimumAda.toString())
615606
);
@@ -621,10 +612,6 @@ class WalletSendForm extends Component<Props, State> {
621612
return AdaInputStateType.Updated;
622613
}
623614

624-
if (isEmpty(selectedAssetUniqueIds)) {
625-
return AdaInputStateType.Reset;
626-
}
627-
628615
return AdaInputStateType.None;
629616
};
630617
trySetMinimumAdaAmount = (

0 commit comments

Comments
 (0)