Allow whitespace in token config

This commit is contained in:
Simon Warta 2020-08-11 09:13:52 +02:00
parent da4648374a
commit e4c5f3d14f
2 changed files with 10 additions and 3 deletions

View File

@ -9,6 +9,14 @@ describe("tokens", () => {
denom: "ucosm",
});
});
it("allows using whitespace", () => {
expect(parseBankToken("COSM = 10^6 ucosm")).toEqual({
tickerSymbol: "COSM",
fractionalDigits: 6,
denom: "ucosm",
});
});
});
describe("parseBankTokens", () => {

View File

@ -21,7 +21,7 @@ export interface BankTokenMeta {
const parseBankTokenPattern = /^([a-zA-Z]{2,20})=10\^([0-9]+)([a-zA-Z]{2,20})$/;
export function parseBankToken(input: string): BankTokenMeta {
const match = input.match(parseBankTokenPattern);
const match = input.replace(/\s/g, "").match(parseBankTokenPattern);
if (!match) {
throw new Error("Token could not be parsed. Format: DISPLAY=10^DIGITSbase, e.g. ATOM=10^6uatom");
}
@ -36,7 +36,6 @@ export function parseBankTokens(input: string): BankTokenMeta[] {
return input
.trim()
.split(",")
.map((part) => part.trim())
.filter((part) => part !== "")
.filter((part) => part.trim() !== "")
.map((part) => parseBankToken(part));
}