Skip to content

Commit

Permalink
Merge pull request #213 from ubq-testing/development
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 authored Mar 29, 2024
2 parents 35b7145 + 94b8ca9 commit aea724e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Ethereum } from "ethereum-protocol";

declare global {
const ethereum: Ethereum;
interface Window {
ethereum: Ethereum;
}
}
6 changes: 3 additions & 3 deletions static/scripts/rewards/ButtonController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ButtonController {
}

public showLoader(): void {
if (ethereum) {
if (window.ethereum) {
this._controls.setAttribute(LOADER, "true");
} else {
throw new Error("Can not show loader without `ethereum`");
Expand All @@ -27,7 +27,7 @@ export class ButtonController {
}

public showMakeClaim(): void {
if (ethereum) {
if (window.ethereum) {
this._controls.setAttribute(MAKE_CLAIM, "true");
} else {
throw new Error("Can not show make claim button without `ethereum`");
Expand All @@ -47,7 +47,7 @@ export class ButtonController {
}

public showInvalidator(): void {
if (ethereum) {
if (window.ethereum) {
this._controls.setAttribute(INVALIDATOR, "true");
} else {
throw new Error("Can not show invalidator button without `ethereum`");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ export async function readClaimDataFromUrl(app: AppState) {
} catch (e) {
toaster.create("error", `${e}`);
}
if (ethereum) {
if (window.ethereum) {
try {
app.signer = await connectWallet();
} catch (error) {
/* empty */
}
ethereum.on("accountsChanged", () => {
window.ethereum.on("accountsChanged", () => {
checkRenderMakeClaimControl(app).catch(console.error);
checkRenderInvalidatePermitAdminControl(app).catch(console.error);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function renderTransaction(): Promise<Success> {
if (app.claimTxs[app.reward.permit.nonce.toString()] !== undefined) {
buttonController.showViewClaim();
viewClaimButton.addEventListener("click", () => window.open(`${app.currentExplorerUrl}/tx/${app.claimTxs[app.reward.permit.nonce.toString()]}`));
} else if (ethereum) {
} else if (window.ethereum) {
// requires wallet connection to claim
buttonController.showMakeClaim();
getMakeClaimButton().addEventListener("click", claimErc20PermitHandlerWrapper(app));
Expand Down
2 changes: 1 addition & 1 deletion static/scripts/rewards/web3/connect-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { buttonController, toaster } from "../toaster";

export async function connectWallet(): Promise<JsonRpcSigner | null> {
try {
const wallet = new ethers.providers.Web3Provider(ethereum);
const wallet = new ethers.providers.Web3Provider(window.ethereum);

await wallet.send("eth_requestAccounts", []);

Expand Down
6 changes: 3 additions & 3 deletions static/scripts/rewards/web3/verify-current-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import { notOnCorrectNetwork } from "./not-on-correct-network";

// verifyCurrentNetwork checks if the user is on the correct network and displays an error if not
export async function verifyCurrentNetwork(desiredNetworkId: number) {
if (!ethereum) {
if (!window.ethereum) {
buttonController.hideAll();
return;
}

const web3provider = new ethers.providers.Web3Provider(ethereum);
const web3provider = new ethers.providers.Web3Provider(window.ethereum);

const network = await web3provider.getNetwork();
const currentNetworkId = network.chainId;

// watch for network changes
ethereum.on("chainChanged", <T>(newNetworkId: T | string) => handleIfOnCorrectNetwork(parseInt(newNetworkId as string, 16), desiredNetworkId));
window.ethereum.on("chainChanged", <T>(newNetworkId: T | string) => handleIfOnCorrectNetwork(parseInt(newNetworkId as string, 16), desiredNetworkId));

// if its not on ethereum mainnet, gnosis, or goerli, display error
notOnCorrectNetwork(currentNetworkId, desiredNetworkId, web3provider);
Expand Down

0 comments on commit aea724e

Please sign in to comment.