From 3f810edadea32f1336b1a06b542dd1c89fe7e7ee Mon Sep 17 00:00:00 2001 From: cong_wang Date: Thu, 12 Dec 2024 17:25:47 +0800 Subject: [PATCH] chore: Add new trigger for Solscan --- CHANGELOG.md | 4 ++ package.json | 2 +- src/background/listeners/explore.ts | 6 ++- src/common/api/index.ts | 9 +++- src/common/api/types.ts | 7 +++ src/common/constants/event.ts | 1 + src/common/event/index.ts | 7 ++- src/content/solscan/helper.ts | 51 ++++++++++++++++++++ src/content/solscan/page-scripts/account.tsx | 3 +- src/content/solscan/page-scripts/token.tsx | 3 +- 10 files changed, 85 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab65af3..34b7c7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### v5.5.1 + +- [fix] Fixed known issues + ### v5.5.0 - [feat] Adapt to OKX Explorer diff --git a/package.json b/package.json index a2d4d7d..705e0a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "metasuites", - "version": "5.5.0", + "version": "5.5.2", "repository": { "type": "git", "url": "https://github.com/blocksecteam/metasuites.git" diff --git a/src/background/listeners/explore.ts b/src/background/listeners/explore.ts index 974d533..634b565 100644 --- a/src/background/listeners/explore.ts +++ b/src/background/listeners/explore.ts @@ -25,7 +25,8 @@ import { GET_CREATION_BLOCK, GET_CONTRACT_VARIABLE_LOGS, GET_CONTRACT_VARIABLE_LIST, - GET_SIMULATION_FEES + GET_SIMULATION_FEES, + POST_ADDRESS_TAGS } from '@common/constants' import commonApi from '@common/api' @@ -113,4 +114,7 @@ export default function initExploreRequest() { chromeEvent.on(GET_SIMULATION_FEES, async params => { return await commonApi.getSimulationFees(params) }) + chromeEvent.on(POST_ADDRESS_TAGS, async params => { + return await commonApi.postAddressTags(params) + }) } diff --git a/src/common/api/index.ts b/src/common/api/index.ts index 856f1ed..092862f 100644 --- a/src/common/api/index.ts +++ b/src/common/api/index.ts @@ -42,7 +42,8 @@ import type { PostContractVariableLogsReq, ContractVariableLog, ContractVariableListItem, - SimulationFeesParams + SimulationFeesParams, + PostAddressTagsReq } from './types' export default { @@ -208,5 +209,9 @@ export default { return request .get(`api/v1/simulation/${chain}/base-fee?${queryString}`) .json>() - } + }, + postAddressTags: (params: PostAddressTagsReq) => + request + .post('api/v1/address-tags', { json: params }) + .json>() } diff --git a/src/common/api/types.ts b/src/common/api/types.ts index e770de8..158438b 100644 --- a/src/common/api/types.ts +++ b/src/common/api/types.ts @@ -381,3 +381,10 @@ export interface SimulationFeesParams { blockNumber?: number isPrerun: boolean } + +export interface PostAddressTagsReq { + chain: string + address: string + labels?: string[] + nameTag?: string +} diff --git a/src/common/constants/event.ts b/src/common/constants/event.ts index 76423c9..96b0bee 100644 --- a/src/common/constants/event.ts +++ b/src/common/constants/event.ts @@ -42,3 +42,4 @@ export const GET_SOLSCAN_TRANSACTION = 'getSolscanTransaction' export const GET_SOLSCAN_BLOCK_TXS = 'getSolscanBlockTxList' export const GET_SOLANAFM_ACCOUNT_INFO = 'getSolanaFMAccountInfo' export const GET_SOLANAFM_ACCOUNT_TRANSFERS = 'getSolanaFMAccountTransfers' +export const POST_ADDRESS_TAGS = 'postAddressTags' diff --git a/src/common/event/index.ts b/src/common/event/index.ts index d0fc115..88f3a00 100644 --- a/src/common/event/index.ts +++ b/src/common/event/index.ts @@ -21,7 +21,8 @@ import type { PostSignatureReq, PostContractVariableLogsReq, FundFlowParams, - SimulationFeesParams + SimulationFeesParams, + PostAddressTagsReq } from '@common/api/types' import type { REFRESH, @@ -54,7 +55,8 @@ import type { GET_CONTRACT_VARIABLE_LOGS, GET_CREATION_BLOCK, GET_CONTRACT_VARIABLE_LIST, - GET_SIMULATION_FEES + GET_SIMULATION_FEES, + POST_ADDRESS_TAGS } from '@common/constants/event' export type EventInfo = { @@ -89,6 +91,7 @@ export type EventInfo = { [GET_CREATION_BLOCK]: PostAddressParams [GET_CONTRACT_VARIABLE_LIST]: PostPrivateVariablesParams [GET_SIMULATION_FEES]: SimulationFeesParams + [POST_ADDRESS_TAGS]: PostAddressTagsReq } export const chromeEvent = new Event(SCOPE) diff --git a/src/content/solscan/helper.ts b/src/content/solscan/helper.ts index 70d6597..4148b1f 100644 --- a/src/content/solscan/helper.ts +++ b/src/content/solscan/helper.ts @@ -1,4 +1,7 @@ import $ from 'jquery' +import { chromeEvent } from '@common/event' +import { POST_ADDRESS_TAGS } from '@common/constants' +import { pickSolanaAddress } from '@common/utils' export const lazyLoad = ( callback: () => void, @@ -19,3 +22,51 @@ export const lazyLoad = ( }) } } + +export const getNameTag = () => { + const profile = $('.shadow-m > div:nth-of-type(2)')[1] + const tokenNameLabel = $(profile) + .find('> div:first-child > div:nth-of-type(1)') + .text() + if (tokenNameLabel.toLocaleLowerCase().indexOf('token name') > -1) { + return $(profile) + .find('> div:first-child > div:nth-of-type(2)') + .text() + .trim() + } + const publicNameLabel = $(profile) + .find('> div:first-child > div:nth-of-type(1)') + .text() + if (publicNameLabel.toLocaleLowerCase().indexOf('public name') > -1) { + return $(profile) + .find('> div:first-child > div:nth-of-type(2)') + .text() + .trim() + } +} + +export const getTags = () => { + const profile = $('.shadow-m > div:nth-of-type(2)')[1] + const tagsLabel = $(profile) + .find('> div:last-child > div:nth-of-type(1)') + .text() + if (tagsLabel.toLocaleLowerCase().indexOf('tags') > -1) { + const container = $(profile).find( + '> div:last-child > div:nth-of-type(2) > div > div' + ) + return container.map((index, el) => el.innerText.trim()).get() + } + return [] +} + +export const trigger = async () => { + const address = pickSolanaAddress(window.location.pathname) + console.log('trigger', address) + if (!address) return + await chromeEvent.emit(POST_ADDRESS_TAGS, { + chain: 'solana', + address, + labels: getTags(), + nameTag: getNameTag() + }) +} diff --git a/src/content/solscan/page-scripts/account.tsx b/src/content/solscan/page-scripts/account.tsx index 9c97738..c86b745 100644 --- a/src/content/solscan/page-scripts/account.tsx +++ b/src/content/solscan/page-scripts/account.tsx @@ -9,7 +9,7 @@ import { renderEnhancedLabels, renderTransactionHashPhalconLink } from '../feat-scripts' -import { lazyLoad } from '../helper' +import { lazyLoad, trigger } from '../helper' const initAccountPageScript = async () => { const { fundFlow, enhancedLabels, quick2Parsers } = await store.get('options') @@ -20,6 +20,7 @@ const initAccountPageScript = async () => { renderMainAddressLabel() renderEnhancedLabels() } + trigger() }, '#account-tabs') lazyLoad( diff --git a/src/content/solscan/page-scripts/token.tsx b/src/content/solscan/page-scripts/token.tsx index f25e784..fb68032 100644 --- a/src/content/solscan/page-scripts/token.tsx +++ b/src/content/solscan/page-scripts/token.tsx @@ -4,7 +4,7 @@ import { store } from '@src/store' import { GET_SOLSCAN_ACCOUNT_TAB_DATA, SOLSCAN_PAGES } from '@common/constants' import { renderFundFlowButton, renderEnhancedLabels } from '../feat-scripts' -import { lazyLoad } from '../helper' +import { lazyLoad, trigger } from '../helper' const initTokenPageScript = async () => { const { fundFlow, enhancedLabels } = await store.get('options') @@ -14,6 +14,7 @@ const initTokenPageScript = async () => { if (enhancedLabels) { renderEnhancedLabels() } + trigger() }, 'div[data-state="active"] table tbody tr:not(:has(div.animate-pulse))') browser.runtime.onMessage.addListener((message, _sender, sendResponse) => {