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

ibc transfer에서 기본 send로 변할때 recipient를 초기화하도록 수정 #1298

Merged
merged 1 commit into from
Jan 23, 2025
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
33 changes: 33 additions & 0 deletions apps/extension/src/hooks/use-previous.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useRef } from "react";

export type Predicate<T> = (prev: T | undefined, next: T) => boolean;

const strictEquals = <T>(prev: T | undefined, next: T) => prev === next;

const useFirstMountState = (): boolean => {
const isFirst = useRef(true);

if (isFirst.current) {
isFirst.current = false;

return true;
}

return isFirst.current;
};

export const usePreviousDistinct = <T>(
value: T,
compare: Predicate<T> = strictEquals
): T | undefined => {
const prevRef = useRef<T>();
const curRef = useRef<T>(value);
const isFirstMount = useFirstMountState();

if (!isFirstMount && !compare(curRef.current, value)) {
prevRef.current = curRef.current;
curRef.current = value;
}

return prevRef.current;
};
9 changes: 9 additions & 0 deletions apps/extension/src/pages/send/amount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { GuideBox } from "../../../components/guide-box";
import { ChainIdHelper } from "@keplr-wallet/cosmos";
import { amountToAmbiguousAverage, isRunningInSidePanel } from "../../../utils";
import { EthTxStatus } from "@keplr-wallet/types";
import { usePreviousDistinct } from "../../../hooks/use-previous";

const Styles = {
Flex1: styled.div`
Expand Down Expand Up @@ -392,6 +393,14 @@ export const SendAmountPage: FunctionComponent = observer(() => {
}
});

const isIBCTransferPrevious = usePreviousDistinct(isIBCTransfer);
useEffect(() => {
if (isIBCTransferPrevious && !isIBCTransfer) {
// ibc transfer에서 기본 send로 변할때 recipient를 초기화한다.
sendConfigs.recipientConfig.setValue("");
}
}, [isIBCTransfer, isIBCTransferPrevious, sendConfigs.recipientConfig]);

const txConfigsValidate = useTxConfigsValidate({
...sendConfigs,
gasSimulator,
Expand Down
Loading