From 52dc06af69b87b1efee7e14e3213b2903318c59c Mon Sep 17 00:00:00 2001 From: Juan Patricio Marroquin Date: Mon, 4 Nov 2024 11:49:27 -0500 Subject: [PATCH 1/4] fix: hide transaction amount hint for recipients --- .../TransactionRow/TransactionAmount.blocks.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionAmount.blocks.tsx b/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionAmount.blocks.tsx index 1e639d88d0..280a320425 100644 --- a/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionAmount.blocks.tsx +++ b/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionAmount.blocks.tsx @@ -3,6 +3,7 @@ import React from "react"; import { DTO } from "@ardenthq/sdk-profiles"; import { useTranslation } from "react-i18next"; import { useExchangeRate } from "@/app/hooks/use-exchange-rate"; +import { useActiveWallet } from "@/app/hooks"; type ExtendedTransactionData = DTO.ExtendedConfirmedTransactionData | DTO.ExtendedSignedTransactionData; @@ -18,16 +19,16 @@ const calculateReturnedAmount = function (transaction: ExtendedTransactionData): returnedAmount += recipient.amount; } } - return returnedAmount; }; export const TransactionAmountLabel = ({ transaction }: { transaction: ExtendedTransactionData }): JSX.Element => { const { t } = useTranslation(); + const activeWallet = useActiveWallet(); const currency = transaction.wallet().currency(); - const returnedAmount = calculateReturnedAmount(transaction); + const returnedAmount = transaction.sender() === activeWallet.address() ? calculateReturnedAmount(transaction) : 0; const amount = transaction.total() - returnedAmount; const usesMultiSignature = "usesMultiSignature" in transaction ? transaction.usesMultiSignature() : false; From 43cb2221a90d57850ce2a151a063d1097c7f7d41 Mon Sep 17 00:00:00 2001 From: Juan Patricio Marroquin Date: Mon, 4 Nov 2024 11:49:44 -0500 Subject: [PATCH 2/4] refactor: display hint for transaction details --- .../TransactionSummary/TransactionSummary.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/domains/transaction/components/TransactionDetail/TransactionSummary/TransactionSummary.tsx b/src/domains/transaction/components/TransactionDetail/TransactionSummary/TransactionSummary.tsx index 260ecef58b..af3fec1ad6 100644 --- a/src/domains/transaction/components/TransactionDetail/TransactionSummary/TransactionSummary.tsx +++ b/src/domains/transaction/components/TransactionDetail/TransactionSummary/TransactionSummary.tsx @@ -4,6 +4,7 @@ import { Contracts, DTO } from "@ardenthq/sdk-profiles"; import { DetailDivider, DetailLabelText, DetailWrapper } from "@/app/components/DetailWrapper"; import { Amount, AmountLabel } from "@/app/components/Amount"; import { BigNumber } from "@ardenthq/sdk-helpers"; +import { TransactionAmountLabel } from "../../TransactionTable/TransactionRow/TransactionAmount.blocks"; interface Properties { transaction: DTO.ExtendedSignedTransactionData | DTO.ExtendedConfirmedTransactionData; @@ -20,11 +21,8 @@ export const TransactionSummary = ({ transaction, senderWallet, labelClassName } <>
{t("COMMON.AMOUNT")} -
From 8493a48289591000e91c37f2b0962fe2e2cf5568 Mon Sep 17 00:00:00 2001 From: Juan Patricio Marroquin Date: Mon, 4 Nov 2024 11:49:50 -0500 Subject: [PATCH 3/4] test: transaction summary label --- .../TransactionRow/TransactionBlocks.test.tsx | 102 +++++++++++++++++- 1 file changed, 100 insertions(+), 2 deletions(-) diff --git a/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionBlocks.test.tsx b/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionBlocks.test.tsx index 8cb5ea4262..d4d55a95b1 100644 --- a/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionBlocks.test.tsx +++ b/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionBlocks.test.tsx @@ -1,13 +1,47 @@ import React from "react"; +import { Route } from "react-router-dom"; import { TransactionFixture } from "@/tests/fixtures/transactions"; -import { env, render, screen } from "@/utils/testing-library"; +import { env, render, screen, getDefaultProfileId, MNEMONICS, triggerMessageSignOnce } from "@/utils/testing-library"; import { renderHook } from "@testing-library/react"; import { useTranslation } from "react-i18next"; import userEvent from "@testing-library/user-event"; import { TransactionAmountLabel, TransactionFiatAmount } from "./TransactionAmount.blocks"; +import { createHashHistory } from "history"; +import { Contracts } from "@ardenthq/sdk-profiles"; + +const history = createHashHistory(); + +const walletUrl = (walletId: string) => `/profiles/${getDefaultProfileId()}/wallets/${walletId}`; + +let profile: Contracts.IProfile; +let wallet: Contracts.IReadWriteWallet; + +const mnemonic = MNEMONICS[0]; describe("TransactionAmount.blocks", () => { + beforeAll(async () => { + profile = env.profiles().findById(getDefaultProfileId()); + + wallet = await profile.walletFactory().fromMnemonicWithBIP39({ + coin: "ARK", + mnemonic, + network: "ark.devnet", + }); + + profile.wallets().push(wallet); + + profile.coins().set("ARK", "ark.devnet"); + + await triggerMessageSignOnce(wallet); + }); + + beforeEach(() => { + history.push(walletUrl(wallet.id())); + }); + + const path = "/profiles/:profileId/wallets/:walletId"; + const fixture = { ...TransactionFixture, fee: () => 5, @@ -28,8 +62,43 @@ describe("TransactionAmount.blocks", () => { it("should show hint and amount for multiPayment transaction", async () => { const { result } = renderHook(() => useTranslation()); const { t } = result.current; + const secret = "secret"; + + const encryptedWallet = await profile.walletFactory().fromSecret({ + coin: "ARK", + network: "ark.devnet", + secret, + }); + + encryptedWallet.signingKey().set(secret, "password"); + + encryptedWallet + .data() + .set(Contracts.WalletData.ImportMethod, Contracts.WalletImportMethod.SECRET_WITH_ENCRYPTION); + + profile.wallets().push(encryptedWallet); - render(); + history.push(walletUrl(encryptedWallet.id())); + + const fixtureWithSender = { + ...fixture, + recipients: () => [ + { address: "address-1", amount: 10 }, + { address: "address-2", amount: 20 }, + { address: encryptedWallet.address(), amount: 30 }, + ], + sender: () => encryptedWallet.address(), + } + + render( + + + , + { + history, + route: walletUrl(encryptedWallet.id()), + }, + ); // should have a label expect(screen.getByTestId("AmountLabel__hint")).toBeInTheDocument(); @@ -44,6 +113,35 @@ describe("TransactionAmount.blocks", () => { expect(screen.getByText(/35 DARK/)).toBeInTheDocument(); }); + it("should not show hint if the active wallet is not the sender of the transaction", async () => { + const fixture = { + ...TransactionFixture, + fee: () => 5, + isMultiPayment: () => true, + isReturn: () => true, + recipients: () => [ + { address: "address-1", amount: 10 }, + { address: "address-2", amount: 20 }, + { address: "address-3", amount: 30 }, + ], + total: () => 65, + wallet: () => ({ + ...TransactionFixture.wallet(), + currency: () => "DARK", + }), + }; + + + render( + + + , { + history + }); + + expect(screen.queryByTestId("AmountLabel__hint")).not.toBeInTheDocument(); + }); + it("should show fiat value for multiPayment transaction", () => { const exchangeMock = vi.spyOn(env.exchangeRates(), "exchange").mockReturnValue(5); From 877e4d9cd232c1971c2be9fb474675b789c5889f Mon Sep 17 00:00:00 2001 From: Juan Patricio Marroquin Date: Mon, 4 Nov 2024 12:03:02 -0500 Subject: [PATCH 4/4] fix: eslint issues --- .../TransactionSummary/TransactionSummary.tsx | 5 +++-- .../TransactionRow/TransactionBlocks.test.tsx | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/domains/transaction/components/TransactionDetail/TransactionSummary/TransactionSummary.tsx b/src/domains/transaction/components/TransactionDetail/TransactionSummary/TransactionSummary.tsx index af3fec1ad6..93fb4870c5 100644 --- a/src/domains/transaction/components/TransactionDetail/TransactionSummary/TransactionSummary.tsx +++ b/src/domains/transaction/components/TransactionDetail/TransactionSummary/TransactionSummary.tsx @@ -2,9 +2,10 @@ import React, { ReactElement } from "react"; import { useTranslation } from "react-i18next"; import { Contracts, DTO } from "@ardenthq/sdk-profiles"; import { DetailDivider, DetailLabelText, DetailWrapper } from "@/app/components/DetailWrapper"; -import { Amount, AmountLabel } from "@/app/components/Amount"; +import { Amount } from "@/app/components/Amount"; import { BigNumber } from "@ardenthq/sdk-helpers"; -import { TransactionAmountLabel } from "../../TransactionTable/TransactionRow/TransactionAmount.blocks"; +import { TransactionAmountLabel } from "@/domains/transaction/components/TransactionTable/TransactionRow/TransactionAmount.blocks"; + interface Properties { transaction: DTO.ExtendedSignedTransactionData | DTO.ExtendedConfirmedTransactionData; diff --git a/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionBlocks.test.tsx b/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionBlocks.test.tsx index d4d55a95b1..0a88b950f5 100644 --- a/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionBlocks.test.tsx +++ b/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionBlocks.test.tsx @@ -113,7 +113,7 @@ describe("TransactionAmount.blocks", () => { expect(screen.getByText(/35 DARK/)).toBeInTheDocument(); }); - it("should not show hint if the active wallet is not the sender of the transaction", async () => { + it("should not show hint if the active wallet is not the sender of the transaction", () => { const fixture = { ...TransactionFixture, fee: () => 5,