Skip to content

Commit

Permalink
fix: abstract constants + rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Oct 18, 2023
1 parent dca7424 commit 398638f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useCompatibilityWarning } from '../useCompatibilityWarning'

describe('useCompatibilityWarning', () => {
it('should return an error for a dangerous bridge', () => {
jest.spyOn(bridges, 'isDangerousBridge').mockReturnValue(true)
jest.spyOn(bridges, 'isStrictAddressBridge').mockReturnValue(true)

const proposal = {
params: { proposer: { metadata: { name: 'Fake Bridge' } } },
Expand All @@ -24,8 +24,8 @@ describe('useCompatibilityWarning', () => {
})

it('should return a warning for a risky bridge', () => {
jest.spyOn(bridges, 'isDangerousBridge').mockReturnValue(false)
jest.spyOn(bridges, 'isRiskyBridge').mockReturnValue(true)
jest.spyOn(bridges, 'isStrictAddressBridge').mockReturnValue(false)
jest.spyOn(bridges, 'isDefaultAddressBridge').mockReturnValue(true)

const proposal = {
params: { proposer: { metadata: { name: 'Fake Bridge' } } },
Expand All @@ -42,8 +42,8 @@ describe('useCompatibilityWarning', () => {
})

it('should return an error for an unsupported chain', () => {
jest.spyOn(bridges, 'isDangerousBridge').mockReturnValue(false)
jest.spyOn(bridges, 'isRiskyBridge').mockReturnValue(false)
jest.spyOn(bridges, 'isStrictAddressBridge').mockReturnValue(false)
jest.spyOn(bridges, 'isDefaultAddressBridge').mockReturnValue(false)

const proposal = {
params: { proposer: { metadata: { name: 'Fake dApp' } } },
Expand All @@ -61,8 +61,8 @@ describe('useCompatibilityWarning', () => {

describe('should otherwise return info', () => {
it('if chains are loaded', () => {
jest.spyOn(bridges, 'isDangerousBridge').mockReturnValue(false)
jest.spyOn(bridges, 'isRiskyBridge').mockReturnValue(false)
jest.spyOn(bridges, 'isStrictAddressBridge').mockReturnValue(false)
jest.spyOn(bridges, 'isDefaultAddressBridge').mockReturnValue(false)

const proposal = {
params: { proposer: { metadata: { name: 'Fake dApp' } } },
Expand Down Expand Up @@ -99,8 +99,8 @@ describe('useCompatibilityWarning', () => {
})

it("if chains aren't loaded", () => {
jest.spyOn(bridges, 'isDangerousBridge').mockReturnValue(false)
jest.spyOn(bridges, 'isRiskyBridge').mockReturnValue(false)
jest.spyOn(bridges, 'isStrictAddressBridge').mockReturnValue(false)
jest.spyOn(bridges, 'isDefaultAddressBridge').mockReturnValue(false)

const proposal = {
params: { proposer: { metadata: { name: 'Fake dApp' } } },
Expand Down
46 changes: 7 additions & 39 deletions src/components/walletconnect/ProposalForm/bridges.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,11 @@
const DangerousBridges = [
'bridge.arbitrum.io',
'bridge.base.org',
'cbridge.celer.network',
'www.orbiter.finance',
'zksync-era.l2scan.co',
'app.optimism.io',
'www.portalbridge.com',
'wallet.polygon.technology',
'app.rhino.fi',
]
import { StrictAddressBridges, DefaultAddressBridges } from '../constants'

const RiskyBridges = [
'across.to',
'app.allbridge.io',
'core.allbridge.io',
'bungee.exchange',
'www.carrier.so',
'app.chainport.io',
'bridge.gnosischain.com',
'app.hop.exchange',
'app.interport.fi',
'jumper.exchange',
'www.layerswap.io',
'meson.fi',
'satellite.money',
'stargate.finance',
'app.squidrouter.com',
'app.symbiosis.finance',
'www.synapseprotocol.com',
'app.thevoyager.io',
'portal.txsync.io',
'bridge.wanchain.org',
'app.xy.finance',
]

export const isDangerousBridge = (origin: string) => {
return DangerousBridges.some((bridge) => origin.includes(bridge))
// Bridge enforces the same address on destination chain
export const isStrictAddressBridge = (origin: string) => {
return StrictAddressBridges.some((bridge) => origin.includes(bridge))
}

export const isRiskyBridge = (origin: string) => {
return RiskyBridges.some((bridge) => origin.includes(bridge))
// Bridge defaults to same address on destination chain but allows changing it
export const isDefaultAddressBridge = (origin: string) => {
return DefaultAddressBridges.some((bridge) => origin.includes(bridge))
}
6 changes: 3 additions & 3 deletions src/components/walletconnect/ProposalForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CompatibilityWarning } from './CompatibilityWarning'
import useChains from '@/hooks/useChains'
import useSafeInfo from '@/hooks/useSafeInfo'
import { getSupportedChainIds } from '@/services/walletconnect/utils'
import { isDangerousBridge, isRiskyBridge } from './bridges'
import { isStrictAddressBridge, isDefaultAddressBridge } from './bridges'

type ProposalFormProps = {
proposal: Web3WalletTypes.SessionProposal
Expand All @@ -28,8 +28,8 @@ const ProposalForm = ({ proposal, onApprove, onReject }: ProposalFormProps): Rea
const chainIds = useMemo(() => getSupportedChainIds(configs, proposal.params), [configs, proposal.params])
const isUnsupportedChain = !chainIds.includes(safe.chainId)

const isHighRisk = proposal.verifyContext.verified.validation === 'INVALID' || isRiskyBridge(origin)
const disabled = isUnsupportedChain || isScam || isDangerousBridge(origin) || (isHighRisk && !understandsRisk)
const isHighRisk = proposal.verifyContext.verified.validation === 'INVALID' || isDefaultAddressBridge(origin)
const disabled = isUnsupportedChain || isScam || isStrictAddressBridge(origin) || (isHighRisk && !understandsRisk)

return (
<div className={css.container}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import type { Web3WalletTypes } from '@walletconnect/web3wallet'

import useChains from '@/hooks/useChains'
import useSafeInfo from '@/hooks/useSafeInfo'
import { isDangerousBridge, isRiskyBridge } from './bridges'
import { isStrictAddressBridge, isDefaultAddressBridge } from './bridges'

const NAME_PLACEHOLDER = '%%name%%'
const CHAIN_PLACEHOLDER = '%%chain%%'

const Warnings: Record<string, { severity: AlertColor; message: string }> = {
DANGEROUS_BRIDGE: {
BLOCKED_BRIDGE: {
severity: 'error',
message: `${NAME_PLACEHOLDER} is a bridge that is unusable in Safe{Wallet} due to the current implementation of WalletConnect — the bridged funds will be lost. Consider using a different bridge.`,
},
RISKY_BRIDGE: {
WARNED_BRIDGE: {
severity: 'warning',
message: `While using ${NAME_PLACEHOLDER}, please make sure that the desination address you send funds to matches the Safe address you have on the respective chain. Otherwise, the funds will be lost.`,
},
Expand All @@ -39,9 +39,9 @@ export const useCompatibilityWarning = (
const { origin } = proposal.verifyContext.verified
const { proposer } = proposal.params

let { message, severity } = isDangerousBridge(origin)
let { message, severity } = isStrictAddressBridge(origin)
? Warnings.DANGEROUS_BRIDGE
: isRiskyBridge(origin)
: isDefaultAddressBridge(origin)
? Warnings.RISKY_BRIDGE
: isUnsupportedChain
? Warnings.UNSUPPORTED_CHAIN
Expand Down
37 changes: 37 additions & 0 deletions src/components/walletconnect/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Bridges enforcing same address on destination chains
export const StrictAddressBridges = [
'bridge.arbitrum.io',
'bridge.base.org',
'cbridge.celer.network',
'www.orbiter.finance',
'zksync-era.l2scan.co',
'app.optimism.io',
'www.portalbridge.com',
'wallet.polygon.technology',
'app.rhino.fi',
]

// Bridges that initially select the same address on the destination chain but allow changing it
export const DefaultAddressBridges = [
'across.to',
'app.allbridge.io',
'core.allbridge.io',
'bungee.exchange',
'www.carrier.so',
'app.chainport.io',
'bridge.gnosischain.com',
'app.hop.exchange',
'app.interport.fi',
'jumper.exchange',
'www.layerswap.io',
'meson.fi',
'satellite.money',
'stargate.finance',
'app.squidrouter.com',
'app.symbiosis.finance',
'www.synapseprotocol.com',
'app.thevoyager.io',
'portal.txsync.io',
'bridge.wanchain.org',
'app.xy.finance',
]

0 comments on commit 398638f

Please sign in to comment.