-
Notifications
You must be signed in to change notification settings - Fork 8
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 auto generated tfchain types to tfchain_client #3020
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- add polkadot/typegen pachage - update paths in tsconfig to make the compiler aware of the generated types - use generateTypes script
- add required types files to the client
- add generated types to chain dir and export them
0oM4R
requested review from
AhmedHanafy725,
zaelgohary,
maayarosama,
MohamedElmdary,
Mahmoud-Emad,
amiraabouhadid,
AlaaElattar,
mohamedamer453 and
samaradel
as code owners
June 26, 2024 13:35
remove typo
amiraabouhadid
approved these changes
Jul 1, 2024
zaelgohary
reviewed
Jul 2, 2024
|
||
There are two blockers now from building the project: | ||
|
||
1. As we din't have any defined types `src/interfaces/chain/types` is empty and will gives an error while build, for now we just need to export an empty object on it so we add `export {}` to the file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
1. As we din't have any defined types `src/interfaces/chain/types` is empty and will gives an error while build, for now we just need to export an empty object on it so we add `export {}` to the file. | |
1. As we don't have any defined types `src/interfaces/chain/types` is empty and will give an error while build, for now we just need to export an empty object on it so we add `export {}` to the file. |
zaelgohary
reviewed
Jul 2, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really good job, @0oM4R. Just a small typo.
zaelgohary
approved these changes
Jul 2, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Integrate chain types in our project provide such better development experience, We can use the generated types and check auto complete via IDE. Polkadot provides typegen to generate pre defined types and chain types, currently, we only need the chain types.
Changes
Details:
@polkadot/typegen
package of the same version as@polkadot/api
.Generating
First we need to have chain metadata, to generate types based on it, this is done by running the following command:
The result of this command will be
chainMeta.json
with a content likeThis file will be used in the following two commands:
polkadot-types-from-defs
polkadot-types-from-chain
Now types are generated, but we need to let the compiler aware of the generated types, we can do that by add the following paths to
tsconfig-*.json
inside compilerOptions.paths add those lines:Finally we need to export the generated types
in
src/interfaces/index.ts
Usage
We need to import the augmented definitions "somewhere" as documentation says, in our case we will import them in
src/client
.Now we can import any type anywhere in the client as follows:
There are two blockers now from building the project:
src/interfaces/chain/types
is empty and will gives an error while build, for now we just need to export an empty object on it so we addexport {}
to the file.In
src/interfaces/chain/augment-api-tx.ts
we havecreateFarmingPolicy
andupdateFarmingPolicy
functions in tfgridmodule each of them contains parameter nameddefault
this is not acceptable on Typescript as it is a reserved word, so we could replace it with_default
.Related Issues
polkadot/typegen
#3000Documentation PR
For UI changes, Please provide the Documetation PR on info_grid
Checklist