Skip to content

Commit

Permalink
feat: 🎸 allow special characters for ticker
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan committed May 15, 2024
1 parent 0d05e22 commit 7258de0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/api/procedures/__tests__/createAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ describe('createAsset procedure', () => {
});

return expect(
prepareCreateAsset.call(proc, { ...args, ticker: 'SOME_TICKER' })
).rejects.toThrow('New Tickers can only contain alphanumeric values');
prepareCreateAsset.call(proc, { ...args, ticker: 'SOME_TICKER!' })
).rejects.toThrow('New Tickers can only contain alphanumeric values "_", "-", ".", and "/"');
});

it('should add an Asset creation transaction to the batch', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/api/procedures/__tests__/createNftCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ describe('createNftCollection procedure', () => {
});

return expect(
prepareCreateNftCollection.call(proc, { ...args, ticker: 'SOME_TICKER' })
).rejects.toThrow('New Tickers can only contain alphanumeric values');
prepareCreateNftCollection.call(proc, { ...args, ticker: 'SOME_TICKER!' })
).rejects.toThrow('New Tickers can only contain alphanumeric values "_", "-", ".", and "/"');
});

describe('prepareCreateNftCollection', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/api/procedures/createAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
stringToTicker,
stringToTickerKey,
} from '~/utils/conversion';
import { checkTxType, isAlphanumeric, optionize } from '~/utils/internal';
import { checkTxType, isAllowedCharacters, optionize } from '~/utils/internal';

/**
* @hidden
Expand Down Expand Up @@ -79,10 +79,10 @@ function assertTickerAvailable(
});
}

if (!isAlphanumeric(ticker)) {
if (!isAllowedCharacters(ticker)) {
throw new PolymeshError({
code: ErrorCode.ValidationError,
message: 'New Tickers can only contain alphanumeric values',
message: 'New Tickers can only contain alphanumeric values "_", "-", ".", and "/"',
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/api/procedures/createNftCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ import {
stringToBytes,
stringToTicker,
} from '~/utils/conversion';
import { checkTxType, isAlphanumeric, optionize } from '~/utils/internal';
import { checkTxType, isAllowedCharacters, optionize } from '~/utils/internal';

/**
* @hidden
*/
function assertTickerOk(ticker: string): void {
if (!isAlphanumeric(ticker)) {
if (!isAllowedCharacters(ticker)) {
throw new PolymeshError({
code: ErrorCode.ValidationError,
message: 'New Tickers can only contain alphanumeric values',
message: 'New Tickers can only contain alphanumeric values "_", "-", ".", and "/"',
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/api/procedures/reserveTicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Context, PolymeshError, Procedure, TickerReservation } from '~/internal
import { ErrorCode, ReserveTickerParams, RoleType, TickerReservationStatus, TxTags } from '~/types';
import { ExtrinsicParams, ProcedureAuthorization, TransactionSpec } from '~/types/internal';
import { stringToTicker, tickerToString } from '~/utils/conversion';
import { filterEventRecords, isAlphanumeric } from '~/utils/internal';
import { filterEventRecords, isAllowedCharacters } from '~/utils/internal';

/**
* @hidden
Expand Down Expand Up @@ -34,10 +34,10 @@ export async function prepareReserveTicker(
} = this;
const { ticker, extendPeriod = false } = args;

if (!isAlphanumeric(ticker)) {
if (!isAllowedCharacters(ticker)) {
throw new PolymeshError({
code: ErrorCode.ValidationError,
message: 'New Tickers can only contain alphanumeric values',
message: 'New Tickers can only contain alphanumeric values "_", "-", ".", and "/"',
});
}

Expand Down
12 changes: 6 additions & 6 deletions src/utils/__tests__/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ import {
getPortfolioIdsByName,
getSecondaryAccountPermissions,
hasSameElements,
isAlphanumeric,
isAllowedCharacters,
isModuleOrTagMatch,
isPrintableAscii,
mergeReceipts,
Expand Down Expand Up @@ -2247,17 +2247,17 @@ describe('method: getSecondaryAccountPermissions', () => {
});
});

describe('isAlphaNumeric', () => {
describe('isAllowedCharacters', () => {
it('should return true for alphanumeric strings', () => {
const alphaNumericStrings = ['abc', 'TICKER', '123XYZ99'];
const alphaNumericStrings = ['abc', 'TICKER', '123XYZ99', 'T-A/z.1'];

expect(alphaNumericStrings.every(input => isAlphanumeric(input))).toBe(true);
expect(alphaNumericStrings.every(input => isAllowedCharacters(input))).toBe(true);
});

it('should return false for non alphanumeric strings', () => {
const alphaNumericStrings = ['**abc**', 'TICKER-Z', '💎'];
const alphaNumericStrings = ['**abc**', 'TICKER$Z', '💎'];

expect(alphaNumericStrings.some(input => isAlphanumeric(input))).toBe(false);
expect(alphaNumericStrings.some(input => isAllowedCharacters(input))).toBe(false);
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/utils/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,10 @@ export function isPrintableAscii(value: string): boolean {
/**
* @hidden
*
* Return whether the string is fully alphanumeric
* Return whether the string contains alphanumeric values or _ - . /
*/
export function isAlphanumeric(value: string): boolean {
return /^[0-9a-zA-Z]*$/.test(value);
export function isAllowedCharacters(value: string): boolean {
return /^[0-9a-zA-Z_\-./]*$/.test(value);
}

/**
Expand Down

0 comments on commit 7258de0

Please sign in to comment.