import { STATIC_IMAGES_URL } from "@hey/data/constants"; import { ERRORS } from "@hey/data/errors"; import { useSwitchAccountMutation } from "@hey/indexer"; import type { ApolloClientError } from "@hey/types/errors"; import { useCallback, useEffect } from "react"; import { H4, Image } from "@/components/Shared/UI"; import errorToast from "@/helpers/errorToast"; import reloadAllTabs from "@/helpers/reloadAllTabs"; import { signIn } from "@/store/persisted/useAuthStore"; import { useSignupStore } from "."; const Success = () => { const { accountAddress, onboardingToken } = useSignupStore(); const onError = useCallback((error: ApolloClientError) => { errorToast(error); }, []); const [switchAccount] = useSwitchAccountMutation({ onError }); const handleAuth = async () => { try { const auth = await switchAccount({ context: { headers: { "X-Access-Token": onboardingToken } }, variables: { request: { account: accountAddress } } }); if (auth.data?.switchAccount.__typename === "AuthenticationTokens") { const accessToken = auth.data?.switchAccount.accessToken; const refreshToken = auth.data?.switchAccount.refreshToken; signIn({ accessToken, refreshToken }); reloadAllTabs(); return; } return onError({ message: ERRORS.SomethingWentWrong }); } catch { onError({ message: ERRORS.SomethingWentWrong }); } }; useEffect(() => { handleAuth(); }, []); return (