import { ethers } from "ethers"; import { VNode } from "vue"; import { gnosisSafeAbi, networkScanBaseUrl } from "./web3"; export type TaskCheckResponse = { status: "success" | "error" | "warning"; metadata?: object; }; export type TaskCheckFun = ({ address: string, provider: any, }) => PromiseLike; export type Task = { description: string; networkResults?: { [network: string]: TaskCheckResponse; }; renderMetadata?: ({ network: Network, metadata: object }) => VNode; renderMetadataValue?: ({ network: Network, key: string, value: any }) => VNode; statusStrategy?: "some" | "every"; check: TaskCheckFun; }; export const tasks: Array = [ { description: "This is an EOA", async check({ address, provider }) { const code = await provider.getCode(address); if (code != "0x") { return { status: "error" }; } return { status: "success" }; }, }, { description: "Not a smart contract address", statusStrategy: "some", async check({ address, provider }) { const code = await provider.getCode(address); if (code !== "0x") { return { status: "error" }; } return { status: "success" }; }, }, { description: "Not a gnosis safe address", statusStrategy: "some", async check({ address, provider }) { const contract = new ethers.Contract(address, gnosisSafeAbi, provider); try { const [owners, threshold] = await Promise.all([ contract.getOwners(), contract.getThreshold(), ]); return { status: "error", metadata: { owners, threshold: threshold.toString() }, }; } catch (error) { return { status: "success" }; } }, renderMetadataValue({ network, key, value }) { if (key === "owners") { return
    { value.map((owner : string) =>
  • {owner}
  • ) }
} return {String(value)} } }, { description: "This address has transactions", statusStrategy: "some", async check({ address, provider }) { const count = await provider.getTransactionCount(address); if (count === 0) { return { status: "error" }; } return { status: "success", metadata: { count } }; }, renderMetadata({ metadata }) { return {metadata.count} transaction(s) } }, ];