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

fix(llm): release prevent debounce causing memo change miss #8657

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
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