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 interactive ABI for calling contract methods #6

Merged
merged 29 commits into from
Jun 9, 2023

Conversation

sdankel
Copy link
Member

@sdankel sdankel commented May 27, 2023

Based on the idea from https://github.com/FuelLabs/sway-playground/pull/2/files

This PR adds an "Interact" button that opens a drawer with the ability to call all of the functions in the ABI. For complex arguments (enums, structs, vectors, and options), there is a JSON editor where the user can supply the input. The JSON editor has a default value populated based on the schema of the input, making it easier to tell what a proper input should look like.

Also restyled the compile button, replaced the logo with the sway logo, and fixed a DOM error by importing 'ace-builds/webpack-resolver' before other ace-build imports.

Tested locally with the production build to make sure it's all working with the static webpack JS. It's deployed here if you want to play with it: https://sway-playground-sdankel.vercel.app/

To test it locally, just do:

cd app && npm start

Consistency with Fuel UI

I decided not to use fuel-ui/react since it added 4MB to the bundle size (without it, it's <2MB). Bundle size is important since it affects how fast the app feels to the users. 6MB is very large. The majority of the size came from the phosphorus dependency in fuel-ui/react, which imports ALL of the phosphorus icons into the browser. As an alternative I used Material UI which allows you to import only the icons you need.

I would like to use the shared fuel React components, but not at the cost of making the app run unnecessarily slow. I would suggest that we switch fuel-ui/react to use Material UI for icons (and maybe other components!?) since it makes it easy to optimize bundle size, it looks good, has great documentation, and is totally free.

I did use fuel-ui/css for the colors.

Follow up: #8

Feedback

From @SilentCicero

  • UX Improvement: Okay, when I opened this up, it immediately prompted the Fuel wallet to connect. Not sure if this is a bug, but not great UX. I can leave this in an issue for tracking if you like.
  • Bug: When the app booted for me, there was an error in the command line. Better to just clear that or start empty first.
  • Bug: When I hit deploy, the screen just went blank. This was after connecting my wallet and hitting compile. I do have test ether. On the second pass after restarting the app and deploying, it went through okay.
  • UX improvement: after a deployment, the interactive contract interface window should come up automatically. I shouldn't have to hit "Interact" to prompt this after deployment.
  • UX improvement: after deployment, I got no message in the console or anywhere the contract was either successfully deployed or failed deployment. Just report in the compiler console that the "Contract has been deployed successfully to beta-3 [link to tx hash]"
  • Example improvement: I can increment the counter, but there is not method to get the counter value, so I can't see that anything has changed. I'd recommend adding a getter method for the counter.
  • UX Improvement: I'd recommend keeping or reporting more logs in the console as to what is happening, and clear button to clear those logs if I want to do something else.
  • Feature Request: be able to use "forc test --logs" with a "test" button, which should be the recommended first action, so that people can use it without having to install the Fuel wallet. Support forc test #7

Getting to the interact panel: compile & deploy

May-30-2023 13-22-31

Dry run call (default)

May-30-2023 13-21-23

Live call

May-30-2023 13-23-08

@sdankel sdankel marked this pull request as ready for review June 5, 2023 18:37
@sdankel sdankel requested review from SilentCicero and a team June 5, 2023 18:37
Copy link
Member

@kayagokalp kayagokalp left a comment

Choose a reason for hiding this comment

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

This is super cool! Played with it and it feels really nice! Out of the scope for this PR but maybe having a drop-down or something to select desired forc/compiler version could be cool.

setResults([<>Add some code to compile.</>]);
return;
}

setResults([<>Compiling...</>]);

// TODO: Determine the URL based on the NODE_ENV.
const server_uri = 'https://api.sway-playground.org/compile';
// const server_uri = 'https://127.0.0.1/compile';
Copy link
Member

Choose a reason for hiding this comment

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

Should we keep this line seems like left from debugging

Copy link
Member Author

Choose a reason for hiding this comment

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

This prints Compiling... in the console that the user sees, so it's useful to keep it in :)

Copy link
Member

Choose a reason for hiding this comment

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

Oh I meant line 48, but nothing important 🙌

@kayagokalp kayagokalp requested a review from a team June 8, 2023 09:52
Copy link
Member

@JoshuaBatty JoshuaBatty left a comment

Choose a reason for hiding this comment

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

Also had a play around and it feels really cool to play with.

Great work

@sdankel
Copy link
Member Author

sdankel commented Jun 9, 2023

This is super cool! Played with it and it feels really nice! Out of the scope for this PR but maybe having a drop-down or something to select desired forc/compiler version could be cool.

Agreed! #10

@sdankel sdankel merged commit 33e72af into master Jun 9, 2023
@sdankel sdankel deleted the sophie/react-contract-calls branch August 1, 2023 22:46
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.

3 participants