diff --git a/package.json b/package.json index 5394e9b2..c9791add 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ ], "dependencies": { "@ethersproject/providers": "^5.7.2", - "@keyrxng/rpc-handler": "^1.0.1", + "@keyrxng/rpc-handler": "^1.0.2", "@octokit/core": "^5.1.0", "@octokit/plugin-create-or-update-text-file": "^4.0.1", "@octokit/plugin-throttling": "^8.1.3", diff --git a/static/scripts/rewards/app-state.ts b/static/scripts/rewards/app-state.ts index 5cbbf7d4..a350314a 100644 --- a/static/scripts/rewards/app-state.ts +++ b/static/scripts/rewards/app-state.ts @@ -1,5 +1,5 @@ import { JsonRpcProvider } from "@ethersproject/providers"; -import { networkExplorers } from "@keyrxng/rpc-handler/dist/esm/src/constants"; +import { networkExplorers } from "@keyrxng/rpc-handler/dist"; import { RewardPermit } from "./render-transaction/tx-type"; export class AppState { @@ -17,8 +17,8 @@ export class AppState { this._signer = value; } - get networkId(): number | null { - return this.reward?.networkId || null; + get networkId(): number { + return this.reward?.networkId || this.permitNetworkId; } get provider(): JsonRpcProvider { diff --git a/static/scripts/rewards/cirip/ens-lookup.ts b/static/scripts/rewards/cirip/ens-lookup.ts index fe01c3a0..af41d527 100644 --- a/static/scripts/rewards/cirip/ens-lookup.ts +++ b/static/scripts/rewards/cirip/ens-lookup.ts @@ -2,9 +2,8 @@ import { ethers } from "ethers"; import abi from "../abis/cirip.json"; import { fetchEns } from "./fetch-ens"; import { queryReverseEns } from "./query-reverse-ens"; -import { RPCHandler } from "@keyrxng/rpc-handler/dist/esm/src"; +import { RPCHandler } from "@keyrxng/rpc-handler/dist"; -// export const UBIQUITY_RPC_ENDPOINT = "https://rpc-pay.ubq.fi/v1/mainnet"; export const reverseEnsInterface = new ethers.utils.Interface(abi); // addEventListener("fetch", event => { @@ -25,7 +24,7 @@ export async function ensLookup(addr: string, handler: RPCHandler) { let reverseRecord = null as null | string; try { reverseRecord = await queryReverseEns(address, handler); - if (reverseRecord !== undefined) { + if (reverseRecord !== undefined && reverseRecord !== null && reverseRecord !== "") { const responseParsed = JSON.parse(reverseRecord).result; const _reverseRecord = ethers.utils.defaultAbiCoder.decode([ethers.utils.ParamType.from("string[]")], responseParsed); reverseRecord = _reverseRecord[0][0]; diff --git a/static/scripts/rewards/cirip/query-reverse-ens.ts b/static/scripts/rewards/cirip/query-reverse-ens.ts index 5e541e77..3830ea5b 100644 --- a/static/scripts/rewards/cirip/query-reverse-ens.ts +++ b/static/scripts/rewards/cirip/query-reverse-ens.ts @@ -1,4 +1,4 @@ -import { RPCHandler } from "@keyrxng/rpc-handler/dist/esm/src"; +import { RPCHandler } from "@keyrxng/rpc-handler/dist"; import { reverseEnsInterface } from "./ens-lookup"; export async function queryReverseEns(address: string, handler: RPCHandler) { @@ -14,6 +14,7 @@ export async function queryReverseEns(address: string, handler: RPCHandler) { const provider = handler.getProvider(); + // ENS registrar const ensName = await provider.send("eth_call", [{ to: "0x3671aE578E63FdF66ad4F3E12CC0c0d71Ac7510C", data: data }, "latest"]); if (ensName === "0x") { diff --git a/static/scripts/rewards/render-transaction/read-claim-data-from-url.ts b/static/scripts/rewards/render-transaction/read-claim-data-from-url.ts index cf5978d6..d91eb6a2 100644 --- a/static/scripts/rewards/render-transaction/read-claim-data-from-url.ts +++ b/static/scripts/rewards/render-transaction/read-claim-data-from-url.ts @@ -34,7 +34,6 @@ export async function readClaimDataFromUrl(app: AppState) { const handler = await useRpcHandler(app); app.provider = handler.getProvider(); - console.log("app.provider", app.provider); if (window.ethereum) { app.signer = await connectWallet().catch(console.error); window.ethereum.on("accountsChanged", () => { diff --git a/static/scripts/rewards/render-transaction/render-transaction.ts b/static/scripts/rewards/render-transaction/render-transaction.ts index fd0e3725..82fcad79 100644 --- a/static/scripts/rewards/render-transaction/render-transaction.ts +++ b/static/scripts/rewards/render-transaction/render-transaction.ts @@ -1,5 +1,5 @@ import { app } from "../app-state"; -import { networkExplorers } from "@keyrxng/rpc-handler/dist/esm/src/constants"; +import { networkExplorers } from "@keyrxng/rpc-handler/dist"; import { buttonController, getMakeClaimButton, viewClaimButton } from "../toaster"; import { checkRenderInvalidatePermitAdminControl, claimErc20PermitHandlerWrapper, fetchTreasury } from "../web3/erc20-permit"; import { claimErc721PermitHandler } from "../web3/erc721-permit"; diff --git a/static/scripts/rewards/web3/add-network.ts b/static/scripts/rewards/web3/add-network.ts index 770eaa23..107401c8 100644 --- a/static/scripts/rewards/web3/add-network.ts +++ b/static/scripts/rewards/web3/add-network.ts @@ -1,5 +1,5 @@ import { ethers } from "ethers"; -import { getNetworkName, networkCurrencies, networkExplorers, networkRpcs } from "@keyrxng/rpc-handler/dist/esm/src/constants"; +import { getNetworkName, networkCurrencies, networkExplorers, networkRpcs } from "@keyrxng/rpc-handler/dist"; export async function addNetwork(provider: ethers.providers.Web3Provider, networkId: number): Promise { try { diff --git a/static/scripts/rewards/web3/erc20-permit.ts b/static/scripts/rewards/web3/erc20-permit.ts index 98966d17..84bfd12a 100644 --- a/static/scripts/rewards/web3/erc20-permit.ts +++ b/static/scripts/rewards/web3/erc20-permit.ts @@ -2,7 +2,7 @@ import { JsonRpcSigner, TransactionResponse } from "@ethersproject/providers"; import { BigNumber, BigNumberish, Contract, ethers } from "ethers"; import { erc20Abi, permit2Abi } from "../abis"; import { AppState, app } from "../app-state"; -import { permit2Address } from "@keyrxng/rpc-handler/dist/esm/src/constants"; +import { permit2Address } from "@keyrxng/rpc-handler/dist"; import { supabase } from "../render-transaction/read-claim-data-from-url"; import { Erc20Permit, Erc721Permit } from "../render-transaction/tx-type"; import { MetaMaskError, buttonController, errorToast, getMakeClaimButton, toaster } from "../toaster"; diff --git a/static/scripts/rewards/web3/not-on-correct-network.ts b/static/scripts/rewards/web3/not-on-correct-network.ts index a723b438..ad862f61 100644 --- a/static/scripts/rewards/web3/not-on-correct-network.ts +++ b/static/scripts/rewards/web3/not-on-correct-network.ts @@ -1,5 +1,5 @@ import { ethers } from "ethers"; -import { getNetworkName } from "@keyrxng/rpc-handler/dist/esm/src/constants"; +import { getNetworkName } from "@keyrxng/rpc-handler/dist"; import { buttonController, toaster } from "../toaster"; import { switchNetwork } from "./switch-network"; diff --git a/static/scripts/rewards/web3/use-rpc-handler.ts b/static/scripts/rewards/web3/use-rpc-handler.ts index 71ce31f6..17bc1924 100644 --- a/static/scripts/rewards/web3/use-rpc-handler.ts +++ b/static/scripts/rewards/web3/use-rpc-handler.ts @@ -1,10 +1,14 @@ -import { RPCHandler } from "@keyrxng/rpc-handler/dist/esm/src/rpc-handler"; -import { HandlerConstructorConfig } from "@keyrxng/rpc-handler/dist/esm/src"; +import { RPCHandler, HandlerConstructorConfig } from "@keyrxng/rpc-handler/dist"; import { AppState } from "../app-state"; export async function useRpcHandler(app: AppState) { + const networkId = app.networkId; + if (!networkId) { + throw new Error("Network ID not set"); + } + const config: HandlerConstructorConfig = { - networkId: app.networkId ?? app.reward.networkId, + networkId, autoStorage: true, cacheRefreshCycles: 10, }; diff --git a/yarn.lock b/yarn.lock index 78d18204..79742e8a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1194,10 +1194,10 @@ wrap-ansi "^8.1.0" wrap-ansi-cjs "npm:wrap-ansi@^7.0.0" -"@keyrxng/rpc-handler@^1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@keyrxng/rpc-handler/-/rpc-handler-1.0.1.tgz#b9cf9166fbf0f983131ac48f1afbbe9cf5413062" - integrity sha512-F08mCZfee/zou0oKQsU7Y4Gm2gsHg86fHBQUbWv23lf6p9Ew0ZWTojZAANQXQrOSi5zFeexGE4gxOkeried2dg== +"@keyrxng/rpc-handler@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@keyrxng/rpc-handler/-/rpc-handler-1.0.2.tgz#c0924f5d60a944a451a66a7731baff91d0425140" + integrity sha512-L8C4003tFKC5LzpoTlBf1VVACvSb509WgepTyJrTu6/Kac8/kw96GIpMJRdkCTjZsLTaX/kgnPMzSUAycAERGg== dependencies: "@ethersproject/providers" "5.7.2"