jimmychu0807 / substrate-front-end-template

A Polkadot.js API + React based template for building Substrate Front Ends
The Unlicense
315 stars 351 forks source link

Unable to create Enum via index #180

Closed frankli-dev closed 2 years ago

frankli-dev commented 3 years ago

The querying through the substrate frontend template interactor fails with the following error.

Unhandled Rejection (Error): createType(Vec<StorageKey>):: createType(CurrencyId):: Unable to create Enum via index 203, in dot, token

I added the additional types as the following

"CurrencyId": {
    "_enum": {
      "DOT": null,
      "TOKEN": "H160"
    }
  },

The query works well if I use the polkadotjs app with the provided additional types. Is this because the frontend template still uses the @polkadot ^3.9.3 ?

frankli-dev commented 3 years ago

Does substrate-front-end-template support for enum types on the UI? sth like as a dropdown of enum options?

The CurrencyId is defined as enum. But on the interactor, not sure how to specify it. image

Using polkadotjs/api, how can I call the query with the enum parameter?

const transformed = ["xxxx", "token(0xcb82e435e4665fda7cc0e6ced374085d850f23a8)"];
    await api.query.tokens.accounts(...transformed, result => {
      console.log(result)
    });
jimmychu0807 commented 3 years ago
stojanov-igor commented 3 years ago

REGISTRY: Error: Unable to create Enum via index 13, in V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12 at assert (assert.mjs:24) at createFromValue (Enum.mjs:31) at decodeFromValue (Enum.mjs:60) at decodeEnum (Enum.mjs:84) at new Enum (Enum.mjs:131) at new <anonymous> (Enum.mjs:143) at new Type (registry.mjs:318) at decodeU8a (decodeU8a.mjs:17) at decodeStruct (Struct.mjs:85) at new Struct (Struct.mjs:119) at new MetadataVersioned (MetadataVersioned.mjs:23) at decodeMetadata (Metadata.mjs:24) at new Metadata (Metadata.mjs:46) at initType (createType.mjs:39) at createTypeUnsafe (createType.mjs:59) at RpcCore._formatOutput (index.js:394) at callWithRegistry (index.js:262)

This is the error when I am getting when running the latest substrate-front-end, with the latest substrate-node-template.

Manuelandro commented 3 years ago

REGISTRY: Error: Unable to create Enum via index 13, in V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12 at assert (assert.mjs:24) at createFromValue (Enum.mjs:31) at decodeFromValue (Enum.mjs:60) at decodeEnum (Enum.mjs:84) at new Enum (Enum.mjs:131) at new <anonymous> (Enum.mjs:143) at new Type (registry.mjs:318) at decodeU8a (decodeU8a.mjs:17) at decodeStruct (Struct.mjs:85) at new Struct (Struct.mjs:119) at new MetadataVersioned (MetadataVersioned.mjs:23) at decodeMetadata (Metadata.mjs:24) at new Metadata (Metadata.mjs:46) at initType (createType.mjs:39) at createTypeUnsafe (createType.mjs:59) at RpcCore._formatOutput (index.js:394) at callWithRegistry (index.js:262)

This is the error when I am getting when running the latest substrate-front-end, with the latest substrate-node-template.

Same here, have you found a solution?

stojanov-igor commented 2 years ago

This problem was resolved for me when I updated "caniuse-lite@npm:^1.0.0," npm package.

The exact details for the package that fixed the issue are listed below. (copied from yarn.lock)

version: 1.0.30001274 resolution: "caniuse-lite@npm:1.0.30001274" checksum: 75790d021edbc68dbb36c0bc63255fad1e7aa3986039e685d10340e7e9a37147b0ddedaba22cf6c52b3657cca794ed41af88045ad5cce79084e9361e95f1c5d4

jimmychu0807 commented 2 years ago

Custom types are no longer needed and is made known to polkadot-js api via metadata. So this issue is no longer relevant.