diff --git a/apps/marginfi-v2-ui/src/components/common/Portfolio/components/move-position/move-position-dialog.tsx b/apps/marginfi-v2-ui/src/components/common/Portfolio/components/move-position/move-position-dialog.tsx index b5ad5992a8..6484617358 100644 --- a/apps/marginfi-v2-ui/src/components/common/Portfolio/components/move-position/move-position-dialog.tsx +++ b/apps/marginfi-v2-ui/src/components/common/Portfolio/components/move-position/move-position-dialog.tsx @@ -162,7 +162,16 @@ export const MovePositionDialog = ({ } finally { setIsExecutionLoading(false); } - }, [marginfiClient, accountToMoveTo, actionTxns, broadcastType, priorityFees, fetchMrgnlendState, setIsOpen]); + }, [ + marginfiClient, + accountToMoveTo, + actionTxns, + broadcastType, + priorityFees, + selectedAccount?.address, + fetchMrgnlendState, + setIsOpen, + ]); React.useEffect(() => { if (!accountToMoveTo) return; diff --git a/apps/marginfi-v2-ui/src/context/MrgnlendProvider.tsx b/apps/marginfi-v2-ui/src/context/MrgnlendProvider.tsx index 766298ae46..1cbb07b97e 100644 --- a/apps/marginfi-v2-ui/src/context/MrgnlendProvider.tsx +++ b/apps/marginfi-v2-ui/src/context/MrgnlendProvider.tsx @@ -56,7 +56,7 @@ export const MrgnlendProvider: React.FC<{ }, [router.query]); // eslint-disable-line react-hooks/exhaustive-deps React.useEffect(() => { - const fetchData = () => { + const initializeAndFetch = () => { setIsRefreshingStore(true); fetchPriorityFee(connection); fetchMrgnlendState({ @@ -71,29 +71,27 @@ export const MrgnlendProvider: React.FC<{ }).catch(console.error); }; + const periodicFetch = () => { + console.log("🔄 Periodically fetching marginfi state"); + setIsRefreshingStore(true); + fetchPriorityFee(connection); + fetchMrgnlendState().catch(console.error); + }; + if (debounceId.current) { clearTimeout(debounceId.current); } - debounceId.current = setTimeout(() => { - fetchData(); - - const id = setInterval(() => { - setIsRefreshingStore(true); - fetchPriorityFee(connection); - fetchMrgnlendState().catch(console.error); - }, 30_000); + debounceId.current = setTimeout(initializeAndFetch, 1000); - return () => { - clearInterval(id); - clearTimeout(debounceId.current!); - }; - }, 1000); + // Periodic updates without needing full configuration + const intervalId = setInterval(periodicFetch, 30_000); return () => { if (debounceId.current) { clearTimeout(debounceId.current); } + clearInterval(intervalId); }; }, [wallet, isOverride]); // eslint-disable-line react-hooks/exhaustive-deps // ^ crucial to omit both `connection` and `fetchMrgnlendState` from the dependency array diff --git a/packages/mrgn-ui/src/components/wallet-v2/hooks/use-wallet.hook.tsx b/packages/mrgn-ui/src/components/wallet-v2/hooks/use-wallet.hook.tsx index 1b825c764b..f24dcf3a97 100644 --- a/packages/mrgn-ui/src/components/wallet-v2/hooks/use-wallet.hook.tsx +++ b/packages/mrgn-ui/src/components/wallet-v2/hooks/use-wallet.hook.tsx @@ -161,10 +161,10 @@ const WalletProvider = ({ children }: { children: React.ReactNode }) => { const [walletContextState, setWalletContextState] = React.useState( walletContextStateDefault ); + const walletQueryParam = query?.wallet as string; // update wallet object, 3 potential sources: web3auth, anchor, override const { wallet, isOverride }: { wallet: Wallet; isOverride: boolean } = React.useMemo(() => { - const override = query?.wallet as string; // web3auth wallet if (web3AuthWalletData && web3Auth?.connected) { return { @@ -192,11 +192,11 @@ const WalletProvider = ({ children }: { children: React.ReactNode }) => { // wallet address override // e.g simulating a wallet using ?wallet= query string - if (override) { + if (walletQueryParam) { return { wallet: { ...anchorWallet, - publicKey: new PublicKey(override) as PublicKey, + publicKey: new PublicKey(walletQueryParam), signMessage: walletContextState?.signMessage, signTransaction: walletContextState?.signTransaction as ( transactions: T @@ -229,7 +229,7 @@ const WalletProvider = ({ children }: { children: React.ReactNode }) => { isOverride: false, }; } - }, [anchorWallet, web3AuthWalletData, query, web3Auth?.connected, walletContextState]); + }, [anchorWallet, web3AuthWalletData, walletQueryParam, web3Auth?.connected, walletContextState]); // login to web3auth with specified social provider const loginWeb3Auth = React.useCallback(