diff --git a/.changeset/witty-swans-share.md b/.changeset/witty-swans-share.md new file mode 100644 index 000000000000..06b13f0ebd3c --- /dev/null +++ b/.changeset/witty-swans-share.md @@ -0,0 +1,5 @@ +--- +"live-mobile": minor +--- + +Prevent debounce from causing the memo tag not being saved diff --git a/apps/ledger-live-mobile/src/newArch/features/MemoTag/hooks/useMemoTagInput.ts b/apps/ledger-live-mobile/src/newArch/features/MemoTag/hooks/useMemoTagInput.ts index b9adae6e9daa..07fe7d4545c4 100644 --- a/apps/ledger-live-mobile/src/newArch/features/MemoTag/hooks/useMemoTagInput.ts +++ b/apps/ledger-live-mobile/src/newArch/features/MemoTag/hooks/useMemoTagInput.ts @@ -1,5 +1,5 @@ import debounce from "lodash/debounce"; -import { FC, useCallback, useMemo, useState } from "react"; +import { FC, useMemo, useState } from "react"; import { useFeature } from "@ledgerhq/live-common/featureFlags/index"; import { Transaction } from "@ledgerhq/live-common/generated/types"; @@ -17,22 +17,23 @@ export const useMemoTagInput = ( (perFamily[family as keyof typeof perFamily] as FC)) || null; + const [isDebouncePending, setIsDebouncePending] = useState(false); const [isEmpty, setIsEmpty] = useState(true); const [error, setError] = useState(); - const debouncedUpdateTransaction = useMemo( - () => debounce(updateTransaction, DEBOUNCE_DELAY), - [updateTransaction], - ); - const handleChange = useCallback( - ({ patch, value, error }) => { + const handleChange = useMemo(() => { + const debouncedUpdateTransaction = debounce(patch => { + setIsDebouncePending(false); + updateTransaction(patch); + }, DEBOUNCE_DELAY); + return ({ patch, value, error }) => { + setIsDebouncePending(true); setIsEmpty(!value); setError(error); debouncedUpdateTransaction(patch); - }, - [debouncedUpdateTransaction], - ); + }; + }, [updateTransaction]); - return Input && { Input, isEmpty, error, handleChange }; + return Input && { Input, isEmpty, isDebouncePending, error, handleChange }; }; const DEBOUNCE_DELAY = 300; diff --git a/apps/ledger-live-mobile/src/screens/SendFunds/02-SelectRecipient.tsx b/apps/ledger-live-mobile/src/screens/SendFunds/02-SelectRecipient.tsx index 2003f1d6fbb1..8e97d93e2fea 100644 --- a/apps/ledger-live-mobile/src/screens/SendFunds/02-SelectRecipient.tsx +++ b/apps/ledger-live-mobile/src/screens/SendFunds/02-SelectRecipient.tsx @@ -218,6 +218,12 @@ export default function SendSelectRecipient({ navigation, route }: Props) { !isConfirmedOperation(op, mainAccount, currencySettings.confirmationsNb), ); + const isContinueDisabled = + debouncedBridgePending || + !!status.errors.recipient || + memoTag?.isDebouncePending || + !!memoTag?.error; + const stuckAccountAndOperation = getStuckAccountAndOperation(account, mainAccount); return ( <> @@ -341,7 +347,7 @@ export default function SendSelectRecipient({ navigation, route }: Props) { testID="recipient-continue-button" type="primary" title={} - disabled={debouncedBridgePending || !!status.errors.recipient || !!memoTag?.error} + disabled={isContinueDisabled} pending={debouncedBridgePending} onPress={onPressContinue} />