Skip to content

Commit

Permalink
Merge pull request #42 from Vigilance-DAO/feat/sahit-alert
Browse files Browse the repository at this point in the history
Feature: contract alert
  • Loading branch information
VenkatTeja authored Jul 23, 2023
2 parents 2c50fbf + d3365f3 commit 405940d
Show file tree
Hide file tree
Showing 25 changed files with 2,479 additions and 246 deletions.
20 changes: 12 additions & 8 deletions chrome-extension/bundle-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,20 @@ const prebuildOptions = {
{
name: "run-prebuild-script",
setup(build) {
build.onStart(async () => {
build.onStart(() => {
console.log("Building", prebuildScript);
try {
await rm("./build/static", {
recursive: true,
force: true
const directory = "./build/static";
console.log("Removing", directory);

return rm(directory, {
recursive: true,
force: true,
})
.then(() => console.log("Removing", directory, "done"))
.catch((_e) => {
console.error("Couldn't remove", directory);
console.error(_e);
});
} catch (_e) {
console.log(_e);
}
});
build.onEnd(async (result) => {
if (result.metafile == undefined) {
Expand Down
6 changes: 4 additions & 2 deletions chrome-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"scripts": {
"build:other": "node bundle-config.mjs",
"dev:other": "node bundle-config.mjs --watch",
"build": "concurrently npm:build:content npm:build:other",
"dev": "concurrently npm:dev:other npm:dev:content",
"build": "concurrently npm:build:content npm:build:other npm:build:inject",
"dev": "concurrently npm:dev:other npm:dev:content npm:dev:inject",
"build:content": "browserify src/content.js -o build/content.js",
"dev:content": "nodemon --exec \"browserify src/content.js -o build/content.js\" --watch src/content.js",
"build:inject": "browserify src/inject.js -o build/inject.js",
"dev:inject": "nodemon --exec \"browserify src/inject.js -o build/inject.js\" --watch src/inject.js",
"copy:assets": "cp -r assets/ build/static/",
"release": "yarn build && yarn build:content && yarn build:inject && yarn copy:assets"
},
Expand Down Expand Up @@ -54,6 +55,7 @@
"web3.storage": "4.4.0"
},
"devDependencies": {
"@types/mixpanel-browser": "^2.47.0",
"concurrently": "^8.2.0",
"esbuild-envfile-plugin": "^1.0.5",
"mkdirp": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion chrome-extension/public/content.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.____vigilance-dao-alert-dialog____::backdrop {
.____vigilance-dao-dialog____::backdrop {
background-color: hsl(20deg 8.57% 6.86% / 34.12%);
}
6 changes: 6 additions & 0 deletions chrome-extension/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import { initializeConnector } from "@web3-react/core";
import { useWeb3Hook } from "./services/web3.hook";
import Index from "./prebuild-components";

// ! For production uncomment these lines
console.log = function(){};
console.debug = function(){};
console.error = function(){};
console.warn = function(){};

function getLibrary(provider: any) {
return new Web3Provider(provider);
}
Expand Down
123 changes: 63 additions & 60 deletions chrome-extension/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
/// <reference types="psl" />
/// <reference lib="webworker" />

// ! For production uncomment these lines
console.log = function(){};
console.debug = function(){};
console.error = function(){};
console.warn = function(){};

try {
importScripts("./psl.min.js" /*, and so on */);
} catch (e) {
Expand All @@ -12,7 +18,7 @@ try {
const DONT_SHOW_AGAIN_DOMAINS_KEY = "dont_show_again_domains";
const env = {
// host: "http://localhost:4000", // backend API endpoint
host: 'https://8md2nmtej9.execute-api.ap-northeast-1.amazonaws.com',
host: "https://api.vigilancedao.org",
alertPeriod: 4 * 30 * 86400 * 1000,
SUBGRAPH_URL:
"https://api.thegraph.com/subgraphs/name/venkatteja/vigilancedao",
Expand Down Expand Up @@ -675,66 +681,63 @@ chrome.action.onClicked.addListener(function (tab) {
// so the below functions proxies the msg between index.html and content.js
// Look for `chrome.runtime.onMessage.addListener` in the code
// to see how the msgs are being recieved and sent
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
(async () => {
console.log("msg in background", request, sender);
if (sender.tab == undefined) {
console.error("sender", sender);
throw new Error("sender.tab is undefined");
}
if (request.type == "take-screenshot") {
await sendMessage(sender.tab, "toggle", {});
await takeScreenshot(sender.tab);
await sendMessage(sender.tab, "toggle", {});
} else if (request.type == "connect-wallet") {
await sendMessage(sender.tab, "connect-wallet-2", {});
} else if (request.type == "wallet-connected") {
await sendMessage(sender.tab, "wallet-connected", request.data);
} else if (request.type == "switch-network") {
await sendMessage(sender.tab, "switch-network-2", request.data);
} else if (request.type == "chainID") {
await sendMessage(sender.tab, "chainID", request.data);
} else if (request.type == "submit-report") {
await sendMessage(sender.tab, "submit-report-2", request.data);
} else if (request.type == "transaction-update") {
await sendMessage(sender.tab, "transaction-update", request.data);
} else if (request.type == "get-stake-amount") {
await sendMessage(sender.tab, "get-stake-amount-2", request.data);
} else if (request.type == "stake-amount") {
await sendMessage(sender.tab, "stake-amount", request.data);
} else if (request.type == "alert-dont-show-again") {
/**
* @type {string[]}
*/
const dontShowAgainDomains = await chrome.storage.sync
.get(DONT_SHOW_AGAIN_DOMAINS_KEY)
.then((items) => items[DONT_SHOW_AGAIN_DOMAINS_KEY] || [])
.catch((error) => {
console.error(
`Error while getting ${DONT_SHOW_AGAIN_DOMAINS_KEY}`,
error
);
return [];
});
chrome.storage.sync.set({
[DONT_SHOW_AGAIN_DOMAINS_KEY]: dontShowAgainDomains.concat(
request.data.url
),
async function processMsg(request, sender, sendResponse) {
if (sender.tab == undefined) {
console.error("sender", sender);
throw new Error("sender.tab is undefined");
}
if (request.type == "take-screenshot") {
await sendMessage(sender.tab, "toggle", {});
await takeScreenshot(sender.tab);
await sendMessage(sender.tab, "toggle", {});
} else if (request.type == "connect-wallet") {
await sendMessage(sender.tab, "connect-wallet-2", {});
} else if (request.type == "wallet-connected") {
await sendMessage(sender.tab, "wallet-connected", request.data);
} else if (request.type == "switch-network") {
await sendMessage(sender.tab, "switch-network-2", request.data);
} else if (request.type == "chainID") {
await sendMessage(sender.tab, "chainID", request.data);
} else if (request.type == "submit-report") {
await sendMessage(sender.tab, "submit-report-2", request.data);
} else if (request.type == "transaction-update") {
await sendMessage(sender.tab, "transaction-update", request.data);
} else if (request.type == "get-stake-amount") {
await sendMessage(sender.tab, "get-stake-amount-2", request.data);
} else if (request.type == "stake-amount") {
await sendMessage(sender.tab, "stake-amount", request.data);
} else if (request.type == "alert-dont-show-again") {
/**
* @type {string[]}
*/
const dontShowAgainDomains = await chrome.storage.sync
.get(DONT_SHOW_AGAIN_DOMAINS_KEY)
.then((items) => items[DONT_SHOW_AGAIN_DOMAINS_KEY] || [])
.catch((error) => {
console.error(
`Error while getting ${DONT_SHOW_AGAIN_DOMAINS_KEY}`,
error
);
return [];
});
} else if (request.type == "close-website") {
const currentTab = (
await chrome.tabs.query({ active: true, currentWindow: true })
)[0];
if (currentTab.id == undefined) return;
chrome.tabs.remove(currentTab.id);
}
})()
.then((v) => {
if (v != undefined) sendResponse(v);
})
.catch((error) => {
console.error(error);
chrome.storage.sync.set({
[DONT_SHOW_AGAIN_DOMAINS_KEY]: dontShowAgainDomains.concat(
request.data.url
),
});
} else if (request.type == "close-website") {
const currentTab = (
await chrome.tabs.query({ active: true, currentWindow: true })
)[0];
if (currentTab.id == undefined) return;
chrome.tabs.remove(currentTab.id);
}
return true;
}

chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
console.log("msg in background", request, sender);
processMsg(request, sender, sendResponse)
return true;
});

Expand All @@ -761,4 +764,4 @@ function takeScreenshot(tab) {
}
);
});
}
}
75 changes: 36 additions & 39 deletions chrome-extension/src/components/ReviewForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,37 +161,31 @@ export default function ReviewForm() {
};

useEffect(() => {
console.log(
"connectingWallet triggered",
account,
stakeETH,
account,
chainId,
CHAIN_ID
);
if (account.loading) {
setButtonTxt("Connecting...");
setButtonDisabled(true);
} else if(chainId.chainId == CHAIN_ID) {
if (stakeETH.loading) {
setButtonTxt("loading...");
setButtonDisabled(true);
} else {
setButtonDisabled(false);
if (account.account && stakeETH.stakeETH == 0) {
setButtonTxt("loading...");
setButtonDisabled(true);
getStakeAmount();
} else if (account.account && stakeETH.stakeETH != 0) {
setButtonTxt("Report");
setButtonDisabled(false);
}
}
}
}, [account, stakeETH]);
console.log('connectingWallet triggered', account, stakeETH, account, stakeETH)
if(chainId.chainId == CHAIN_ID) {
if(account.loading) {
setButtonTxt("Connecting...")
setButtonDisabled(true)
} else if(stakeETH.loading){
setButtonTxt('loading...')
setButtonDisabled(true)
} else {
setButtonDisabled(false)
if(account.account && stakeETH.stakeETH == 0) {
setButtonTxt('loading...')
setButtonDisabled(true)
getStakeAmount()
} else if(account.account && stakeETH.stakeETH != 0) {
setButtonTxt("Report")
setButtonDisabled(false)
}
}
}

}, [account, stakeETH])

useEffect(() => {
console.log("chainId changed", chainId);
console.log('chainId triggered', chainId, CHAIN_ID, account)
if(chainId.loading) {
setButtonTxt("Switching...")
setButtonDisabled(true)
Expand All @@ -200,13 +194,13 @@ export default function ReviewForm() {
} else if(chainId.chainId == CHAIN_ID && account.account) {
setButtonDisabled(false)
if (account.account && stakeETH.stakeETH == 0) {
setButtonTxt("loading...");
setButtonDisabled(true);
getStakeAmount();
} else if (account.account && stakeETH.stakeETH != 0) {
setButtonTxt("Report");
setButtonDisabled(false);
}
setButtonTxt("loading...");
setButtonDisabled(true);
getStakeAmount();
} else if (account.account && stakeETH.stakeETH != 0) {
setButtonTxt("Report");
setButtonDisabled(false);
}
}
}, [chainId])

Expand Down Expand Up @@ -243,7 +237,9 @@ export default function ReviewForm() {
async function handleButtonClick() {
if (!account.account) {
connectWallet();
} else if (buttonTxt == "Report") {
} else if(buttonTxt == 'Switch Network') {
switchNetwork()
} else if (buttonTxt == "Report") {
reportDomain();
} else if(buttonTxt == 'Switch Network') {
connectWallet()
Expand Down Expand Up @@ -313,6 +309,7 @@ export default function ReviewForm() {
rules={[{ required: true }]}
>
<TextArea
style={{lineHeight: 1.3}}
rows={5}
value={fraudInfo.explanation}
onChange={(event) =>
Expand All @@ -323,7 +320,7 @@ export default function ReviewForm() {
"How? This website uses original logos and similar design as Uniswap. It prompts users to connect wallet and then automatically triggers Approve transactions to drain users wallet.",
].join("\n")}
/>
<span>Use this template message</span>
{/* <span>Use this template message</span> */}
</Form.Item>
) : null}

Expand All @@ -344,7 +341,7 @@ export default function ReviewForm() {
onChange={(event) =>
onFraudInfoChange("explanation", event.target.value)
}
placeholder="e.g. The website tries to look like a legitimate NFT site and claims to drop free NFTs to users. Upon interaction with the site, the website automatically trigger Approve token transactions to drain connected wallet."
placeholder="Example: The website tries to look like a legitimate NFT site and claims to drop free NFTs to users. Upon interaction with the site, the website automatically trigger Approve token transactions to drain connected wallet."
/>
</Form.Item>
) : null}
Expand Down
Loading

0 comments on commit 405940d

Please sign in to comment.