From e5e06e97da914b0093febdb36b7961c6f99b84e7 Mon Sep 17 00:00:00 2001 From: Yonathan Benolol Date: Mon, 5 Sep 2022 19:55:16 +0300 Subject: [PATCH 1/2] Provide the balance dynamically depending on TxType in ConfirmSendModal (GH Issue 401) --- src/pages/Home/SendModal/SendModal.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/Home/SendModal/SendModal.tsx b/src/pages/Home/SendModal/SendModal.tsx index e84db408..979bd676 100644 --- a/src/pages/Home/SendModal/SendModal.tsx +++ b/src/pages/Home/SendModal/SendModal.tsx @@ -108,7 +108,9 @@ const SendModal: FC = ({ lnBalance, onClose, onchainBalance }) => { amount={amount} address={addr} back={() => setConfirm(false)} - balance={lnBalance} + balance={ + invoiceType === TxType.LIGHTNING ? lnBalance : onchainBalance + } close={onClose} comment={comment} expiry={expiry} From d291edefd0b0436d0fa1918a63008163a55ca2b2 Mon Sep 17 00:00:00 2001 From: Yonathan Benolol Date: Wed, 7 Sep 2022 10:50:35 +0300 Subject: [PATCH 2/2] Added tests --- .../__tests__/ConfirmSendModal.test.tsx | 66 +++++++++++++++++-- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/src/pages/Home/SendModal/__tests__/ConfirmSendModal.test.tsx b/src/pages/Home/SendModal/__tests__/ConfirmSendModal.test.tsx index e0daa812..9a6e6a4e 100644 --- a/src/pages/Home/SendModal/__tests__/ConfirmSendModal.test.tsx +++ b/src/pages/Home/SendModal/__tests__/ConfirmSendModal.test.tsx @@ -9,7 +9,7 @@ import ConfirmSendModal from "../ConfirmSendModal"; const closeSpy = jest.fn(); -const basicProps: Props = { +const basicLnTxProps: Props = { amount: 0, address: "lnbcrt10u1pscxuktpp5k4hp6wxafdaqfhk84krlt26q80dfdg5df3cdagwjpr5v8xc7s5qqdpz2phkcctjypykuan0d93k2grxdaezqcn0vgxqyjw5qcqp2sp5ndav50eqfh32xxpwd4wa645hevumj7ze5meuajjs40vtgkucdams9qy9qsqc34r4wlyytf68xvt540gz7yq80wsdhyy93dgetv2d2x44dhtg4fysu9k8v0aec8r649tcgtu5s9xths93nuxklvf93px6gnlw2h7u0gq602rww", @@ -24,12 +24,26 @@ const basicProps: Props = { timestamp: 1893456000, // 01 Jan 2030 00:00:00 GMT }; +const basicOnChainTxProps: Props = { + amount: 50, + address: "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq", + back: () => {}, + balance: 100, + close: closeSpy, + comment: "", + expiry: 36000, + fee: "1", + invoiceAmount: 50, + invoiceType: TxType.ONCHAIN, + timestamp: 1893456000, // 01 Jan 2030 00:00:00 GMT +}; + describe("ConfirmSendModal", () => { describe("ln-invoice with zero amount", () => { const setup = () => { render( - + ); }; @@ -121,7 +135,7 @@ describe("ConfirmSendModal", () => { render( @@ -142,7 +156,7 @@ describe("ConfirmSendModal", () => { test("show error if amount is bigger than balance", async () => { render( - + ); @@ -157,7 +171,49 @@ describe("ConfirmSendModal", () => { test("valid form passes", async () => { render( - + + + ); + + const submitButton = screen.queryByText("wallet.amount"); + expect(submitButton).not.toBeInTheDocument(); + + expect( + await screen.findByRole("button", { + name: "settings.confirm", + }) + ).toBeDisabled(); + }); + }); + + describe("on chain tx with amount above zero", () => { + test("show error if amount is bigger than balance", async () => { + render( + + + + ); + + expect( + await screen.findByText("forms.validation.lnInvoice.max") + ).toBeInTheDocument(); + expect( + screen.getByRole("button", { name: "settings.confirm" }) + ).toBeDisabled(); + }); + + test("valid form passes", async () => { + render( + + );