From e723113432edeb080b6a420ddcd2dda03738087e Mon Sep 17 00:00:00 2001 From: Kevin Le Seigle Date: Tue, 10 Dec 2024 18:12:35 +0100 Subject: [PATCH] Revert "fix(lld): use a debounce on memotag field" This reverts commit 3a9758f7642cea56e49b45a9e36dc5c4babc57ef. --- .changeset/seven-ravens-rest.md | 5 ----- .../MemoTag/__tests__/MemoTagField.test.tsx | 12 +---------- .../MemoTag/components/MemoTagField.tsx | 21 ++++--------------- .../renderer/families/casper/MemoField.tsx | 2 +- .../families/xrp/SendRecipientFields.tsx | 3 +-- 5 files changed, 7 insertions(+), 36 deletions(-) delete mode 100644 .changeset/seven-ravens-rest.md diff --git a/.changeset/seven-ravens-rest.md b/.changeset/seven-ravens-rest.md deleted file mode 100644 index 8a4f89f57f08..000000000000 --- a/.changeset/seven-ravens-rest.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"ledger-live-desktop": minor ---- - -LLD: LIVE-15143 use a debounce on the memotag field diff --git a/apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/MemoTagField.test.tsx b/apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/MemoTagField.test.tsx index 6dc92249e143..8e75955c2f66 100644 --- a/apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/MemoTagField.test.tsx +++ b/apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/MemoTagField.test.tsx @@ -7,14 +7,6 @@ import { render, screen, fireEvent } from "tests/testUtils"; import MemoTagField from "../components/MemoTagField"; describe("MemoTagField", () => { - beforeAll(() => { - jest.useFakeTimers(); - }); - - afterAll(() => { - jest.useRealTimers(); - }); - it("renders MemoTagField with label and text field", () => { render(); expect(screen.getByText(/Tag \/ Memo/gi)).toBeInTheDocument(); @@ -27,14 +19,12 @@ describe("MemoTagField", () => { expect(screen.queryByText(/Tag \/ Memo/gi)).not.toBeInTheDocument(); }); - it("should call onChange when input value changes with a debounce", () => { + it("should call onChange when input value changes", () => { const handleChange = jest.fn(); render(); fireEvent.change(screen.getByPlaceholderText(/Enter Tag \/ Memo/gi), { target: { value: "new memo" }, }); - expect(handleChange).not.toHaveBeenCalled(); - jest.runAllTimers(); expect(handleChange).toHaveBeenCalledTimes(1); }); diff --git a/apps/ledger-live-desktop/src/newArch/features/MemoTag/components/MemoTagField.tsx b/apps/ledger-live-desktop/src/newArch/features/MemoTag/components/MemoTagField.tsx index c54b41585285..a6be608741a6 100644 --- a/apps/ledger-live-desktop/src/newArch/features/MemoTag/components/MemoTagField.tsx +++ b/apps/ledger-live-desktop/src/newArch/features/MemoTag/components/MemoTagField.tsx @@ -1,12 +1,12 @@ -import React, { useState, useEffect } from "react"; +import React from "react"; import Input, { Props as InputBaseProps } from "~/renderer/components/Input"; -import { useDebounce } from "@ledgerhq/live-common//hooks/useDebounce"; import Label from "~/renderer/components/Label"; import Box from "~/renderer/components/Box"; import { useTranslation } from "react-i18next"; import { Flex, Text, Tooltip } from "@ledgerhq/react-ui"; import styled from "styled-components"; import InfoCircle from "~/renderer/icons/InfoCircle"; + const TooltipContainer = styled(Box)` background-color: ${({ theme }) => theme.colors.palette.neutral.c100}; padding: 10px; @@ -30,7 +30,6 @@ type MemoTagFieldProps = InputBaseProps & { placeholder?: string; label?: string; tooltipText?: string; - validationHandler?: (newValue: string) => string; }; const MemoTagField = ({ @@ -45,20 +44,8 @@ const MemoTagField = ({ placeholder, label, tooltipText, - validationHandler, }: MemoTagFieldProps) => { const { t } = useTranslation(); - const [memoValue, setMemoValue] = useState(value); - const debouncedMemoValue = useDebounce(memoValue, 300); - - useEffect(() => { - if (debouncedMemoValue !== value) onChange?.(debouncedMemoValue || ""); - }, [debouncedMemoValue, onChange, value]); - - const handleChange = (newValue: string) => { - setMemoValue(validationHandler ? validationHandler(newValue) : newValue); - }; - return ( {showLabel && ( @@ -81,10 +68,10 @@ const MemoTagField = ({ {CaracterCountComponent && } { + value = value.replace(/\D/g, ""); if (value !== "") onChange(bridge.updateTransaction(transaction, { transferId: value })); else onChange(bridge.updateTransaction(transaction, { transferId: undefined })); }, @@ -31,7 +32,6 @@ const MemoField = ({ onChange, account, transaction, status, autoFocus }: MemoTa onChange={onTransferIdFieldChange} spellCheck="false" autoFocus={autoFocus} - validationHandler={newValue => newValue.replace(/\D/g, "")} /> ); }; diff --git a/apps/ledger-live-desktop/src/renderer/families/xrp/SendRecipientFields.tsx b/apps/ledger-live-desktop/src/renderer/families/xrp/SendRecipientFields.tsx index 8c9a3e56239d..14b073addb19 100644 --- a/apps/ledger-live-desktop/src/renderer/families/xrp/SendRecipientFields.tsx +++ b/apps/ledger-live-desktop/src/renderer/families/xrp/SendRecipientFields.tsx @@ -15,7 +15,7 @@ const TagField = ({ onChange, account, transaction, autoFocus }: Props) => { const onChangeTag = useCallback( (str: string) => { const bridge = getAccountBridge(account); - const tag = BigNumber(str); + const tag = BigNumber(str.replace(/[^0-9]/g, "")); const patch = { tag: !tag.isNaN() && @@ -37,7 +37,6 @@ const TagField = ({ onChange, account, transaction, autoFocus }: Props) => { value={String(transaction.tag || "")} onChange={onChangeTag} autoFocus={autoFocus} - validationHandler={str => str.replace(/[^0-9]/g, "")} /> ); };