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

fix: Fixes #320. Memoize form field values in state to prevent reseting on sync#326

Closed
ltfschoen wants to merge 4 commits intomasterfrom
luke-320-sync-reset-send-form-fields
Closed

fix: Fixes #320. Memoize form field values in state to prevent reseting on sync#326
ltfschoen wants to merge 4 commits intomasterfrom
luke-320-sync-reset-send-form-fields

Conversation

@ltfschoen
Copy link
Contributor

@ltfschoen ltfschoen commented Dec 27, 2018

  • Uses parse property of the react-final-form Field for the amount, gasPrice, and to input fields, which is passed the current input field value and returns the value to be shown on the form, but we use it to backup/store the current value of the form in the component's state, and just return the current input value back again. We use these stored values when form initialises so initialValues correspond to the values stored in the state, which prevents all the form input field values disappearing and causing the user to have to re-enter them all again if syncing or bad connectivity occurs after they have entered values but not yet finished sending the transaction.

Refer to below video showing how the form field values aren't reset when a sync occurs
https://drive.google.com/open?id=14APiLMK6zDoUjCS2DST6VkHtOAmbTrw8

Relates to #218

@amaury1093
Copy link
Collaborator

@ltfschoen Did you find a way to manually reproduce the syncing behavior, so that we can test it?

@ltfschoen
Copy link
Contributor Author

@amaurymartiny I'll see if I can try to replicate the syncing behaviour with a test

@ltfschoen
Copy link
Contributor Author

ltfschoen commented Jan 3, 2019

@amaurymartiny Initially I thought I'd be best to actually write a unit test, but I couldn't get mocking to work https://github.com/paritytech/fether/compare/luke-320-sync-reset-send-form-fields-tests?expand=1.

So instead of writing a unit test I decided to just simulated it in the code. I changed the componentDidUpdate in RequireHealthOverlay.js as follows which triggers the overlay to switch on/off every 10 seconds. I found that even the proposed changes in this PR so far that it actually wasn't saving the current input field values. Then I found that each time the visibility changed it was re-mounting the TxForm.js component (which should have been obvious if I had looked closer at the render method of RequireHealthOverlay.js which doesn't render {this.props.children} when the this.state.visibility is false.

  componentDidUpdate () {
    const visible = this.state.visible;

    setTimeout(() => {
      this.setState({ visible: !visible });
    }, 10000);
  }

So I think what needs to be done is to start from scratch and simply update RequireHealthOverlay.js so we always render {this.props.children} but conditionally render the health overlay alert when visibility equals true (using CSS so the overlay floats over the children). I think such changes also relate to this issue #218

@amaury1093
Copy link
Collaborator

amaury1093 commented Jan 3, 2019

@ltfschoen Yes, let RequireHealthOverlay always render children is a good idea, I agree that this PR should be redone to make it that way. It will solve the original problem more cleanly.

Btw, initially, it was a real overlay (as in a layer on top of other components), but changed in #216 (cc @axelchalon was there a technical reason for that? I can't remember now). If you want to see the old CSS, look at https://github.com/paritytech/fether/pull/216/files#diff-e6912b69f6175ae14cf8eeb2923a231bL38

Edit: We could make RequireHealthOverlay a SUI Modal that takes all screen, to avoid custom CSS.

@ltfschoen
Copy link
Contributor Author

ltfschoen commented Jan 3, 2019

@ltfschoen Yes, let RequireHealthOverlay always render children is a good idea, I agree that this PR should be redone to make it that way. It will solve the original problem more cleanly.

Btw, initially, it was a real overlay (as in a layer on top of other components), but changed in #216 (cc @axelchalon was there a technical reason for that? I can't remember now). If you want to see the old CSS, look at https://github.com/paritytech/fether/pull/216/files#diff-e6912b69f6175ae14cf8eeb2923a231bL38

Edit: We could make RequireHealthOverlay a SUI Modal that takes all screen, to avoid custom CSS.

Yes, I think it should comprise:

screen shot 2019-01-03 at 9 41 15 pm

I'm more in favour of non- full screen modal, I prefer just a small modal in the middle to get the message across to the user (or even better would be if it was out of the way all together, perhaps up in the top-right corner and using colour codes red/green like on the account list screen so you don't even have to read the connection error message, you just notice the colour change to 'red'), but allows the user can still continue modifying input fields values whilst they're waiting for the syncing or bad connection or whatever to restore (since with some transparency they can still select the input fields to edit them and mostly see what they're typing). Otherwise they lose time having to wait for the full screen modal to disappear.

Even if it's a bad connection, Parity's downloading, or there's no internet, or there's no peers, or it's syncing, ... i think the user shouldn't be interrupted from entering values into the input fields, nor from clicking the "Send" button

And after they click the "Send" button, we could use the full-screen modal for the "Submitted" modal (since doing so wouldn't interrupt the user from doing anything), and if there happens to be a connection issue we can show up in the top-right the connection issue and colour code

@amaury1093
Copy link
Collaborator

amaury1093 commented Jan 3, 2019

Even if it's a bad connection, Parity's downloading, or there's no internet, or there's no peers, or it's syncing, ... i think the user shouldn't be interrupted from entering values into the input fields, nor from clicking the "Send" button

@ltfschoen After some very long discussions between a lot of disagreeing people (in the Fether riot channel, surely in some issues and prs too), we decided that:

  • We show a full modal on all screens that read/write blockchain state: tokens balances, send tx etc.
  • We don't show a modal on other screens (account management), only a green/yellow/red button as you described.

Let's not revive that debate anymore :) (pm me if you want a summary of the reasons for this)

@axelchalon
Copy link
Contributor

axelchalon commented Jan 3, 2019

Btw, initially, it was a real overlay (as in a layer on top of other components), but changed in #216 (cc @axelchalon was there a technical reason for that? I can't remember now).

(edited)

Yes.

https://github.com/paritytech/fether/blob/3eb3ebf2f1d643bd0fed377505131adfa2099b8c/packages/fether-react/src/App/App.js#L63-L64

If we render components (such as AccountsList) that use light.js RPC decorators before we have setApi in light.js, then it errors out https://github.com/paritytech/js-libs/blob/master/packages/light.js/src/api.ts#L47

setApi is currently called only after Parity has been downloaded and launched https://github.com/paritytech/fether/blob/3eb3ebf2f1d643bd0fed377505131adfa2099b8c/packages/fether-react/src/stores/parityStore.js#L84

@amaury1093
Copy link
Collaborator

amaury1093 commented Jan 3, 2019

@axelchalon Ah, I think you're right.

@axelchalon @ltfschoen I still propose to go for an overlay as proposed by Luke. If the overlay makes the app break in App.js, we can for example add a prop mountChildren={true/false} in RequireHealthOverlay.

@ltfschoen
Copy link
Contributor Author

Replaced by this PR that builds a solution based on a SUI modal #355

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants