Skip to content

Commit

Permalink
Fix Metamask locking issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kewbish committed Jan 2, 2023
1 parent d9d5641 commit 315db45
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
Binary file modified build.crx
Binary file not shown.
2 changes: 1 addition & 1 deletion landing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h2 class="display mx-auto text-center mb-3">get started</h2>
<a href="https://github.com/kewbish/cobweb/releases/latest" class="btn glassy-cw-btn mt-1" role="button">download</a>
</div>
<div class="col">
<p>Cobweb is MIT-licensed and fully open source - the source is <a href="https://github.com/kewbish/cobweb">available on GitHub</a> should you wish to build from source. The checksum of the current version is <code style="word-break:break-all;">29aec681ca1ed9d2da4f09bf558012dec69ef8f7bf81e1ccbcf8521602db7df2</code>.
<p>Cobweb is MIT-licensed and fully open source - the source is <a href="https://github.com/kewbish/cobweb">available on GitHub</a> should you wish to build from source. The checksum of the current version is <code style="word-break:break-all;">e76cb27d110f9544d3345644827af159e2750ffaad9e0660d63a931c907a32ba</code>.
</p>
<a href="https://github.com/kewbish/cobweb" class="btn glassy-cw-btn mt-1" role="button">view source</a>
</div>
Expand Down
33 changes: 23 additions & 10 deletions src/pages/Background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/tsarpaul/citadelnfts-extension/blob/master/patch_metamask_provider.py
import createMetaMaskProvider from "metamask-extension-provider";
import { MetaMaskInpageProvider } from "@metamask/inpage-provider";
import { BigNumber, ethers, constants, Signer } from "ethers";
import { BigNumber, ethers } from "ethers";
import { Framework } from "@superfluid-finance/sdk-core";
import {
INFURA_PROJECT_ID,
Expand Down Expand Up @@ -62,16 +62,28 @@ metamaskProvider.on("disconnect", () => {
storage.local.set({ mmNotFound: true });
});

metamaskProvider.on("connect", async () => {
try {
storage.local.set({
mmNotFound: (await mmProvider.listAccounts()).length === 0,
});
} catch {
storage.local.set({ mmNotFound: true });
}
});

metamaskProvider.on("accountsChanged", (accounts) => {
setNewAddress({
address: (accounts as Array<string>)[0],
provider: mmProvider,
});
if ((accounts as Array<String>).length === 0) {
storage.local.set({ mmNotFound: true });
} else {
setNewAddress({
address: (accounts as Array<string>)[0],
provider: mmProvider,
});
}
});

export const mmProvider = new ethers.providers.Web3Provider(
metamaskProvider as any
);
const mmProvider = new ethers.providers.Web3Provider(metamaskProvider as any);

storage.local.set({ toasts: [] });

Expand All @@ -82,6 +94,9 @@ if (!addressTry || addressTry === "NO_ADDRESS") {
storage.local.set({
address: metamaskProvider.selectedAddress ?? "NO_ADDRESS",
});
if (!metamaskProvider.selectedAddress) {
storage.local.set({ mmNotFound: true });
}
}

let infuraProvider: InfuraProvider | null = null;
Expand Down Expand Up @@ -378,5 +393,3 @@ chrome.alarms.onAlarm.addListener(async (alarm) => {
}
} catch {}
});

chrome.runtime.onConnect.addListener(() => {});
2 changes: 1 addition & 1 deletion src/pages/Background/lib/fetchAndUpdateBalance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { storage } from "@extend-chrome/storage";
import { Web3Provider } from "@ethersproject/providers";
import { Framework, SuperToken } from "@superfluid-finance/sdk-core";
import { BigNumber, constants, Signer, utils } from "ethers";
import { BigNumber, constants, utils } from "ethers";
import errorToast, { toast } from "../../shared/toast";
import { DELETE_STREAM } from "../../shared/events";
import { Rate } from "../../shared/types";
Expand Down
4 changes: 1 addition & 3 deletions src/pages/Popup/ListSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React from "react";
import { useChromeStorageLocal } from "use-chrome-storage";
import { useState } from "react";
import { PayRates, Rate, RateSettings, Stream } from "../shared/types";
Expand All @@ -9,8 +9,6 @@ import Setting from "./components/Setting";
import "bootstrap-icons/font/bootstrap-icons.css";
import { UPDATE_STREAM } from "../shared/events";
import CobwebPage from "./components/CobwebPage";
// @ts-expect-error
import bootstrap from "bootstrap/dist/js/bootstrap.bundle";
import { toast } from "../shared/toast";
import verifySignature from "../shared/verifySignature";
import ToastHandler from "./components/ToastHandler";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Popup/Popup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers, BigNumber, constants } from "ethers";
import { ethers, BigNumber } from "ethers";
import React, { useEffect, useState } from "react";
import { Link, Navigate, useSearchParams } from "react-router-dom";
import {
Expand Down

0 comments on commit 315db45

Please sign in to comment.