From 6383cfa244909276fcf9d5c9820ad78ca10dcd10 Mon Sep 17 00:00:00 2001 From: Burnt Val Date: Fri, 19 Apr 2024 16:15:15 -0400 Subject: [PATCH] fix state persistance bug --- .../components/AbstraxionWallets/index.tsx | 13 +++++++++---- .../AddAuthenticators/AddAuthenticatorsForm.tsx | 15 +++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/apps/abstraxion-dashboard/components/AbstraxionWallets/index.tsx b/apps/abstraxion-dashboard/components/AbstraxionWallets/index.tsx index ec1b40a6..2b4d23d6 100644 --- a/apps/abstraxion-dashboard/components/AbstraxionWallets/index.tsx +++ b/apps/abstraxion-dashboard/components/AbstraxionWallets/index.tsx @@ -72,11 +72,16 @@ export const AbstraxionWallets = () => { useEffect(() => { if (abstractAccount && previousData && data !== previousData) { // Updating abstract account in context on poll - setAbstractAccount( - data?.smartAccounts?.nodes.find( - (smartAccount) => smartAccount.id === abstractAccount.id, - ), + const node = data?.smartAccounts?.nodes.find( + (smartAccount) => smartAccount.id === abstractAccount.id, ); + setAbstractAccount({ + ...node, + userId: user?.user_id, + currentAuthenticatorIndex: node.authenticators.nodes.find( + (authenticator) => authenticator.authenticator === loginAuthenticator, + ).authenticatorIndex, + }); } }, [data, previousData]); diff --git a/apps/abstraxion-dashboard/components/ModalViews/AddAuthenticators/AddAuthenticatorsForm.tsx b/apps/abstraxion-dashboard/components/ModalViews/AddAuthenticators/AddAuthenticatorsForm.tsx index d8f56476..a020d934 100644 --- a/apps/abstraxion-dashboard/components/ModalViews/AddAuthenticators/AddAuthenticatorsForm.tsx +++ b/apps/abstraxion-dashboard/components/ModalViews/AddAuthenticators/AddAuthenticatorsForm.tsx @@ -8,6 +8,7 @@ import { import Image from "next/image"; import { WalletType, useAccount, useSuggestChainAndConnect } from "graz"; import { useQuery } from "@apollo/client"; +import { useStytchUser } from "@stytch/nextjs"; import { Button, KeplrLogo, @@ -49,6 +50,7 @@ export function AddAuthenticatorsForm({ const { loginAuthenticator } = useAbstraxionAccount(); const { client } = useAbstraxionSigningClient(); const { data: grazAccount } = useAccount(); + const { user } = useStytchUser(); const { suggestAndConnect } = useSuggestChainAndConnect({ onSuccess: async () => await addKeplrAuthenticator(), onError: () => setIsLoading(false), @@ -72,11 +74,16 @@ export function AddAuthenticatorsForm({ stopPolling(); setIsLoading(false); setIsSuccess(true); - setAbstractAccount( - data?.smartAccounts?.nodes.find( - (smartAccount) => smartAccount.id === abstractAccount.id, - ), + const node = data?.smartAccounts?.nodes.find( + (smartAccount) => smartAccount.id === abstractAccount.id, ); + setAbstractAccount({ + ...node, + userId: user?.user_id, + currentAuthenticatorIndex: node.authenticators.nodes.find( + (authenticator) => authenticator.authenticator === loginAuthenticator, + ).authenticatorIndex, + }); } }, [data, previousData]);