Skip to content

Commit

Permalink
API-82: tokens with prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-rosianu committed Nov 18, 2024
1 parent 0cca266 commit bf143d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/common/src/utils/token.utils.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
8 changes: 6 additions & 2 deletions packages/common/test/utils/token.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit bf143d6

Please sign in to comment.