diff --git a/src/domains/transaction/components/TransactionDetail/TransactionSummary/TransactionSummary.tsx b/src/domains/transaction/components/TransactionDetail/TransactionSummary/TransactionSummary.tsx index 260ecef58b..93fb4870c5 100644 --- a/src/domains/transaction/components/TransactionDetail/TransactionSummary/TransactionSummary.tsx +++ b/src/domains/transaction/components/TransactionDetail/TransactionSummary/TransactionSummary.tsx @@ -2,8 +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 "@/domains/transaction/components/TransactionTable/TransactionRow/TransactionAmount.blocks"; + interface Properties { transaction: DTO.ExtendedSignedTransactionData | DTO.ExtendedConfirmedTransactionData; @@ -20,11 +22,8 @@ export const TransactionSummary = ({ transaction, senderWallet, labelClassName } <>
{t("COMMON.AMOUNT")} -
diff --git a/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionAmount.blocks.tsx b/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionAmount.blocks.tsx index 4b8160f236..fad42580cb 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; @@ -36,12 +37,12 @@ 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(); diff --git a/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionBlocks.test.tsx b/src/domains/transaction/components/TransactionTable/TransactionRow/TransactionBlocks.test.tsx index c939b5816f..06afb6da12 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"); - render(); + encryptedWallet + .data() + .set(Contracts.WalletData.ImportMethod, Contracts.WalletImportMethod.SECRET_WITH_ENCRYPTION); + + profile.wallets().push(encryptedWallet); + + 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();