Skip to content

Commit

Permalink
fix: Fix the address resolution error and FundFlow button style issue…
Browse files Browse the repository at this point in the history
… on the Solscan website
  • Loading branch information
0xbe37e committed Jun 5, 2024
1 parent f6dbe68 commit 26c9555
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 30 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.5

- [fix] Fix the bug in the Fund Flow feature on the Solscan website that causes the current Solana address to be retrieved incorrectly

### v5.0.4

- [feat] Enhance the address label functionality on the Solscan token page
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.0.4",
"version": "5.0.5",
"repository": {
"type": "git",
"url": "https://github.com/blocksecteam/metasuites.git"
Expand Down
12 changes: 9 additions & 3 deletions src/common/utils/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ export const isMethod = (str: string, isExact = true): boolean => {
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_SOLANA_ADDRESS_LOOSE)?.[0]
str.match(PATTERN_BTC_ADDRESS_LOOSE)?.[0]
)
}

export const pickTrxAddress = (str: string): string | undefined => {
return str.match(PATTERN_TRX_ADDRESS_LOOSE)?.[0]
}

export const pickSolanaAddress = (str: string): string | undefined => {
return str.match(PATTERN_SOLANA_ADDRESS_LOOSE)?.[0]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

.button {
display: flex !important;
margin-left: 16px;
.items-center;
}
14 changes: 11 additions & 3 deletions src/content/solscan/components/FundFlowButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import { type FC, useState } from 'react'
import { Button, ConfigProvider } from 'antd'
import { StyleProvider } from '@ant-design/cssinjs'
import cls from 'classnames'

import { ModalFundFlow, IconFundflow } from '@common/components'
import type { BaseComponent } from '@common/types'

import styles from './index.module.less'

interface Props {
interface Props extends BaseComponent {
chain: string
mainAddress: string
}

const FundFlowButton: FC<Props> = ({ chain, mainAddress }) => {
const FundFlowButton: FC<Props> = ({
chain,
mainAddress,
className,
style
}) => {
const [visible, setVisible] = useState(false)

return (
Expand All @@ -23,7 +30,8 @@ const FundFlowButton: FC<Props> = ({ chain, mainAddress }) => {
<Button
type="primary"
icon={<IconFundflow size={20} />}
className={styles.button}
style={style}
className={cls(styles.button, className)}
onClick={() => setVisible(true)}
>
Fund Flow
Expand Down
31 changes: 23 additions & 8 deletions src/content/solscan/feat-scripts/fund-flow.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import { createRoot } from 'react-dom/client'
import $ from 'jquery'
import type { CSSProperties } from 'react'

import { pickAddress } from '@common/utils'
import { pickSolanaAddress } from '@common/utils'
import { type SOLSCAN_PAGE_NAMES, SOLSCAN_PAGES } from '@common/constants'

import { FundFlowButton } from '../components'

const renderFundFlowButton = async () => {
const renderFundFlowButton = async (
pageName: (typeof SOLSCAN_PAGE_NAMES)[number]
) => {
$('#__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'
)
const mainAddress = pickAddress(window.location.pathname)
const isAccountPage = pageName === SOLSCAN_PAGES.ACCOUNT.name
const selector = isAccountPage
? '#__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'
: '#__next > div:nth-of-type(1) > div:nth-of-type(3) > div:first-child > div:first-child > div:last-child > div:first-child'
const mainAddressEl = $(selector)
const mainAddress = pickSolanaAddress(window.location.pathname)
if (mainAddress) {
const btnRootEl = $('<div id="__metadock-fund-flow-btn__"></div>')
btnRootEl.css({ display: 'inline-block', verticalAlign: 'middle' })
btnRootEl.css({
display: isAccountPage ? 'inline-block' : 'block',
verticalAlign: 'middle'
})
mainAddressEl.append(btnRootEl)
const style: CSSProperties = {}
if (isAccountPage) {
style.marginLeft = 16
} else {
style.marginTop = 16
}
createRoot(btnRootEl[0]).render(
<FundFlowButton chain="solana" mainAddress={mainAddress} />
<FundFlowButton chain="solana" mainAddress={mainAddress} style={style} />
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/content/solscan/page-scripts/account.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import browser from 'webextension-polyfill'

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

import {
renderFundFlowButton,
Expand All @@ -14,7 +14,7 @@ const initAccountPageScript = async () => {
const { fundFlow, enhancedLabels } = await store.get('options')

lazyLoad(() => {
if (fundFlow) renderFundFlowButton()
if (fundFlow) renderFundFlowButton(SOLSCAN_PAGES.ACCOUNT.name)
if (enhancedLabels) {
renderMainAddressLabel()
renderEnhancedLabels()
Expand Down
4 changes: 2 additions & 2 deletions src/content/solscan/page-scripts/token.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import browser from 'webextension-polyfill'

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

import { renderFundFlowButton, renderEnhancedLabels } from '../feat-scripts'
import { lazyLoad } from '../helper'
Expand All @@ -10,7 +10,7 @@ const initTokenPageScript = async () => {
const { fundFlow, enhancedLabels } = await store.get('options')

lazyLoad(() => {
if (fundFlow) renderFundFlowButton()
if (fundFlow) renderFundFlowButton(SOLSCAN_PAGES.TOKEN.name)
if (enhancedLabels) {
renderEnhancedLabels()
}
Expand Down
4 changes: 2 additions & 2 deletions src/content/tronscan/components/ExportTableDataBtn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ConfigProvider, Dropdown, type MenuProps, Button, Space } from 'antd'
import $ from 'jquery'
import { DownOutlined } from '@ant-design/icons'

import { pickAddress, downloadJson, downloadCsv } from '@common/utils'
import { pickTrxAddress, downloadJson, downloadCsv } from '@common/utils'
import { IconDownload } from '@common/components'

import { getTextWithoutRemarkLabel } from '../../helper'
Expand Down Expand Up @@ -68,7 +68,7 @@ const ExportTableDataBtn: FC<Props> = ({ chain, table }) => {

if (addressLinkEl.length && href) {
const addr =
pickAddress(href) || pickAddress(window.location.hash) || text
pickTrxAddress(href) || pickTrxAddress(window.location.hash) || text
const label = addressLinkEl.attr('data-label')
row.push(`${addr}${label ? `(${label})` : ''}`)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/content/tronscan/feat-scripts/compliance-score.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import $ from 'jquery'
import { chromeEvent } from '@common/event'
import type { RiskScore } from '@common/api/types'
import { GET_ADDRESS_RISK_SCORE } from '@common/constants'
import { pickAddress } from '@common/utils'
import { pickTrxAddress } from '@common/utils'

import { ComplianceScoreLabel } from '../components'

/** address compliance score*/
const genComplianceScoresBtn = async (container: JQuery<HTMLElement>) => {
const mainAddress = pickAddress(window.location.hash)
const mainAddress = pickTrxAddress(window.location.hash)

if (!mainAddress) return

Expand Down
4 changes: 2 additions & 2 deletions src/content/tronscan/feat-scripts/decompile-in-ethervm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createRoot } from 'react-dom/client'
import $ from 'jquery'
import browser from 'webextension-polyfill'

import { pickAddress } from '@common/utils'
import { pickTrxAddress } from '@common/utils'
import { TRONSCAN_TABS_CHANGED } from '@common/constants'

import { DecompileInEthervmBtn } from '../components'
Expand All @@ -11,7 +11,7 @@ import { lazyLoad } from '../helper'
const genDecompileInEthervmBtn = () => {
const main = async () => {
if ($('#decompile-btn').length) return
const mainAddress = pickAddress(window.location.hash)
const mainAddress = pickTrxAddress(window.location.hash)

if (!mainAddress) return

Expand Down
4 changes: 2 additions & 2 deletions src/content/tronscan/feat-scripts/fund-flow.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createRoot } from 'react-dom/client'
import $ from 'jquery'

import { pickAddress } from '@common/utils'
import { pickTrxAddress } from '@common/utils'

import { FundFlowBtn } from '../components'

/** fund flow */
const genFundFlowBtn = async (container: JQuery<HTMLElement>) => {
const mainAddress = pickAddress(window.location.hash)
const mainAddress = pickTrxAddress(window.location.hash)

if (!mainAddress) return

Expand Down
4 changes: 2 additions & 2 deletions src/content/tronscan/feat-scripts/main-address-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import $ from 'jquery'
import { chromeEvent } from '@common/event'
import type { AddressLabel } from '@common/api/types'
import { GET_IMPL_LABELS } from '@common/constants'
import { pickAddress } from '@common/utils'
import { pickTrxAddress } from '@common/utils'

import { MainAddressLabel } from '../components'

const genMainAddressLabel = async () => {
const mainAddress = pickAddress(window.location.hash)
const mainAddress = pickTrxAddress(window.location.hash)

if (!mainAddress) return

Expand Down

0 comments on commit 26c9555

Please sign in to comment.