diff --git a/src/components/safe-apps/AppFrame/useAppCommunicator.ts b/src/components/safe-apps/AppFrame/useAppCommunicator.ts index 9380e905d1..54e2d90671 100644 --- a/src/components/safe-apps/AppFrame/useAppCommunicator.ts +++ b/src/components/safe-apps/AppFrame/useAppCommunicator.ts @@ -33,7 +33,7 @@ import { SAFE_APPS_EVENTS, trackSafeAppEvent } from '@/services/analytics' import { useAppSelector } from '@/store' import { selectRpc } from '@/store/settingsSlice' import { createSafeAppsWeb3Provider } from '@/hooks/wallets/web3' -import { useGetSafeNetConfigQuery } from '@/store/safenet' +import { useGetSafenetConfigQuery } from '@/store/safenet' import { QueryStatus } from '@reduxjs/toolkit/query' import { SafenetChainType, isSupportedChain } from '@/utils/safenet' import { SAFENET_API_URL } from '@/config/constants' @@ -78,12 +78,12 @@ const useAppCommunicator = ( ): AppCommunicator | undefined => { const [communicator, setCommunicator] = useState(undefined) const customRpc = useAppSelector(selectRpc) - const { data: safeNetConfig, status: safeNetConfigStatus } = useGetSafeNetConfigQuery() - const shouldUseSafeNetRpc = - safeNetConfigStatus === QueryStatus.fulfilled && + const { data: safenetConfig, status: safenetConfigStatus } = useGetSafenetConfigQuery() + const shouldUseSafenetRpc = + safenetConfigStatus === QueryStatus.fulfilled && chain && - safeNetConfig && - isSupportedChain(Number(chain.chainId), safeNetConfig, SafenetChainType.DESTINATION) + safenetConfig && + isSupportedChain(Number(chain.chainId), safenetConfig, SafenetChainType.DESTINATION) const isDarkMode = useDarkMode() const safeAppWeb3Provider = useMemo(() => { @@ -91,12 +91,12 @@ const useAppCommunicator = ( return } - if (shouldUseSafeNetRpc) { + if (shouldUseSafenetRpc) { return createSafeAppsWeb3Provider(chain, SAFENET_API_URL + `/jsonrpc/${chain.chainId}/`) } return createSafeAppsWeb3Provider(chain, customRpc?.[chain.chainId]) - }, [chain, customRpc, shouldUseSafeNetRpc]) + }, [chain, customRpc, shouldUseSafenetRpc]) useEffect(() => { let communicatorInstance: AppCommunicator @@ -242,7 +242,7 @@ const useAppCommunicator = ( msg.data.id, ) }) - }, [safeAppWeb3Provider, handlers, chain, communicator, isDarkMode, shouldUseSafeNetRpc]) + }, [safeAppWeb3Provider, handlers, chain, communicator, isDarkMode, shouldUseSafenetRpc]) return communicator } diff --git a/src/components/sidebar/SidebarNavigation/config.tsx b/src/components/sidebar/SidebarNavigation/config.tsx index e9ebd2af63..db2f56c6fe 100644 --- a/src/components/sidebar/SidebarNavigation/config.tsx +++ b/src/components/sidebar/SidebarNavigation/config.tsx @@ -92,7 +92,7 @@ export const balancesNavItems = [ export const settingsNavItems = [ { - label: 'SafeNet', + label: 'Safenet', href: AppRoutes.settings.safenet, }, { diff --git a/src/components/tx-flow/flows/EnableSafenet/ReviewEnableSafenet.tsx b/src/components/tx-flow/flows/EnableSafenet/ReviewEnableSafenet.tsx index 667e4d9779..f04ce0878f 100644 --- a/src/components/tx-flow/flows/EnableSafenet/ReviewEnableSafenet.tsx +++ b/src/components/tx-flow/flows/EnableSafenet/ReviewEnableSafenet.tsx @@ -51,7 +51,7 @@ export const ReviewEnableSafenet = ({ params }: { params: EnableSafenetFlowProps - Once the transaction guard has been enabled, SafeNet will be enabled for your Safe. + Once the transaction guard has been enabled, Safenet will be enabled for your Safe. ) diff --git a/src/components/tx-flow/flows/EnableSafenet/index.tsx b/src/components/tx-flow/flows/EnableSafenet/index.tsx index 2e5f01f421..f1019721c7 100644 --- a/src/components/tx-flow/flows/EnableSafenet/index.tsx +++ b/src/components/tx-flow/flows/EnableSafenet/index.tsx @@ -9,7 +9,7 @@ export type EnableSafenetFlowProps = { const EnableSafenetFlow = ({ guardAddress, tokensForPresetAllowances, allowanceSpender }: EnableSafenetFlowProps) => { return ( - + ) diff --git a/src/components/tx/SignOrExecuteForm/SafeNetTxChecks.tsx b/src/components/tx/SignOrExecuteForm/SafenetTxChecks.tsx similarity index 55% rename from src/components/tx/SignOrExecuteForm/SafeNetTxChecks.tsx rename to src/components/tx/SignOrExecuteForm/SafenetTxChecks.tsx index cbf17f1ae6..ba647be580 100644 --- a/src/components/tx/SignOrExecuteForm/SafeNetTxChecks.tsx +++ b/src/components/tx/SignOrExecuteForm/SafenetTxChecks.tsx @@ -1,29 +1,29 @@ import { type ReactElement, useContext } from 'react' -import { SafeNetTxSimulation } from '@/components/tx/security/safenet' +import { SafenetTxSimulation } from '@/components/tx/security/safenet' import TxCard from '@/components/tx-flow/common/TxCard' import { SafeTxContext } from '@/components/tx-flow/SafeTxProvider' -import useIsSafeNetEnabled from '@/hooks/useIsSafeNetEnabled' +import useIsSafenetEnabled from '@/hooks/useIsSafenetEnabled' import { Typography } from '@mui/material' import useChainId from '@/hooks/useChainId' import useSafeAddress from '@/hooks/useSafeAddress' -const SafeNetTxChecks = (): ReactElement | null => { +const SafenetTxChecks = (): ReactElement | null => { const safe = useSafeAddress() const chainId = useChainId() const { safeTx } = useContext(SafeTxContext) - const isSafeNetEnabled = useIsSafeNetEnabled() + const isSafenetEnabled = useIsSafenetEnabled() - if (!isSafeNetEnabled) { + if (!isSafenetEnabled) { return null } return ( - SafeNet checks + Safenet checks - + ) } -export default SafeNetTxChecks +export default SafenetTxChecks diff --git a/src/components/tx/SignOrExecuteForm/index.tsx b/src/components/tx/SignOrExecuteForm/index.tsx index 5785e79fd9..ece1fdca03 100644 --- a/src/components/tx/SignOrExecuteForm/index.tsx +++ b/src/components/tx/SignOrExecuteForm/index.tsx @@ -12,7 +12,7 @@ import SignForm from './SignForm' import { SafeTxContext } from '@/components/tx-flow/SafeTxProvider' import ErrorMessage from '../ErrorMessage' import TxChecks from './TxChecks' -import SafeNetTxChecks from './SafeNetTxChecks' +import SafenetTxChecks from './SafenetTxChecks' import TxCard from '@/components/tx-flow/common/TxCard' import ConfirmationTitle, { ConfirmationTitleTypes } from '@/components/tx/SignOrExecuteForm/ConfirmationTitle' import { useAppSelector } from '@/store' @@ -200,7 +200,7 @@ export const SignOrExecuteForm = ({ {!isCounterfactualSafe && !props.isRejection && } - + ): { display: string; success: boolean }[] { +}: Pick): { display: string; success: boolean }[] { const groups = results.reduce((groups, { guarantee, success }) => { const display = _getGuaranteeDisplayName(guarantee) return { @@ -42,7 +42,7 @@ function _groupResultGuarantees({ .sort((a, b) => a.display.localeCompare(b.display)) } -function _getSafeTxHash({ safe, chainId, safeTx }: Required): string { +function _getSafeTxHash({ safe, chainId, safeTx }: Required): string { return hashTypedData({ domain: { chainId, @@ -66,9 +66,9 @@ function _getSafeTxHash({ safe, chainId, safeTx }: Required { +const SafenetTxTxSimulationSummary = ({ simulation }: { simulation: SafenetSimulationResponse }): ReactElement => { if (simulation.results.length === 0) { - return No SafeNet checks enabled... + return No Safenet checks enabled... } const guarantees = _groupResultGuarantees(simulation) @@ -77,7 +77,7 @@ const SafeNetTxTxSimulationSummary = ({ simulation }: { simulation: SafeNetSimul {simulation.hasError && ( - One or more SafeNet checks failed! + One or more Safenet checks failed! )} @@ -99,9 +99,9 @@ const SafeNetTxTxSimulationSummary = ({ simulation }: { simulation: SafeNetSimul ) } -export const SafeNetTxSimulation = ({ safe, chainId, safeTx }: SafeNetTxSimulationProps): ReactElement | null => { +export const SafenetTxSimulation = ({ safe, chainId, safeTx }: SafenetTxSimulationProps): ReactElement | null => { const [dataDecoded] = useDecodeTx(safeTx) - const [simulate, { data: simulation, status }] = useLazySimulateSafeNetTxQuery() + const [simulate, { data: simulation, status }] = useLazySimulateSafenetTxQuery() useEffect(() => { if (!safeTx || !dataDecoded) { @@ -134,12 +134,12 @@ export const SafeNetTxSimulation = ({ safe, chainId, safeTx }: SafeNetTxSimulati switch (status) { case 'fulfilled': - return + return case 'rejected': return ( - Unexpected error simulating with SafeNet! + Unexpected error simulating with Safenet! ) default: diff --git a/src/config/constants.ts b/src/config/constants.ts index 5c966fbd06..16116ea655 100644 --- a/src/config/constants.ts +++ b/src/config/constants.ts @@ -111,7 +111,7 @@ export const SAFE_PASS_URL = 'community.safe.global' export const ECOSYSTEM_ID_ADDRESS = process.env.NEXT_PUBLIC_ECOSYSTEM_ID_ADDRESS || '0x0000000000000000000000000000000000000000' -// SafeNet +// Safenet export const SAFENET_API_URL = process.env.NEXT_PUBLIC_SAFENET_API_URL export const MULTICHAIN_HELP_ARTICLE = `${HELP_CENTER_URL}/en/articles/222612-multi-chain-safe` diff --git a/src/hooks/__tests__/useLoadBalances.test.ts b/src/hooks/__tests__/useLoadBalances.test.ts index 9e38f0661f..188edfa604 100644 --- a/src/hooks/__tests__/useLoadBalances.test.ts +++ b/src/hooks/__tests__/useLoadBalances.test.ts @@ -1,5 +1,5 @@ import * as store from '@/store' -import * as safeNetStore from '@/store/safenet' +import * as safenetStore from '@/store/safenet' import { defaultSafeInfo } from '@/store/safeInfoSlice' import { act, renderHook, waitFor } from '@/tests/test-utils' import { toBeHex } from 'ethers' @@ -98,7 +98,7 @@ describe('useLoadBalances', () => { jest.clearAllMocks() localStorage.clear() jest.spyOn(useChainId, 'useChainId').mockReturnValue('5') - jest.spyOn(safeNetStore, 'useGetSafeNetConfigQuery').mockReturnValue({ + jest.spyOn(safenetStore, 'useGetSafenetConfigQuery').mockReturnValue({ data: { chains: { sources: [11155111], diff --git a/src/hooks/loadables/useLoadBalances.ts b/src/hooks/loadables/useLoadBalances.ts index 784f751167..59f34f3368 100644 --- a/src/hooks/loadables/useLoadBalances.ts +++ b/src/hooks/loadables/useLoadBalances.ts @@ -11,9 +11,9 @@ import { FEATURES, hasFeature } from '@/utils/chains' import { POLLING_INTERVAL } from '@/config/constants' import useIntervalCounter from '../useIntervalCounter' import useSafeInfo from '../useSafeInfo' -import { useGetSafeNetConfigQuery } from '@/store/safenet' -import { SafenetChainType, convertSafeNetBalanceToSafeClientGatewayBalance, isSupportedChain } from '@/utils/safenet' -import { getSafeNetBalances } from '@/store/safenet' +import { useGetSafenetConfigQuery } from '@/store/safenet' +import { SafenetChainType, convertSafenetBalanceToSafeClientGatewayBalance, isSupportedChain } from '@/utils/safenet' +import { getSafenetBalances } from '@/store/safenet' export const useTokenListSetting = (): boolean | undefined => { const chain = useCurrentChain() @@ -30,12 +30,12 @@ export const useTokenListSetting = (): boolean | undefined => { const mergeBalances = (cgw: SafeBalanceResponse, sn: SafeBalanceResponse): SafeBalanceResponse => { // Create a Map using token addresses as keys const uniqueBalances = new Map( - // Process SafeNet items last so they take precedence by overwriting the CGW items + // Process Safenet items last so they take precedence by overwriting the CGW items [...cgw.items, ...sn.items].map((item) => [item.tokenInfo.address, item]), ) return { - // We do not sum the fiatTotal as SafeNet doesn't return it + // We do not sum the fiatTotal as Safenet doesn't return it // And if it did, we would have to do something fancy with calculations so balances aren't double counted fiatTotal: cgw.fiatTotal, items: Array.from(uniqueBalances.values()), @@ -45,23 +45,23 @@ const mergeBalances = (cgw: SafeBalanceResponse, sn: SafeBalanceResponse): SafeB export const useLoadBalances = (): AsyncResult => { const [pollCount, resetPolling] = useIntervalCounter(POLLING_INTERVAL) const { - data: safeNetConfig, - isSuccess: isSafeNetConfigSuccess, - isLoading: isSafeNetConfigLoading, - } = useGetSafeNetConfigQuery() + data: safenetConfig, + isSuccess: isSafenetConfigSuccess, + isLoading: isSafenetConfigLoading, + } = useGetSafenetConfigQuery() const currency = useAppSelector(selectCurrency) const isTrustedTokenList = useTokenListSetting() const { safe, safeAddress } = useSafeInfo() const web3 = useWeb3() const chain = useCurrentChain() const chainId = safe.chainId - const chainSupportedBySafeNet = - isSafeNetConfigSuccess && isSupportedChain(Number(chainId), safeNetConfig, SafenetChainType.DESTINATION) + const chainSupportedBySafenet = + isSafenetConfigSuccess && isSupportedChain(Number(chainId), safenetConfig, SafenetChainType.DESTINATION) // Re-fetch assets when the entire SafeInfo updates const [data, error, loading] = useAsync( () => { - if (!chainId || !safeAddress || isTrustedTokenList === undefined || isSafeNetConfigLoading) return + if (!chainId || !safeAddress || isTrustedTokenList === undefined || isSafenetConfigLoading) return if (!safe.deployed) { return getCounterfactualBalance(safeAddress, web3, chain) @@ -73,11 +73,11 @@ export const useLoadBalances = (): AsyncResult => { }), ] - if (isSafeNetConfigSuccess && chainSupportedBySafeNet) { + if (isSafenetConfigSuccess && chainSupportedBySafenet) { balanceQueries.push( - getSafeNetBalances(chainId, safeAddress) + getSafenetBalances(chainId, safeAddress) .then((safenetBalances) => - convertSafeNetBalanceToSafeClientGatewayBalance(safenetBalances, safeNetConfig, Number(chainId)), + convertSafenetBalanceToSafeClientGatewayBalance(safenetBalances, safenetConfig, Number(chainId)), ) .catch(() => ({ fiatTotal: '0', @@ -98,10 +98,10 @@ export const useLoadBalances = (): AsyncResult => { safe.deployed, web3, chain, - safeNetConfig, - isSafeNetConfigSuccess, - isSafeNetConfigLoading, - chainSupportedBySafeNet, + safenetConfig, + isSafenetConfigSuccess, + isSafenetConfigLoading, + chainSupportedBySafenet, ], false, // don't clear data between polls ) @@ -117,7 +117,7 @@ export const useLoadBalances = (): AsyncResult => { } }, [error]) - return [data, error, loading || isSafeNetConfigLoading] + return [data, error, loading || isSafenetConfigLoading] } export default useLoadBalances diff --git a/src/hooks/useIsSafeNetEnabled.ts b/src/hooks/useIsSafeNetEnabled.ts deleted file mode 100644 index 86f8c4c3a1..0000000000 --- a/src/hooks/useIsSafeNetEnabled.ts +++ /dev/null @@ -1,12 +0,0 @@ -import useSafeInfo from '@/hooks/useSafeInfo' -import { useGetSafeNetConfigQuery } from '@/store/safenet' -import { sameAddress } from '@/utils/addresses' - -const useIsSafeNetEnabled = () => { - const { safe } = useSafeInfo() - const { data: safeNetConfig } = useGetSafeNetConfigQuery() - - return sameAddress(safe.guard?.value, safeNetConfig?.guards[safe.chainId]) -} - -export default useIsSafeNetEnabled diff --git a/src/hooks/useIsSafenetEnabled.ts b/src/hooks/useIsSafenetEnabled.ts new file mode 100644 index 0000000000..4bda964382 --- /dev/null +++ b/src/hooks/useIsSafenetEnabled.ts @@ -0,0 +1,12 @@ +import useSafeInfo from '@/hooks/useSafeInfo' +import { useGetSafenetConfigQuery } from '@/store/safenet' +import { sameAddress } from '@/utils/addresses' + +const useIsSafenetEnabled = () => { + const { safe } = useSafeInfo() + const { data: safenetConfig } = useGetSafenetConfigQuery() + + return sameAddress(safe.guard?.value, safenetConfig?.guards[safe.chainId]) +} + +export default useIsSafenetEnabled diff --git a/src/pages/settings/safenet.tsx b/src/pages/settings/safenet.tsx index 7fdab37d16..e4f78073e8 100644 --- a/src/pages/settings/safenet.tsx +++ b/src/pages/settings/safenet.tsx @@ -10,11 +10,11 @@ import { sameAddress } from '@/utils/addresses' import { useContext, useEffect, useMemo } from 'react' import { TxModalContext } from '@/components/tx-flow' import { EnableSafenetFlow } from '@/components/tx-flow/flows/EnableSafenet' -import type { SafeNetConfigEntity } from '@/store/safenet' +import type { SafenetConfigEntity } from '@/store/safenet' import { - useLazyGetSafeNetOffchainStatusQuery, - useRegisterSafeNetMutation, - useGetSafeNetConfigQuery, + useLazyGetSafenetOffchainStatusQuery, + useRegisterSafenetMutation, + useGetSafenetConfigQuery, } from '@/store/safenet' import type { ExtendedSafeInfo } from '@/store/safeInfoSlice' import { SAFE_FEATURES } from '@safe-global/protocol-kit/dist/src/utils' @@ -22,12 +22,12 @@ import { hasSafeFeature } from '@/utils/safe-versions' import { SafenetChainType, isSupportedChain } from '@/utils/safenet' import { getRTKErrorMessage } from '@/utils/redux-toolkit-query' -const getSafeNetTokensByChain = (chainId: number, safeNetConfig: SafeNetConfigEntity): string[] => { - const tokenSymbols = Object.keys(safeNetConfig.tokens) +const getSafenetTokensByChain = (chainId: number, safenetConfig: SafenetConfigEntity): string[] => { + const tokenSymbols = Object.keys(safenetConfig.tokens) const tokens: string[] = [] for (const symbol of tokenSymbols) { - const tokenAddress = safeNetConfig.tokens[symbol][chainId] + const tokenAddress = safenetConfig.tokens[symbol][chainId] if (tokenAddress) { tokens.push(tokenAddress) } @@ -36,38 +36,38 @@ const getSafeNetTokensByChain = (chainId: number, safeNetConfig: SafeNetConfigEn return tokens } -const SafeNetContent = ({ safeNetConfig, safe }: { safeNetConfig: SafeNetConfigEntity; safe: ExtendedSafeInfo }) => { +const SafenetContent = ({ safenetConfig, safe }: { safenetConfig: SafenetConfigEntity; safe: ExtendedSafeInfo }) => { const isVersionWithGuards = hasSafeFeature(SAFE_FEATURES.SAFE_TX_GUARDS, safe.version) - const safeNetGuardAddress = safeNetConfig.guards[safe.chainId] - const safeNetProcessorAddress = safeNetConfig.processors[safe.chainId] - const isSafeNetGuardEnabled = isVersionWithGuards && sameAddress(safe.guard?.value, safeNetGuardAddress) - const chainSupported = isSupportedChain(Number(safe.chainId), safeNetConfig, SafenetChainType.SOURCE) + const safenetGuardAddress = safenetConfig.guards[safe.chainId] + const safenetProcessorAddress = safenetConfig.processors[safe.chainId] + const isSafenetGuardEnabled = isVersionWithGuards && sameAddress(safe.guard?.value, safenetGuardAddress) + const chainSupported = isSupportedChain(Number(safe.chainId), safenetConfig, SafenetChainType.SOURCE) const { setTxFlow } = useContext(TxModalContext) // Lazy query because running it on unsupported chain throws an error const [ - triggerGetSafeNetOffchainStatus, + triggerGetSafenetOffchainStatus, { - data: safeNetOffchainStatus, - error: safeNetOffchainStatusError, - isLoading: safeNetOffchainStatusLoading, - status: safeNetOffchainStatusStatus, + data: safenetOffchainStatus, + error: safenetOffchainStatusError, + isLoading: safenetOffchainStatusLoading, + status: safenetOffchainStatusStatus, }, - ] = useLazyGetSafeNetOffchainStatusQuery() + ] = 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 offchainLookupError = safenetOffchainStatusError?.status === 404 ? null : safenetOffchainStatusError const registeredOffchainStatus = - !offchainLookupError && sameAddress(safeNetOffchainStatus?.guard, safeNetGuardAddress) - - const safeNetStatusQueryWorked = - safeNetOffchainStatusStatus === QueryStatus.fulfilled || safeNetOffchainStatusStatus === QueryStatus.rejected - const needsRegistration = safeNetStatusQueryWorked && isSafeNetGuardEnabled && !registeredOffchainStatus - const [registerSafeNet, { error: registerSafeNetError }] = useRegisterSafeNetMutation() - const error = offchainLookupError || registerSafeNetError - const safeNetAssets = useMemo( - () => getSafeNetTokensByChain(Number(safe.chainId), safeNetConfig), - [safe.chainId, safeNetConfig], + !offchainLookupError && sameAddress(safenetOffchainStatus?.guard, safenetGuardAddress) + + const safenetStatusQueryWorked = + safenetOffchainStatusStatus === QueryStatus.fulfilled || safenetOffchainStatusStatus === QueryStatus.rejected + const needsRegistration = safenetStatusQueryWorked && isSafenetGuardEnabled && !registeredOffchainStatus + const [registerSafenet, { error: registerSafenetError }] = useRegisterSafenetMutation() + const error = offchainLookupError || registerSafenetError + const safenetAssets = useMemo( + () => getSafenetTokensByChain(Number(safe.chainId), safenetConfig), + [safe.chainId, safenetConfig], ) if (error) { @@ -76,40 +76,40 @@ const SafeNetContent = ({ safeNetConfig, safe }: { safeNetConfig: SafeNetConfigE useEffect(() => { if (needsRegistration) { - registerSafeNet({ chainId: safe.chainId, safeAddress: safe.address.value }) + registerSafenet({ chainId: safe.chainId, safeAddress: safe.address.value }) } - }, [needsRegistration, registerSafeNet, safe.chainId, safe.address.value]) + }, [needsRegistration, registerSafenet, safe.chainId, safe.address.value]) useEffect(() => { if (chainSupported) { - triggerGetSafeNetOffchainStatus({ chainId: safe.chainId, safeAddress: safe.address.value }) + triggerGetSafenetOffchainStatus({ chainId: safe.chainId, safeAddress: safe.address.value }) } - }, [chainSupported, triggerGetSafeNetOffchainStatus, safe.chainId, safe.address.value]) + }, [chainSupported, triggerGetSafenetOffchainStatus, safe.chainId, safe.address.value]) switch (true) { case !chainSupported: return ( - SafeNet is not supported on this chain. List of supported chains ids:{' '} - {safeNetConfig.chains.sources.join(', ')} + Safenet is not supported on this chain. List of supported chains ids:{' '} + {safenetConfig.chains.sources.join(', ')} ) case !isVersionWithGuards: - return Please upgrade your Safe to the latest version to use SafeNet - case isSafeNetGuardEnabled: - return SafeNet is enabled. Enjoy your unified experience. - case !isSafeNetGuardEnabled: + return Please upgrade your Safe to the latest version to use Safenet + case isSafenetGuardEnabled: + return Safenet is enabled. Enjoy your unified experience. + case !isSafenetGuardEnabled: return (
- SafeNet is not enabled. Enable it to enhance your Safe experience. + Safenet is not enabled. Enable it to enhance your Safe experience.
) - case safeNetOffchainStatusLoading: + case safenetOffchainStatusLoading: return default: return null } } -const SafeNetPage: NextPage = () => { +const SafenetPage: NextPage = () => { const { safe, safeLoaded } = useSafeInfo() - const { data: safeNetConfig, isLoading: safeNetConfigLoading, error: safeNetConfigError } = useGetSafeNetConfigQuery() + const { data: safenetConfig, isLoading: safenetConfigLoading, error: safenetConfigError } = useGetSafenetConfigQuery() - if (!safeLoaded || safeNetConfigLoading) { + if (!safeLoaded || safenetConfigLoading) { return } - if (safeNetConfigError) { - return Error loading SafeNet config + if (safenetConfigError) { + return Error loading Safenet config } - if (!safeNetConfig) { + if (!safenetConfig) { // Should never happen, making TS happy - return No SafeNet config found + return No Safenet config found } - const safeNetContent = + const safenetContent = return ( <> - {'Safe{Wallet} – Settings – SafeNet'} + {'Safe{Wallet} – Settings – Safenet'} @@ -160,10 +160,10 @@ const SafeNetPage: NextPage = () => { - SafeNet Status + Safenet Status { - {safeNetContent} + {safenetContent}
@@ -186,4 +186,4 @@ const SafeNetPage: NextPage = () => { ) } -export default SafeNetPage +export default SafenetPage diff --git a/src/store/safenet.ts b/src/store/safenet.ts index b736f7416c..bff2eefc95 100644 --- a/src/store/safenet.ts +++ b/src/store/safenet.ts @@ -2,13 +2,13 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' import { SAFENET_API_URL } from '@/config/constants' -export type SafeNetSafeEntity = { +export type SafenetSafeEntity = { safe: string chainId: number guard: string } -export type SafeNetConfigEntity = { +export type SafenetConfigEntity = { chains: { sources: number[] destinations: number[] @@ -18,11 +18,11 @@ export type SafeNetConfigEntity = { processors: Record } -export type SafeNetBalanceEntity = { +export type SafenetBalanceEntity = { [tokenSymbol: string]: string } -export type SafeNetSimulateTx = { +export type SafenetSimulateTx = { safe: string safeTxHash: string to: string @@ -38,26 +38,26 @@ export type SafeNetSimulateTx = { dataDecoded: unknown } -export type SafeNetSimulationResultSuccess = { +export type SafenetSimulationResultSuccess = { success: true } -export type SafeNetSimulationResultFailure = { +export type SafenetSimulationResultFailure = { success: false message: string } -export type SafeNetSimulationResult = { +export type SafenetSimulationResult = { guarantee: string success: boolean -} & (SafeNetSimulationResultSuccess | SafeNetSimulationResultFailure) +} & (SafenetSimulationResultSuccess | SafenetSimulationResultFailure) -export type SafeNetSimulationResponse = { +export type SafenetSimulationResponse = { hasError: boolean - results: SafeNetSimulationResult[] + results: SafenetSimulationResult[] } -export const getSafeNetBalances = async (chainId: string, safeAddress: string): Promise => { +export const getSafenetBalances = async (chainId: string, safeAddress: string): Promise => { const response = await fetch(`${SAFENET_API_URL}/safenet/balances/${chainId}/${safeAddress}`) const data = await response.json() return data @@ -66,17 +66,17 @@ export const getSafeNetBalances = async (chainId: string, safeAddress: string): export const safenetApi = createApi({ reducerPath: 'safenetApi', baseQuery: fetchBaseQuery({ baseUrl: `${SAFENET_API_URL}/safenet` }), - tagTypes: ['SafeNetConfig', 'SafeNetOffchainStatus', 'SafeNetBalance', 'SafeNetSimulation'], + tagTypes: ['SafenetConfig', 'SafenetOffchainStatus', 'SafenetBalance', 'SafenetSimulation'], endpoints: (builder) => ({ - getSafeNetConfig: builder.query({ + getSafenetConfig: builder.query({ query: () => `/config/`, - providesTags: ['SafeNetConfig'], + providesTags: ['SafenetConfig'], }), - getSafeNetOffchainStatus: builder.query({ + getSafenetOffchainStatus: builder.query({ query: ({ chainId, safeAddress }) => `/safes/${chainId}/${safeAddress}`, - providesTags: (_, __, arg) => [{ type: 'SafeNetOffchainStatus', id: arg.safeAddress }], + providesTags: (_, __, arg) => [{ type: 'SafenetOffchainStatus', id: arg.safeAddress }], }), - registerSafeNet: builder.mutation({ + registerSafenet: builder.mutation({ query: ({ chainId, safeAddress }) => ({ url: `/register`, method: 'POST', @@ -85,17 +85,17 @@ export const safenetApi = createApi({ safe: safeAddress, }, }), - invalidatesTags: (_, __, arg) => [{ type: 'SafeNetOffchainStatus', id: arg.safeAddress }], + invalidatesTags: (_, __, arg) => [{ type: 'SafenetOffchainStatus', id: arg.safeAddress }], }), - getSafeNetBalance: builder.query({ + getSafenetBalance: builder.query({ query: ({ chainId, safeAddress }) => `/balances/${chainId}/${safeAddress}`, - providesTags: (_, __, arg) => [{ type: 'SafeNetBalance', id: arg.safeAddress }], + providesTags: (_, __, arg) => [{ type: 'SafenetBalance', id: arg.safeAddress }], }), - simulateSafeNetTx: builder.query< - SafeNetSimulationResponse, + simulateSafenetTx: builder.query< + SafenetSimulationResponse, { chainId: string - tx: SafeNetSimulateTx + tx: SafenetSimulateTx } >({ query: ({ chainId, tx }) => ({ @@ -103,15 +103,15 @@ export const safenetApi = createApi({ method: 'POST', body: tx, }), - providesTags: (_, __, arg) => [{ type: 'SafeNetSimulation', id: arg.tx.safeTxHash }], + providesTags: (_, __, arg) => [{ type: 'SafenetSimulation', id: arg.tx.safeTxHash }], }), }), }) export const { - useLazyGetSafeNetOffchainStatusQuery, - useRegisterSafeNetMutation, - useGetSafeNetConfigQuery, - useLazyGetSafeNetBalanceQuery, - useLazySimulateSafeNetTxQuery, + useLazyGetSafenetOffchainStatusQuery, + useRegisterSafenetMutation, + useGetSafenetConfigQuery, + useLazyGetSafenetBalanceQuery, + useLazySimulateSafenetTxQuery, } = safenetApi diff --git a/src/utils/safenet.ts b/src/utils/safenet.ts index 1d95523cf0..7bc7033ee7 100644 --- a/src/utils/safenet.ts +++ b/src/utils/safenet.ts @@ -1,4 +1,4 @@ -import type { SafeNetBalanceEntity, SafeNetConfigEntity } from '@/store/safenet' +import type { SafenetBalanceEntity, SafenetConfigEntity } from '@/store/safenet' import { TokenType, type SafeBalanceResponse } from '@safe-global/safe-gateway-typescript-sdk' const enum SafenetChainType { @@ -6,24 +6,24 @@ const enum SafenetChainType { DESTINATION = 'destination', } -const isSupportedChain = (chainId: number, safeNetConfig: SafeNetConfigEntity, chainType: SafenetChainType) => { +const isSupportedChain = (chainId: number, safenetConfig: SafenetConfigEntity, chainType: SafenetChainType) => { return chainType === SafenetChainType.SOURCE - ? safeNetConfig.chains.sources.includes(chainId) - : safeNetConfig.chains.destinations.includes(chainId) + ? safenetConfig.chains.sources.includes(chainId) + : safenetConfig.chains.destinations.includes(chainId) } -const convertSafeNetBalanceToSafeClientGatewayBalance = ( - safeNetBalance: SafeNetBalanceEntity, - safeNetConfig: SafeNetConfigEntity, +const convertSafenetBalanceToSafeClientGatewayBalance = ( + safenetBalance: SafenetBalanceEntity, + safenetConfig: SafenetConfigEntity, chainId: number, ): SafeBalanceResponse => { const balances: SafeBalanceResponse = { - fiatTotal: safeNetBalance.fiatTotal, + fiatTotal: safenetBalance.fiatTotal, items: [], } - for (const [tokenName, balance] of Object.entries(safeNetBalance)) { - const tokenAddress = safeNetConfig.tokens[tokenName][chainId] + for (const [tokenName, balance] of Object.entries(safenetBalance)) { + const tokenAddress = safenetConfig.tokens[tokenName][chainId] if (!tokenAddress) { continue } @@ -34,7 +34,7 @@ const convertSafeNetBalanceToSafeClientGatewayBalance = ( address: tokenAddress, decimals: tokenName === 'USDC' ? 6 : 18, symbol: tokenName, - name: `${tokenName} (SafeNet)`, + name: `${tokenName} (Safenet)`, logoUri: '', }, balance, @@ -46,4 +46,4 @@ const convertSafeNetBalanceToSafeClientGatewayBalance = ( return balances } -export { isSupportedChain, SafenetChainType, convertSafeNetBalanceToSafeClientGatewayBalance } +export { isSupportedChain, SafenetChainType, convertSafenetBalanceToSafeClientGatewayBalance }