From 392798a5ffba81dd0d081cc3b63d30cd533e1ab8 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Sun, 17 Mar 2024 21:38:49 +0000 Subject: [PATCH] chore: even better imports and networkid fix --- package.json | 2 +- static/scripts/rewards/app-state.ts | 6 ++--- static/scripts/rewards/cirip/ens-lookup.ts | 2 +- .../rewards/cirip/query-reverse-ens.ts | 2 +- .../render-transaction/render-transaction.ts | 10 +++++--- static/scripts/rewards/web3/add-network.ts | 2 +- static/scripts/rewards/web3/erc20-permit.ts | 2 +- .../rewards/web3/not-on-correct-network.ts | 2 +- .../scripts/rewards/web3/use-rpc-handler.ts | 4 ++-- yarn.lock | 23 +++++++++++++++---- 10 files changed, 37 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index c9791add..b8ec9657 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ ], "dependencies": { "@ethersproject/providers": "^5.7.2", - "@keyrxng/rpc-handler": "^1.0.2", + "@keyrxng/rpc-handler": "^1.0.3", "@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 a350314a..67e2aab4 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"; +import { networkExplorers } from "@keyrxng/rpc-handler"; import { RewardPermit } from "./render-transaction/tx-type"; export class AppState { @@ -17,8 +17,8 @@ export class AppState { this._signer = value; } - get networkId(): number { - return this.reward?.networkId || this.permitNetworkId; + get networkId(): number | null { + return this.reward?.networkId || null; } get provider(): JsonRpcProvider { diff --git a/static/scripts/rewards/cirip/ens-lookup.ts b/static/scripts/rewards/cirip/ens-lookup.ts index af41d527..a168faa9 100644 --- a/static/scripts/rewards/cirip/ens-lookup.ts +++ b/static/scripts/rewards/cirip/ens-lookup.ts @@ -2,7 +2,7 @@ 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"; +import { RPCHandler } from "@keyrxng/rpc-handler"; export const reverseEnsInterface = new ethers.utils.Interface(abi); diff --git a/static/scripts/rewards/cirip/query-reverse-ens.ts b/static/scripts/rewards/cirip/query-reverse-ens.ts index 3830ea5b..45e0eff4 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"; +import { RPCHandler } from "@keyrxng/rpc-handler"; import { reverseEnsInterface } from "./ens-lookup"; export async function queryReverseEns(address: string, handler: RPCHandler) { diff --git a/static/scripts/rewards/render-transaction/render-transaction.ts b/static/scripts/rewards/render-transaction/render-transaction.ts index 82fcad79..b14d8c40 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"; +import { networkExplorers } from "@keyrxng/rpc-handler"; import { buttonController, getMakeClaimButton, viewClaimButton } from "../toaster"; import { checkRenderInvalidatePermitAdminControl, claimErc20PermitHandlerWrapper, fetchTreasury } from "../web3/erc20-permit"; import { claimErc721PermitHandler } from "../web3/erc721-permit"; @@ -26,6 +26,10 @@ export async function renderTransaction(): Promise { return false; } + if (!app.networkId) { + throw new Error("Network ID not set"); + } + verifyCurrentNetwork(app.reward.networkId).catch(console.error); if (permitCheck(app.reward)) { @@ -44,7 +48,7 @@ export async function renderTransaction(): Promise { }).catch(console.error); const toElement = document.getElementById(`rewardRecipient`) as Element; - renderEnsName({ element: toElement, address: app.reward.transferDetails.to, networkId: app.networkId ?? app.reward.networkId }).catch(console.error); + renderEnsName({ element: toElement, address: app.reward.transferDetails.to, networkId: app.networkId }).catch(console.error); if (app.provider) { checkRenderInvalidatePermitAdminControl(app).catch(console.error); @@ -71,7 +75,7 @@ export async function renderTransaction(): Promise { }).catch(console.error); const toElement = document.getElementById(`rewardRecipient`) as Element; - renderEnsName({ element: toElement, address: app.reward.transferDetails.to, networkId: app.networkId ?? app.reward.networkId }).catch(console.error); + renderEnsName({ element: toElement, address: app.reward.transferDetails.to, networkId: app.networkId }).catch(console.error); getMakeClaimButton().addEventListener("click", claimErc721PermitHandler(app.reward)); } diff --git a/static/scripts/rewards/web3/add-network.ts b/static/scripts/rewards/web3/add-network.ts index 107401c8..c9696e04 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"; +import { getNetworkName, networkCurrencies, networkExplorers, networkRpcs } from "@keyrxng/rpc-handler"; 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 84bfd12a..867e838e 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"; +import { permit2Address } from "@keyrxng/rpc-handler"; 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 ad862f61..a5b3f5e4 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"; +import { getNetworkName } from "@keyrxng/rpc-handler"; 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 17bc1924..dcaee7db 100644 --- a/static/scripts/rewards/web3/use-rpc-handler.ts +++ b/static/scripts/rewards/web3/use-rpc-handler.ts @@ -1,4 +1,4 @@ -import { RPCHandler, HandlerConstructorConfig } from "@keyrxng/rpc-handler/dist"; +import { RPCHandler, HandlerConstructorConfig } from "@keyrxng/rpc-handler"; import { AppState } from "../app-state"; export async function useRpcHandler(app: AppState) { @@ -15,7 +15,7 @@ export async function useRpcHandler(app: AppState) { const handler = new RPCHandler(config); - await handler.getFastestRpcProvider(); + await handler.testRpcPerformance(); return handler; } diff --git a/yarn.lock b/yarn.lock index 79742e8a..dcee6024 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1194,12 +1194,13 @@ wrap-ansi "^8.1.0" wrap-ansi-cjs "npm:wrap-ansi@^7.0.0" -"@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== +"@keyrxng/rpc-handler@^1.0.3": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@keyrxng/rpc-handler/-/rpc-handler-1.0.3.tgz#d73f9a1e5c777224fea5f928971851a8145c998a" + integrity sha512-3E2GM4EtEBey5MPeck5g0nryx/TI8O520T+Z3PNWBW29nYuSZNEsDaMc9KTX5h9Yqzsg21q6jRpcGXi2/pzE/Q== dependencies: "@ethersproject/providers" "5.7.2" + axios "^1.6.8" "@nodelib/fs.scandir@2.1.5": version "2.1.5" @@ -1938,6 +1939,15 @@ axios@^1.6.7: form-data "^4.0.0" proxy-from-env "^1.1.0" +axios@^1.6.8: + version "1.6.8" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66" + integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ== + dependencies: + follow-redirects "^1.15.6" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + babylon@^6.9.1: version "6.18.0" resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" @@ -3077,6 +3087,11 @@ follow-redirects@^1.15.4: resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.5.tgz#54d4d6d062c0fa7d9d17feb008461550e3ba8020" integrity sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw== +follow-redirects@^1.15.6: + version "1.15.6" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" + integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== + for-each@^0.3.3: version "0.3.3" resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"