Skip to content

Commit

Permalink
fix: use wallet provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Apr 11, 2024
1 parent ca344eb commit 469161d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
script: |
const { owner, repo } = context.repo;
const sha = "${{ github.event.workflow_run.head_sha }}";
const response = await github.rest.search.issuesAndPullRequests({
q: `repo:${owner}/${repo} is:pr sha:${sha}`,
per_page: 1,
Expand All @@ -82,11 +82,11 @@ jobs:
repo,
issue_number,
});
// Find the comment to update or create a new one if not found
let existingComment = comments.data.find(comment => comment.user.login === 'github-actions[bot]');
let body = '| Preview Deployment |\n| ------------------ |\n';
// If the comment exists, update its body
if (existingComment) {
// Check if the SHA already exists in the comment body to avoid duplicates
Expand Down
5 changes: 5 additions & 0 deletions static/scripts/rewards/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum NetworkIds {
Goerli = 5,
Gnosis = 100,
Anvil = 31337,
Mumbai = 80001,
}

enum Tokens {
Expand All @@ -20,13 +21,15 @@ const networkNames = {
[NetworkIds.Mainnet]: "Ethereum Mainnet",
[NetworkIds.Goerli]: "Goerli Testnet",
[NetworkIds.Gnosis]: "Gnosis Chain",
[NetworkIds.Mumbai]: "Mumbai Testnet",
[NetworkIds.Anvil]: "http://127.0.0.1:8545",
};

export const networkCurrencies: Record<number, object> = {
[NetworkIds.Mainnet]: { symbol: "ETH", decimals: 18 },
[NetworkIds.Goerli]: { symbol: "GoerliETH", decimals: 18 },
[NetworkIds.Gnosis]: { symbol: "XDAI", decimals: 18 },
[NetworkIds.Mumbai]: { symbol: "XMatic", decimals: 18 },
[NetworkIds.Anvil]: { symbol: "XDAI", decimals: 18 },
};

Expand All @@ -43,12 +46,14 @@ export const networkExplorers: Record<number, string> = {
[NetworkIds.Goerli]: "https://goerli.etherscan.io",
[NetworkIds.Gnosis]: "https://gnosisscan.io",
[NetworkIds.Anvil]: "https://gnosisscan.io",
[NetworkIds.Mumbai]: "https://mumbai.polygonscan.com",
};

export const networkRpcs: Record<number, string[]> = {
[NetworkIds.Mainnet]: extraRpcs[NetworkIds.Mainnet],
[NetworkIds.Goerli]: extraRpcs[NetworkIds.Goerli],
[NetworkIds.Gnosis]: extraRpcs[NetworkIds.Gnosis],
[NetworkIds.Mumbai]: extraRpcs[NetworkIds.Mumbai],
[NetworkIds.Anvil]: ["http://127.0.0.1:8545"],
};

Expand Down
22 changes: 2 additions & 20 deletions static/scripts/rewards/web3/connect-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { JsonRpcSigner } from "@ethersproject/providers";
import { ethers } from "ethers";
import { buttonController, toaster } from "../toaster";
import { useFastestRpc } from "../rpc-optimization/get-optimal-provider";
import { AppState } from "../app-state";
import { verifyCurrentNetwork } from "./verify-current-network";

Expand All @@ -19,35 +18,18 @@ export async function connectWallet(app: AppState): Promise<JsonRpcSigner | null
// get account access from the wallet provider i.e metamask
await wallet.send("eth_requestAccounts", []);

// get our optimal rpc provider
const rpc = await useFastestRpc(app);

// take the signer from the wallet
const walletSigner = wallet.getSigner();

// take the address of the signer
const walletAddress = await walletSigner.getAddress();

// use the rpc and connect the signer to an UncheckedRpcSigner instance
const rpcSigner = rpc.getUncheckedSigner(walletAddress) as JsonRpcSigner;

// get the address of the signer
const newJsonSignerAddress = await rpcSigner.getAddress();

// if we have window.eth then we should have an address
if (walletAddress == "" || newJsonSignerAddress == "" || !walletAddress || !newJsonSignerAddress) {
toaster.create("info", "Please connect your wallet to collect this reward.");
if (!walletAddress) {
buttonController.hideAll();
console.error("Wallet not connected");
return null;
}

if (walletAddress !== newJsonSignerAddress) {
// although this should never happen just use the wallet provider if it does
return walletSigner;
} else {
return rpcSigner;
}
return walletSigner;
} catch (error: unknown) {
connectErrorHandler(error);
}
Expand Down

0 comments on commit 469161d

Please sign in to comment.