From b961229545a2f759c6890685abd80f85334d291c Mon Sep 17 00:00:00 2001 From: Mounir Hamzaoui Date: Wed, 9 Oct 2024 17:21:08 +0200 Subject: [PATCH] feat: add memo tag information section in LLD recieve flow (#8055) --- .changeset/new-cougars-develop.md | 5 +++ .../MemoTag/__tests__/MemoTagInfo.test.tsx | 20 +++++++++ .../__tests__/MemoTagInfoBody.test.tsx | 30 +++++++++++++ .../MemoTag/components/MemoTagInfo.tsx | 42 +++++++++++++++++++ .../MemoTag/components/MemoTagInfoBody.tsx | 33 +++++++++++++++ .../src/newArch/features/MemoTag/constants.ts | 14 +++++++ .../modals/Receive/steps/StepReceiveFunds.tsx | 18 +++++++- .../static/i18n/en/app.json | 7 +++- 8 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 .changeset/new-cougars-develop.md create mode 100644 apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/MemoTagInfo.test.tsx create mode 100644 apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/MemoTagInfoBody.test.tsx create mode 100644 apps/ledger-live-desktop/src/newArch/features/MemoTag/components/MemoTagInfo.tsx create mode 100644 apps/ledger-live-desktop/src/newArch/features/MemoTag/components/MemoTagInfoBody.tsx create mode 100644 apps/ledger-live-desktop/src/newArch/features/MemoTag/constants.ts diff --git a/.changeset/new-cougars-develop.md b/.changeset/new-cougars-develop.md new file mode 100644 index 000000000000..834a7cd279b2 --- /dev/null +++ b/.changeset/new-cougars-develop.md @@ -0,0 +1,5 @@ +--- +"ledger-live-desktop": minor +--- + +Add Memo tag info section in LLD diff --git a/apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/MemoTagInfo.test.tsx b/apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/MemoTagInfo.test.tsx new file mode 100644 index 000000000000..aa708eadb79e --- /dev/null +++ b/apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/MemoTagInfo.test.tsx @@ -0,0 +1,20 @@ +/** + * @jest-environment jsdom + */ +import React from "react"; +import { fireEvent, render, screen } from "tests/testUtils"; +import MemoTagInfo from "../components/MemoTagInfo"; + +describe("MemoTagInfo", () => { + it("should display MemoTagInfo", async () => { + render(); + const clickabelLabel = screen.getByText(/Need a Tag\/Memo?/); + expect(clickabelLabel).toBeVisible(); + fireEvent.click(clickabelLabel); + const memoTagInfoBody = await screen.findByTestId("memo-tag-info-body"); + // spec: when a user clicks on the label, it should display the memo tag info body + expect(memoTagInfoBody).toBeVisible(); + // spec: when a user clicks on the label, it should disappear + expect(clickabelLabel).not.toBeInTheDocument(); + }); +}); diff --git a/apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/MemoTagInfoBody.test.tsx b/apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/MemoTagInfoBody.test.tsx new file mode 100644 index 000000000000..3becffa6c68e --- /dev/null +++ b/apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/MemoTagInfoBody.test.tsx @@ -0,0 +1,30 @@ +/** + * @jest-environment jsdom + */ +import React from "react"; +import { fireEvent, render, screen } from "tests/testUtils"; +import MemoTagInfoBody from "../components/MemoTagInfoBody"; +import { MEMO_TAG_LEARN_MORE_LINK } from "../constants"; +import * as LinkingHelpers from "~/renderer/linking"; + +jest.mock("~/renderer/linking", () => ({ + openURL: jest.fn(), +})); + +describe("MemoTagInfoBody", () => { + it("should display MemoTagInfoBody correctly", async () => { + render(); + + const memoTagInfoBody = screen.getByTestId("memo-tag-info-body"); + const learnMoreLink = screen.getByText(/Learn more about Tag\/Memo/); + + expect(memoTagInfoBody).toBeVisible(); + expect(learnMoreLink).toBeVisible(); + + fireEvent.click(learnMoreLink); + + jest.spyOn(LinkingHelpers, "openURL"); + // spec: when a user clicks on the learn more link, it should open the link + expect(LinkingHelpers.openURL).toHaveBeenCalledWith(MEMO_TAG_LEARN_MORE_LINK); + }); +}); diff --git a/apps/ledger-live-desktop/src/newArch/features/MemoTag/components/MemoTagInfo.tsx b/apps/ledger-live-desktop/src/newArch/features/MemoTag/components/MemoTagInfo.tsx new file mode 100644 index 000000000000..39b99bbbadb8 --- /dev/null +++ b/apps/ledger-live-desktop/src/newArch/features/MemoTag/components/MemoTagInfo.tsx @@ -0,0 +1,42 @@ +import React, { useState } from "react"; +import { Trans } from "react-i18next"; + +import { Alert } from "@ledgerhq/react-ui"; + +import { colors } from "~/renderer/styles/theme"; + +import Label from "~/renderer/components/Label"; + +import MemoTagInfoBody from "./MemoTagInfoBody"; + +const MemoTagInfo = () => { + const [isAlertDisplayed, toggleAlertDisplay] = useState(false); + + const handleOnToggleAlertDisplay = () => { + toggleAlertDisplay(!isAlertDisplayed); + }; + + return !isAlertDisplayed ? ( + + ) : ( + } + /> + ); +}; + +export default MemoTagInfo; diff --git a/apps/ledger-live-desktop/src/newArch/features/MemoTag/components/MemoTagInfoBody.tsx b/apps/ledger-live-desktop/src/newArch/features/MemoTag/components/MemoTagInfoBody.tsx new file mode 100644 index 000000000000..6354db4e01d1 --- /dev/null +++ b/apps/ledger-live-desktop/src/newArch/features/MemoTag/components/MemoTagInfoBody.tsx @@ -0,0 +1,33 @@ +import React from "react"; +import { Link, Text } from "@ledgerhq/react-ui"; +import { Trans } from "react-i18next"; +import { openURL } from "~/renderer/linking"; +import { MEMO_TAG_LEARN_MORE_LINK } from "../constants"; + +const MemoTagInfoBody = () => { + const handleOpenLMLink = () => openURL(MEMO_TAG_LEARN_MORE_LINK); + + return ( +
+ + + + + +
+ + + +
+ ); +}; + +export default MemoTagInfoBody; diff --git a/apps/ledger-live-desktop/src/newArch/features/MemoTag/constants.ts b/apps/ledger-live-desktop/src/newArch/features/MemoTag/constants.ts new file mode 100644 index 000000000000..43d38061a4ee --- /dev/null +++ b/apps/ledger-live-desktop/src/newArch/features/MemoTag/constants.ts @@ -0,0 +1,14 @@ +export const MEMO_TAG_LEARN_MORE_LINK = "https://support.ledger.com/article/4409603715217-zd"; +export const MEMO_TAG_COINS: string[] = [ + "ripple", + "stellar", + "cosmos", + "hedera", + "injective", + "crypto_org", + "crypto_org_croeseid", + "stacks", + "ton", + "eos", + "bsc", +]; diff --git a/apps/ledger-live-desktop/src/renderer/modals/Receive/steps/StepReceiveFunds.tsx b/apps/ledger-live-desktop/src/renderer/modals/Receive/steps/StepReceiveFunds.tsx index fc9fed00f4d4..55f74e5fde7d 100644 --- a/apps/ledger-live-desktop/src/renderer/modals/Receive/steps/StepReceiveFunds.tsx +++ b/apps/ledger-live-desktop/src/renderer/modals/Receive/steps/StepReceiveFunds.tsx @@ -29,7 +29,7 @@ import ModalBody from "~/renderer/components/Modal/ModalBody"; import QRCode from "~/renderer/components/QRCode"; import { getEnv } from "@ledgerhq/live-env"; import AccountTagDerivationMode from "~/renderer/components/AccountTagDerivationMode"; -import { useFeature } from "@ledgerhq/live-common/featureFlags/index"; +import { FeatureToggle, useFeature } from "@ledgerhq/live-common/featureFlags/index"; import { LOCAL_STORAGE_KEY_PREFIX } from "./StepReceiveStakingFlow"; import { useDispatch } from "react-redux"; import { openModal } from "~/renderer/actions/modals"; @@ -41,6 +41,8 @@ import { getDefaultAccountName } from "@ledgerhq/live-wallet/accountName"; import { useMaybeAccountName } from "~/renderer/reducers/wallet"; import { UTXOAddressAlert } from "~/renderer/components/UTXOAddressAlert"; import { isUTXOCompliant } from "@ledgerhq/live-common/currencies/helpers"; +import MemoTagInfo from "~/newArch/features/MemoTag/components/MemoTagInfo"; +import { MEMO_TAG_COINS } from "~/newArch/features/MemoTag/constants"; const Separator = styled.div` border-top: 1px solid #99999933; @@ -68,7 +70,12 @@ const Receive1ShareAddress = ({ address: string; showQRCodeModal: () => void; }) => { - const isUTXOCompliantCurrency = isUTXOCompliant(account.currency.family); + const { currency } = account; + + const isUTXOCompliantCurrency = isUTXOCompliant(currency.family); + const shouldRenderMemoTagInfo = + currency.explorerId && MEMO_TAG_COINS.includes(currency.explorerId); + return ( <> @@ -103,6 +110,13 @@ const Receive1ShareAddress = ({ )} + + {shouldRenderMemoTagInfo && ( + + + + )} + ); }; diff --git a/apps/ledger-live-desktop/static/i18n/en/app.json b/apps/ledger-live-desktop/static/i18n/en/app.json index 9d36c2d28a50..fa027947bb6b 100644 --- a/apps/ledger-live-desktop/static/i18n/en/app.json +++ b/apps/ledger-live-desktop/static/i18n/en/app.json @@ -2253,7 +2253,12 @@ "description": "Stake your CELO with Ledger by Figment validator. It guarantees complete cover against slashing, backed by Ledger’s uncompromising security." } } - } + }, + "memoTag": { + "title": "Need a Tag/Memo?", + "description": "You might need a <0>Tag/Memo for receiving this asset from an exchange. You can use any combination of numbers like 1234.", + "learnMore": "Learn more about Tag/Memo" + } }, "send": { "title": "Send",