Skip to content

Commit

Permalink
chore: even better imports and networkid fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Mar 17, 2024
1 parent e5a3cca commit 392798a
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions static/scripts/rewards/app-state.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion static/scripts/rewards/cirip/ens-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion static/scripts/rewards/cirip/query-reverse-ens.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
10 changes: 7 additions & 3 deletions static/scripts/rewards/render-transaction/render-transaction.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -26,6 +26,10 @@ export async function renderTransaction(): Promise<Success> {
return false;
}

if (!app.networkId) {
throw new Error("Network ID not set");
}

verifyCurrentNetwork(app.reward.networkId).catch(console.error);

if (permitCheck(app.reward)) {
Expand All @@ -44,7 +48,7 @@ export async function renderTransaction(): Promise<Success> {
}).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);
Expand All @@ -71,7 +75,7 @@ export async function renderTransaction(): Promise<Success> {
}).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));
}
Expand Down
2 changes: 1 addition & 1 deletion static/scripts/rewards/web3/add-network.ts
Original file line number Diff line number Diff line change
@@ -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<boolean> {
try {
Expand Down
2 changes: 1 addition & 1 deletion static/scripts/rewards/web3/erc20-permit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion static/scripts/rewards/web3/not-on-correct-network.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
4 changes: 2 additions & 2 deletions static/scripts/rewards/web3/use-rpc-handler.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -15,7 +15,7 @@ export async function useRpcHandler(app: AppState) {

const handler = new RPCHandler(config);

await handler.getFastestRpcProvider();
await handler.testRpcPerformance();

return handler;
}
23 changes: 19 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]":
version "2.1.5"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 392798a

Please sign in to comment.