Skip to content

Commit

Permalink
Troubleshoot blocking + add uninstall page
Browse files Browse the repository at this point in the history
  • Loading branch information
kewbish committed Dec 30, 2022
1 parent cdee69c commit 9815315
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 85 deletions.
Binary file added landing/cobweb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions landing/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,18 @@ code {
#differences-content-javascript {
display: none;
}

.fp-container {
width: max(40%, 300px);
height: 100vh;
}

.fp-container img {
width: 64px;
height: 64px;
margin-top: -5rem;
}

.fp-container .card {
max-height: max-content;
}
36 changes: 36 additions & 0 deletions landing/removed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Cobweb - A new way for teens to connect</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="../src/assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="../src/assets/css/fonts.css" />
<link rel="stylesheet" href="../src/pages/Popup/index.css" />
<link rel="stylesheet" href="index.css" />
</head>
<body>
<div class="fp-container mx-auto d-flex justify-content-center flex-column">
<a href="https://kewbi.sh/cobweb" class="mx-auto">
<img src="./cobweb.png" alt="Cobweb logo" class="mx-auto mb-2" />
</a>
<div class="card text-center p-3">
<h1 class="display">Sorry to see you go.</h1>
<p>We've detected that you've uninstalled or disabled Cobweb.</p>
<p>
Please make sure that you visit
<a href="https://app.superfluid.finance/">app.superfluid.finance</a>
and log in with the Metamask wallet you use with Cobweb to close out
any streams that are still open. Otherwise, your token balance will
continue to drain.
</p>
<button
role="button"
class="btn glassy-cw-btn p-1 mb-2 mx-auto d-inline-block"
>
Reinstall
</button>
</div>
</div>
</body>
</html>
112 changes: 61 additions & 51 deletions src/pages/Background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
MONTAG_FOUND,
USER_SET_WALLET,
DELETE_STREAM,
BLOCK_SITE,
BLOCK_TAG,
UPDATE_SETTING,
EDIT_CURRENT_STREAM,
FETCH_BALANCE,
Expand All @@ -29,13 +29,13 @@ import {
APPROVE_FULL,
} from "../shared/events";
import TOKEN_MAP, { PROD_TOKEN_MAP } from "../shared/tokens";
import { Wallet } from "../shared/types";
import { PayRates, Wallet } from "../shared/types";
import createStream, { updateStream } from "./lib/createStream";
import deleteStreamByTabId from "./lib/deleteStreamByTabId";
import setNewWallet from "./lib/setNewWallet";
import { getRate } from "./lib/getRate";
import setDefaultSettings from "./lib/initializeCobweb";
import blockSite from "./lib/blockSite";
import blockTag from "./lib/blockTag";
import updateRateSetting from "./lib/updateRateSetting";
import fetchAndUpdateBalance from "./lib/fetchAndUpdateBalance";
import setNewAddress from "./lib/updateAddress";
Expand All @@ -52,6 +52,7 @@ import { isDev } from "./lib/isDev";
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === chrome.runtime.OnInstalledReason.INSTALL) {
setDefaultSettings();
chrome.runtime.setUninstallURL("https://kewbi.sh/cobweb");
}
});

Expand Down Expand Up @@ -79,7 +80,7 @@ storage.local.set({ toasts: [] });
let { address: addressTry } = (await storage.local.get("address")) as {
address: string | null;
};
if (!addressTry) {
if (!addressTry || addressTry === "NO_ADDRESS") {
storage.local.set({
address: metamaskProvider.selectedAddress ?? "NO_ADDRESS",
});
Expand Down Expand Up @@ -156,7 +157,7 @@ const getWalletAndSigner = async (): Promise<{
}
} catch (e) {
errorToast(e as Error);
throw e;
// throw e;
}
return { wallet: walletRes, signer: sfSigner };
};
Expand All @@ -180,19 +181,21 @@ const montagFound = async ({
}
const tabId = sender.tab.id ?? 0;
const rate = await getRate(address);
if (rate && rate.rateAmount !== constants.Zero) {
createStream({
from: walletRes.address,
to: address,
tabId,
url: sender.tab.url ?? "",
rateAmount: rate.rateAmount,
sf,
sfSigner,
sfToken,
infuraProvider: infuraProvider as InfuraProvider,
});
if (rate.payWhen === PayRates.BLOCKED) {
return;
}
createStream({
from: walletRes.address,
toTag: request.options.address,
to: address,
tabId,
url: sender.tab.url ?? "",
rateAmount: rate.rateAmount,
sf,
sfSigner,
sfToken,
infuraProvider: infuraProvider as InfuraProvider,
});
};

const deleteStream = async ({ request }: { request: any }) => {
Expand All @@ -214,9 +217,9 @@ const setUserWallet = async ({ request }: { request: any }) => {
setNewWallet(request.options.wallet);
};

const setBlockSite = async ({ request }: { request: any }) => {
blockSite({
site: request.options.site,
const setBlockTag = async ({ request }: { request: any }) => {
blockTag({
address: request.options.address,
});
};

Expand Down Expand Up @@ -247,7 +250,10 @@ const editCurrentStream = async ({ request }: { request: any }) => {

const fetchBalance = async () => {
const { signer: sfSigner } = await getWalletAndSigner();
if (!sfToken || !mmProvider || !sf || !sfSigner) {
const { cwInitialized } = (await storage.local.get("cwInitialized")) as {
cwInitialized: boolean | null;
};
if (!sfToken || !mmProvider || !sf || (cwInitialized && !sfSigner)) {
return;
}
fetchAndUpdateBalance({ sfToken, mmProvider, sfSigner, sf });
Expand Down Expand Up @@ -343,8 +349,8 @@ const handleMessaging = async (
sendResponse();
return;
}
case BLOCK_SITE: {
setBlockSite({ request });
case BLOCK_TAG: {
setBlockTag({ request });
sendResponse();
return;
}
Expand Down Expand Up @@ -431,34 +437,38 @@ chrome.alarms.create("cobwebAllowanceCheck" + alarmSuffix, {
delayInMinutes: 5,
});
chrome.alarms.onAlarm.addListener(async (alarm) => {
var parsedName = alarm.name.match(/^([\S\s]*?)(\d+)$/);
let name = "";
let suffix = 0;
if (parsedName) {
name = parsedName[0];
suffix = +parsedName[1];
}
if (suffix !== alarmSuffix) {
return;
}
const { wallet, signer: sfSigner } = await getWalletAndSigner();
if (!sf || !sfSigner || !sfToken) {
return;
}
if (name === "cobwebStreamCleanup") {
cleanUpStreams({ sfSigner, sfToken, sf });
} else if (name === "cobwebAllowanceCheck") {
const { address } = await storage.local.get("address");
if (!wallet || !address) {
try {
var parsedName = alarm.name.match(/^([\S\s]*?)(\d+)$/);
let name = "";
let suffix = 0;
if (parsedName) {
name = parsedName[0];
suffix = +parsedName[1];
}
if (suffix !== alarmSuffix) {
return;
}
fetchBalance();
fetchCobwebAllowance({
sfToken,
sfSigner,
sf,
walletAddress: wallet.address,
mmAddress: address,
});
}
const { wallet, signer: sfSigner } = await getWalletAndSigner();
if (!sf || !sfSigner || !sfToken) {
return;
}
if (name === "cobwebStreamCleanup") {
cleanUpStreams({ sfSigner, sfToken, sf });
} else if (name === "cobwebAllowanceCheck") {
const { address } = await storage.local.get("address");
if (!wallet || !address) {
return;
}
fetchBalance();
fetchCobwebAllowance({
sfToken,
sfSigner,
sf,
walletAddress: wallet.address,
mmAddress: address,
});
}
} catch {}
});

chrome.runtime.onConnect.addListener(() => {});
12 changes: 0 additions & 12 deletions src/pages/Background/lib/blockSite.ts

This file was deleted.

19 changes: 19 additions & 0 deletions src/pages/Background/lib/blockTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { storage } from "@extend-chrome/storage";
import { RateSettings, PayRates } from "../../shared/types";
import { constants } from "ethers";

const blockTag = async ({ address }: { address: string }) => {
storage.local.set(({ settings }: { settings: RateSettings }) => {
if (!settings) {
settings = {};
}
let newSettings = structuredClone(settings);
newSettings[address] = {
payWhen: PayRates.BLOCKED,
rateAmount: constants.Zero,
};
return { settings: newSettings };
});
};

export default blockTag;
3 changes: 3 additions & 0 deletions src/pages/Background/lib/createStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import TOKEN_MAP from "../../shared/tokens";
const createStream = async ({
from,
to,
toTag,
tabId,
url,
rateAmount,
Expand All @@ -27,6 +28,7 @@ const createStream = async ({
}: {
from: string;
to: string;
toTag: string;
tabId: number;
url: string;
rateAmount: BigNumber;
Expand Down Expand Up @@ -115,6 +117,7 @@ const createStream = async ({
...streams,
{
recipient: to,
recipientTag: toTag,
tabId,
rateAmount,
requestId: uuid,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Background/lib/fetchAndUpdateBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const fetchAndUpdateBalance = async ({
mmProvider,
}: {
sf: Framework;
sfSigner: Signer;
sfSigner: Signer | null;
sfToken: SuperToken;
mmProvider: Web3Provider;
}) => {
Expand Down Expand Up @@ -47,7 +47,7 @@ const fetchAndUpdateBalance = async ({
const balance = await mmProvider.getBalance(address);
storage.local.set({ mmBalance: BigNumber.from(balance) });

if (!cwInitialized) {
if (!cwInitialized || !sfSigner) {
return;
}

Expand Down
12 changes: 8 additions & 4 deletions src/pages/Background/lib/getRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ import { Rate, PayRates } from "../../shared/types";
import { storage } from "@extend-chrome/storage";
import { BigNumber } from "ethers";

export const getRate = async (address: string): Promise<Rate | undefined> => {
export const getRate = async (address: string): Promise<Rate> => {
const { settings } = await storage.local.get("settings");
const { defaultRate } = await storage.local.get("defaultRate");
const fallbackRate = {
rateAmount: BigNumber.from(100),
payWhen: PayRates.ANY,
};

if (!settings || !settings.length) {
if (!settings || !Object.keys(settings).length) {
return defaultRate ?? fallbackRate;
}

const tryAddress = Object.keys(settings).filter((k) =>
k.startsWith(`COBWEB:${address}`)
k.toLowerCase().startsWith(`cobweb:${address.toLowerCase()}`)
);

return settings.get(tryAddress) ?? defaultRate ?? fallbackRate;
return (
(tryAddress.length > 0 ? settings[tryAddress[0]] : null) ??
defaultRate ??
fallbackRate
);
};
1 change: 0 additions & 1 deletion src/pages/Background/lib/wrapTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const upgradeTokens = async ({
const upgradeTokenOperation = (sfToken as WrapperSuperToken).upgrade({
amount: BigNumber.from(upgrading).toString(),
});
console.log(upgradeTokenOperation);
await upgradeTokenOperation.exec(sfSigner);
toast("Upgraded!");
} catch (e) {
Expand Down
19 changes: 19 additions & 0 deletions src/pages/Content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,22 @@ if (monetizationTag) {
});
}
}

try {
const port = chrome.runtime.connect({ name: "content-script" });
const onPortDisconnect = () => {
try {
console.log(chrome.runtime.lastError);
setTimeout(() => {
if (!chrome.runtime?.id) {
document.body.insertAdjacentHTML(
"afterend",
"<a href='https://kewbi.sh/cobweb/removed' target='_blank' id='cobweb-removed-link' style='opacity: 0;line-height: 0;' />"
);
document.getElementById("cobweb-removed-link")?.click();
}
}, 1000);
} catch {}
};
port.onDisconnect.addListener(onPortDisconnect);
} catch {}
Loading

0 comments on commit 9815315

Please sign in to comment.