From f9d71f925cbbc3cfd456205087c4df637386e7c1 Mon Sep 17 00:00:00 2001 From: Hugh Cunningham <57735705+hughy@users.noreply.github.com> Date: Wed, 18 Jan 2023 08:46:50 -0800 Subject: [PATCH] changes NotEnoughFundsError messages (#2974) * changes NotEnoughFundsError messages removes message indicating that 'balance changed' since we no longer store pending balances. NotEnoughFundsError when sending a transaction is now likely to occur if not enough notes are available to spend because of pending or unconfirmed transactions. * fixes test that relies on error message --- ironfish/src/rpc/routes/wallet/sendTransaction.test.ts | 1 - ironfish/src/rpc/routes/wallet/sendTransaction.ts | 2 +- ironfish/src/wallet/errors.ts | 4 +++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ironfish/src/rpc/routes/wallet/sendTransaction.test.ts b/ironfish/src/rpc/routes/wallet/sendTransaction.test.ts index 647049cb15..eab572a5d5 100644 --- a/ironfish/src/rpc/routes/wallet/sendTransaction.test.ts +++ b/ironfish/src/rpc/routes/wallet/sendTransaction.test.ts @@ -158,7 +158,6 @@ describe('Transactions sendTransaction', () => { await expect(routeTest.client.sendTransaction(TEST_PARAMS)).rejects.toThrow( expect.objectContaining({ - message: expect.stringContaining('Your balance changed while creating a transaction.'), status: 400, code: ERROR_CODES.INSUFFICIENT_BALANCE, }), diff --git a/ironfish/src/rpc/routes/wallet/sendTransaction.ts b/ironfish/src/rpc/routes/wallet/sendTransaction.ts index 48e00c245d..fcb5be3106 100644 --- a/ironfish/src/rpc/routes/wallet/sendTransaction.ts +++ b/ironfish/src/rpc/routes/wallet/sendTransaction.ts @@ -159,7 +159,7 @@ router.register( } catch (e) { if (e instanceof NotEnoughFundsError) { throw new ValidationError( - `Your balance changed while creating a transaction.`, + `Not enough unspent notes available to fund the transaction. Please wait for any pending transactions to be confirmed.`, 400, ERROR_CODES.INSUFFICIENT_BALANCE, ) diff --git a/ironfish/src/wallet/errors.ts b/ironfish/src/wallet/errors.ts index ae8d878db7..c681c188dc 100644 --- a/ironfish/src/wallet/errors.ts +++ b/ironfish/src/wallet/errors.ts @@ -13,6 +13,8 @@ export class NotEnoughFundsError extends Error { amountNeeded, true, assetId.toString('hex'), - )} but have '${CurrencyUtils.renderIron(amount)}'` + )} but have '${CurrencyUtils.renderIron( + amount, + )} available to spend. Please fund your account and/or wait for any pending transactions to be confirmed.'` } }