Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not forward eth_chainId #3208

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/safe-apps/AppFrame/useAppCommunicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import type { Permission, PermissionRequest } from '@safe-global/safe-apps-sdk/d
import type { SafeSettings } from '@safe-global/safe-apps-sdk'
import AppCommunicator from '@/services/safe-apps/AppCommunicator'
import { Errors, logError } from '@/services/exceptions'
import { createSafeAppsWeb3Provider } from '@/hooks/wallets/web3'
import type { SafePermissionsRequest } from '@/hooks/safe-apps/permissions'
import { SAFE_APPS_EVENTS, trackSafeAppEvent } from '@/services/analytics'
import { useAppSelector } from '@/store'
import { selectRpc } from '@/store/settingsSlice'
import { createSafeAppsWeb3Provider } from '@/hooks/wallets/web3'

export enum CommunicatorMessages {
REJECT_TRANSACTION_MESSAGE = 'Transaction was rejected',
Expand Down Expand Up @@ -79,7 +79,7 @@ const useAppCommunicator = (
return
}

return createSafeAppsWeb3Provider(chain.rpcUri, customRpc?.[chain.chainId])
return createSafeAppsWeb3Provider(chain, customRpc?.[chain.chainId])
}, [chain, customRpc])

useEffect(() => {
Expand Down
7 changes: 7 additions & 0 deletions src/components/tx/SignOrExecuteForm/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ describe('SignOrExecute hooks', () => {
data: '0x0001',
staticPart: () => '',
dynamicPart: () => '',
isContractSignature: false,
})

const id = await executeTx({ gasPrice: 1 }, tx, '123', 'origin.com', true)
Expand Down Expand Up @@ -442,6 +443,7 @@ describe('SignOrExecute hooks', () => {
data: '0x0001',
staticPart: () => '',
dynamicPart: () => '',
isContractSignature: false,
})

const proposeSpy = jest
Expand All @@ -453,6 +455,7 @@ describe('SignOrExecute hooks', () => {
data: '0x0001',
staticPart: () => '',
dynamicPart: () => '',
isContractSignature: false,
})
return Promise.resolve(tx)
})
Expand Down Expand Up @@ -492,6 +495,7 @@ describe('SignOrExecute hooks', () => {
data: '0x0001',
staticPart: () => '',
dynamicPart: () => '',
isContractSignature: false,
})

const proposeSpy = jest
Expand All @@ -503,6 +507,7 @@ describe('SignOrExecute hooks', () => {
data: '0x0001',
staticPart: () => '',
dynamicPart: () => '',
isContractSignature: false,
})
return Promise.resolve(tx)
})
Expand Down Expand Up @@ -535,6 +540,7 @@ describe('SignOrExecute hooks', () => {
data: '0x0001',
staticPart: () => '',
dynamicPart: () => '',
isContractSignature: false,
})
const { result } = renderHook(() => useAlreadySigned(tx))
expect(result.current).toEqual(true)
Expand All @@ -554,6 +560,7 @@ describe('SignOrExecute hooks', () => {
data: '0x0001',
staticPart: () => '',
dynamicPart: () => '',
isContractSignature: false,
})
const { result } = renderHook(() => useAlreadySigned(tx))
expect(result.current).toEqual(false)
Expand Down
7 changes: 3 additions & 4 deletions src/hooks/wallets/useInitWeb3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { selectRpc } from '@/store/settingsSlice'
export const useInitWeb3 = () => {
const chain = useCurrentChain()
const chainId = chain?.chainId
const rpcUri = chain?.rpcUri
const wallet = useWallet()
const customRpc = useAppSelector(selectRpc)
const customRpcUrl = chain ? customRpc?.[chain.chainId] : undefined
Expand All @@ -24,11 +23,11 @@ export const useInitWeb3 = () => {
}, [wallet, chainId])

useEffect(() => {
if (!rpcUri) {
if (!chain) {
setWeb3ReadOnly(undefined)
return
}
const web3ReadOnly = createWeb3ReadOnly(rpcUri, customRpcUrl)
const web3ReadOnly = createWeb3ReadOnly(chain, customRpcUrl)
setWeb3ReadOnly(web3ReadOnly)
}, [rpcUri, customRpcUrl])
}, [chain, customRpcUrl])
}
20 changes: 12 additions & 8 deletions src/hooks/wallets/web3.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RPC_AUTHENTICATION, type RpcUri } from '@safe-global/safe-gateway-typescript-sdk'
import { type ChainInfo, RPC_AUTHENTICATION, type RpcUri } from '@safe-global/safe-gateway-typescript-sdk'
import { INFURA_TOKEN, SAFE_APPS_INFURA_TOKEN } from '@/config/constants'
import { JsonRpcProvider, BrowserProvider, type Eip1193Provider, type Provider } from 'ethers'
import { JsonRpcProvider, BrowserProvider, type Eip1193Provider, type Provider, Network } from 'ethers'
import ExternalStore from '@/services/ExternalStore'
import { EMPTY_DATA } from '@safe-global/protocol-kit/dist/src/utils/constants'

Expand All @@ -20,20 +20,24 @@ export const getRpcServiceUrl = (rpcUri: RpcUri): string => {
return formatRpcServiceUrl(rpcUri, INFURA_TOKEN)
}

export const createWeb3ReadOnly = (rpcUri: RpcUri, customRpc?: string): JsonRpcProvider | undefined => {
const url = customRpc || getRpcServiceUrl(rpcUri)
export const createWeb3ReadOnly = (chain: ChainInfo, customRpc?: string): JsonRpcProvider | undefined => {
const url = customRpc || getRpcServiceUrl(chain.rpcUri)
if (!url) return
return new JsonRpcProvider(url)
return new JsonRpcProvider(url, new Network(chain.chainName, chain.chainId), {
staticNetwork: true,
})
}

export const createWeb3 = (walletProvider: Eip1193Provider): BrowserProvider => {
return new BrowserProvider(walletProvider)
}

export const createSafeAppsWeb3Provider = (safeAppsRpcUri: RpcUri, customRpc?: string): JsonRpcProvider | undefined => {
const url = customRpc || formatRpcServiceUrl(safeAppsRpcUri, SAFE_APPS_INFURA_TOKEN)
export const createSafeAppsWeb3Provider = (chain: ChainInfo, customRpc?: string): JsonRpcProvider | undefined => {
const url = customRpc || formatRpcServiceUrl(chain.rpcUri, SAFE_APPS_INFURA_TOKEN)
if (!url) return
return new JsonRpcProvider(url)
return new JsonRpcProvider(url, new Network(chain.chainName, chain.chainId), {
staticNetwork: true,
})
}

export const { setStore: setWeb3, useStore: useWeb3 } = new ExternalStore<BrowserProvider>()
Expand Down
3 changes: 3 additions & 0 deletions src/services/tx/__tests__/encodeSignatures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ describe('encodeSignatures', () => {
data: '0xEEE',
staticPart: () => '0xEEE',
dynamicPart: () => '',
isContractSignature: false,
})

safeTx.addSignature({
signer: '0x345',
data: '0xAAA',
staticPart: () => '0xAAA',
dynamicPart: () => '',
isContractSignature: false,
})

const owner = '0x123'
Expand All @@ -57,6 +59,7 @@ describe('encodeSignatures', () => {
data: '0xAAA',
staticPart: () => '0xAAA',
dynamicPart: () => '',
isContractSignature: false,
})

const owner = '0x123'
Expand Down
Loading