Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: transaction amount with hint in summary #796

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,11 +22,8 @@ export const TransactionSummary = ({ transaction, senderWallet, labelClassName }
<>
<div className="flex w-full justify-between sm:justify-start">
<DetailLabelText className={labelClassName}>{t("COMMON.AMOUNT")}</DetailLabelText>
<AmountLabel
isNegative={transaction.isSent()}
value={transaction.amount()}
ticker={senderWallet.currency()}
textClassName="text-sm leading-[17px] sm:text-base sm:leading-5"
<TransactionAmountLabel
transaction={transaction}
/>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;

Expand Down Expand Up @@ -36,12 +37,12 @@
returnedAmount += recipient.amount;
}
}

return returnedAmount;
};

export const TransactionAmountLabel = ({ transaction }: { transaction: ExtendedTransactionData }): JSX.Element => {
const { t } = useTranslation();
const activeWallet = useActiveWallet();

Check failure on line 45 in src/domains/transaction/components/TransactionTable/TransactionRow/TransactionAmount.blocks.tsx

View workflow job for this annotation

GitHub Actions / eslint (20.12.2)

'activeWallet' is assigned a value but never used. Allowed unused vars must match /_/u

const currency = transaction.wallet().currency();

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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(<TransactionAmountLabel transaction={fixture as any} />);
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(
<Route path={path}>
<TransactionAmountLabel transaction={fixtureWithSender as any} />
</Route>,
{
history,
route: walletUrl(encryptedWallet.id()),
},
);

// should have a label
expect(screen.getByTestId("AmountLabel__hint")).toBeInTheDocument();
Expand Down
Loading