Skip to content

Commit d5abcef

Browse files
authored
fix: mf-6637 reset provider after cancel connect in popup (#12165)
* fix: mf-6637 reset provider after cancel connect in popup * fix: post has address should be replaced * fix: adjust order of providers in checking link
1 parent 5cf000e commit d5abcef

File tree

7 files changed

+57
-26
lines changed

7 files changed

+57
-26
lines changed

packages/mask/content-script/components/InjectedComponents/PostReplacer.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import {
1212
makeTypedMessageText,
1313
isTypedMessageText,
1414
} from '@masknet/typed-message'
15-
import { MaskMessages } from '@masknet/shared-base'
15+
import {
16+
EXIST_EVM_ADDRESS_RE,
17+
EXIST_SOLANA_ADDRESS_RE,
18+
EXIST_TORN_ADDRESS_RE,
19+
MaskMessages,
20+
} from '@masknet/shared-base'
1621
import { TypedMessageRender, useTransformedValue } from '@masknet/typed-message-react'
1722
import {
1823
usePostInfoAuthor,
@@ -90,6 +95,7 @@ function Transformer({
9095
if (!isTypedMessageEqual(flatten, after)) return true
9196
if (hasCashOrHashTag(after)) return true
9297
if (shouldHiddenPostReplacer(message)) return true
98+
if (hasAddresses(message)) return true
9399
return false
94100
}, [message, after])
95101

@@ -118,6 +124,23 @@ function hasCashOrHashTag(message: TypedMessage): boolean {
118124
return result
119125
}
120126

127+
function hasAddresses(message: TypedMessage): boolean {
128+
let result = false
129+
function visitor(node: TypedMessage): 'stop' | void {
130+
if (result) return
131+
if (!isTypedMessageText(node)) return
132+
const content = node.content
133+
const hasAddresses =
134+
EXIST_EVM_ADDRESS_RE.test(content) ||
135+
EXIST_SOLANA_ADDRESS_RE.test(content) ||
136+
EXIST_TORN_ADDRESS_RE.test(content)
137+
result = result || hasAddresses
138+
}
139+
visitor(message)
140+
forEachTypedMessageChild(message, visitor)
141+
return result
142+
}
143+
121144
function shouldHiddenPostReplacer(message: TypedMessage): boolean {
122145
return isTypedMessageText(message) && message.content === ''
123146
}

packages/mask/content-script/site-adaptors/twitter.com/injection/PostReplacer.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { PostInfo } from '@masknet/plugin-infra/content-script'
2+
import { EXIST_EVM_ADDRESS_RE, EXIST_SOLANA_ADDRESS_RE, EXIST_TORN_ADDRESS_RE } from '@masknet/shared-base'
23
import { injectPostReplacer } from '../../../site-adaptor-infra/defaults/inject/PostReplacer.js'
34

45
function resolveLangNode(node: HTMLElement) {
@@ -8,26 +9,24 @@ function resolveLangNode(node: HTMLElement) {
89
)
910
}
1011

11-
// There are different from what ScamWarning uses, they are not global
12-
const EVM_ADDRESS = /(^|\s)(0x[\dA-Fa-f]{40})/
13-
const SOLANA_ADDRESS = /(^|\s)([1-9A-HJ-NP-Za-km-z]{32,44})/
14-
const TORN_ADDRESS = /(^|\s)(T[1-9A-Za-z]{33})/
15-
1612
function detectPotentialScam(postInfo: PostInfo) {
1713
const textContent = postInfo.rootNode?.textContent?.trim()
1814
if (!textContent) return false
1915
const hasAddresses =
20-
EVM_ADDRESS.test(textContent) || SOLANA_ADDRESS.test(textContent) || TORN_ADDRESS.test(textContent)
16+
EXIST_EVM_ADDRESS_RE.test(textContent) ||
17+
EXIST_SOLANA_ADDRESS_RE.test(textContent) ||
18+
EXIST_TORN_ADDRESS_RE.test(textContent)
2119
const hasLinks = postInfo.mentionedLinks.getCurrentValue().length > 0
2220
return hasAddresses || hasLinks
2321
}
2422

2523
export async function injectPostReplacerAtTwitter(signal: AbortSignal, current: PostInfo) {
2624
const rootNode = current.rootNode
27-
const hasPotentialScam = detectPotentialScam(current)
2825
if (!rootNode) return
2926
const isPromotionPost = !!rootNode.querySelector('svg path[d$="996V8h7v7z"]')
3027
if (isPromotionPost) return
28+
29+
const hasPotentialScam = detectPotentialScam(current)
3130
if (!hasPotentialScam) {
3231
const isCollapsedPost = !!rootNode.querySelector('[data-testid="tweet-text-show-more-link"]')
3332
if (isCollapsedPost) return

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ export function useCheckLink(link: string, text: string) {
1616
queryFn: async () => {
1717
const resolvedLink = isTCO(link) ? await resolveTCOLink(link) : link
1818
if (!resolvedLink) return { isScam: false }
19-
const result = await GoPlusLabs.checkIsPhishingSite(resolvedLink)
19+
const result = await PluginScamRPC.checkUrl(resolvedLink)
2020
if (result)
2121
return {
2222
isScam: result,
23-
provider: SecurityProvider.GoPlus,
23+
provider: SecurityProvider.ScamSniffer,
2424
resolvedLink,
2525
}
2626
const isEllipsis = text.endsWith('…')
2727
// We assume that the link contains only one address
2828
const address = isEllipsis ? extractAddresses(resolvedLink, true)[0] : undefined
2929

3030
return {
31-
isScam: await PluginScamRPC.checkUrl(resolvedLink),
31+
isScam: await GoPlusLabs.checkIsPhishingSite(resolvedLink),
3232
provider: SecurityProvider.ScamSniffer,
3333
resolvedLink,
3434
address,

packages/plugins/ScamWarning/src/constants.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ export const PLUGIN_ID = PluginID.ScamWarning
44
export const PLUGIN_DESCRIPTION = ''
55
export const PLUGIN_NAME = 'ScamWarning'
66

7-
export const EVM_ADDRESS = /(^|\s)(0x[a-fA-F0-9]{40})/gu
8-
export const SOLANA_ADDRESS = /(^|\s)([1-9A-HJ-NP-Za-km-z]{32,44})/gu
9-
export const TRON_ADDRESS = /(^|\s)(T[A-Za-z1-9]{33})/gu
10-
11-
export const EXIST_EVM_ADDRESS = /\b(0x[a-fA-F0-9]{40})/gu
12-
export const EXIST_SOLANA_ADDRESS = /\b([1-9A-HJ-NP-Za-km-z]{32,44})/gu
13-
export const EXIST_TRON_ADDRESS = /\b(T[A-Za-z1-9]{33})/gu
14-
157
export enum SecurityProvider {
168
ScamSniffer = 'ScamSniffer',
179
GoPlus = 'GoPlus',

packages/plugins/ScamWarning/src/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import { EVM_ADDRESS, SOLANA_ADDRESS } from '@masknet/plugin-scam-warning'
2-
import { EXIST_EVM_ADDRESS, EXIST_SOLANA_ADDRESS, EXIST_TRON_ADDRESS, TRON_ADDRESS } from './constants.js'
1+
import {
2+
MATCH_EVM_ADDRESS_RE,
3+
MATCH_SOLANA_ADDRESS_RE,
4+
MATCH_TRON_ADDRESS_RE,
5+
TRON_ADDRESS_RE,
6+
SOLANA_ADDRESS_RE,
7+
EVM_ADDRESS_RE,
8+
} from '@masknet/shared-base'
39

410
export function isTronAddress(address: string) {
5-
return !!address.match(TRON_ADDRESS)
11+
return !!address.match(TRON_ADDRESS_RE)
612
}
713

814
export function extractAddresses(text: string, exist = false) {
9-
const evmAddresses = text.match(exist ? EXIST_EVM_ADDRESS : EVM_ADDRESS) || []
10-
const solAddresses = text.match(exist ? EXIST_SOLANA_ADDRESS : SOLANA_ADDRESS) || []
11-
const tronAddresses = text.match(exist ? EXIST_TRON_ADDRESS : TRON_ADDRESS) || []
15+
const evmAddresses = text.match(exist ? MATCH_EVM_ADDRESS_RE : EVM_ADDRESS_RE) || []
16+
const solAddresses = text.match(exist ? MATCH_SOLANA_ADDRESS_RE : SOLANA_ADDRESS_RE) || []
17+
const tronAddresses = text.match(exist ? MATCH_TRON_ADDRESS_RE : TRON_ADDRESS_RE) || []
1218
return [...evmAddresses, ...solAddresses, ...tronAddresses]
1319
}

packages/shared-base/src/constants.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,15 @@ export const DEFAULT_PLUGIN_PUBLISHER = { name: { fallback: 'Mask Network' }, li
4040
export const RedPacketMetaKey = `${PluginID.RedPacket}:1`
4141
export const RedPacketNftMetaKey = `${PluginID.RedPacket}_nft:1`
4242
export const SolanaRedPacketMetaKey = `${PluginID.RedPacket}_solana:1`
43+
44+
export const EVM_ADDRESS_RE = /(^|\s)(0x[a-fA-F0-9]{40})/gu
45+
export const SOLANA_ADDRESS_RE = /(^|\s)([1-9A-HJ-NP-Za-km-z]{32,44})/gu
46+
export const TRON_ADDRESS_RE = /(^|\s)(T[A-Za-z1-9]{33})/gu
47+
48+
export const MATCH_EVM_ADDRESS_RE = /\b(0x[a-fA-F0-9]{40})/gu
49+
export const MATCH_SOLANA_ADDRESS_RE = /\b([1-9A-HJ-NP-Za-km-z]{32,44})/gu
50+
export const MATCH_TRON_ADDRESS_RE = /\b(T[A-Za-z1-9]{33})/gu
51+
52+
export const EXIST_EVM_ADDRESS_RE = /(^|\s)(2x[\dA-Fa-f]{40})/
53+
export const EXIST_SOLANA_ADDRESS_RE = /(^|\s)([1-9A-HJ-NP-Za-km-z]{32,44})/
54+
export const EXIST_TORN_ADDRESS_RE = /(^|\s)(T[1-9A-Za-z]{33})/

0 commit comments

Comments
 (0)