Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for symbols containing unicode chars #176

Merged
merged 3 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release coin

"minLength": 0,
"maxLength": 40,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zzmp btw, this limit isn't correct. You can have more than 40 chars and as far as I know there isn't a limit.

This pair is one https://dexscreener.com/polygon/0x841120E51aD43EfE489244728532854A352073aD

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks I lost all my devices and I was able to recover some databases now

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

"pattern": "^[ \\w.'+\\-%/À-ÖØ-öø-ÿ:&\\[\\]\\(\\)]+$",
"anyOf": [
{
"const": ""
},
{
"pattern": "^[ \\S+]+$"
}
],
"examples": [
"USD Coin"
]
},
"symbol": {
alexandrebini marked this conversation as resolved.
Show resolved Hide resolved
"type": "string",
"description": "The symbol for the token; must be alphanumeric",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

],

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"examples":

"minLength": 1,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USD COIN

"description": "The symbol for the token",
"minLength": 0,
"maxLength": 20,
"anyOf": [
{
"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",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

"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', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zzmp @tolitsjr Yes, you can have empty names and symbols.

Check 0xc31C535F4d9A789df0c16D461B4F811543b72FEb and 0xF336f5624D34c3Be82eF3EFc4978bd2397B1524A on polygon.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have many errors in the past I want to make amends

checkSchema(emptyNameSymbol, true);
});

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