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

CosmWasm smart contract hooks #51

Merged
merged 15 commits into from
Nov 10, 2022
Merged

Conversation

bigs
Copy link
Contributor

@bigs bigs commented Nov 9, 2022

Description

This closes feature request #50.

First, want to highlight that the primary author of this change is @BurntVal and that my role has merely been to review, give advice, and liaise!

This PR introduces four hooks for interacting with CosmWasm smart contracts in React applications. They are:

  • useInstantiateContract—a mutator to instantiate a smart contract with a message provided by the caller.
  • useExecuteContract—a mutator to execute a smart contract, passing it a message provided by the caller.
  • useQueryRaw and useQuerySmart—Hooks to query the state stored within a smart contract.

We made our best effort to follow the style and standards of the graz codebase. We generally made an effort to keep the typing as strong as possible, so the mutators are all parameterized by input and output types.

Checklist

  • I have made sure the upstream branch for this PR is correct
  • I have made sure this PR is ready to merge
  • I have made sure that I have assigned reviewers related to this project

Changes

  • Added useInstantiateContract hook
  • Added useExecuteContract hook
  • Added useQuerySmart hook
  • Added useQueryRaw hook

Screenshots

n/a

Testing

To test our changes, we locally extended the sample project in templates/default to include queries and transactions made to various sample contracts using all of the hooks added in this change request. Through testing in this application setting, we confirmed instantiation, execution, smart queries, and raw queries all worked.

Links/References

Notes

  • In order to make the hooks flexible, many of the hook arguments are optional (in the event that they are not yet known at first component render). In these instances (in the queries, specifically), the hooks will be automatically disabled until they are present to avoid invalid queries.

@vercel vercel bot temporarily deployed to Preview – graz-example November 9, 2022 19:58 Inactive
@vercel vercel bot temporarily deployed to Preview – graz-docs November 9, 2022 19:59 Inactive
@vercel vercel bot temporarily deployed to Preview – graz-example November 9, 2022 20:57 Inactive
@vercel vercel bot temporarily deployed to Preview – graz-docs November 9, 2022 20:57 Inactive
@bigs
Copy link
Contributor Author

bigs commented Nov 10, 2022

@codingki This is ready for a review! I'm not sure what's failing in the graz-example deploy, as I've not got permissions to view the project on Vercel.

@codingki
Copy link
Member

Dont mind the failing builds, we are currently working on it get it fixed @bigs

Copy link
Member

@codingki codingki left a comment

Choose a reason for hiding this comment

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

Awesome work @bigs🔥 Thanks for working on this, We are really appreciate your work🫡
There are some comments that needs to be resolved and suggestions before merging💪

packages/graz/src/actions/methods.ts Outdated Show resolved Hide resolved
packages/graz/src/actions/methods.ts Outdated Show resolved Hide resolved
packages/graz/src/actions/methods.ts Outdated Show resolved Hide resolved
packages/graz/src/actions/methods.ts Outdated Show resolved Hide resolved
packages/graz/src/actions/methods.ts Outdated Show resolved Hide resolved
packages/graz/src/hooks/methods.ts Outdated Show resolved Hide resolved
packages/graz/src/hooks/methods.ts Outdated Show resolved Hide resolved
packages/graz/src/hooks/methods.ts Outdated Show resolved Hide resolved
packages/graz/src/hooks/methods.ts Outdated Show resolved Hide resolved
packages/graz/src/hooks/methods.ts Outdated Show resolved Hide resolved
@codingki
Copy link
Member

In order to make the hooks flexible, many of the hook arguments are optional (in the event that they are not yet known at first component render). In these instances (in the queries, specifically), the hooks will be automatically disabled until they are present to avoid invalid queries.

We can make the hooks params optional and have a enabled options on the query options

@vercel vercel bot temporarily deployed to Preview – graz-docs November 10, 2022 21:43 Inactive
@vercel vercel bot temporarily deployed to Preview – graz-example November 10, 2022 21:44 Inactive
@vercel vercel bot temporarily deployed to Preview – graz-docs November 10, 2022 22:03 Inactive
@vercel vercel bot temporarily deployed to Preview – graz-example November 10, 2022 22:04 Inactive
@BurntVal
Copy link
Contributor

@codingki The requested changes were implemented and is ready for review again :)

Copy link
Member

@codingki codingki left a comment

Choose a reason for hiding this comment

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

Looks good to me! found couples suggestion non blocking the merge. Great job🫡

packages/graz/src/actions/methods.ts Outdated Show resolved Hide resolved
packages/graz/src/actions/methods.ts Outdated Show resolved Hide resolved
packages/graz/src/hooks/methods.ts Outdated Show resolved Hide resolved
packages/graz/src/hooks/methods.ts Outdated Show resolved Hide resolved
@codingki codingki added the enhancement New feature or request label Nov 10, 2022
@vercel vercel bot temporarily deployed to Preview – graz-example November 10, 2022 22:50 Inactive
@vercel vercel bot temporarily deployed to Preview – graz-docs November 10, 2022 22:50 Inactive
@BurntVal
Copy link
Contributor

Sorry for any inconvenience. It's the little things that always escape my mind. That should be everything now :)

@codingki
Copy link
Member

Awesome🔥

@codingki codingki merged commit e79087e into graz-sh:dev Nov 10, 2022
@codingki
Copy link
Member

These will be included in 0.0.28 and up

@BurntVal
Copy link
Contributor

Awesome. Thank you guys for the support and quick responses!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

3 participants