Skip to content

Commit

Permalink
chore: Add new trigger for Solscan
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbe37e committed Dec 12, 2024
1 parent 60c0298 commit 3f810ed
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v5.5.1

- [fix] Fixed known issues

### v5.5.0

- [feat] Adapt to OKX Explorer
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metasuites",
"version": "5.5.0",
"version": "5.5.2",
"repository": {
"type": "git",
"url": "https://github.com/blocksecteam/metasuites.git"
Expand Down
6 changes: 5 additions & 1 deletion src/background/listeners/explore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
})
}
9 changes: 7 additions & 2 deletions src/common/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import type {
PostContractVariableLogsReq,
ContractVariableLog,
ContractVariableListItem,
SimulationFeesParams
SimulationFeesParams,
PostAddressTagsReq
} from './types'

export default {
Expand Down Expand Up @@ -208,5 +209,9 @@ export default {
return request
.get(`api/v1/simulation/${chain}/base-fee?${queryString}`)
.json<BscResponse<{ baseFee: string }>>()
}
},
postAddressTags: (params: PostAddressTagsReq) =>
request
.post('api/v1/address-tags', { json: params })
.json<BscResponse<void>>()
}
7 changes: 7 additions & 0 deletions src/common/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,10 @@ export interface SimulationFeesParams {
blockNumber?: number
isPrerun: boolean
}

export interface PostAddressTagsReq {
chain: string
address: string
labels?: string[]
nameTag?: string
}
1 change: 1 addition & 0 deletions src/common/constants/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
7 changes: 5 additions & 2 deletions src/common/event/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import type {
PostSignatureReq,
PostContractVariableLogsReq,
FundFlowParams,
SimulationFeesParams
SimulationFeesParams,
PostAddressTagsReq
} from '@common/api/types'
import type {
REFRESH,
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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<EventInfo>(SCOPE)
51 changes: 51 additions & 0 deletions src/content/solscan/helper.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<typeof POST_ADDRESS_TAGS>(POST_ADDRESS_TAGS, {
chain: 'solana',
address,
labels: getTags(),
nameTag: getNameTag()
})
}
3 changes: 2 additions & 1 deletion src/content/solscan/page-scripts/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -20,6 +20,7 @@ const initAccountPageScript = async () => {
renderMainAddressLabel()
renderEnhancedLabels()
}
trigger()
}, '#account-tabs')

lazyLoad(
Expand Down
3 changes: 2 additions & 1 deletion src/content/solscan/page-scripts/token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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) => {
Expand Down

0 comments on commit 3f810ed

Please sign in to comment.