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

update TokenInfo extensions type to support objects nested 2 levels deep #140

Merged
merged 1 commit into from
Jun 16, 2022

Conversation

matteenm
Copy link
Contributor

There is an inconsistency between the tokenlist schema and the TokenInfo interface. The schema supports objects nested 2 levels deep (as it should), however the interface does not. This PR updates the TokenInfo extensions type/interface to also support 2-level nested objects.

This change was tested by importing a token list JSON file with the nested objects (cross-chain list) and verifying that there are no errors when setting it as a TokenList type.

@@ -1,4 +1,4 @@
type ExtensionValue = string | number | boolean | null;
type ExtensionValue = string | number | boolean | null | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

what prompted this bit?

Copy link
Contributor Author

@matteenm matteenm Jun 13, 2022

Choose a reason for hiding this comment

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

The case where a mapping doesn't exist for a token/chain, so there is no value for a key that other entries may have. For example the '42161' object here:


      ...
      "extensions": {
        "bridgeInfo": {
          "137": {
            "tokenAddress": "0x9c2C5fd7b07E95EE044DDeba0E97a665F142394f"
          },
          "42161": {
            "tokenAddress": "0x6314C31A7a1652cE482cffe247E9CB7c3f4BB9aF"
          }
        }
    },
    {
      ...
      "extensions": {
        "bridgeInfo": {
          "137": {
            "tokenAddress": "0xD6DF932A45C0f255f85145f286eA0b292B21C90B"
          }
        }
      
    },

Copy link
Contributor

Choose a reason for hiding this comment

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

undefined wouldn't be relevant in this case because the key isn't defined, unless I'm missing something?

Copy link
Contributor Author

@matteenm matteenm Jun 14, 2022

Choose a reason for hiding this comment

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

That's what I initially thought too, but this is the error im getting when not including undefined (using a list with the extensions from the above comment):
Property '"42161"' is incompatible with index signature. Type 'undefined' is not assignable to type 'ExtensionValue | { [key: string]: ExtensionValue; }'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline and assumption is that this may be a typescript bug where the typechecker is assuming a uniform type where the same properties need to appear in repeated objects. Decision is to keep undefined in the ExtensionValue type as a workaround for this.

Choose a reason for hiding this comment

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

Okay I understand you better with the ways and how u explained to me. I am Moses Okeoghene Ojero from Nigeria

Choose a reason for hiding this comment

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

Ok

@magid20
Copy link

magid20 commented Jun 14, 2022

Thank you

@mosesojero
Copy link

mosesojero commented Jun 14, 2022 via email

@matteenm matteenm merged commit 1023c40 into main Jun 16, 2022
@matteenm matteenm deleted the matteen--update-token-interface branch June 16, 2022 17:31
@mosesojero
Copy link

mosesojero commented Jun 16, 2022 via email

Copy link

@NkN121 NkN121 left a comment

Choose a reason for hiding this comment

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

good job ;)

@THU2447 THU2447 linked an issue May 21, 2023 that may be closed by this pull request
Copy link

@Imebeez Imebeez left a comment

Choose a reason for hiding this comment

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

👍

Copy link

@Imebeez Imebeez left a comment

Choose a reason for hiding this comment

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

Copy link

@mosesojero mosesojero left a comment

Choose a reason for hiding this comment

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

Please confirm

@@ -1,4 +1,4 @@
type ExtensionValue = string | number | boolean | null;
type ExtensionValue = string | number | boolean | null | undefined;

Choose a reason for hiding this comment

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

Okay I understand you better with the ways and how u explained to me. I am Moses Okeoghene Ojero from Nigeria

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

withdrow mode
7 participants