feat: recognize ens domains (#351)

* feat: recognize ens domains

* refactor: added ens recognition and more tests

* fix: validation mechanism to accept ENS and CIDs

* feat: support non-ascii characters for ENS

* fix: asset summary component to support ENS issue
This commit is contained in:
Vojtech Simetka
2022-05-31 13:37:37 +02:00
committed by GitHub
parent b6f138b423
commit 5917a13317
7 changed files with 130 additions and 50 deletions
+12 -2
View File
@@ -144,8 +144,18 @@ export function extractSwarmCid(s: string): string | undefined {
}
}
export function recognizeSwarmHash(value: string): string {
return extractSwarmHash(value) || extractSwarmCid(value) || value
// Matches any number of subdomain with .eth
// e.g. this.is.just-a-test.eth
export const regexpEns = /((?:(?:[^-./?:\s][^./?:\s]{0,61}[^-./?:\s]|[^-./?:\s]{1,2})\.)+eth)(?:$|[/?:#].*)/i
export function extractEns(value: string): string | undefined {
const matches = value.match(regexpEns)
return (matches && matches[1]) || undefined
}
export function recognizeEnsOrSwarmHash(value: string): string {
return extractEns(value) || extractSwarmHash(value) || extractSwarmCid(value) || value
}
export function uuidV4(): string {