Skip to content

Commit

Permalink
Add support for symbols containing unicode chars (#176)
Browse files Browse the repository at this point in the history
* [#175] Add support for symbols containing unicode chars

* [#175] Adding support for empty symbols and names

* [#175] Add support for names containing unicode chars
  • Loading branch information
alexandrebini authored Dec 12, 2022
1 parent 245d0ab commit 61c4411
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/tokenlist.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,33 @@
"name": {
"type": "string",
"description": "The name of the token",
"minLength": 1,
"minLength": 0,

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

"maxLength": 40,
"pattern": "^[ \\w.'+\\-%/À-ÖØ-öø-ÿ:&\\[\\]\\(\\)]+$",

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

"anyOf": [
{
"const": ""
},
{
"pattern": "^[ \\S+]+$"

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

}
],
"examples": [
"USD Coin"

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

]
},
"symbol": {
"type": "string",
"description": "The symbol for the token; must be alphanumeric",

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

"pattern": "^[a-zA-Z0-9+\\-%/$.]+$",

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

"minLength": 1,

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

"description": "The symbol for the token",

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

"minLength": 0,

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

"maxLength": 20,
"anyOf": [

This comment has been minimized.

Copy link
@Deacon77

Deacon77 Aug 18, 2023

src/tokenlist.schema.json

{
"const": ""
},
{
"pattern": "^\\S+$"
}
],
"examples": [
"USDC"
]
Expand Down
2 changes: 2 additions & 0 deletions test/__snapshots__/tokenlist.schema.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@ exports[`schema token symbols may contain periods 1`] = `null`;

exports[`schema works for big example schema 1`] = `null`;

exports[`schema works for empty names and symbols 1`] = `null`;

exports[`schema works for example schema 1`] = `null`;

exports[`schema works for special characters schema 1`] = `null`;
25 changes: 25 additions & 0 deletions test/schema/empty-name-symbol.tokenlist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "My Token List",
"timestamp": "2020-06-12T00:00:00+00:00",
"tokens": [
{
"chainId": 137,
"address": "0xc31C535F4d9A789df0c16D461B4F811543b72FEb",
"decimals": 0,
"name": "",
"symbol": ""
},
{
"chainId": 137,
"address": "0xF336f5624D34c3Be82eF3EFc4978bd2397B1524A",
"decimals": 0,
"name": "",
"symbol": ""
}
],
"version": {
"major": 1,
"minor": 0,
"patch": 0
}
}
14 changes: 14 additions & 0 deletions test/schema/example-name-symbol-special-characters.tokenlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@
"decimals": 18,
"name": "[brackets]&(parenthesis)",
"symbol": "symbol"
},
{
"chainId": 1,
"address": "0x76ee13b775331eeae2bc5e3b67f4a44101b27a94",
"decimals": 18,
"name": "Amatsukami",
"symbol": "天津神"
},
{
"chainId": 137,
"address": "0x841120E51aD43EfE489244728532854A352073aD",
"decimals": 6,
"name": "Timeless ERC4626-Wrapped",
"symbol": "∞-waUSDC-xPYT"
}
],
"version": {
Expand Down
5 changes: 5 additions & 0 deletions test/tokenlist.schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import exampleNameSymbolSpecialCharacters from './schema/example-name-symbol-spe
import bigExampleList from './schema/bigexample.tokenlist.json';
import exampleListMinimum from './schema/exampleminimum.tokenlist.json';
import emptyList from './schema/empty.tokenlist.json';
import emptyNameSymbol from './schema/empty-name-symbol.tokenlist.json';
import bigWords from './schema/bigwords.tokenlist.json';
import invalidTokenAddress from './schema/invalidtokenaddress.tokenlist.json';
import invalidTimestamp from './schema/invalidtimestamp.tokenlist.json';
Expand Down Expand Up @@ -63,6 +64,10 @@ describe('schema', () => {
checkSchema(emptyList, false);
});

it('works for empty names and symbols', () => {
checkSchema(emptyNameSymbol, true);
});

it('fails with big names', () => {
checkSchema(bigWords, false);
});
Expand Down

0 comments on commit 61c4411

Please sign in to comment.