Skip to content

Commit

Permalink
Moved regex pattern for SymbolCode to proper class
Browse files Browse the repository at this point in the history
Resolves #91
  • Loading branch information
aaroncox committed Nov 7, 2023
1 parent 015df9f commit 6d1e7d0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/chain/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export namespace Asset {
export type SymbolType = Symbol | UInt64 | string
export class Symbol implements ABISerializableObject {
static abiName = 'symbol'
static symbolNamePattern = /^[A-Z]{0,7}$/
static maxPrecision = 18

static from(value: SymbolType) {
Expand Down Expand Up @@ -153,7 +152,7 @@ export namespace Asset {
if (toSymbolPrecision(value) > Symbol.maxPrecision) {
throw new Error('Invalid asset symbol, precision too large')
}
if (!Symbol.symbolNamePattern.test(toSymbolName(value))) {
if (!SymbolCode.pattern.test(toSymbolName(value))) {
throw new Error('Invalid asset symbol, name must be uppercase A-Z')
}
this.value = value
Expand Down Expand Up @@ -207,6 +206,7 @@ export namespace Asset {
export type SymbolCodeType = SymbolCode | UInt64 | string | number
export class SymbolCode implements ABISerializableObject {
static abiName = 'symbol_code'
static pattern = /^[A-Z]{0,7}$/

static from(value: SymbolCodeType) {
if (isInstanceOf(value, SymbolCode)) {
Expand All @@ -229,6 +229,9 @@ export namespace Asset {
value: UInt64

constructor(value: UInt64) {
if (!SymbolCode.pattern.test(toSymbolName(value))) {
throw new Error('Invalid asset symbol, name must be uppercase A-Z')
}
this.value = value
}

Expand Down

0 comments on commit 6d1e7d0

Please sign in to comment.