Skip to content

Commit e064e17

Browse files
authored
fix: mf-6660 check solana address (#12163)
* fix: mf-6660 check solana address * fix: hide claim plugin from plugin switch * fixup! fix: mf-6660 check solana address
1 parent 36d34d8 commit e064e17

File tree

7 files changed

+23
-57
lines changed

7 files changed

+23
-57
lines changed

packages/plugins/Claim/src/SiteAdaptor/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const site: Plugin.SiteAdaptor.Definition = {
5858
iconFilterColor: 'rgba(240, 51, 51, 0.3)',
5959
category: 'dapp',
6060
entryWalletConnectedNotRequired: true,
61+
hiddenInList: true,
6162
},
6263
],
6364
}

packages/plugins/ScamWarning/src/SiteAdaptor/components/LinkModifier.tsx

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import { Icons } from '@masknet/icons'
22
import type { Plugin } from '@masknet/plugin-infra'
3-
import { resolveTCOLink } from '@masknet/plugin-infra/dom/context'
43
import { makeStyles, ShadowRootPopper } from '@masknet/theme'
54
import { Link } from '@mui/material'
6-
import { useQuery } from '@tanstack/react-query'
75
import { memo } from 'react'
8-
import { PluginScamRPC } from '../../messages.js'
96
import { usePopoverControl } from './usePopoverControl.js'
107
import { WarningCard } from './WarningCard.js'
11-
import { SecurityProvider } from '../../constants.js'
12-
import { GoPlusLabs } from '@masknet/web3-providers'
13-
import { extractAddresses } from '../../utils.js'
148
import { useDetectAddress } from '../hooks/useDetectAddress.js'
159
import { AddressTag } from './TextModifier.js'
10+
import { useCheckLink } from '../hooks/useCheckLink.js'
1611

1712
const useStyles = makeStyles()((theme) => ({
1813
link: {
@@ -37,40 +32,12 @@ const useStyles = makeStyles()((theme) => ({
3732
},
3833
}))
3934

40-
function isTCO(url: string | null) {
41-
if (!url) return false
42-
return url.startsWith('https://t.co/')
43-
}
44-
4535
export const LinkModifier = memo<PropsOf<Plugin.SiteAdaptor.Definition['LinkModifier']>>(function LinkModifier({
4636
fallback,
4737
...props
4838
}) {
4939
const { classes } = useStyles()
50-
const { data } = useQuery({
51-
queryKey: ['scam-warning', 'check-link', props.href, props.children],
52-
queryFn: async () => {
53-
const resolvedLink = isTCO(props.href) ? await resolveTCOLink(props.href) : props.href
54-
if (!resolvedLink) return { isScam: false }
55-
const result = await GoPlusLabs.checkIsPhishingSite(resolvedLink)
56-
if (result)
57-
return {
58-
isScam: result,
59-
provider: SecurityProvider.GoPlus,
60-
resolvedLink,
61-
}
62-
const isEllipsis = props.children.endsWith('…')
63-
// We assume that the link contains only one address
64-
const address = isEllipsis ? extractAddresses(resolvedLink, true)[0] : undefined
65-
66-
return {
67-
isScam: await PluginScamRPC.checkUrl(resolvedLink),
68-
provider: SecurityProvider.ScamSniffer,
69-
resolvedLink,
70-
address,
71-
}
72-
},
73-
})
40+
const { data } = useCheckLink(props.href, props.children)
7441
const { data: detected } = useDetectAddress(data?.address, data?.isScam === false)
7542
const { open, anchorEl, iconRef, onMouseEnter, onMouseLeave } = usePopoverControl()
7643

packages/plugins/ScamWarning/src/SiteAdaptor/hooks/useCheckLink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function useCheckLink(link: string, text: string) {
2525
}
2626
const isEllipsis = text.endsWith('…')
2727
// We assume that the link contains only one address
28-
const address = isEllipsis ? extractAddresses(resolvedLink)[0] : undefined
28+
const address = isEllipsis ? extractAddresses(resolvedLink, true)[0] : undefined
2929

3030
return {
3131
isScam: await PluginScamRPC.checkUrl(resolvedLink),

packages/plugins/ScamWarning/src/SiteAdaptor/hooks/useDetectAddress.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function useDetectAddress(address: string | null | undefined, enabled = t
2222
}
2323
if (isTronAddress(address))
2424
return {
25-
isScam: GoPlusLabs.checkIfAddressIsScam('tron', address),
25+
isScam: await GoPlusLabs.checkIfAddressIsScam('tron', address),
2626
provider: SecurityProvider.GoPlus,
2727
}
2828
return { isScam: false, provider: null }

packages/plugins/ScamWarning/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { EVM_ADDRESS, SOLANA_ADDRESS } from '@masknet/plugin-scam-warning'
22
import { EXIST_EVM_ADDRESS, EXIST_SOLANA_ADDRESS, EXIST_TRON_ADDRESS, TRON_ADDRESS } from './constants.js'
33

44
export function isTronAddress(address: string) {
5-
return !!address.match(address)
5+
return !!address.match(TRON_ADDRESS)
66
}
77

88
export function extractAddresses(text: string, exist = false) {

packages/web3-shared/solana/src/helpers/address.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import bs58 from 'bs58'
2-
import { memoize } from 'lodash-es'
3-
import * as Web3 from /* webpackDefer: true */ '@solana/web3.js'
41
import { getEnumAsArray } from '@masknet/kit'
5-
import { isSameAddress } from '@masknet/web3-shared-base'
62
import { NetworkPluginID, createLookupTableResolver } from '@masknet/shared-base'
7-
import { ChainId, NetworkType, ProviderType, SchemaType } from '../types.js'
3+
import { isSameAddress } from '@masknet/web3-shared-base'
4+
import * as Web3 from /* webpackDefer: true */ '@solana/web3.js'
5+
import bs58 from 'bs58'
6+
import { memoize } from 'lodash-es'
87
import { getTokenConstant } from '../constants/constants.js'
98
import { ZERO_ADDRESS } from '../constants/primitives.js'
10-
import { isTronAddress } from './isTronAddress.js'
9+
import { ChainId, NetworkType, ProviderType, SchemaType } from '../types.js'
1110

1211
export function encodePublicKey(key: Web3.PublicKey) {
1312
return key.toBase58()
@@ -20,7 +19,7 @@ export function decodeAddress(initData: string | Buffer | Uint8Array) {
2019
}
2120

2221
export function formatAddress(address: string, size = 0) {
23-
if (!isValidAddress(address, false)) return address
22+
if (!isValidAddress(address)) return address
2423
if (size === 0 || size >= 22) return address
2524
return `${address.slice(0, Math.max(0, size))}...${address.slice(-size)}`
2625
}
@@ -42,12 +41,12 @@ export function formatTokenId(tokenId = '', size_ = 4) {
4241
return `#${head}...${tail}`
4342
}
4443

45-
export function isValidAddress(address?: string, strict?: boolean): address is string {
44+
export function isValidAddress(address?: string): address is string {
4645
const length = address?.length
4746
if (!length || length < 32 || length > 44) return false
4847
try {
4948
const buffer = bs58.decode(address)
50-
return strict === false ? true : Web3.PublicKey.isOnCurve(buffer) && !isTronAddress(address)
49+
return buffer.byteLength === 32
5150
} catch {
5251
return false
5352
}
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { describe, test, expect } from 'vitest'
1+
import { describe, expect, test } from 'vitest'
22
import { isValidAddress } from '../src/helpers/address.js'
33

44
describe('Solana address utilities', () => {
5-
test.each<[address: string, strict: boolean | undefined, result: boolean]>([
6-
['EZXbaV3', undefined, false],
7-
['EZXbaV3Lntre7DdvRyxmQoEk8cpMvfY8v2eC3qP9ntZUEZXbaV3Lntre7DdvRyxmQoEk8cpMvfY8v2eC3qP9ntZU', undefined, false],
8-
['EZXbaV3Lntre7DdvRyxmQoEk8cpMvfY8v2eC3qP9ntZU', undefined, true],
9-
['5afERTeXF8diWPy5P8AP2EkmcCFGkV9Z7LeSo9fpjcuf', undefined, false],
10-
['5afERTeXF8diWPy5P8AP2EkmcCFGkV9Z7LeSo9fpjcuf', false, true],
11-
['TPpADS2avP3rKgUcjZgnQNw5oMhjW2J6Za', true, false],
12-
])('isValidAddress(%s)', (address, strict, result) => {
13-
expect(isValidAddress(address, strict)).toBe(result)
5+
test.each<[address: string, result: boolean]>([
6+
['EZXbaV3', false],
7+
['EZXbaV3Lntre7DdvRyxmQoEk8cpMvfY8v2eC3qP9ntZUEZXbaV3Lntre7DdvRyxmQoEk8cpMvfY8v2eC3qP9ntZU', false],
8+
['EZXbaV3Lntre7DdvRyxmQoEk8cpMvfY8v2eC3qP9ntZU', true],
9+
['5afERTeXF8diWPy5P8AP2EkmcCFGkV9Z7LeSo9fpjcuf', true],
10+
['TPpADS2avP3rKgUcjZgnQNw5oMhjW2J6Za', false],
11+
])('isValidAddress(%s)', (address, result) => {
12+
expect(isValidAddress(address)).toBe(result)
1413
})
1514
})

0 commit comments

Comments
 (0)