Skip to content

Commit

Permalink
crack down on number of rpc calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jfschwarz committed Jan 31, 2024
1 parent 5a56047 commit 0dc53ea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@
"typescript-plugin-css-modules": "^3.4.0"
},
"packageManager": "[email protected]"
}
}
4 changes: 2 additions & 2 deletions extension/src/bridge/SafeAppBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ export default class SafeAppBridge {
console.debug('SAFE_APP_MESSAGE', msg.data)
try {
const response = await handler(msg.data.params, msg.data.id, msg.data.env)
console.log({ response })
// TODO can this happen? (If response is not returned, it means the response will be sent somewhere else)
if (typeof response !== 'undefined') {
this.postResponse(msg.source, response, msg.data.id)
} else {
throw new Error('No response returned from handler')
}
} catch (e) {
console.error('Error handling message via SafeAppCommunicator', e)
Expand Down
14 changes: 8 additions & 6 deletions extension/src/providers/readOnlyProvider.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import EventEmitter from 'events'
import { hexValue } from 'ethers/lib/utils'
import {
JsonRpcBatchProvider,
StaticJsonRpcProvider,
TransactionRequest,
} from '@ethersproject/providers'
import { ChainId, RPC } from '../chains'

const readOnlyProviderCache = new Map<ChainId, JsonRpcBatchProvider>()
const readOnlyProviderCache = new Map<ChainId, StaticJsonRpcProvider>()
const eip1193ProviderCache = new Map<string, Eip1193JsonRpcProvider>()

const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'

export const getReadOnlyProvider = (chainId: ChainId): JsonRpcBatchProvider => {
export const getReadOnlyProvider = (
chainId: ChainId
): StaticJsonRpcProvider => {
if (readOnlyProviderCache.has(chainId)) {
return readOnlyProviderCache.get(chainId)!
}

const provider = new JsonRpcBatchProvider(RPC[chainId], chainId)
const provider = new StaticJsonRpcProvider(RPC[chainId], chainId)
readOnlyProviderCache.set(chainId, provider)
return provider
}
Expand All @@ -41,7 +43,7 @@ export const getEip1193ReadOnlyProvider = (
}

const hexlifyTransaction = (transaction: TransactionRequest) =>
JsonRpcBatchProvider.hexlifyTransaction(transaction, {
StaticJsonRpcProvider.hexlifyTransaction(transaction, {
from: true,
customData: true,
ccipReadEnabled: true,
Expand All @@ -52,7 +54,7 @@ const hexlifyTransaction = (transaction: TransactionRequest) =>
* Copyright (c) 2019 Richard Moore, released under MIT license.
*/
export class Eip1193JsonRpcProvider extends EventEmitter {
readonly provider: JsonRpcBatchProvider
readonly provider: StaticJsonRpcProvider
readonly chainId: ChainId
readonly address: string

Expand Down

0 comments on commit 0dc53ea

Please sign in to comment.