Skip to content

Commit

Permalink
fix(llm): prevent debounce causing memo change miss
Browse files Browse the repository at this point in the history
  • Loading branch information
thesan committed Dec 10, 2024
1 parent daf5ee9 commit 31764d0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-swans-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": minor
---

Prevent debounce from causing the memo tag not being saved
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -17,22 +17,23 @@ export const useMemoTagInput = (
(perFamily[family as keyof typeof perFamily] as FC<MemoTagInputProps>)) ||
null;

const [isDebouncePending, setIsDebouncePending] = useState(false);
const [isEmpty, setIsEmpty] = useState(true);
const [error, setError] = useState<Error | undefined>();
const debouncedUpdateTransaction = useMemo(
() => debounce(updateTransaction, DEBOUNCE_DELAY),
[updateTransaction],
);
const handleChange = useCallback<MemoTagInputProps["onChange"]>(
({ patch, value, error }) => {
const handleChange = useMemo<MemoTagInputProps["onChange"]>(() => {
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;
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand Down Expand Up @@ -341,7 +347,7 @@ export default function SendSelectRecipient({ navigation, route }: Props) {
testID="recipient-continue-button"
type="primary"
title={<Trans i18nKey="common.continue" />}
disabled={debouncedBridgePending || !!status.errors.recipient || !!memoTag?.error}
disabled={isContinueDisabled}
pending={debouncedBridgePending}
onPress={onPressContinue}
/>
Expand Down

0 comments on commit 31764d0

Please sign in to comment.