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

Format send result to work with ethers #8

Merged
merged 7 commits into from
Aug 23, 2018

Conversation

ryanchristo
Copy link
Contributor

@ryanchristo ryanchristo commented Aug 16, 2018

Description

Adds formatResult static function to RemoteMetamaskProvider, which ensures the gasPrice and value of the result object are properly formatted to work with ethers. If gasPrice or value is a string, the string is converted to a number using parseInt.

Ideally, we would convert the string to a standard big number type but ethers does not support any big number types other than its own proprietary type using ethers.utils.bigNumberify.

Also adds a condition to formatResult that returns the result in an array if the result object has a logIndex property. This provides the correct formatting for eht_filter to work with ethers.

Other Changes

Added comments and updated formatting.

Related Issues

JoinColony/colonyStarter#14

@ryanchristo ryanchristo requested a review from chmanie August 16, 2018 14:51
@ryanchristo ryanchristo force-pushed the fix/ethers-support-and-formatting branch from b851368 to a0c0ab2 Compare August 16, 2018 16:23
Copy link
Member

@chmanie chmanie left a comment

Choose a reason for hiding this comment

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

Just the two things, otherwise I'm happy!


// Format "gasPrice"
if (result && typeof result.gasPrice === 'string') {
result.gasPrice = Number(result.gasPrice);
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd rather see parseInt(x, 10) here as it is more explicit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


// Because requests are handled across a WebSocket, their callbacks need to
// be associated with an ID which is returned with the response.
const requestId = RemoteMetaMaskProvider.generateRequestId();
Copy link
Member

Choose a reason for hiding this comment

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

We like to use this.constructor.xxx instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

if (result && result.logIndex) {
const array = [];
array.push(result);
return array;
Copy link
Member

Choose a reason for hiding this comment

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

Isn't that the same as return [result]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@ryanchristo ryanchristo force-pushed the fix/ethers-support-and-formatting branch from 2eb40e7 to ee60f08 Compare August 18, 2018 04:28
@ryanchristo
Copy link
Contributor Author

@chmanie It's working with the latest commit! Could you please review once more?

@ryanchristo ryanchristo merged commit cab732d into master Aug 23, 2018
@ryanchristo ryanchristo deleted the fix/ethers-support-and-formatting branch August 23, 2018 06:08
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.

2 participants