Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Fix bug that executing an RPC call (ERC-20 transfer message) crashed the UI #13

Open
Robbepop opened this issue Oct 20, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@Robbepop
Copy link

The situation was the following:

I was deploying and executing an instance of the demo'ed ERC-20 contract on-chain on the Canvas test network.
I tried to execute the ERC-20 transfer method as RPC call which resolves return values for me because I wanted to know if the call resulted in some error with the given arguments.
Unfortunately the UI crashed telling it could not properly decode the Result type.
Maybe this is connected to the fact that the UI cannot really handle enum types, yet but I still wanted to clarify this issue.

@Robbepop Robbepop added the bug Something isn't working label Oct 20, 2020
@awolokita
Copy link

Possibly related to #52. I've opened PR #106 to address this issue + handling Option. However; I'm not sure if Result will be handled correctly either. I can take a look once the PR has been merged.

As an aside, does anyone know if there's a more graceful way to handle constructing components in the Data::Data function? Adding an additional case for each possible Codec subclass doesn't scale.

@awolokita
Copy link

Possibly related to #52. I've opened PR #106 to address this issue + handling Option. However; I'm not sure if Result will be handled correctly either. I can take a look once the PR has been merged.

As an aside, does anyone know if there's a more graceful way to handle constructing components in the Data::Data function?
Adding an additional case for each possible Codec subclass doesn't scale.

I've reproduced using the fix in #106 with the attached erc20.zip. The UI no longer crashes, however the returned value is the hex encoded value 0x00 because there's no handler for this type.
@Robbepop - should we open a new enhancement issue to handle Result?

@awolokita
Copy link

@Robbepop - should we open a new enhancement issue to handle Result?

I found a pretty easy way to handle Result - if we change the catch-all return at the end of Data from

return truncate(codec.toHex(), TRUNCATE_TO);

to

return JSON.stringify(codec.toHuman());

then the resulting value for Result is nicely defined in a stringified JSON. In your ERC-20 example, we get {"Ok":[]} and {"Err":"InsufficientBalance"}, respectively.

Ideally, we could generically use codec.toHuman() to construct all of the return components out of the resulting JSON; however Codecs like Option have their toHuman method defined in such a way that doesn't yeild this nice object.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants