diff --git a/src/pages/settings/safenet.tsx b/src/pages/settings/safenet.tsx index ddd00e20f2..b91c248120 100644 --- a/src/pages/settings/safenet.tsx +++ b/src/pages/settings/safenet.tsx @@ -6,15 +6,14 @@ import InfoIcon from '@/public/images/notifications/info.svg' import SettingsHeader from '@/components/settings/SettingsHeader' import useSafeInfo from '@/hooks/useSafeInfo' import { sameAddress } from '@/utils/addresses' -import { useContext, useEffect, useMemo } from 'react' +import { useContext, useMemo } from 'react' import { TxModalContext } from '@/components/tx-flow' import { EnableSafenetFlow } from '@/components/tx-flow/flows/EnableSafenet' import type { SafenetConfigEntity } from '@/store/safenet' -import { useLazyGetSafenetOffchainStatusQuery, useGetSafenetConfigQuery } from '@/store/safenet' +import { useGetSafenetConfigQuery } from '@/store/safenet' import type { ExtendedSafeInfo } from '@/store/safeInfoSlice' import { SAFE_FEATURES } from '@safe-global/protocol-kit/dist/src/utils' import { hasSafeFeature } from '@/utils/safe-versions' -import { getRTKErrorMessage } from '@/utils/redux-toolkit-query' const getSafenetTokensByChain = (chainId: number, safenetConfig: SafenetConfigEntity): string[] => { const tokenSymbols = Object.keys(safenetConfig.tokens) @@ -38,34 +37,11 @@ const SafenetContent = ({ safenetConfig, safe }: { safenetConfig: SafenetConfigE const chainSupported = safenetConfig.chains.includes(Number(safe.chainId)) const { setTxFlow } = useContext(TxModalContext) - // Lazy query because running it on unsupported chain throws an error - const [ - triggerGetSafenetOffchainStatus, - { - data: safenetOffchainStatus, - error: safenetOffchainStatusError, - isLoading: safenetOffchainStatusLoading, - status: safenetOffchainStatusStatus, - }, - ] = useLazyGetSafenetOffchainStatusQuery() - - // @ts-expect-error bad types. We don't want 404 to be an error - it just means that the safe is not registered - const offchainLookupError = safenetOffchainStatusError?.status === 404 ? null : safenetOffchainStatusError const safenetAssets = useMemo( () => getSafenetTokensByChain(Number(safe.chainId), safenetConfig), [safe.chainId, safenetConfig], ) - if (offchainLookupError) { - throw getRTKErrorMessage(offchainLookupError) - } - - useEffect(() => { - if (chainSupported) { - triggerGetSafenetOffchainStatus({ chainId: safe.chainId, safeAddress: safe.address.value }) - } - }, [chainSupported, triggerGetSafenetOffchainStatus, safe.chainId, safe.address.value]) - switch (true) { case !chainSupported: return ( @@ -98,8 +74,6 @@ const SafenetContent = ({ safenetConfig, safe }: { safenetConfig: SafenetConfigE ) - case safenetOffchainStatusLoading: - return default: return null } diff --git a/src/store/safenet.ts b/src/store/safenet.ts index 53e6dd9da3..e754db459a 100644 --- a/src/store/safenet.ts +++ b/src/store/safenet.ts @@ -73,6 +73,17 @@ export const safenetApi = createApi({ query: ({ chainId, safeAddress }) => `/account/${chainId}/${safeAddress}`, providesTags: (_, __, arg) => [{ type: 'SafenetOffchainStatus', id: arg.safeAddress }], }), + registerSafenet: builder.mutation({ + query: ({ chainId, safeAddress }) => ({ + url: `/account`, + method: 'POST', + body: { + chainId: Number(chainId), + safe: safeAddress, + }, + }), + invalidatesTags: (_, __, arg) => [{ type: 'SafenetOffchainStatus', id: arg.safeAddress }], + }), getSafenetBalance: builder.query({ query: ({ safeAddress }) => `/balances/${safeAddress}`, providesTags: (_, __, arg) => [{ type: 'SafenetBalance', id: arg.safeAddress }], @@ -94,9 +105,4 @@ export const safenetApi = createApi({ }), }) -export const { - useLazyGetSafenetOffchainStatusQuery, - useGetSafenetConfigQuery, - useLazyGetSafenetBalanceQuery, - useLazySimulateSafenetTxQuery, -} = safenetApi +export const { useGetSafenetConfigQuery, useLazyGetSafenetBalanceQuery, useLazySimulateSafenetTxQuery } = safenetApi