Skip to content

Commit

Permalink
feat: Enhance the address label functionality on the Solscan token page
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbe37e committed Jun 3, 2024
1 parent 29a05d6 commit 4358944
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v5.0.4

- [feat] Enhance the address label functionality on the Solscan token page

### v5.0.3

- [fix] Restore the copy functionality for transaction hashes
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ For up to the minute news, follow our [Twitter](https://twitter.com/MetaDockTeam
- [x] Show evm.storage shortcut
- [x] Show transaction simulator
- [x] Show Variable Logs
- [x] Manage Local Private Labels

## Supported Websites List

Expand All @@ -65,6 +66,12 @@ For up to the minute news, follow our [Twitter](https://twitter.com/MetaDockTeam
- tronscan.org
- era.zksync.network
- blockscout.com
- debank.com
- platform.arkhamintelligence.com
- scan.merlinchain.io
- solscan.io
- solana.fm
- explorer.solana.com

## Contributing

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "metasuites",
"version": "5.0.3",
"version": "5.0.4",
"repository": {
"type": "git",
"url": "https://github.com/blocksecteam/metasuites.git"
},
"engines": {
"node": "18.17.0"
"node": "18.18.0"
},
"type": "module",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ browser.webRequest.onCompleted.addListener(
'https://api.solscan.io/v2/account/transaction?*',
'https://api.solscan.io/v2/account/v2/tokenaccounts?*',
'https://api.solscan.io/v2/account/stake?*',
'https://api-v2.solscan.io/v2/account/activity/dextrading?*'
'https://api-v2.solscan.io/v2/account/activity/dextrading?*',
'https://api-v2.solscan.io/v2/token/transfer?address=*',
'https://api.solscan.io/v2/account/transaction?address=*',
'https://api.solscan.io/v2/token/holders?token=*',
'https://api-v2.solscan.io/v2/token/activity/dextrading/total?address=*'
]
}
)
Expand Down
6 changes: 5 additions & 1 deletion src/common/constants/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const TRONSCAN_PAGE_NAMES = [

export const BLOCKSCOUT_PAGE_NAMES = ['TX', 'ADDRESS'] as const
export const MERLINSCAN_PAGE_NAMES = ['TX'] as const
export const SOLSCAN_PAGE_NAMES = ['ACCOUNT', 'TX'] as const
export const SOLSCAN_PAGE_NAMES = ['ACCOUNT', 'TX', 'TOKEN'] as const
export const SOLANAFM_PAGE_NAMES = ['ADDRESS', 'TX'] as const
export const SOLANAEXPL_PAGE_NAMES = ['ADDRESS', 'TX'] as const
export const ARKHAM_PAGE_NAMES = ['ADDRESS', 'TX'] as const
Expand Down Expand Up @@ -171,6 +171,10 @@ export const SOLSCAN_PAGES: Record<
name: 'ACCOUNT',
pattern: /^\/account\/([1-9A-HJ-NP-Za-km-z]{32,44})/i
},
TOKEN: {
name: 'TOKEN',
pattern: /^\/token\/([1-9A-HJ-NP-Za-km-z]{32,44})/i
},
TX: {
name: 'TX',
pattern: /^\/tx\/([1-9A-Za-z]+)/i
Expand Down
6 changes: 4 additions & 2 deletions src/common/utils/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
PATTERN_SELECTOR_LOOSE,
PATTERN_TRX_ADDRESS_LOOSE,
PATTERN_TRX_ADDRESS_EXAC,
PATTERN_SOLANA_ADDRESS_EXAC
PATTERN_SOLANA_ADDRESS_EXAC,
PATTERN_SOLANA_ADDRESS_LOOSE
} from '@common/constants'

export const isAddress = (str: string): boolean => {
Expand Down Expand Up @@ -37,6 +38,7 @@ export const pickAddress = (str: string): string | undefined => {
return (
str.match(PATTERN_EVM_ADDRESS_LOOSE)?.[0] ||
str.match(PATTERN_BTC_ADDRESS_LOOSE)?.[0] ||
str.match(PATTERN_TRX_ADDRESS_LOOSE)?.[0]
str.match(PATTERN_TRX_ADDRESS_LOOSE)?.[0] ||
str.match(PATTERN_SOLANA_ADDRESS_LOOSE)?.[0]
)
}
10 changes: 7 additions & 3 deletions src/content/etherscan/feat-scripts/main-address-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ const genMainAddressLabel = async (chain: string) => {
await chromeEvent
.emit(GET_IMPL_LABELS, { chain: chain, addresses: [mainAddress] })
.then((res: CallbackResponse<AddressLabel[]> | undefined) => {
const containerEl = $(
'#ContentPlaceHolder1_divSummary > div:first-child > div:first-child'
const divSummaryEl = $('#ContentPlaceHolder1_divSummary')
const containerEl = divSummaryEl.find(
'> div:first-child > div:first-child'
)
$('#ContentPlaceHolder1_divSummary > div').removeAttr('style')
divSummaryEl.find('> div').removeAttr('style')
if (!divSummaryEl.hasClass('pt-2')) {
divSummaryEl.addClass('pt-2')
}
if (res?.success && res.data.length) {
const label = res.data[0].label
if (
Expand Down
8 changes: 5 additions & 3 deletions src/content/solscan/feat-scripts/fund-flow.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { createRoot } from 'react-dom/client'
import $ from 'jquery'

import { pickAddress } from '@common/utils'

import { FundFlowButton } from '../components'

const renderFundFlowButton = async () => {
$('#__metadock-modal-fund-flow__, #__metadock-fund-flow-btn__').remove()
const mainAddressEl = $(
'#__next > div:nth-of-type(1) > div:nth-of-type(3) > div:first-child > div:first-child > div:last-child > div:first-child > div:first-child > div'
)
if (mainAddressEl[0]) {
const mainAddress = mainAddressEl[0].innerText.trim()
const mainAddress = pickAddress(window.location.pathname)
if (mainAddress) {
const btnRootEl = $('<div id="__metadock-fund-flow-btn__"></div>')
btnRootEl.css({ display: 'inline-block', verticalAlign: 'middle' })
mainAddressEl?.append(btnRootEl)
mainAddressEl.append(btnRootEl)
createRoot(btnRootEl[0]).render(
<FundFlowButton chain="solana" mainAddress={mainAddress} />
)
Expand Down
9 changes: 8 additions & 1 deletion src/content/solscan/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { store } from '@src/store'
import { isAllowed, getPageName } from '@common/utils'
import { SOLSCAN_PAGES } from '@common/constants'

import { initAccountPageScript, initTxPageScript } from './page-scripts'
import {
initAccountPageScript,
initTxPageScript,
initTokenPageScript
} from './page-scripts'

const execute = async () => {
const supportWebList = await store.get('supportWebList')
Expand All @@ -18,6 +22,9 @@ const execute = async () => {
case SOLSCAN_PAGES.ACCOUNT.name:
initAccountPageScript()
break
case SOLSCAN_PAGES.TOKEN.name:
initTokenPageScript()
break
case SOLSCAN_PAGES.TX.name:
initTxPageScript()
break
Expand Down
1 change: 1 addition & 0 deletions src/content/solscan/page-scripts/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as initAccountPageScript } from './account'
export { default as initTxPageScript } from './tx'
export { default as initTokenPageScript } from './token'
29 changes: 29 additions & 0 deletions src/content/solscan/page-scripts/token.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import browser from 'webextension-polyfill'

import { store } from '@src/store'
import { GET_SOLSCAN_ACCOUNT_TAB_DATA } from '@common/constants'

import { renderFundFlowButton, renderEnhancedLabels } from '../feat-scripts'
import { lazyLoad } from '../helper'

const initTokenPageScript = async () => {
const { fundFlow, enhancedLabels } = await store.get('options')

lazyLoad(() => {
if (fundFlow) renderFundFlowButton()
if (enhancedLabels) {
renderEnhancedLabels()
}
}, 'div[data-state="active"] table tbody tr:not(:has(div.animate-pulse))')

browser.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (message === GET_SOLSCAN_ACCOUNT_TAB_DATA) {
requestIdleCallback(() => {
if (enhancedLabels) renderEnhancedLabels()
})
sendResponse()
}
})
}

export default initTokenPageScript

0 comments on commit 4358944

Please sign in to comment.