|
1 | | -import { ethers } from 'ethers' |
2 | 1 | import { useMemo } from 'react' |
3 | 2 |
|
| 3 | +// once upon a time, infura was giving timeout errors. |
| 4 | +// alchemy was used as a result. but users tend to use |
| 5 | +// metamask, which defaults to infura as rpc provider, |
| 6 | +// and thus these errors kept happening. |
| 7 | +// the solution then was to override the library used to |
| 8 | +// fetch the logs, and use the once provided in the env. |
| 9 | + |
| 10 | +// alchemy is now giving 429 errors a bit too frequently, |
| 11 | +// and infura somehow works seamlessly again, so this function |
| 12 | +// doesn't seem to do anything anymore. but, it's there in case |
| 13 | +// these overrides come useful again. plus, refactoring it out |
| 14 | +// would be time consuming. |
4 | 15 | const useGetLogs = library => { |
5 | | - const key = JSON.parse(process.env.REACT_APP_RPC_URLS)[1] |
6 | | - const provider = new ethers.providers.JsonRpcProvider(key) |
7 | 16 | const getLogs = useMemo( |
8 | 17 | () => async query => { |
9 | | - if (library.network.chainId === 1) { |
10 | | - const mainnetResult = await provider.getLogs(query) |
11 | | - return mainnetResult |
12 | | - } else { |
13 | | - const defResult = await library.getLogs(query) |
14 | | - return defResult |
15 | | - } |
| 18 | + const defResult = await library.getLogs(query) |
| 19 | + return defResult |
16 | 20 | }, |
17 | 21 | // eslint-disable-next-line react-hooks/exhaustive-deps |
18 | 22 | [library, library.network] |
|
0 commit comments