Skip to content

Commit 37a08d4

Browse files
committed
Refactor useEffect dependencies in SwapComponent and ConfirmationModal
1 parent aeda8fd commit 37a08d4

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

lib/components/Swap/Swap.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ export const SwapComponent: FC<SwapProps> = ({
5252
disconnect,
5353
} = useWalletStore();
5454
useEffect(() => {
55-
if (tonConnectInstance.wallet) {
56-
setWallet(tonConnectInstance.wallet);
57-
} else if (stateWallet && !tonConnectInstance.wallet) {
58-
disconnect();
59-
}
60-
}, []);
55+
tonConnectInstance.onStatusChange((wallet) => {
56+
if (wallet) {
57+
setWallet(wallet);
58+
} else if (stateWallet && !wallet) {
59+
disconnect();
60+
}
61+
});
62+
}, [tonConnectInstance.wallet]);
6163

6264
const { initializeApp, receive_token, refetchBestRoute, swapModal } =
6365
useSwapStore();

lib/components/SwapButton/ConfirmationModal.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { FaArrowRightArrowLeft } from "react-icons/fa6";
66
import SwapKeyValue from "../SwapDetails/SwapKeyValue";
77
import formatNumber from "../../utils/formatNum";
88
import swap from "../../utils/swap";
9-
import { FC } from "react";
9+
import { FC, useEffect } from "react";
1010
import "./ConfirmationModal.scss";
1111
import { useOptionsStore } from "../../store/options.store";
1212
type ConfirmationModalProps = {
@@ -18,9 +18,13 @@ const ConfirmationModal: FC<ConfirmationModalProps> = ({ setConfirmModal }) => {
1818
setConfirmModal(false);
1919
};
2020
const { tonConnectInstance } = useOptionsStore();
21-
// tonConnectInstance?.uiOptions = {
22-
// actionsConfiguration: { modals: [] },
23-
// }
21+
useEffect(() => {
22+
if (tonConnectInstance) {
23+
tonConnectInstance.uiOptions = {
24+
actionsConfiguration: { modals: [] },
25+
};
26+
}
27+
}, [tonConnectInstance]);
2428

2529
const { colors } = useThemeStore();
2630
const {

lib/components/SwapButton/SwapButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const SwapButton = () => {
5555
const buttonDisabled = isButtonDisabled();
5656

5757
const handleSwapClick = () => {
58-
if (!tonConnectInstance?.wallet) {
58+
if (tonConnectInstance && !tonConnectInstance?.wallet) {
5959
tonConnectInstance?.openModal();
6060
} else {
6161
setConfirmModal(true);

0 commit comments

Comments
 (0)