From bf143d602e081347e4465ea4f2295eb028280f77 Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Mon, 18 Nov 2024 14:53:13 +0200 Subject: [PATCH] API-82: tokens with prefix --- packages/common/src/utils/token.utils.ts | 4 ++-- packages/common/test/utils/token.utils.spec.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/common/src/utils/token.utils.ts b/packages/common/src/utils/token.utils.ts index 02e5cc8a..facd2992 100644 --- a/packages/common/src/utils/token.utils.ts +++ b/packages/common/src/utils/token.utils.ts @@ -1,6 +1,6 @@ export class TokenUtils { - static tokenValidateRegex: RegExp = /^[A-Za-z0-9]{3,10}-[a-fA-F0-9]{6}$/; - static nftValidateRegex: RegExp = /^[A-Za-z0-9]{3,10}-[a-fA-F0-9]{6}-[a-fA-F0-9]{2,}$/; + static tokenValidateRegex: RegExp = /^([A-Za-z0-9]{3,10}-)?[A-Za-z0-9]{3,10}-[a-fA-F0-9]{6}$/; + static nftValidateRegex: RegExp = /^([A-Za-z0-9]{3,10}-)?[A-Za-z0-9]{3,10}-[a-fA-F0-9]{6}-[a-fA-F0-9]{2,}$/; static isToken(identifier: string): boolean { return this.tokenValidateRegex.test(identifier); diff --git a/packages/common/test/utils/token.utils.spec.ts b/packages/common/test/utils/token.utils.spec.ts index d5a68ebc..8b2618fb 100644 --- a/packages/common/test/utils/token.utils.spec.ts +++ b/packages/common/test/utils/token.utils.spec.ts @@ -3,20 +3,24 @@ import { TokenUtils } from "../../src/utils/token.utils"; describe('isToken', () => { it('Check isToken function', () => { expect(TokenUtils.isToken('MEX-455c57')).toBeTruthy(); - expect(TokenUtils.isToken('EWLD-e23800-455c74')).toBeFalsy(); + expect(TokenUtils.isToken('SOV-EWLD-455c74')).toBeTruthy(); + expect(TokenUtils.isToken('PRF-SOV-e23800-455c74')).toBeFalsy(); }); }); describe('isCollection', () => { it('Check isCollection function', () => { expect(TokenUtils.isCollection('MOS-b9b4b2')).toBeTruthy(); - expect(TokenUtils.isCollection('MOS-b9b4b2-455c74')).toBeFalsy(); + expect(TokenUtils.isCollection('SOV-MOS-b9b4b2')).toBeTruthy(); + expect(TokenUtils.isCollection('SOV-MOS-b9b4b2-455c74')).toBeFalsy(); }); }); describe('isNft', () => { it('Check isNft function', () => { expect(TokenUtils.isNft('MOS-b9b4b2-947a3912')).toBeTruthy(); + expect(TokenUtils.isNft('SOV-MOS-b9b4b2-947a3912')).toBeTruthy(); expect(TokenUtils.isNft('MOS-b9b4b2')).toBeFalsy(); + expect(TokenUtils.isNft('SOV-MOS-b9b4b2')).toBeFalsy(); }); });