From 103497f7c70de3e0bdcdbc8c7aa2985f9b11c1a4 Mon Sep 17 00:00:00 2001 From: cong_wang Date: Fri, 8 Sep 2023 19:31:33 +0800 Subject: [PATCH] feat: Enhanced Dedaub support, automated workflows, fixed Ethereum chain restriction, and resolved website list issue --- CHANGELOG.md | 7 + README.md | 6 +- build/firefox.js | 6 +- build/safari.js | 6 +- manifest.config.ts | 2 +- package.json | 15 +- src/assets/images/logo-circle.png | Bin 830 -> 0 bytes src/assets/images/logo-pure.png | Bin 1212 -> 0 bytes src/common/components/Cell/cell.tsx | 52 +++--- src/common/components/Cell/index.module.less | 72 ++++---- .../components/RarityLabel/index.module.less | 5 +- src/common/components/RarityLabel/index.tsx | 6 +- src/common/components/TokenSymbol/index.tsx | 15 +- .../components/icon/IconMetaDock/index.tsx | 99 +++++++++++ src/common/components/icon/index.ts | 1 + .../constants/abstract/BaseConstants.ts | 104 +++++++++++ src/common/constants/support.ts | 31 +++- src/common/utils/brower.ts | 3 + src/common/utils/permission.ts | 31 +++- src/content/btc/main.tsx | 7 +- .../ContractVariableLogBtn/index.tsx | 2 +- .../ModalFundFlowGraph/index.module.less | 2 +- .../components/ModalFundFlowGraph/index.tsx | 9 +- .../etherscan/components/ParsersBtn/index.tsx | 82 +++++---- .../components/SimulateBtn/index.tsx | 2 +- .../feat-scripts/contract-variable-logs.tsx | 4 +- .../etherscan/feat-scripts/evm-storage.tsx | 3 +- .../etherscan/feat-scripts/quick2parsers.tsx | 5 +- .../feat-scripts/transaction-explanation.tsx | 2 + .../feat-scripts/transaction-simulator.tsx | 3 +- src/content/etherscan/index.tsx | 6 +- .../etherscan/page-scripts/address.tsx | 5 +- src/content/etherscan/page-scripts/token.tsx | 7 +- src/content/etherscan/page-scripts/tx.tsx | 5 +- .../feat-scripts/compliance-analysis.tsx | 5 +- src/content/opensea/index.tsx | 4 +- .../ContractVariableLogBtn/index.tsx | 2 +- .../ModalFundFlowGraph/index.module.less | 4 +- .../components/ModalFundFlowGraph/index.tsx | 11 +- .../scans/components/ParsersBtn/index.tsx | 82 +++++---- .../scans/components/SimulateBtn/index.tsx | 2 +- .../feat-scripts/contract-variable-logs.tsx | 4 +- .../scans/feat-scripts/quick2parsers.tsx | 3 +- src/content/scans/index.tsx | 4 +- src/content/scans/page-scripts/address.tsx | 2 +- src/content/scans/page-scripts/token.tsx | 7 +- src/content/scans/page-scripts/tx.tsx | 3 +- .../components/ConfigExploresDrawer/index.tsx | 162 ++++++++++++++---- .../components/ConfigNFTDrawer/index.tsx | 24 +-- .../index.module.less | 0 .../components/SupportWebsiteDrawer/index.tsx | 55 ++++++ .../SupportWebsitesDrawer/index.tsx | 51 ------ .../components/Settings/components/index.ts | 2 +- src/popup/components/Settings/index.tsx | 44 ++--- src/store/index.ts | 36 ++-- vite.config.ts | 1 + 56 files changed, 756 insertions(+), 357 deletions(-) delete mode 100644 src/assets/images/logo-circle.png delete mode 100644 src/assets/images/logo-pure.png create mode 100644 src/common/components/icon/IconMetaDock/index.tsx create mode 100644 src/common/constants/abstract/BaseConstants.ts rename src/popup/components/Settings/components/{SupportWebsitesDrawer => SupportWebsiteDrawer}/index.module.less (100%) create mode 100644 src/popup/components/Settings/components/SupportWebsiteDrawer/index.tsx delete mode 100644 src/popup/components/Settings/components/SupportWebsitesDrawer/index.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 4594b56..0659cef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### v3.6.0 + +- [feat] Improve MetaDock's Dedaub Support +- [build] Configure GitHub Actions for automated workflows +- [fix] Fix evm.storage to only support Ethereum chain +- [fix] Fix the issue of the supported website list becoming invalid in the settings + ### v3.5.0 - [feat] Change logo diff --git a/README.md b/README.md index b9778e5..b2f5b62 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ yarn ### Chrome and Firefox -- Build the project to the `/dist` folder with `yarn build:prod` or `yarn build-firefox:prod`. +- Build the project to the `/dist/*` folder with `yarn build:prod` or `yarn build-firefox:prod`. ```shell # chrome @@ -40,7 +40,7 @@ yarn build:prod yarn build-firefox:prod # safari yarn build-safari:prod -xcrun safari-web-extension-converter --macos-only /path/to/metadock/dist +xcrun safari-web-extension-converter --macos-only /path/to/metadock/dist/safari-extension ``` - Optionally, you may run `yarn dev` to run dev mode. @@ -57,7 +57,7 @@ To build the extension for distribution, or to run it locally for testing purpos # step 1 yarn build-safari:prod # step 2 -xcrun safari-web-extension-converter --macos-only /path/to/metadock/dist +xcrun safari-web-extension-converter --macos-only /path/to/metadock/dist/safari-extension ``` For more information on building and debugging Safari extensions, see the [official documentation](https://developer.apple.com/documentation/safariservices/safari_web_extensions/). diff --git a/build/firefox.js b/build/firefox.js index da8729a..420ab05 100644 --- a/build/firefox.js +++ b/build/firefox.js @@ -66,7 +66,7 @@ function main() { // Copy background.html to dist/ fs.cp( path.join(__dirname, './', 'background.html'), - path.join(__dirname, '../dist', 'background.html'), + path.join(__dirname, '../dist/firefox-extension', 'background.html'), err => { if (err) throw err } @@ -74,7 +74,9 @@ function main() { // Smooth out the differences in the configuration file: chrome v3 => firefox v2 // TODO: Upgrade to firefox v3 - defineFirefoxManifestV2(path.join(__dirname, '../dist', 'manifest.json')) + defineFirefoxManifestV2( + path.join(__dirname, '../dist/firefox-extension', 'manifest.json') + ) } main() diff --git a/build/safari.js b/build/safari.js index def413e..2a7459b 100644 --- a/build/safari.js +++ b/build/safari.js @@ -36,7 +36,7 @@ function main() { // Copy background.html to dist/ fs.cp( path.join(__dirname, './', 'background.html'), - path.join(__dirname, '../dist', 'background.html'), + path.join(__dirname, '../dist/safari-extension', 'background.html'), err => { if (err) throw err } @@ -44,7 +44,9 @@ function main() { // Smooth out the differences in the configuration file: chrome v3 => firefox v2 // TODO: Upgrade to firefox v3 - defineSafariManifestV2(path.join(__dirname, '../dist', 'manifest.json')) + defineSafariManifestV2( + path.join(__dirname, '../dist/safari-extension', 'manifest.json') + ) } main() diff --git a/manifest.config.ts b/manifest.config.ts index c15ce42..95293ff 100644 --- a/manifest.config.ts +++ b/manifest.config.ts @@ -4,7 +4,7 @@ import { ConfigEnv } from 'vite' import { version } from './package.json' export default defineManifest((env: ConfigEnv) => ({ - name: 'MetaDock', + name: "MetaDock - Builders' Swiss Army Knife", description: 'Improve the usability of blockchain explorers, including BTC.com, Etherscan, BscScan, and *scans of most EVM-compatible chains.', version: version, diff --git a/package.json b/package.json index 8f8dd63..d895e17 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "metadock", - "version": "3.5.0", + "version": "3.6.0", "repository": { "type": "git", "url": "https://github.com/blocksecteam/metadock.git" @@ -8,12 +8,13 @@ "type": "module", "scripts": { "dev": "vite --mode development", - "build:prod": "vite build --mode production", - "build:test": "vite build --mode test", - "build-firefox:prod": "yarn build:prod && node build/firefox.js", - "build-firefox:test": "yarn build:test && node build/firefox.js", - "build-safari:prod": "yarn build:prod && node build/safari.js", - "build-safari:test": "yarn build:test && node build/safari.js", + "build:prod": "vite build --mode production --outDir dist/chrome-extension", + "build:test": "vite build --mode test --outDir dist/chrome-extension", + "build-firefox:prod": "vite build --mode production --outDir dist/firefox-extension && node build/firefox.js", + "build-firefox:test": "vite build --mode test --outDir dist/firefox-extension && node build/firefox.js", + "build-safari:prod": "vite build --mode production --outDir dist/safari-extension && node build/safari.js", + "build-safari:test": "vite build --mode test --outDir dist/safari-extension && node build/safari.js", + "build:all": "yarn build:prod & yarn build-firefox:prod & yarn build-safari:prod", "stylelint": "stylelint \"**/*.{css,scss,less}\"", "stylelint:fix": "stylelint \"**/*.{css,scss,less}\" --fix", "prepare": "husky install && husky set .husky/pre-commit \"npx lint-staged\" && husky set .husky/commit-msg 'npx --no -- commitlint --edit \"$1\"'", diff --git a/src/assets/images/logo-circle.png b/src/assets/images/logo-circle.png deleted file mode 100644 index b1755746520cb789bbf5c9711a5cbad229271072..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 830 zcmV-E1Ht@>P)!hXNltNZ=>M~@LtlN#Xc*NnMp zhqhyJs7FhY75Mx1>hk2N%8zKGJ6f73_4)JV@7}o6qi&``UY#yhmm=Hg(A4F~#@w}| z#)t3r>UXP7+33xczIB4KT*=l{DHNvvJU$@m0*DWfrbm7GA83sFcW4v9 zyZ#6?luy?5ySqm$1PtzP;Fy{jL55fo*i9xoERz{Ar1}9$0>kAk!0mE~Kj=qDMTZu6 z*#gWq0NWQ@pd%WjfO`8Fas2uFHl_p`A|V9;_Nfdo`m?hOBqAmSria*v)8Z;jfmlSO zKo1Y})IZyQ7J*2FegYfi3t7()2!-?$$nbrmu0l5l=`BF`g7gg`BYYtgk+*;%U+I_V z`x!GLkzz8DmZPIYS`q>YnaVhR^Gao^m=u1+l+pq?{Hxs6QO<;+D021uG<{9 diff --git a/src/assets/images/logo-pure.png b/src/assets/images/logo-pure.png deleted file mode 100644 index 515cccde02434049c75e4f7804209db3b6ecce5d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1212 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H3?#oinD`S&%?$7faRt(@-8?QmJkCAbE+E9? z(hXv`cJqP+Colj>hysW#NLepPJq+=>_V77FxV^kCUF@D+T#j8rFj)KIopV&A4xW zZD)X$!o?YCGJ?F%mvtA2a6b<7V%;>^_{hTYBnj6xmM0$^fx4L&c)B=-RNT5d`?cRI z2Z4s;L2I_KW<@{k;}F@?Fun4ByY)#!_2N5@x89VccihkS+~;s-XS4Kf=L?Lkrx*l( zmoIRMdLVvUQ^TN|>!bWd1-3-HcH2MmbGR4nd7km<6Hk)Qw~DTh${hyv93M?iX0iXX z)ccU$#AQ=_{rG1Q;SVQDI=8m?8-F;O+v59z_n@$B&WRUd9G;Aes`*>m7~JHuWf_w$ zM=e-qWyU13;%@UhQQ?eJucM_Mug4v*4X9_0722SnE!*^t<6>094!?t4zik(FGYH;d zdG*u1bw_ zy@UPLal=LBj6HeR3MSpva;yeQ#IkmXF>&X()k?NzC<;s|*b>AMCFsFty=ux6R*l;; z-n6p*IR9gwH+Rl9xBUrMCyR8fdnDZNp`o^6&NZ9G_gG#{dTaDqe}ly#$w$tQLL1t@ zDAhFN@7eoH#9;C)$BvGP6U*)QR|t3XmN_=Xrvxi6yi*~NaHdFw>&LNQYM=BHp7cIE zprN&^j+^2zkdkFPD`j3s5oTYq8*mBMQ20rtDyhs zVJTZR3icnY`emqXd|OB&!C32Y=#P#lp$w_K{D{>HSF1U!Z<@uhb#@4=M(uPFjpsR6 zl(jFs<-NJVJFMXsquVb%RfoR}i@$4W9+3W?si@tsE z4uNDFXA71Ox(u&peY(@^5O&K{qiP+K%fwY%Gcv3_R(rZSANQYYCOdJzwy759(lFhH zSJtRax%IW>(t)M`shb6hR&Tw(Fw}PO&YdNb6u3Ap>^`x-*0E9P>HU2R9KxdbeDAWZ z*z~Ygy}VIt`_1#S-^>-4_`&7=_j$$pjdNp9A1~Z|{-bL4YxfrWwBBj)KQtEYt-YOl z?M?CJrR}b2vrImo|7gEyL3xXsPkf}=v3+Xsr*po1-nD4V89Hju_IDj{QudwI z)MYF7FWgFVt3RLh=ba)ES*q{Oly9F9^?L2hpB}nqpM!!cw$7eD>(J@9d#;GYy;pDR zbiPp99w)z4m|x3sYF~^7lji)NN0@gzFOM&IwY2_C8RPRh@q!O4>OXmYmEhjhRI@JU ud|mzNho4#J)Wsk8`1}68gaQ`ze+;`j(}m7|V`l;8bOujXKbLh*2~7ZD#tsDl diff --git a/src/common/components/Cell/cell.tsx b/src/common/components/Cell/cell.tsx index ff0b156..5c3ce9e 100644 --- a/src/common/components/Cell/cell.tsx +++ b/src/common/components/Cell/cell.tsx @@ -17,31 +17,41 @@ export interface CellProps extends BaseComponent { } const Cell: FC = props => { - const { title, desc, action, icon, border = true, pointer, onClick } = props + const { + className, + style, + title, + desc, + action, + icon, + border = true, + pointer, + onClick + } = props return ( -
-
-
- {icon && } -
- {title} - {desc && {desc}} -
+
+
+ {icon && } +
+ {title} + {desc && {desc}}
- {action ? ( -
{action}
- ) : ( -
- -
- )}
+ {action !== undefined ? ( +
{action}
+ ) : ( +
+ +
+ )}
) } diff --git a/src/common/components/Cell/index.module.less b/src/common/components/Cell/index.module.less index b3c3d56..ffcf743 100644 --- a/src/common/components/Cell/index.module.less +++ b/src/common/components/Cell/index.module.less @@ -1,44 +1,42 @@ @import '@common/styles/common.less'; .container { - .content { - padding: 12px 20px; - display: flex; - align-items: center; - justify-content: space-between; - font-size: 12px; - line-height: 15px; - &.border { - border-bottom: 1px solid #f0f0f2; - } - &.pointer { - cursor: pointer; - } - .icon { - width: 40px; - height: 40px; - margin-right: 14px; - } - .title { - .flex-column; - span { - font-size: 14px; - &:nth-of-type(1) { - font-weight: 400; - color: #000000; - line-height: 17px; - } - &:nth-of-type(2) { - color: #747478; - line-height: 17px; - margin-top: 3px; - } + padding: 12px 20px; + display: flex; + align-items: center; + justify-content: space-between; + font-size: 12px; + line-height: 15px; + &.border { + border-bottom: 1px solid #f0f0f2; + } + &.pointer { + cursor: pointer; + } + .icon { + width: 40px; + height: 40px; + margin-right: 14px; + } + .title { + .flex-column; + span { + font-size: 14px; + &:nth-of-type(1) { + font-weight: 400; + color: #000000; + line-height: 17px; + } + &:nth-of-type(2) { + color: #747478; + line-height: 17px; + margin-top: 3px; } } - .iconContainer { - width: 22px; - height: 22px; - .center; - } + } + .iconContainer { + width: 22px; + height: 22px; + .center; } } diff --git a/src/common/components/RarityLabel/index.module.less b/src/common/components/RarityLabel/index.module.less index dea80c2..6c6f441 100644 --- a/src/common/components/RarityLabel/index.module.less +++ b/src/common/components/RarityLabel/index.module.less @@ -15,7 +15,7 @@ div { transform: translateY(-14px); } - img { + .icon { transform: translateY(0); } } @@ -27,6 +27,7 @@ overflow: hidden; position: relative; margin-right: 3px; + .align-center; div { opacity: 1; @@ -37,7 +38,7 @@ transition: transform 0.2s ease-out 0s, opacity 0.2s ease-out 0s; .center; } - img { + .icon { height: 14px; width: 14px; position: absolute; diff --git a/src/common/components/RarityLabel/index.tsx b/src/common/components/RarityLabel/index.tsx index e4b2697..3020c96 100644 --- a/src/common/components/RarityLabel/index.tsx +++ b/src/common/components/RarityLabel/index.tsx @@ -1,9 +1,9 @@ import React, { type FC } from 'react' import { Tooltip, ConfigProvider } from 'antd' -import { getImageUrl, numFormatter } from '@common/utils' +import { numFormatter } from '@common/utils' import type { NFTRarityRankResItem } from '@common/api/types' -import { IconArrow } from '@common/components' +import { IconArrow, IconMetaDock } from '@common/components' import styles from './index.module.less' @@ -46,7 +46,7 @@ const RarityLabel: FC = ({ data: { rank, total } }) => {
#
- +
{numFormatter(rank.toString())}
diff --git a/src/common/components/TokenSymbol/index.tsx b/src/common/components/TokenSymbol/index.tsx index dd5a5a5..e446532 100644 --- a/src/common/components/TokenSymbol/index.tsx +++ b/src/common/components/TokenSymbol/index.tsx @@ -1,16 +1,18 @@ import { type FC } from 'react' -import { getImageUrl } from '@common/utils' import type { BaseComponent } from '@common/types' +import { IconMetaDock } from '@common/components' interface Props extends BaseComponent { logo?: string size?: number mr?: number ml?: number + color?: string } const TokenSymbol: FC = ({ + color, logo, style = {}, size = 14, @@ -29,13 +31,10 @@ const TokenSymbol: FC = ({ style ) - return ( - + return logo ? ( + + ) : ( + ) } diff --git a/src/common/components/icon/IconMetaDock/index.tsx b/src/common/components/icon/IconMetaDock/index.tsx new file mode 100644 index 0000000..02fa737 --- /dev/null +++ b/src/common/components/icon/IconMetaDock/index.tsx @@ -0,0 +1,99 @@ +import React, { type FC } from 'react' + +import type { BaseComponent } from '@common/types' + +interface Props extends BaseComponent { + color?: string + size?: number + ml?: number + mr?: number +} + +const IconDownload: FC = ({ + size = 16, + color = '#448C0C', + className, + style = {}, + ml = 0, + mr = 0 +}) => { + const stylesheet = Object.assign( + { + margin: 0, + marginLeft: ml, + marginRight: mr + }, + style + ) + + return ( + + + + + + + + + + + + + + + + + + + + + + + + + ) +} + +export default IconDownload diff --git a/src/common/components/icon/index.ts b/src/common/components/icon/index.ts index 1ad6b18..8111f46 100644 --- a/src/common/components/icon/index.ts +++ b/src/common/components/icon/index.ts @@ -3,3 +3,4 @@ export { default as IconCodeSnippet } from './IconCodeSnippet' export { default as IconDownload } from './IconDownload' export { default as IconClose } from './IconClose' export { default as IconRefresh } from './IconRefresh' +export { default as IconMetaDock } from './IconMetaDock' diff --git a/src/common/constants/abstract/BaseConstants.ts b/src/common/constants/abstract/BaseConstants.ts new file mode 100644 index 0000000..462bc10 --- /dev/null +++ b/src/common/constants/abstract/BaseConstants.ts @@ -0,0 +1,104 @@ +import type { FieldNames, BaseOptionType } from 'rc-select/lib/Select' +import type { ColumnFilterItem } from 'antd/es/table/interface' + +export default class BaseConstant { + static getEnumMap() { + const prototypeMap = Object.getOwnPropertyDescriptors(this) + const enumMap = {} as Record> + for (const prototypeName in prototypeMap) { + const val = prototypeMap[prototypeName].value + if (val instanceof BaseConstant && val._name) { + enumMap[val._name] = val + } + } + return enumMap + } + + static getEnumList() { + const prototypeMap = Object.getOwnPropertyDescriptors(this) + const enumList = [] + for (const prototypeName in prototypeMap) { + const val = prototypeMap[prototypeName].value + if (val instanceof BaseConstant && val._name) { + enumList.push(val) + } + } + return enumList as BaseConstant[] + } + + static getValueByName(name: string) { + const enumMap = this.getEnumMap() + const _enum = enumMap[name] + return _enum ? _enum.value() : null + } + + static getNameByValue(value: unknown) { + const enumList = this.getEnumList() + let name = '' + enumList.forEach(_enum => { + if (_enum.value() === value) { + name = _enum.name() + return true + } + }) + return name + } + + static getSelectOptionsByDescAndValue(fieldNames?: FieldNames) { + const enumList = this.getEnumList() + const options: BaseOptionType = [] + enumList.forEach(_enum => { + options.push({ + [fieldNames?.value ?? 'value']: _enum.value(), + [fieldNames?.label ?? 'label']: _enum.desc() + }) + }) + return options + } + + static getSelectOptionsByNameAndValue(fieldNames?: FieldNames) { + const enumList = this.getEnumList() + const options: BaseOptionType[] = [] + enumList.forEach(_enum => { + options.push({ + [fieldNames?.value ?? 'value']: _enum.value(), + [fieldNames?.label ?? 'label']: _enum.name() + }) + }) + return options + } + + static getColumnFilterItemsByNameAndValue() { + const enumList = this.getEnumList() + const options: ColumnFilterItem[] = [] + enumList.forEach(_enum => { + options.push({ + value: _enum.value(), + text: _enum.name() + }) + }) + return options + } + + _name: string + _value: V + _desc: string + + constructor(name: string, value: V, desc = '') { + this._name = name + this._value = value + this._desc = desc + } + + name() { + return this._name + } + + value() { + return this._value + } + + desc() { + return this._desc + } +} diff --git a/src/common/constants/support.ts b/src/common/constants/support.ts index 8577b0f..7473a4f 100644 --- a/src/common/constants/support.ts +++ b/src/common/constants/support.ts @@ -1,6 +1,8 @@ +import BaseConstant from './abstract/BaseConstants' + export const SCOPE = 'metaDockChromeExt' -interface ExtSupportWebsite { +export interface ExtSupportWebsite { name: string domains: string[] chain?: string @@ -151,7 +153,7 @@ export const PHALCON_SUPPORT_LIST = [ } ] -export const TRANSACTION_VIEWER_SUPPORT_LIST = [ +export const OPENCHAIN_SUPPORT_LIST = [ { pathname: 'ethereum', chain: 'eth' @@ -338,3 +340,28 @@ export const SIMULATE_SUPPORT_LIST = [ ] export const TX_EXPLAIN_SUPPORT_LIST = ['eth'] + +export const EVM_STORAGE_SUPPORT_LIST = ['eth'] + +export class TransactionParsers extends BaseConstant { + static PHALCON = new BaseConstant( + 'phalcon', + 'phalcon', + 'https://explorer.phalcon.xyz' + ) + static TENDERLY = new BaseConstant( + 'tenderly', + 'tenderly', + 'https://dashboard.tenderly.co' + ) + static OPENCHAIN = new BaseConstant( + 'openchain', + 'openchain', + 'https://openchain.xyz/trace' + ) + static DEDAUB = new BaseConstant( + 'dedaub', + 'dedaub', + 'https://library.dedaub.com' + ) +} diff --git a/src/common/utils/brower.ts b/src/common/utils/brower.ts index 9ba1a71..c4c0b3b 100644 --- a/src/common/utils/brower.ts +++ b/src/common/utils/brower.ts @@ -9,6 +9,9 @@ export const getURL = (path: string) => { } export const getImageUrl = (name: string, suffix = 'png') => { + if (name.startsWith('/')) { + return getURL(`/src/assets/${name.substring(1)}.${suffix}`) + } return getURL(`/src/assets/images/${name}.${suffix}`) } diff --git a/src/common/utils/permission.ts b/src/common/utils/permission.ts index 521cd9d..9c71223 100644 --- a/src/common/utils/permission.ts +++ b/src/common/utils/permission.ts @@ -3,13 +3,25 @@ import { DEDAUB_SUPPORT_DIRECT_LIST, PHALCON_SUPPORT_LIST, TENDERLY_SUPPORT_LIST, - TRANSACTION_VIEWER_SUPPORT_LIST, - TX_EXPLAIN_SUPPORT_LIST + OPENCHAIN_SUPPORT_LIST, + TX_EXPLAIN_SUPPORT_LIST, + EVM_STORAGE_SUPPORT_LIST } from '@common/constants' /** judge from supportWebList */ export const isAllowed = (supportWebList: OptWebsite[]): boolean => { - return (supportWebList as OptWebsite[]) + // TODO: There is a bug in getting store data, and there will be duplicate items. + const _supportWebList = [...supportWebList] + const map = new Map() + for (const item of supportWebList) { + const name = item.name + if (!map.has(name)) { + map.set(name, item) + } else { + _supportWebList.splice(map.get(name).index, 1) + } + } + return _supportWebList .filter(item => item.enabled) .map(item => item.domains) .flat() @@ -24,11 +36,8 @@ export const isSupportTenderly = (chain: string): boolean => { return TENDERLY_SUPPORT_LIST.findIndex(item => item.chain === chain) !== -1 } -export const isSupportTransactionViewer = (chain: string): boolean => { - return ( - TRANSACTION_VIEWER_SUPPORT_LIST.findIndex(item => item.chain === chain) !== - -1 - ) +export const isSupportOpenchain = (chain: string): boolean => { + return OPENCHAIN_SUPPORT_LIST.findIndex(item => item.chain === chain) !== -1 } export const isSupportDedaub = (chain: string): boolean => { @@ -42,7 +51,7 @@ export const isSupportParsers = (chain: string): boolean => { isSupportDedaub(chain) || isSupportTenderly(chain) || isSupportPhalcon(chain) || - isSupportTransactionViewer(chain) + isSupportOpenchain(chain) ) } @@ -54,3 +63,7 @@ export const isSupportSimulator = (chain: string) => { export const isSupportTxExplain = (chain: string) => { return TX_EXPLAIN_SUPPORT_LIST.findIndex(item => item === chain) !== -1 } + +export const isSupportEvmStorage = (chain: string) => { + return EVM_STORAGE_SUPPORT_LIST.findIndex(item => item === chain) !== -1 +} diff --git a/src/content/btc/main.tsx b/src/content/btc/main.tsx index b3afe9e..b4c450e 100644 --- a/src/content/btc/main.tsx +++ b/src/content/btc/main.tsx @@ -12,12 +12,11 @@ import { const runScript = debounce(async () => { /** get user options */ - const { enhancedLabels, supportWebList, showCopyIcon } = await store.get( - 'options' - ) + const { enhancedLabels, showCopyIcon } = await store.get('options') + const supportWebList = await store.get('supportWebList') /** check whether the script is allowed to run on the current page */ - const allowed = isAllowed(supportWebList as OptWebsite[]) + const allowed = isAllowed(Object.values(supportWebList)) /** get the necessary parameters required by the extension */ const chain: string | undefined = getChainSimpleName() diff --git a/src/content/etherscan/components/ContractVariableLogBtn/index.tsx b/src/content/etherscan/components/ContractVariableLogBtn/index.tsx index 7000392..bb083eb 100644 --- a/src/content/etherscan/components/ContractVariableLogBtn/index.tsx +++ b/src/content/etherscan/components/ContractVariableLogBtn/index.tsx @@ -33,7 +33,7 @@ const ContractVariableLogBtn: FC = ({ onClick, className, style }) => { style={style} onClick={handleClick} > - + Logs {error && ( diff --git a/src/content/etherscan/components/ModalFundFlowGraph/index.module.less b/src/content/etherscan/components/ModalFundFlowGraph/index.module.less index 05962fb..91262c7 100644 --- a/src/content/etherscan/components/ModalFundFlowGraph/index.module.less +++ b/src/content/etherscan/components/ModalFundFlowGraph/index.module.less @@ -225,7 +225,7 @@ width: 100%; .center; - img { + .iconMetaDock { width: 80px; height: 80px; animation-name: loading; diff --git a/src/content/etherscan/components/ModalFundFlowGraph/index.tsx b/src/content/etherscan/components/ModalFundFlowGraph/index.tsx index 3112153..f724f3e 100644 --- a/src/content/etherscan/components/ModalFundFlowGraph/index.tsx +++ b/src/content/etherscan/components/ModalFundFlowGraph/index.tsx @@ -17,7 +17,12 @@ import { EXT_SUPPORT_WEB_LIST, GET_ADDRESS_FUND_FLOW } from '@common/constants' import { chromeEvent } from '@common/event' import type { FundFlowRes, FundFlowEdge, FundFlowNode } from '@common/api/types' import { getImageUrl, getSubStr, unique } from '@common/utils' -import { IconDownload, Switch, IconClose } from '@common/components' +import { + IconDownload, + Switch, + IconClose, + IconMetaDock +} from '@common/components' import { SLEUTH_DOMAIN } from '@common/config/uri' import styles from './index.module.less' @@ -497,7 +502,7 @@ const ModalFundFlowGraph: FC = ({
{loading && (
- +
)} {error && ( diff --git a/src/content/etherscan/components/ParsersBtn/index.tsx b/src/content/etherscan/components/ParsersBtn/index.tsx index 7bbe159..a74eab8 100644 --- a/src/content/etherscan/components/ParsersBtn/index.tsx +++ b/src/content/etherscan/components/ParsersBtn/index.tsx @@ -4,8 +4,10 @@ import { DEDAUB_SUPPORT_DIRECT_LIST, PHALCON_SUPPORT_LIST, TENDERLY_SUPPORT_LIST, - TRANSACTION_VIEWER_SUPPORT_LIST + OPENCHAIN_SUPPORT_LIST, + TransactionParsers } from '@common/constants' +import { useStore } from '@common/hooks' import { getNodeValue } from '@common/utils' import styles from './index.module.less' @@ -16,6 +18,7 @@ interface Props { const ParsersBtn: FC = ({ chain }) => { const txHash = getNodeValue(document.querySelector('#spanTxHash')) + const [alternativeParsers] = useStore('alternativeParsers') if (!txHash) return null @@ -25,7 +28,7 @@ const ParsersBtn: FC = ({ chain }) => { const phalconPathname = PHALCON_SUPPORT_LIST.find( item => item.chain === chain )?.pathname - const transactionViewerPathname = TRANSACTION_VIEWER_SUPPORT_LIST.find( + const openchainPathname = OPENCHAIN_SUPPORT_LIST.find( item => item.chain === chain )?.pathname const tenderlyPathname = TENDERLY_SUPPORT_LIST.find( @@ -43,42 +46,45 @@ const ParsersBtn: FC = ({ chain }) => { Phalcon )} - {phalconPathname && transactionViewerPathname && ( - | - )} - {transactionViewerPathname && ( - - OpenChain - - )} - {transactionViewerPathname && tenderlyPathname && ( - | - )} - {tenderlyPathname && ( - - Tenderly - - )} - {dedaubPathname && ( - <> - | - - Dedaub - - - )} + {openchainPathname && + alternativeParsers[TransactionParsers.OPENCHAIN.value()] && ( + <> + | + + OpenChain + + + )} + {tenderlyPathname && + alternativeParsers[TransactionParsers.TENDERLY.value()] && ( + <> + | + + Tenderly + + + )} + {dedaubPathname && + alternativeParsers[TransactionParsers.DEDAUB.value()] && ( + <> + | + + Dedaub + + + )}
) } diff --git a/src/content/etherscan/components/SimulateBtn/index.tsx b/src/content/etherscan/components/SimulateBtn/index.tsx index 25db990..eabe63f 100644 --- a/src/content/etherscan/components/SimulateBtn/index.tsx +++ b/src/content/etherscan/components/SimulateBtn/index.tsx @@ -58,7 +58,7 @@ const SimulateBtn: FC = ({ style={style} onClick={handleClick} > - {loading ? : } + {loading ? : } Simulate ) diff --git a/src/content/etherscan/feat-scripts/contract-variable-logs.tsx b/src/content/etherscan/feat-scripts/contract-variable-logs.tsx index 3cf66c3..dc91ce0 100644 --- a/src/content/etherscan/feat-scripts/contract-variable-logs.tsx +++ b/src/content/etherscan/feat-scripts/contract-variable-logs.tsx @@ -102,9 +102,7 @@ export const genContractVariableLogsBtn = async (chain: string) => {
${variableNameEl.text()} - ( + ( ${ variable.visibility === ContractVariableVisibility.PRIVATE diff --git a/src/content/etherscan/feat-scripts/evm-storage.tsx b/src/content/etherscan/feat-scripts/evm-storage.tsx index 5f8865d..bf9d8f4 100644 --- a/src/content/etherscan/feat-scripts/evm-storage.tsx +++ b/src/content/etherscan/feat-scripts/evm-storage.tsx @@ -1,11 +1,12 @@ import { createRoot } from 'react-dom/client' import $ from 'jquery' -import { pickAddress } from '@common/utils' +import { pickAddress, isSupportEvmStorage } from '@common/utils' import { EvmStorageShortcut } from '@src/content/etherscan/components' /** Show evm.storage shortcut */ const genEvmStorageShortcut = async (chain: string) => { + if (!isSupportEvmStorage(chain)) return const mainAddress = pickAddress(window.location.pathname) if (!mainAddress) return diff --git a/src/content/etherscan/feat-scripts/quick2parsers.tsx b/src/content/etherscan/feat-scripts/quick2parsers.tsx index b337354..8d435f7 100644 --- a/src/content/etherscan/feat-scripts/quick2parsers.tsx +++ b/src/content/etherscan/feat-scripts/quick2parsers.tsx @@ -4,9 +4,8 @@ import { isSupportParsers } from '@common/utils' import ParsersBtn from '../components/ParsersBtn' -const genQuick2parsersBtn = (chain: string) => { - const isSupport = isSupportParsers(chain) - if (!isSupport) return +const genQuick2parsersBtn = async (chain: string) => { + if (!isSupportParsers(chain)) return const txHashEl = document.querySelector('#referralLink-1')?.parentElement diff --git a/src/content/etherscan/feat-scripts/transaction-explanation.tsx b/src/content/etherscan/feat-scripts/transaction-explanation.tsx index 135b032..8c16f27 100644 --- a/src/content/etherscan/feat-scripts/transaction-explanation.tsx +++ b/src/content/etherscan/feat-scripts/transaction-explanation.tsx @@ -3,8 +3,10 @@ import { isHexString } from 'ethers' import { createRoot } from 'react-dom/client' import { TransactionExplanation } from '@src/content/etherscan/components' +import { isSupportTxExplain } from '@common/utils' const genTransactionExplanation = async (chain: string) => { + if (!isSupportTxExplain(chain)) return const txHash = $('#spanTxHash').text() if (!isHexString(txHash, 32)) return diff --git a/src/content/etherscan/feat-scripts/transaction-simulator.tsx b/src/content/etherscan/feat-scripts/transaction-simulator.tsx index 2356df0..9cf26ba 100644 --- a/src/content/etherscan/feat-scripts/transaction-simulator.tsx +++ b/src/content/etherscan/feat-scripts/transaction-simulator.tsx @@ -1,7 +1,7 @@ import { createRoot } from 'react-dom/client' import $ from 'jquery' -import { pickAddress } from '@common/utils' +import { pickAddress, isSupportSimulator } from '@common/utils' import { DrawerSimulation } from '@common/components' import type { ReadableInputData } from '@common/components/DrawerSimulation/types' @@ -160,6 +160,7 @@ const renderUnverifiedSimulateButton = (chain: string, address: string) => { } export const genSimulateBtn = async (chain: string) => { + if (!isSupportSimulator(chain)) return const address = pickAddress(window.location.pathname) if (!address) return diff --git a/src/content/etherscan/index.tsx b/src/content/etherscan/index.tsx index 6ce6dd3..49a01a2 100644 --- a/src/content/etherscan/index.tsx +++ b/src/content/etherscan/index.tsx @@ -1,5 +1,5 @@ import '@common/styles/inject.common' -import { store } from '@src/store' +import { store, defaultValue } from '@src/store' import { isAllowed, getChainSimpleName, getPageName } from '@common/utils' import { SCAN_PAGES } from '@common/constants' @@ -23,10 +23,10 @@ const init = async () => { return // This page is embedded in an iframe } /** get user options */ - const { supportWebList } = await store.get('options') + const supportWebList = await store.get('supportWebList') /** check whether the script is allowed to run on the current page */ - const allowed = isAllowed(supportWebList) + const allowed = isAllowed(Object.values(supportWebList)) /** get the necessary parameters required by the extension */ const chain: string | undefined = getChainSimpleName() diff --git a/src/content/etherscan/page-scripts/address.tsx b/src/content/etherscan/page-scripts/address.tsx index e2c0c32..4c82070 100644 --- a/src/content/etherscan/page-scripts/address.tsx +++ b/src/content/etherscan/page-scripts/address.tsx @@ -1,6 +1,5 @@ import { store } from '@src/store' import { SCAN_PAGES } from '@common/constants' -import { isSupportSimulator } from '@common/utils' /** main features */ import { @@ -74,7 +73,6 @@ const initAddressPageScript = async (chain: string) => { if (dethCode) genQuickViewSourceCodeBtn(chain) if (quick2debank) genDeBankBtn() if (decompileInDedaub) genDecompileInDedaubBtn(chain) - if (dedaubStorage) genDedaubStorageShortcut(chain) if (utc2locale) convertUTC2locale(SCAN_PAGES.ADDRESS.name) if (quick2NFTGo) genNFTGoBtn() if (addressFunderLabel) displayContractFundFrom(chain) @@ -88,8 +86,9 @@ const initAddressPageScript = async (chain: string) => { if (formatContractParams) formatWriteContractParams() if (tokenMarketplaces) genTokenMarketplacesBtn(chain, SCAN_PAGES.ADDRESS.name) if (proxyLogs) genProxyContractLog(chain) + if (dedaubStorage) genDedaubStorageShortcut(chain) if (evmStorage) genEvmStorageShortcut(chain) - if (txSimulator && isSupportSimulator(chain)) genSimulateBtn(chain) + if (txSimulator) genSimulateBtn(chain) if (variableLogs) genContractVariableLogsBtn(chain) } diff --git a/src/content/etherscan/page-scripts/token.tsx b/src/content/etherscan/page-scripts/token.tsx index 31d1df1..e6e9ee1 100644 --- a/src/content/etherscan/page-scripts/token.tsx +++ b/src/content/etherscan/page-scripts/token.tsx @@ -18,7 +18,8 @@ import { genProxyContractLog, genEvmStorageShortcut, genSimulateBtn, - genContractVariableLogsBtn + genContractVariableLogsBtn, + genDedaubStorageShortcut } from '../feat-scripts' const initTokenPageScript = async (chain: string) => { @@ -38,7 +39,8 @@ const initTokenPageScript = async (chain: string) => { proxyLogs, evmStorage, txSimulator, - variableLogs + variableLogs, + dedaubStorage } = await store.get('options') if (enhancedLabels) genEnhancedLabels(chain) @@ -54,6 +56,7 @@ const initTokenPageScript = async (chain: string) => { if (formatContractParams) formatWriteContractParams() if (tokenMarketplaces) genTokenMarketplacesBtn(chain, SCAN_PAGES.TOKEN.name) if (proxyLogs) genProxyContractLog(chain) + if (dedaubStorage) genDedaubStorageShortcut(chain) if (evmStorage) genEvmStorageShortcut(chain) if (txSimulator && isSupportSimulator(chain)) genSimulateBtn(chain) if (variableLogs) genContractVariableLogsBtn(chain) diff --git a/src/content/etherscan/page-scripts/tx.tsx b/src/content/etherscan/page-scripts/tx.tsx index 6d182ce..2ed6733 100644 --- a/src/content/etherscan/page-scripts/tx.tsx +++ b/src/content/etherscan/page-scripts/tx.tsx @@ -1,5 +1,4 @@ import { store } from '@src/store' -import { isSupportParsers, isSupportTxExplain } from '@common/utils' import { SCAN_PAGES } from '@common/constants' import { @@ -23,14 +22,14 @@ const initTxPageScript = async (chain: string) => { txSummary } = await store.get('options') - if (quick2Parsers && isSupportParsers(chain)) genQuick2ParsersBtn(chain) + if (quick2Parsers) genQuick2ParsersBtn(chain) if (utc2locale) convertUTC2locale(SCAN_PAGES.TX.name) if (alternativeBlockExplorers) genAlternativeBlockExplorersBtn(SCAN_PAGES.TX.name, chain) if (txnFortaAlert) genTxFortaAlertTip(chain) if (showCopyIcon) genCopyIconBtn(SCAN_PAGES.TX.name) if (enhancedLabels) genTxPageAddressLabels(chain) - if (txSummary && isSupportTxExplain(chain)) genTransactionExplanation(chain) + if (txSummary) genTransactionExplanation(chain) } export default initTxPageScript diff --git a/src/content/opensea/feat-scripts/compliance-analysis.tsx b/src/content/opensea/feat-scripts/compliance-analysis.tsx index 98350fe..9c356f6 100644 --- a/src/content/opensea/feat-scripts/compliance-analysis.tsx +++ b/src/content/opensea/feat-scripts/compliance-analysis.tsx @@ -52,7 +52,10 @@ const genComplianceRadarPlot = async () => { const rootEl = document.createElement('div') rootEl.id = '__metadock-ComplianceRadarPlot__' if (!isMobile()) { - rootEl.setAttribute('style', 'position:absolute;right:0;top:0') + rootEl.setAttribute( + 'style', + 'position:absolute;right:0;top:0;z-index:2147483647;' + ) } containerEl.appendChild(rootEl) createRoot(rootEl).render() diff --git a/src/content/opensea/index.tsx b/src/content/opensea/index.tsx index 4831c8f..e88b366 100644 --- a/src/content/opensea/index.tsx +++ b/src/content/opensea/index.tsx @@ -12,9 +12,9 @@ import { } from './page-scripts' const runContentScript = debounce(async () => { - const { supportWebList } = await store.get('options') + const supportWebList = await store.get('supportWebList') - const allowed = isAllowed(supportWebList) + const allowed = isAllowed(Object.values(supportWebList)) if (!allowed) return diff --git a/src/content/scans/components/ContractVariableLogBtn/index.tsx b/src/content/scans/components/ContractVariableLogBtn/index.tsx index b9679aa..0e2d78e 100644 --- a/src/content/scans/components/ContractVariableLogBtn/index.tsx +++ b/src/content/scans/components/ContractVariableLogBtn/index.tsx @@ -33,7 +33,7 @@ const ContractVariableLogBtn: FC = ({ onClick, className, style }) => { style={style} onClick={handleClick} > - + Logs {error && ( diff --git a/src/content/scans/components/ModalFundFlowGraph/index.module.less b/src/content/scans/components/ModalFundFlowGraph/index.module.less index f0f954e..07d9907 100644 --- a/src/content/scans/components/ModalFundFlowGraph/index.module.less +++ b/src/content/scans/components/ModalFundFlowGraph/index.module.less @@ -206,7 +206,7 @@ right: 8px; bottom: 8px; width: 262px; - height: 57px; + height: 66px; cursor: pointer; img { width: 100%; @@ -226,7 +226,7 @@ width: 100%; .center; - img { + .iconMetaDock { width: 80px; height: 80px; animation-name: loading; diff --git a/src/content/scans/components/ModalFundFlowGraph/index.tsx b/src/content/scans/components/ModalFundFlowGraph/index.tsx index 0acbaab..ab4e154 100644 --- a/src/content/scans/components/ModalFundFlowGraph/index.tsx +++ b/src/content/scans/components/ModalFundFlowGraph/index.tsx @@ -17,7 +17,12 @@ import { EXT_SUPPORT_WEB_LIST, GET_ADDRESS_FUND_FLOW } from '@common/constants' import { chromeEvent } from '@common/event' import type { FundFlowRes, FundFlowEdge, FundFlowNode } from '@common/api/types' import { getImageUrl, getSubStr, unique } from '@common/utils' -import { IconDownload, Switch, IconClose } from '@common/components' +import { + IconDownload, + Switch, + IconClose, + IconMetaDock +} from '@common/components' import { SLEUTH_DOMAIN } from '@common/config/uri' import styles from './index.module.less' @@ -497,7 +502,7 @@ const ModalFundFlowGraph: FC = ({
{loading && (
- +
)} {error && ( @@ -536,7 +541,7 @@ const ModalFundFlowGraph: FC = ({ rel="noreferrer" > diff --git a/src/content/scans/components/ParsersBtn/index.tsx b/src/content/scans/components/ParsersBtn/index.tsx index 2a80f5a..6077790 100644 --- a/src/content/scans/components/ParsersBtn/index.tsx +++ b/src/content/scans/components/ParsersBtn/index.tsx @@ -4,9 +4,11 @@ import { DEDAUB_SUPPORT_DIRECT_LIST, PHALCON_SUPPORT_LIST, TENDERLY_SUPPORT_LIST, - TRANSACTION_VIEWER_SUPPORT_LIST + OPENCHAIN_SUPPORT_LIST, + TransactionParsers } from '@common/constants' import { getNodeValue } from '@common/utils' +import { useStore } from '@common/hooks' import styles from './index.module.less' @@ -16,6 +18,7 @@ interface Props { const ParsersBtn: FC = ({ chain }) => { const txHash = getNodeValue(document.getElementById('spanTxHash')) + const [alternativeParsers] = useStore('alternativeParsers') if (!txHash) return null @@ -25,7 +28,7 @@ const ParsersBtn: FC = ({ chain }) => { const phalconPathname = PHALCON_SUPPORT_LIST.find( item => item.chain === chain )?.pathname - const transactionViewerPathname = TRANSACTION_VIEWER_SUPPORT_LIST.find( + const transactionViewerPathname = OPENCHAIN_SUPPORT_LIST.find( item => item.chain === chain )?.pathname const tenderlyPathname = TENDERLY_SUPPORT_LIST.find( @@ -43,42 +46,45 @@ const ParsersBtn: FC = ({ chain }) => { Phalcon )} - {phalconPathname && transactionViewerPathname && ( - | - )} - {transactionViewerPathname && ( - - OpenChain - - )} - {transactionViewerPathname && tenderlyPathname && ( - | - )} - {tenderlyPathname && ( - - Tenderly - - )} - {dedaubPathname && ( - <> - | - - Dedaub - - - )} + {transactionViewerPathname && + alternativeParsers[TransactionParsers.OPENCHAIN.value()] && ( + <> + | + + OpenChain + + + )} + {tenderlyPathname && + alternativeParsers[TransactionParsers.TENDERLY.value()] && ( + <> + | + + Tenderly + + + )} + {dedaubPathname && + alternativeParsers[TransactionParsers.DEDAUB.value()] && ( + <> + | + + Dedaub + + + )}
) } diff --git a/src/content/scans/components/SimulateBtn/index.tsx b/src/content/scans/components/SimulateBtn/index.tsx index 25db990..eabe63f 100644 --- a/src/content/scans/components/SimulateBtn/index.tsx +++ b/src/content/scans/components/SimulateBtn/index.tsx @@ -58,7 +58,7 @@ const SimulateBtn: FC = ({ style={style} onClick={handleClick} > - {loading ? : } + {loading ? : } Simulate ) diff --git a/src/content/scans/feat-scripts/contract-variable-logs.tsx b/src/content/scans/feat-scripts/contract-variable-logs.tsx index 2380b23..0a8fb1a 100644 --- a/src/content/scans/feat-scripts/contract-variable-logs.tsx +++ b/src/content/scans/feat-scripts/contract-variable-logs.tsx @@ -102,9 +102,7 @@ export const genContractVariableLogsBtn = async (chain: string) => {
${variableNameEl.text()} - ( + ( ${ variable.visibility === ContractVariableVisibility.PRIVATE diff --git a/src/content/scans/feat-scripts/quick2parsers.tsx b/src/content/scans/feat-scripts/quick2parsers.tsx index b053006..4bdb3a1 100644 --- a/src/content/scans/feat-scripts/quick2parsers.tsx +++ b/src/content/scans/feat-scripts/quick2parsers.tsx @@ -5,8 +5,7 @@ import { isSupportParsers } from '@common/utils' import ParsersBtn from '../components/ParsersBtn' const genQuick2parsersBtn = (chain: string) => { - const isSupport = isSupportParsers(chain) - if (!isSupport) return + if (!isSupportParsers(chain)) return const txHashEl = document.querySelector( '#ContentPlaceHolder1_maintable > div > div:nth-child(2)' ) diff --git a/src/content/scans/index.tsx b/src/content/scans/index.tsx index 90216d8..e22048f 100644 --- a/src/content/scans/index.tsx +++ b/src/content/scans/index.tsx @@ -23,10 +23,10 @@ const init = async () => { } /** get user options */ - const { supportWebList } = await store.get('options') + const supportWebList = await store.get('supportWebList') /** check whether the script is allowed to run on the current page */ - const allowed = isAllowed(supportWebList) + const allowed = isAllowed(Object.values(supportWebList)) /** get the necessary parameters required by the extension */ const chain: string | undefined = getChainSimpleName() diff --git a/src/content/scans/page-scripts/address.tsx b/src/content/scans/page-scripts/address.tsx index aaf3bb4..a8b7058 100644 --- a/src/content/scans/page-scripts/address.tsx +++ b/src/content/scans/page-scripts/address.tsx @@ -70,7 +70,6 @@ const initAddressPageScript = async (chain: string) => { if (dethCode) genQuickViewSourceCodeBtn(chain) if (quick2debank) genDeBankBtn() if (decompileInDedaub) genDecompileInDedaubBtn(chain) - if (dedaubStorage) genDedaubStorageShortcut(chain) if (utc2locale) convertUTC2locale(SCAN_PAGES.ADDRESS.name) if (showCopyIcon) genCopyIconBtn(SCAN_PAGES.ADDRESS.name) if (quick2NFTGo) genNFTGoBtn() @@ -83,6 +82,7 @@ const initAddressPageScript = async (chain: string) => { if (privateVariables) genContractPrivateVariables(chain) if (formatContractParams) formatWriteContractParams() if (proxyLogs) genProxyContractLog(chain) + if (dedaubStorage) genDedaubStorageShortcut(chain) if (txSimulator && isSupportSimulator(chain)) genSimulateBtn(chain) if (variableLogs) genContractVariableLogsBtn(chain) } diff --git a/src/content/scans/page-scripts/token.tsx b/src/content/scans/page-scripts/token.tsx index 7dfc2ba..d3ec236 100644 --- a/src/content/scans/page-scripts/token.tsx +++ b/src/content/scans/page-scripts/token.tsx @@ -18,7 +18,8 @@ import { genDecompileInEthervmBtn, genProxyContractLog, genSimulateBtn, - genContractVariableLogsBtn + genContractVariableLogsBtn, + genDedaubStorageShortcut } from '../feat-scripts' const initTokenPageScript = async (chain: string) => { @@ -38,7 +39,8 @@ const initTokenPageScript = async (chain: string) => { decompileInEthervm, proxyLogs, txSimulator, - variableLogs + variableLogs, + dedaubStorage } = await store.get('options') if (showCopyIcon) genCopyIconBtn(SCAN_PAGES.TOKEN.name) if (enhancedLabels) genEnhancedLabels(chain) @@ -54,6 +56,7 @@ const initTokenPageScript = async (chain: string) => { if (decompileInDedaub) genDecompileInDedaubBtn(chain) if (decompileInEthervm) genDecompileInEthervmBtn(chain) if (proxyLogs) genProxyContractLog(chain) + if (dedaubStorage) genDedaubStorageShortcut(chain) if (txSimulator && isSupportSimulator(chain)) genSimulateBtn(chain) if (variableLogs) genContractVariableLogsBtn(chain) } diff --git a/src/content/scans/page-scripts/tx.tsx b/src/content/scans/page-scripts/tx.tsx index 2fe6d98..323e354 100644 --- a/src/content/scans/page-scripts/tx.tsx +++ b/src/content/scans/page-scripts/tx.tsx @@ -1,5 +1,4 @@ import { store } from '@src/store' -import { isSupportParsers } from '@common/utils' import { SCAN_PAGES } from '@common/constants' import { @@ -20,7 +19,7 @@ const initTxPageScript = async (chain: string) => { showCopyIcon, enhancedLabels } = await store.get('options') - if (quick2Parsers && isSupportParsers(chain)) genQuick2ParsersBtn(chain) + if (quick2Parsers) genQuick2ParsersBtn(chain) if (utc2locale) convertUTC2locale(SCAN_PAGES.TX.name) if (alternativeBlockExplorers) genAlternativeBlockExplorersBtn(SCAN_PAGES.TX.name, chain) diff --git a/src/popup/components/Settings/components/ConfigExploresDrawer/index.tsx b/src/popup/components/Settings/components/ConfigExploresDrawer/index.tsx index 9514879..93f80ac 100644 --- a/src/popup/components/Settings/components/ConfigExploresDrawer/index.tsx +++ b/src/popup/components/Settings/components/ConfigExploresDrawer/index.tsx @@ -1,23 +1,28 @@ import React, { type FC } from 'react' +import { Space, Checkbox, Switch } from 'antd' import type { OptKeys } from '@src/store' -import { Cell, Drawer, Switch } from '@common/components' +import { Cell, Drawer } from '@common/components' import { useStore } from '@common/hooks' +import { TransactionParsers } from '@common/constants' import styles from './index.module.less' interface Props { visible: boolean onClose: () => void - onChange: ( - key: Exclude, - value: boolean, - refresh?: boolean - ) => void + onSwitchChange: (key: OptKeys, value: boolean, refresh?: boolean) => void + onAlternativeParsersChange: (parser: string, enabled: boolean) => void } -const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { +const ConfigExploresDrawer: FC = ({ + visible, + onClose, + onSwitchChange, + onAlternativeParsersChange +}) => { const [options] = useStore('options') + const [alternativeParsers] = useStore('alternativeParsers') return ( @@ -28,8 +33,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show transaction summary" action={ onChange('txSummary', val)} + onChange={val => onSwitchChange('txSummary', val)} /> } /> @@ -37,8 +43,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show the fund flow chart" action={ onChange('fundFlow', val)} + onChange={val => onSwitchChange('fundFlow', val)} /> } /> @@ -46,8 +53,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show enhanced function signatures" action={ onChange('enhancedSignatures', val)} + onChange={val => onSwitchChange('enhancedSignatures', val)} /> } /> @@ -55,8 +63,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show compliance scores for addresses" action={ onChange('complianceScores', val)} + onChange={val => onSwitchChange('complianceScores', val)} /> } /> @@ -64,8 +73,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show enhanced address labels" action={ onChange('enhancedLabels', val)} + onChange={val => onSwitchChange('enhancedLabels', val)} /> } /> @@ -73,8 +83,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Convert UTC to Local Time Zone" action={ onChange('utc2locale', val)} + onChange={val => onSwitchChange('utc2locale', val)} /> } /> @@ -82,8 +93,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show enhanced copy icon" action={ onChange('showCopyIcon', val)} + onChange={val => onSwitchChange('showCopyIcon', val)} /> } /> @@ -91,8 +103,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show NFT floor price in major markets" action={ onChange('nftFloorPrice', val)} + onChange={val => onSwitchChange('nftFloorPrice', val)} /> } /> @@ -100,8 +113,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show the source of funding for contract deployers" action={ onChange('addressFunderLabel', val)} + onChange={val => onSwitchChange('addressFunderLabel', val)} /> } /> @@ -109,26 +123,80 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Enable batch download of contract source code and ABI" action={ onChange('contractSourcecode', val)} + onChange={val => onSwitchChange('contractSourcecode', val)} /> } /> onChange('quick2Parsers', val)} + onChange={val => onSwitchChange('quick2Parsers', val)} /> } /> + + + Openchain + + onAlternativeParsersChange( + TransactionParsers.OPENCHAIN.value(), + e.target.checked + ) + } + /> + + + Tenderly + + onAlternativeParsersChange( + TransactionParsers.TENDERLY.value(), + e.target.checked + ) + } + /> + + + Dedaub + + onAlternativeParsersChange( + TransactionParsers.DEDAUB.value(), + e.target.checked + ) + } + /> + +
+ } + /> onChange('quick2debank', val)} + onChange={val => onSwitchChange('quick2debank', val)} /> } /> @@ -136,18 +204,19 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show quick open in Dedaub for unverified contracts" action={ onChange('decompileInDedaub', val)} + onChange={val => onSwitchChange('decompileInDedaub', val)} /> } /> onChange('decompileInEthervm', val)} + onChange={val => onSwitchChange('decompileInEthervm', val)} /> } /> @@ -155,8 +224,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show quick open in DethCode for verified contracts" action={ onChange('dethCode', val)} + onChange={val => onSwitchChange('dethCode', val)} /> } /> @@ -164,8 +234,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show quick open in NFTGo for NFT contracts" action={ onChange('quick2NFTGo', val)} + onChange={val => onSwitchChange('quick2NFTGo', val)} /> } /> @@ -173,8 +244,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show export data for a part of transactions" action={ onChange('exportTableData', val)} + onChange={val => onSwitchChange('exportTableData', val)} /> } /> @@ -182,8 +254,11 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show alternative block explorers" action={ onChange('alternativeBlockExplorers', val)} + onChange={val => + onSwitchChange('alternativeBlockExplorers', val) + } /> } /> @@ -191,8 +266,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show approval diagnosis" action={ onChange('approvalDiagnosis', val)} + onChange={val => onSwitchChange('approvalDiagnosis', val)} /> } /> @@ -200,8 +276,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show enhanced address labels by Forta" action={ onChange('enhancedFortaLabels', val)} + onChange={val => onSwitchChange('enhancedFortaLabels', val)} /> } /> @@ -209,8 +286,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Alert suspicious transactions by Forta" action={ onChange('txnFortaAlert', val)} + onChange={val => onSwitchChange('txnFortaAlert', val)} /> } /> @@ -218,8 +296,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show private variables" action={ onChange('privateVariables', val)} + onChange={val => onSwitchChange('privateVariables', val)} /> } /> @@ -227,8 +306,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Quick format parameters" action={ onChange('formatContractParams', val)} + onChange={val => onSwitchChange('formatContractParams', val)} /> } /> @@ -236,8 +316,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show nft marketplaces" action={ onChange('tokenMarketplaces', val)} + onChange={val => onSwitchChange('tokenMarketplaces', val)} /> } /> @@ -246,8 +327,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show proxy upgrade log" action={ onChange('proxyLogs', val)} + onChange={val => onSwitchChange('proxyLogs', val)} /> } /> @@ -255,8 +337,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show Dedaub storage shortcut" action={ onChange('dedaubStorage', val)} + onChange={val => onSwitchChange('dedaubStorage', val)} /> } /> @@ -264,8 +347,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show evm.storage shortcut" action={ onChange('evmStorage', val)} + onChange={val => onSwitchChange('evmStorage', val)} /> } /> @@ -273,8 +357,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show transaction simulator" action={ onChange('txSimulator', val)} + onChange={val => onSwitchChange('txSimulator', val)} /> } /> @@ -283,8 +368,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show Variable Logs" action={ onChange('variableLogs', val)} + onChange={val => onSwitchChange('variableLogs', val)} /> } /> diff --git a/src/popup/components/Settings/components/ConfigNFTDrawer/index.tsx b/src/popup/components/Settings/components/ConfigNFTDrawer/index.tsx index 0a319d0..6262ce9 100644 --- a/src/popup/components/Settings/components/ConfigNFTDrawer/index.tsx +++ b/src/popup/components/Settings/components/ConfigNFTDrawer/index.tsx @@ -1,7 +1,8 @@ import React, { type FC } from 'react' +import { Switch } from 'antd' import type { OptKeys } from '@src/store' -import { Cell, Drawer, Switch } from '@common/components' +import { Cell, Drawer } from '@common/components' import { useStore } from '@common/hooks' import styles from './index.module.less' @@ -9,14 +10,14 @@ import styles from './index.module.less' interface Props { visible: boolean onClose: () => void - onChange: ( - key: Exclude, - value: boolean, - refresh?: boolean - ) => void + onSwitchChange: (key: OptKeys, value: boolean, refresh?: boolean) => void } -const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { +const ConfigExploresDrawer: FC = ({ + visible, + onClose, + onSwitchChange +}) => { const [options] = useStore('options') return ( @@ -28,8 +29,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show comprehensive risk graph of the collection" action={ onChange('nftCollectionRisk', val)} + onChange={val => onSwitchChange('nftCollectionRisk', val)} /> } /> @@ -37,8 +39,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show owner's address label" action={ onChange('nftOwnersLabel', val)} + onChange={val => onSwitchChange('nftOwnersLabel', val)} /> } /> @@ -47,8 +50,9 @@ const ConfigExploresDrawer: FC = ({ visible, onClose, onChange }) => { title="Show enhanced rarity information" action={ onChange('nftRarity', val)} + onChange={val => onSwitchChange('nftRarity', val)} /> } /> diff --git a/src/popup/components/Settings/components/SupportWebsitesDrawer/index.module.less b/src/popup/components/Settings/components/SupportWebsiteDrawer/index.module.less similarity index 100% rename from src/popup/components/Settings/components/SupportWebsitesDrawer/index.module.less rename to src/popup/components/Settings/components/SupportWebsiteDrawer/index.module.less diff --git a/src/popup/components/Settings/components/SupportWebsiteDrawer/index.tsx b/src/popup/components/Settings/components/SupportWebsiteDrawer/index.tsx new file mode 100644 index 0000000..d05ff1b --- /dev/null +++ b/src/popup/components/Settings/components/SupportWebsiteDrawer/index.tsx @@ -0,0 +1,55 @@ +import React, { type FC } from 'react' +import { Checkbox } from 'antd' + +import { getImageUrl } from '@common/utils' +import { Cell, Drawer } from '@common/components' +import { useStore } from '@common/hooks' +import { type OptWebsite } from '@src/store' +import { EXT_SUPPORT_WEB_LIST } from '@common/constants' + +import styles from './index.module.less' + +interface Props { + visible: boolean + onClose: () => void + onChange: (opt: OptWebsite, value: boolean) => void +} + +const SupportWebsiteDrawer: FC = ({ visible, onClose, onChange }) => { + const [supportWebList] = useStore('supportWebList') + + return ( + +
+
+ + {EXT_SUPPORT_WEB_LIST.map(item => { + const opt = Object.values(supportWebList).find( + opt => opt.name === item.name + )! + return ( + onChange(opt, e.target.checked)} + /> + } + onClick={() => onChange(opt, !opt.enabled)} + /> + ) + })} + +
+
+
+ ) +} + +export default SupportWebsiteDrawer diff --git a/src/popup/components/Settings/components/SupportWebsitesDrawer/index.tsx b/src/popup/components/Settings/components/SupportWebsitesDrawer/index.tsx deleted file mode 100644 index 33dab5b..0000000 --- a/src/popup/components/Settings/components/SupportWebsitesDrawer/index.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import React, { type FC } from 'react' - -import { unique, getImageUrl } from '@common/utils' -import type { OptWebsite } from '@src/store' -import { Cell, Checkbox, Drawer } from '@common/components' -import { useStore } from '@common/hooks' - -import styles from './index.module.less' - -interface Props { - visible: boolean - onClose: () => void - onChange: (opt: OptWebsite, value: boolean) => void -} - -const SupportWebsitesDrawer: FC = ({ visible, onClose, onChange }) => { - const [options] = useStore('options') - - return ( - -
-
- - {unique( - options.supportWebList as OptWebsite[], - 'name' - ).map(item => ( - onChange(item, val)} - /> - } - onClick={() => onChange(item, !item.enabled)} - /> - ))} - -
-
-
- ) -} - -export default SupportWebsitesDrawer diff --git a/src/popup/components/Settings/components/index.ts b/src/popup/components/Settings/components/index.ts index 6554275..562bf1a 100644 --- a/src/popup/components/Settings/components/index.ts +++ b/src/popup/components/Settings/components/index.ts @@ -1,3 +1,3 @@ -export { default as SupportWebsitesDrawer } from './SupportWebsitesDrawer' +export { default as SupportWebsiteDrawer } from './SupportWebsiteDrawer' export { default as ConfigNFTDrawer } from './ConfigNFTDrawer' export { default as ConfigExploresDrawer } from './ConfigExploresDrawer' diff --git a/src/popup/components/Settings/index.tsx b/src/popup/components/Settings/index.tsx index 2376bfc..d1aaddf 100644 --- a/src/popup/components/Settings/index.tsx +++ b/src/popup/components/Settings/index.tsx @@ -7,7 +7,7 @@ import { REFRESH } from '@common/constants' import { chromeEvent } from '@common/event' import { - SupportWebsitesDrawer, + SupportWebsiteDrawer, ConfigNFTDrawer, ConfigExploresDrawer } from './components' @@ -15,30 +15,26 @@ import styles from './index.module.less' const Settings: FC = () => { const [options, setOptions] = useStore('options') + const [supportWebList, setSupportWebList] = useStore('supportWebList') + const [alternativeParsers, setAlternativeParsers] = + useStore('alternativeParsers') const [configSupportWebVisible, setConfigSupportWebVisible] = useState(false) const [configExploresVisible, setConfigExploresVisible] = useState(false) const [configNFTVisible, setConfigNFTVisible] = useState(false) - const onWebsitesChange = (opt: OptWebsite, value: boolean) => { - const newWebOpt: OptWebsite[] = options.supportWebList.map(item => { - return { - ...item, - enabled: opt.name === item.name ? value : item.enabled + const onWebsiteChange = (opt: OptWebsite, value: boolean) => { + const newWebOpt = { ...supportWebList } + for (const key in newWebOpt) { + if (key === opt.name) { + newWebOpt[key].enabled = value } - }) - setOptions({ - ...options, - supportWebList: newWebOpt - }) + } + setSupportWebList(newWebOpt) onRefresh() } - const onChange = ( - key: Exclude, - value: boolean, - refresh = true - ) => { + const onSwitchChange = (key: OptKeys, value: boolean, refresh = true) => { setOptions({ ...options, [key]: value @@ -46,6 +42,13 @@ const Settings: FC = () => { if (refresh) onRefresh() } + const onAlternativeParsersChange = (parser: string, enabled: boolean) => { + setAlternativeParsers({ + ...alternativeParsers, + [parser]: enabled + }) + } + const onRefresh = () => { chromeEvent.emit(REFRESH, true) } @@ -69,20 +72,21 @@ const Settings: FC = () => { />
- setConfigSupportWebVisible(false)} - onChange={onWebsitesChange} + onChange={onWebsiteChange} /> setConfigExploresVisible(false)} - onChange={onChange} + onSwitchChange={onSwitchChange} + onAlternativeParsersChange={onAlternativeParsersChange} /> setConfigNFTVisible(false)} - onChange={onChange} + onSwitchChange={onSwitchChange} />
) diff --git a/src/store/index.ts b/src/store/index.ts index 1467492..c2ec013 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,12 +1,16 @@ import { ChromeStorage } from 'chrome-extension-core' -import { SCOPE, EXT_SUPPORT_WEB_LIST } from '@common/constants' +import { + SCOPE, + EXT_SUPPORT_WEB_LIST, + TransactionParsers, + type ExtSupportWebsite +} from '@common/constants' /** * current support options */ const OPTIONS = [ - 'supportWebList', 'fundFlow', 'enhancedSignatures', 'complianceScores', @@ -43,27 +47,26 @@ const OPTIONS = [ export type OptKeys = (typeof OPTIONS)[number] -export interface OptWebsite extends Record { - name: string - domains: string[] - enabled: boolean -} - export type Options = { - [key in OptKeys]: key extends 'supportWebList' ? OptWebsite[] : boolean + [key in OptKeys]: boolean } +export type OptWebsite = ExtSupportWebsite & { enabled: boolean } + export type StorageInfo = { + supportWebList: { + [key: ExtSupportWebsite['name']]: OptWebsite + } options: Options + alternativeParsers: Record } export const defaultValue: StorageInfo = { - /** default settings */ + supportWebList: EXT_SUPPORT_WEB_LIST.reduce((obj: any, item) => { + obj[item.name] = { ...item, enabled: true } + return obj + }, {}), options: { - supportWebList: EXT_SUPPORT_WEB_LIST.map(item => ({ - ...item, - enabled: true - })), fundFlow: true, enhancedSignatures: true, complianceScores: true, @@ -96,6 +99,11 @@ export const defaultValue: StorageInfo = { evmStorage: true, txSimulator: true, variableLogs: true + }, + alternativeParsers: { + [TransactionParsers.OPENCHAIN.name()]: true, + [TransactionParsers.TENDERLY.name()]: true, + [TransactionParsers.DEDAUB.name()]: false } } diff --git a/vite.config.ts b/vite.config.ts index 9a8628a..dee3277 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -32,6 +32,7 @@ export default defineConfig(({ mode }) => { open: '' }, build: { + outDir: 'dist/dev', sourcemap: false, assetsDir: 'bundle', minify: 'terser',