diff --git a/apps/deploy-web/src/hooks/useManagedWallet.ts b/apps/deploy-web/src/hooks/useManagedWallet.ts index 084b382f0..7eb002487 100644 --- a/apps/deploy-web/src/hooks/useManagedWallet.ts +++ b/apps/deploy-web/src/hooks/useManagedWallet.ts @@ -2,6 +2,7 @@ import { useEffect, useMemo } from "react"; import { useAtom } from "jotai"; import { browserEnvConfig } from "@src/config/browser-env.config"; +import { useSelectedChain } from "@src/context/CustomChainProvider"; import { useUser } from "@src/hooks/useUser"; import { useCreateManagedWalletMutation, useManagedWalletQuery } from "@src/queries/useManagedWalletQuery"; import walletStore from "@src/store/walletStore"; @@ -14,7 +15,20 @@ const isBillingEnabled = NEXT_PUBLIC_BILLING_ENABLED; export const useManagedWallet = () => { const user = useUser(); const { user: signedInUser } = useCustomUser(); - const { data: queried, isFetched, isLoading: isFetching, refetch } = useManagedWalletQuery(isBillingEnabled ? user?.id : undefined); + const userWallet = useSelectedChain(); + const [selectedWalletType, setSelectedWalletType] = useAtom(walletStore.selectedWalletType); + const { + data: queried, + isFetched, + isLoading: isFetching, + refetch + } = useManagedWalletQuery(isBillingEnabled ? user?.id : undefined, { + onSuccess: wallet => { + if (selectedWalletType === "custodial" && wallet && !userWallet.isWalletConnected) { + setSelectedWalletType("managed"); + } + } + }); const { mutate: create, data: created, isLoading: isCreating, isSuccess: isCreated } = useCreateManagedWalletMutation(); const wallet = useMemo(() => queried || created, [queried, created]); const isLoading = isFetching || isCreating; diff --git a/apps/deploy-web/src/queries/useManagedWalletQuery.ts b/apps/deploy-web/src/queries/useManagedWalletQuery.ts index 8425be579..bafa66d14 100644 --- a/apps/deploy-web/src/queries/useManagedWalletQuery.ts +++ b/apps/deploy-web/src/queries/useManagedWalletQuery.ts @@ -1,10 +1,11 @@ -import { useMutation, useQuery, useQueryClient } from "react-query"; +import { QueryKey, useMutation, useQuery, useQueryClient, UseQueryOptions } from "react-query"; +import { ApiWalletOutput } from "@akashnetwork/http-sdk"; import { managedWalletHttpService } from "@src/services/managed-wallet-http/managed-wallet-http.service"; const MANAGED_WALLET = "MANAGED_WALLET"; -export function useManagedWalletQuery(userId?: string) { +export function useManagedWalletQuery(userId?: string, options?: Omit, "queryKey" | "queryFn">) { return useQuery( [MANAGED_WALLET, userId], async () => { @@ -14,7 +15,8 @@ export function useManagedWalletQuery(userId?: string) { }, { enabled: !!userId, - staleTime: Infinity + staleTime: Infinity, + ...options } ); }