Skip to content

Commit

Permalink
remove more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
gjeanmart committed Nov 15, 2024
1 parent 39b6d8b commit 3f016de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 34 deletions.
30 changes: 2 additions & 28 deletions src/pages/settings/safenet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 (
Expand Down Expand Up @@ -98,8 +74,6 @@ const SafenetContent = ({ safenetConfig, safe }: { safenetConfig: SafenetConfigE
</Button>
</div>
)
case safenetOffchainStatusLoading:
return <CircularProgress />
default:
return null
}
Expand Down
18 changes: 12 additions & 6 deletions src/store/safenet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ export const safenetApi = createApi({
query: ({ chainId, safeAddress }) => `/account/${chainId}/${safeAddress}`,
providesTags: (_, __, arg) => [{ type: 'SafenetOffchainStatus', id: arg.safeAddress }],
}),
registerSafenet: builder.mutation<boolean, { chainId: string; safeAddress: string }>({
query: ({ chainId, safeAddress }) => ({
url: `/account`,
method: 'POST',
body: {
chainId: Number(chainId),
safe: safeAddress,
},
}),
invalidatesTags: (_, __, arg) => [{ type: 'SafenetOffchainStatus', id: arg.safeAddress }],
}),
getSafenetBalance: builder.query<SafenetBalanceEntity, { safeAddress: string }>({
query: ({ safeAddress }) => `/balances/${safeAddress}`,
providesTags: (_, __, arg) => [{ type: 'SafenetBalance', id: arg.safeAddress }],
Expand All @@ -94,9 +105,4 @@ export const safenetApi = createApi({
}),
})

export const {
useLazyGetSafenetOffchainStatusQuery,
useGetSafenetConfigQuery,
useLazyGetSafenetBalanceQuery,
useLazySimulateSafenetTxQuery,
} = safenetApi
export const { useGetSafenetConfigQuery, useLazyGetSafenetBalanceQuery, useLazySimulateSafenetTxQuery } = safenetApi

0 comments on commit 3f016de

Please sign in to comment.