-
Notifications
You must be signed in to change notification settings - Fork 33
refactor: Don't call transactionCountOf$ until needed #414
Conversation
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.
Good! Maybe you can have a look at #355 (comment) as well
Ah yeah, I think you're right. I think in this case we should add |
I'm unfortunately out for vacation for 2 weeks, so this will stay in-progress for a while. If someone wants to push commits on this pr, feel free |
@amaurymartiny Sorry I don't understand, why would we want to add those props to Is the idea to add them as follows:
And then show validation errors with them instead as follows:
But I think we need to shows these messages in a notification message (like we do when the sender and receiver address are the same) instead of as input field validation error |
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.
I think we need to:
-
Refactor to create and use
@withTxCount
and@withChainId
decorators -
On the "Send Ether" and "Send THIBCoin" pages check in the
handleSubmit
method thatchainId
,transactionCount
andethBalance
values are not undefined, since those values may change to undefined between the time that the user enters valid form values and the time that they actually click the "Send" or "Scan" button, and could result in an invalid transaction being generated infether-react/src/utils/transaction.js -
On the "Send Ether" and "Send THIBCoin" pages we now need to save the prop values of
chainId
,balance
,ethBalance
,erc20Balance
, andtransactionCount
in the TxForm component state usinggetDerivedStateFromProps
and use the values in the state for rendering. And then only re-render if we receive different updated values for those props. Otherwise if we don't do this then the input fields will keep being reset at intervals, which is frustrating for the user.
An alternative is to show a "loading" overlay each time update values for these props are received, but that would be incredibly annoying to the user.
I've tried saving the values in the state using getDerivedStateFromProps
but so far the values still keep reseting.
To observe their values changing just add the following in the render method of TxForm
console.log('TxForm chainId: ', this.props.chainId && this.props.chainId.toString());
console.log('TxForm balance: ', this.props.balance && this.props.balance.toString());
console.log('TxForm ethBalance: ', this.props.ethBalance && this.props.ethBalance.toString());
console.log('TxForm erc20Balance: ', this.props.erc20Balance && this.props.erc20Balance.toString());
console.log('TxForm transactionCount: ', this.props.transactionCount && this.props.transactionCount.toString());
I've pushed additional commits in a separate branch "am-optimize-txcount-luke". I can't get it to save the input field values without them being reset |
Yes, see #355 (comment)
I don't think that's necessary, using the
Why can they change back to undefined? afaik they start with undefined but as soon as they have a value they can't go back to undefined? (cannot test the bit of code you pasted right now as my light node cannot connect to peers) |
What's your take @ltfschoen? Are we good to merge? |
@Tbaut No, still not, there are still some weird behavior. I'll clean up this PR this week. |
3364d65
to
53bac8f
Compare
// initialValues. As such, they don't have visible fields, so putting an | ||
// error here just means we're keeping the form state as not valid. | ||
if (!values.chainId) { | ||
return { chainId: 'Fetching chainId' }; |
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.
Previously I found that the validation errors only appear in the UI if when the key is amount
(i.e. { amount: 'some message' }
, I have not figured out why, so if you comment out the if statement, and run the code, it will not display 'Fetching chainId'.
Since it may be shown to the user who don't need to know about variable names, suggest changing it to Fetching chain ID
, i.e. return { amount: 'Fetching chain ID' };
.
The validation errors popup will all appear above the Amount input field with the small arrow, indicating that it's associated with a problem with that input field, which would be incorrect. But unless we can get it to associate with the correct input field we could do this in the interim, and could create a separate issue to find out why it is not working with key names of other input fields. It may be more appropriate to address these issues as general notifications as part of #331, since some aren't associated with a specific input field but instead are overall form validation errors
if (!ethBalance) { | ||
throw new Error('No "ethBalance"'); | ||
if (!values.ethBalance) { | ||
return { ethBalance: 'Fetching ethBalance' }; |
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.
For same reason as mentioned in comment https://github.com/paritytech/fether/pull/414/files#r268440068.
Suggest changing to return { amount: 'Fetching Ether balance' };
(or Fetching balance of Ether
)
return preValidation; | ||
if (!values.transactionCount) { | ||
return { | ||
transactionCount: 'Fetching transactionCount' |
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.
For same reason as mentioned in comment https://github.com/paritytech/fether/pull/414/files#r268440068.
Suggest changing to return { amount: 'Fetching transaction count' };
(or even Fetching transaction count for nonce
)
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.
LGTM, suggested adding amount
in the interim as the key so all the validation errors open as popups, otherwise if values.chainId
, values.transactionCount
, or values.ethBalance
is undefined after the user has entered a valid amount and recipient address, they'll have no idea why the "Send" or "Scan" button is still disabled. Suggest creating new issue to resolve why we can't associate input field validation errors with other input fields other than the amount
input field
Yes, I agree with that. However are you sure it's a good idea to put a tooltip on the An alternative I can propose is to put "
It seems to me that this works well: if you return |
Your idea is great. Let's not put the tooltip on the I agree with doing |
Done. |
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.
This PR makes the experience so much smoother, thanks a lot!
(Agreed with not showing any "chainId" or other weird names to our users, it's not needed.)
@amaurymartiny I'm not sure if this is related to this issue, but I just created this issue #474 and this PR #475 |
Only the TxForm component needs the transaction count, so we don't make additional RPC calls on other screens.
fixes #420. It makes the overall transitions between screens quicker.