From 76c47d2a9ec83f030b42028ee1fbd536789478df Mon Sep 17 00:00:00 2001 From: Jeremy Lee <37092291+yogurtandjam@users.noreply.github.com> Date: Thu, 19 Sep 2024 18:58:23 -0400 Subject: [PATCH] fix: solana set for source address (#1041) --- src/hooks/useAccounts.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/hooks/useAccounts.tsx b/src/hooks/useAccounts.tsx index cc4cc618a..5736124da 100644 --- a/src/hooks/useAccounts.tsx +++ b/src/hooks/useAccounts.tsx @@ -89,6 +89,13 @@ const useAccountsContext = () => { } setPreviousEvmAddress(evmAddress); + // TODO: create a better pattern than this. + // We only want to set the source evm address if the evm address changes + // OR when our connection state changes. + // The evm address can be cached via local storage, so it won't change when we reconnect + // But the hasSubAccount value will become true once you reconnect + // This allows us to trigger a state update and make sure abacus knows the source address + // eslint-disable-next-line react-hooks/exhaustive-deps }, [evmAddress, hasSubAccount]); const { ready, authenticated } = usePrivy(); @@ -206,7 +213,13 @@ const useAccountsContext = () => { } setPreviousSolAddress(solAddress); - }, [solAddress]); + // We only want to set the source sol address if the sol address changes + // OR when our connection state changes. + // The sol address can be cached via local storage, so it won't change when we reconnect + // But the hasSubAccount value will become true once you reconnect + // This allows us to trigger a state update and make sure abacus knows the source address + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [solAddress, hasSubAccount]); const decryptSignature = (encryptedSignature: string | undefined) => { const staticEncryptionKey = import.meta.env.VITE_PK_ENCRYPTION_KEY;