Skip to content

Commit

Permalink
chore: better imports and networkId handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Mar 17, 2024
1 parent 4b7d4bc commit e5a3cca
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 20 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.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",
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/esm/src/constants";
import { networkExplorers } from "@keyrxng/rpc-handler/dist";
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 | null {
return this.reward?.networkId || null;
get networkId(): number {
return this.reward?.networkId || this.permitNetworkId;
}

get provider(): JsonRpcProvider {
Expand Down
5 changes: 2 additions & 3 deletions static/scripts/rewards/cirip/ens-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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];
Expand Down
3 changes: 2 additions & 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/esm/src";
import { RPCHandler } from "@keyrxng/rpc-handler/dist";
import { reverseEnsInterface } from "./ens-lookup";

export async function queryReverseEns(address: string, handler: RPCHandler) {
Expand All @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
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/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";
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/esm/src/constants";
import { getNetworkName, networkCurrencies, networkExplorers, networkRpcs } from "@keyrxng/rpc-handler/dist";

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/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";
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/esm/src/constants";
import { getNetworkName } from "@keyrxng/rpc-handler/dist";
import { buttonController, toaster } from "../toaster";
import { switchNetwork } from "./switch-network";

Expand Down
10 changes: 7 additions & 3 deletions static/scripts/rewards/web3/use-rpc-handler.ts
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit e5a3cca

Please sign in to comment.