Skip to content

Commit

Permalink
feat: Add new test cases, enhance domain name whitelist matching, and…
Browse files Browse the repository at this point in the history
… optimize content script code
  • Loading branch information
0xbe37e committed Aug 14, 2024
1 parent 2a29d79 commit 0485405
Show file tree
Hide file tree
Showing 27 changed files with 565 additions and 344 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### v5.3.0

- [test] Add new test cases to ensure the functionality of the code is thoroughly tested
- [feat] Link Solana Fundflow to the current blockchain explorer
- [feat] Enhance domain name whitelist matching to support parameter-level and multi-level subdomain URL matching rules
- [chore] Optimize content script code
- [update] Phalcon Explorer Polygon will no longer support simulate functionality
- [fix] Fix the issue of Phalcon Explorer button not working on Jito Explorer

### v5.2.2

-[fix] Fix the issue of exporting CSV files causing character encoding problems
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metasuites",
"version": "5.2.2",
"version": "5.3.0",
"repository": {
"type": "git",
"url": "https://github.com/blocksecteam/metasuites.git"
Expand All @@ -22,9 +22,11 @@
"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\"'",
"lint": "eslint 'src/**/*.{ts,tsx}'"
"lint": "eslint 'src/**/*.{ts,tsx}'",
"test": "vitest"
},
"dependencies": {
"@remusao/url-match-patterns": "^1.2.0",
"antd": "^5.11.2",
"big.js": "^6.2.1",
"blockies-ts": "^1.0.0",
Expand Down Expand Up @@ -93,7 +95,8 @@
"terser": "^5.16.3",
"tslib": "2.4.0",
"typescript": "4.8.4",
"vite": "3.1.4"
"vite": "3.1.4",
"vitest": "^2.0.5"
},
"license": "Apache-2.0"
}
13 changes: 12 additions & 1 deletion src/common/components/ModalFundFlow/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,18 @@ export const nodeHover = (
ele.clone(true)

nodeAClone.classed('pointer', true).on('click', function () {
window.open(nodeData.url)
const isSolana = nodeData.chain === 'solana'
if (isSolana) {
try {
const url = new URL(nodeData.url)
url.hostname = window.location.hostname
window.open(url.href)
} catch (e) {
window.open(nodeData.url)
}
} else {
window.open(nodeData.url)
}
})

nodeAClone.selectAll('text').each(function (_: any, index: number) {
Expand Down
5 changes: 1 addition & 4 deletions src/common/config/allowlist.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
export default {
ETHERSCAN_V1_MATCHES: [
'*://opbnb-testnet.bscscan.com/*',
'*://goerli-optimism.etherscan.io/*'
],
ETHERSCAN_V1_MATCHES: ['*://opbnb-testnet.bscscan.com/*'],
ETHERSCAN_V2_MATCHES: [
'*://ftmscan.com/*',
'*://cn.etherscan.com/*',
Expand Down
14 changes: 2 additions & 12 deletions src/common/constants/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,7 @@ export const EXT_SUPPORT_WEB_LIST: ExtSupportWebsite[] = [
chain: 'optimism',
domains: ['optimistic.etherscan.io'],
siteName: 'ETHERSCAN',
logo: 'https://assets.blocksec.com/image/1671777583236-2.png',
testNets: [
{
name: 'Optimism Goerli',
chainID: 420,
chain: 'gor.optimism',
domains: ['goerli-optimism.etherscan.io'],
siteName: 'ETHERSCAN',
logo: 'https://assets.blocksec.com/image/1671777583236-2.png'
}
]
logo: 'https://assets.blocksec.com/image/1671777583236-2.png'
},
{
name: 'Optimism (Blockscout)',
Expand Down Expand Up @@ -503,7 +493,7 @@ export const PHALCON_SUPPORT_LIST = [
{
pathname: 'polygon',
chain: 'polygon',
supportSimulator: true
supportSimulator: false
},
{
pathname: 'bsc',
Expand Down
2 changes: 1 addition & 1 deletion src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare const ButtonTypes: [
'secondary'
]

export type ButtonType = typeof ButtonTypes[number]
export type ButtonType = (typeof ButtonTypes)[number]

export interface BaseComponent {
style?: CSSProperties
Expand Down
22 changes: 6 additions & 16 deletions src/common/utils/permission.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { uniq } from 'lodash-es'
import URLMatchPattern from '@remusao/url-match-patterns'

import type { OptWebsite } from '@src/store'
import {
DEDAUB_SUPPORT_DIRECT_LIST,
Expand All @@ -6,24 +9,11 @@ import {
OPENCHAIN_SUPPORT_LIST,
ETHERVM_SUPPORT_DIRECT_LIST
} from '@common/constants'
import { uniq } from 'lodash-es'

// TODO: Exclude the effect of the link in the parameters
export const isMatchURL = (url: string, patternList: string[]) => {
function toRegex(input: string) {
input = input.replace('*://', '(.*)://')
input = input.replace('*.', '(.*\\.|)')
input = input.replace('/*', '(.*)?')
return input
}

try {
return patternList.some(pattern => {
return new RegExp(toRegex(pattern)).test(url)
})
} catch (e) {
return false
}
return patternList.some(pattern => {
return URLMatchPattern(pattern, url)
})
}

/** judge from supportWebList */
Expand Down
20 changes: 12 additions & 8 deletions src/content/arkham/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import browser from 'webextension-polyfill'

import '@common/styles/inject.common'
import { URL_UPDATED } from '@common/constants'
import allowlist from '@common/config/allowlist'

import execute from './main'

export const initArkham = async () => {
execute()
browser.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (message === URL_UPDATED) {
execute()
sendResponse()
}
})
export class ArkhamInitializer {
static matches = allowlist.ARKHAM_MATCHES
async init() {
execute()
browser.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (message === URL_UPDATED) {
execute()
sendResponse()
}
})
}
}
67 changes: 36 additions & 31 deletions src/content/blockscout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,54 @@ import type { BlockscoutPageName } from '@common/constants'
import { BLOCKSCOUT_PAGES } from '@common/constants'
import { isAllowed, getChainSimpleName } from '@common/utils'
import { store } from '@src/store'
import allowlist from '@common/config/allowlist'

import { initTxPageScript, initAddressPageScript } from './page-scripts'
import './styles/index'
import { page } from './utils'
import './styles/index'

export const initBlockscout = async () => {
if (window.self !== window.top) {
return // This page is embedded in an iframe
}
/** get user options */
const supportWebList = await store.get('supportWebList')
export class BlockscoutInitializer {
static matches = allowlist.BLOCKSCOUT_MATCHES
async init() {
if (window.self !== window.top) {
return // This page is embedded in an iframe
}
/** get user options */
const supportWebList = await store.get('supportWebList')

/** check whether the script is allowed to run on the current page */
const allowed = isAllowed(Object.values(supportWebList))
/** check whether the script is allowed to run on the current page */
const allowed = isAllowed(Object.values(supportWebList))

/** get the necessary parameters required by the extension */
const chain: string | undefined = getChainSimpleName()
/** get the necessary parameters required by the extension */
const chain: string | undefined = getChainSimpleName()

if (!allowed || !chain) return
if (!allowed || !chain) return

page.runScript((pageName: string) => {
switch (pageName) {
case BLOCKSCOUT_PAGES.TX.name: {
const { pattern } = BLOCKSCOUT_PAGES[pageName as BlockscoutPageName]
const [, txHash] = window.location.pathname.match(pattern) || []
page.runScript((pageName: string) => {
switch (pageName) {
case BLOCKSCOUT_PAGES.TX.name: {
const { pattern } = BLOCKSCOUT_PAGES[pageName as BlockscoutPageName]
const [, txHash] = window.location.pathname.match(pattern) || []

if (!txHash) return
if (!txHash) return

const tab = new URL(window.location.href).searchParams.get('tab')
const tab = new URL(window.location.href).searchParams.get('tab')

if (!(tab === null || tab === 'index')) return
if (!(tab === null || tab === 'index')) return

initTxPageScript(chain, txHash)
break
}
case BLOCKSCOUT_PAGES.ADDRESS.name: {
const { pattern } = BLOCKSCOUT_PAGES[pageName as BlockscoutPageName]
const [, addressHash] = window.location.pathname.match(pattern) || []
initTxPageScript(chain, txHash)
break
}
case BLOCKSCOUT_PAGES.ADDRESS.name: {
const { pattern } = BLOCKSCOUT_PAGES[pageName as BlockscoutPageName]
const [, addressHash] = window.location.pathname.match(pattern) || []

if (!addressHash) return
if (!addressHash) return

initAddressPageScript(chain, addressHash)
break
initAddressPageScript(chain, addressHash)
break
}
}
}
})
})
}
}
8 changes: 6 additions & 2 deletions src/content/blocksec/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { MSG_METADOCK_INSTALLED } from '@common/constants'
import allowlist from '@common/config/allowlist'

export const initBlockSec = () => {
window.postMessage(MSG_METADOCK_INSTALLED)
export class BlockSecInitializer {
static matches = allowlist.BLOCKSEC_MATCHES
init() {
window.postMessage(MSG_METADOCK_INSTALLED)
}
}
20 changes: 12 additions & 8 deletions src/content/btc/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import browser from 'webextension-polyfill'
import '@common/styles/inject.common'

import { EXECUTE_BTC_CONTENT_SCRIPT } from '@common/constants'
import allowlist from '@common/config/allowlist'

import execute from './main'

export const initBTCExplorer = () => {
execute()
browser.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (message === EXECUTE_BTC_CONTENT_SCRIPT) {
execute()
sendResponse()
}
})
export class BTCInitializer {
static matches = allowlist.BTC_EXPLORER_MATCHES
async init() {
execute()
browser.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (message === EXECUTE_BTC_CONTENT_SCRIPT) {
execute()
sendResponse()
}
})
}
}
34 changes: 19 additions & 15 deletions src/content/debank/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@ import browser from 'webextension-polyfill'
import '@common/styles/inject.common'
import { URL_UPDATED } from '@common/constants'
import { store } from '@src/store'
import allowlist from '@common/config/allowlist'

import { renderMainAddressLabel } from './feat-scripts'
import { lazyLoad } from './helper'

export const initDebank = async () => {
execute()
async function execute() {
const { enablePrivateLabels } = await store.get('options')
// profile page
if (/^\/profile\/(0x[a-fA-F\d]{40})/i.test(window.location.pathname)) {
lazyLoad(() => {
if (enablePrivateLabels) renderMainAddressLabel()
}, 'div[class^="HeaderInfo_headerInfo"]')
export class DebankInitializer {
static matches = allowlist.DEBANK_MATCHES
async init() {
execute()
async function execute() {
const { enablePrivateLabels } = await store.get('options')
// profile page
if (/^\/profile\/(0x[a-fA-F\d]{40})/i.test(window.location.pathname)) {
lazyLoad(() => {
if (enablePrivateLabels) renderMainAddressLabel()
}, 'div[class^="HeaderInfo_headerInfo"]')
}
}
browser.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (message === URL_UPDATED) {
execute()
sendResponse()
}
})
}
browser.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (message === URL_UPDATED) {
execute()
sendResponse()
}
})
}
Loading

0 comments on commit 0485405

Please sign in to comment.