Skip to content

Commit

Permalink
Correct Occurences of SafeNet to Safenet
Browse files Browse the repository at this point in the history
We should be calling it `Safenet` and not `SafeNet`, this PR corrects
all occurences.
  • Loading branch information
nlordell committed Oct 25, 2024
1 parent c325be5 commit f1b943f
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 167 deletions.
18 changes: 9 additions & 9 deletions src/components/safe-apps/AppFrame/useAppCommunicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -78,25 +78,25 @@ const useAppCommunicator = (
): AppCommunicator | undefined => {
const [communicator, setCommunicator] = useState<AppCommunicator | undefined>(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(() => {
if (!chain) {
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
Expand Down Expand Up @@ -242,7 +242,7 @@ const useAppCommunicator = (
msg.data.id,
)
})
}, [safeAppWeb3Provider, handlers, chain, communicator, isDarkMode, shouldUseSafeNetRpc])
}, [safeAppWeb3Provider, handlers, chain, communicator, isDarkMode, shouldUseSafenetRpc])

return communicator
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar/SidebarNavigation/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const balancesNavItems = [

export const settingsNavItems = [
{
label: 'SafeNet',
label: 'Safenet',
href: AppRoutes.settings.safenet,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const ReviewEnableSafenet = ({ params }: { params: EnableSafenetFlowProps
<EthHashInfo address={params.guardAddress} showCopyButton hasExplorer shortAddress={false} />

<Typography my={2}>
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.
</Typography>
</SignOrExecuteForm>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/tx-flow/flows/EnableSafenet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type EnableSafenetFlowProps = {

const EnableSafenetFlow = ({ guardAddress, tokensForPresetAllowances, allowanceSpender }: EnableSafenetFlowProps) => {
return (
<TxLayout title="Confirm transaction" subtitle="Enable SafeNet">
<TxLayout title="Confirm transaction" subtitle="Enable Safenet">
<ReviewEnableSafenet params={{ guardAddress, tokensForPresetAllowances, allowanceSpender }} />
</TxLayout>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<TxCard>
<Typography variant="h5">SafeNet checks</Typography>
<Typography variant="h5">Safenet checks</Typography>

<SafeNetTxSimulation safe={safe} chainId={chainId} safeTx={safeTx} />
<SafenetTxSimulation safe={safe} chainId={chainId} safeTx={safeTx} />
</TxCard>
)
}

export default SafeNetTxChecks
export default SafenetTxChecks
4 changes: 2 additions & 2 deletions src/components/tx/SignOrExecuteForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -200,7 +200,7 @@ export const SignOrExecuteForm = ({

{!isCounterfactualSafe && !props.isRejection && <TxChecks />}

<SafeNetTxChecks />
<SafenetTxChecks />

<TxCard>
<ConfirmationTitle
Expand Down
24 changes: 12 additions & 12 deletions src/components/tx/security/safenet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import type { SafeTransaction } from '@safe-global/safe-core-sdk-types'
import useDecodeTx from '@/hooks/useDecodeTx'
import CheckIcon from '@/public/images/common/check.svg'
import CloseIcon from '@/public/images/common/close.svg'
import type { SafeNetSimulationResponse } from '@/store/safenet'
import { useLazySimulateSafeNetTxQuery } from '@/store/safenet'
import type { SafenetSimulationResponse } from '@/store/safenet'
import { useLazySimulateSafenetTxQuery } from '@/store/safenet'
import { useEffect, type ReactElement } from 'react'
import css from './styles.module.css'
import { hashTypedData } from '@/utils/web3'

export type SafeNetTxSimulationProps = {
export type SafenetTxSimulationProps = {
safe: string
chainId: string
safeTx?: SafeTransaction
Expand All @@ -29,7 +29,7 @@ function _getGuaranteeDisplayName(guarantee: string): string {

function _groupResultGuarantees({
results,
}: Pick<SafeNetSimulationResponse, 'results'>): { display: string; success: boolean }[] {
}: Pick<SafenetSimulationResponse, 'results'>): { display: string; success: boolean }[] {
const groups = results.reduce((groups, { guarantee, success }) => {
const display = _getGuaranteeDisplayName(guarantee)
return {
Expand All @@ -42,7 +42,7 @@ function _groupResultGuarantees({
.sort((a, b) => a.display.localeCompare(b.display))
}

function _getSafeTxHash({ safe, chainId, safeTx }: Required<SafeNetTxSimulationProps>): string {
function _getSafeTxHash({ safe, chainId, safeTx }: Required<SafenetTxSimulationProps>): string {
return hashTypedData({
domain: {
chainId,
Expand All @@ -66,9 +66,9 @@ function _getSafeTxHash({ safe, chainId, safeTx }: Required<SafeNetTxSimulationP
})
}

const SafeNetTxTxSimulationSummary = ({ simulation }: { simulation: SafeNetSimulationResponse }): ReactElement => {
const SafenetTxTxSimulationSummary = ({ simulation }: { simulation: SafenetSimulationResponse }): ReactElement => {
if (simulation.results.length === 0) {
return <Typography>No SafeNet checks enabled...</Typography>
return <Typography>No Safenet checks enabled...</Typography>
}

const guarantees = _groupResultGuarantees(simulation)
Expand All @@ -77,7 +77,7 @@ const SafeNetTxTxSimulationSummary = ({ simulation }: { simulation: SafeNetSimul
<Paper variant="outlined" className={css.wrapper}>
{simulation.hasError && (
<Typography color="error" className={css.errorSummary}>
One or more SafeNet checks failed!
One or more Safenet checks failed!
</Typography>
)}

Expand All @@ -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) {
Expand Down Expand Up @@ -134,12 +134,12 @@ export const SafeNetTxSimulation = ({ safe, chainId, safeTx }: SafeNetTxSimulati

switch (status) {
case 'fulfilled':
return <SafeNetTxTxSimulationSummary simulation={simulation!} />
return <SafenetTxTxSimulationSummary simulation={simulation!} />
case 'rejected':
return (
<Typography color="error">
<SvgIcon component={CloseIcon} inheritViewBox fontSize="small" sx={{ verticalAlign: 'middle', mr: 1 }} />
Unexpected error simulating with SafeNet!
Unexpected error simulating with Safenet!
</Typography>
)
default:
Expand Down
2 changes: 1 addition & 1 deletion src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
4 changes: 2 additions & 2 deletions src/hooks/__tests__/useLoadBalances.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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],
Expand Down
40 changes: 20 additions & 20 deletions src/hooks/loadables/useLoadBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()),
Expand All @@ -45,23 +45,23 @@ const mergeBalances = (cgw: SafeBalanceResponse, sn: SafeBalanceResponse): SafeB
export const useLoadBalances = (): AsyncResult<SafeBalanceResponse> => {
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<SafeBalanceResponse | undefined>(
() => {
if (!chainId || !safeAddress || isTrustedTokenList === undefined || isSafeNetConfigLoading) return
if (!chainId || !safeAddress || isTrustedTokenList === undefined || isSafenetConfigLoading) return

if (!safe.deployed) {
return getCounterfactualBalance(safeAddress, web3, chain)
Expand All @@ -73,11 +73,11 @@ export const useLoadBalances = (): AsyncResult<SafeBalanceResponse> => {
}),
]

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',
Expand All @@ -98,10 +98,10 @@ export const useLoadBalances = (): AsyncResult<SafeBalanceResponse> => {
safe.deployed,
web3,
chain,
safeNetConfig,
isSafeNetConfigSuccess,
isSafeNetConfigLoading,
chainSupportedBySafeNet,
safenetConfig,
isSafenetConfigSuccess,
isSafenetConfigLoading,
chainSupportedBySafenet,
],
false, // don't clear data between polls
)
Expand All @@ -117,7 +117,7 @@ export const useLoadBalances = (): AsyncResult<SafeBalanceResponse> => {
}
}, [error])

return [data, error, loading || isSafeNetConfigLoading]
return [data, error, loading || isSafenetConfigLoading]
}

export default useLoadBalances
12 changes: 0 additions & 12 deletions src/hooks/useIsSafeNetEnabled.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/hooks/useIsSafenetEnabled.ts
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit f1b943f

Please sign in to comment.