Skip to content

Commit

Permalink
fix: Update regex for flagged NFTs (#8161)
Browse files Browse the repository at this point in the history
* fix: Update regex for flagged NFTs

* improvements

* typo

* Update packages/shared/locales/en.json

Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>

* fix

---------

Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>
  • Loading branch information
marc2332 and begonaalvarezd authored Mar 7, 2024
1 parent 3d9ad5e commit ac1a099
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/shared/lib/core/nfts/utils/isFlaggedNft.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { localize } from '../../i18n'
import { INft } from '../interfaces'

/**
Expand All @@ -10,10 +11,13 @@ export function isFlaggedNft(nft: INft): string | undefined {
const parsedMetadata = nft.parsedMetadata
const parsedName = parsedMetadata?.name ?? ''
const parsedDescription = parsedMetadata?.description ?? ''
const urlRegex = /((https?|ftp|file):\/\/)?([\da-z-]+\.)+([a-z]{2,6})([/\w .-]*)*\/?$/gi
const urlRegex = new RegExp(
'\\b(?:https?:\\/\\/)?[a-zA-Z0-9-]+(?:[\\.\\u2024\\uFE52\\uFF0E\\uFF61][a-zA-Z0-9-]+)+\\b(?:[\\/\\?#][^\\s()<>]*)?',
'i'
)
const containsUrl = urlRegex.test(name) || urlRegex.test(parsedName) || urlRegex.test(parsedDescription)
// Note: in order to avoid issues with the translations, we are using a hardcoded string here
const WARNING_MESSAGE =
'Be careful when following unknown links. Never share your private keys, nor enter them into any websites or services. '
return containsUrl ? WARNING_MESSAGE : undefined

if (containsUrl) {
return localize('warning.nft.flagged')
}
}
3 changes: 3 additions & 0 deletions packages/shared/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,9 @@
},
"participation": {
"noFunds": "You do not have any IOTA."
},
"nft": {
"flagged": "Be careful when following unknown links. Never share your private keys, nor enter them into any websites or services."
}
},
"tooltips": {
Expand Down

0 comments on commit ac1a099

Please sign in to comment.