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

feat - Fixes #293. Shows tx fee estimate and total tx amount. See issues in commit details #307

Merged
merged 40 commits into from Jan 6, 2019

Conversation

ltfschoen
Copy link
Contributor

@ltfschoen ltfschoen commented Dec 18, 2018

Screenshot:

screen shot 2018-12-18 at 10 56 41 pm

…es in commit details

* After entering a valid value and a recipient address, it works but the console displays error: `Uncaught TypeError: Cannot read property 'resolve' of null at flush (index.js:62)`

* On the 'Send THIBCoin' if you enter a valid value and a recipient address, the Tx Fee Estimate is shown as being the same value as the Amount, which is incorrect!
@Tbaut
Copy link
Collaborator

Tbaut commented Dec 19, 2018

Thanks a lot @ltfschoen for the contributions. I'd like to keep the design as simple as possible, I'll try to come up with a Mockup soon to keep the screen simple because I find it overwhelming right now.

@Tbaut
Copy link
Collaborator

Tbaut commented Dec 19, 2018

Here is the most simple way to show what you've built, but only to interested users.
We will need this "details" dropdown if we want to let users chose the gas price (cf #306 )
image

@ltfschoen
Copy link
Contributor Author

ltfschoen commented Dec 19, 2018

@Tbaut I've pushed commits so it functions with show/hide details like in your wireframes as shown in screenshot below. I might darken the text to match though

I still have to resolve the two issues shown in the description.

screen shot 2018-12-19 at 11 26 21 pm

Copy link
Collaborator

@Tbaut Tbaut left a comment

Choose a reason for hiding this comment

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

that's cool, some nits

{estimatedTxFee &&
!estimatedTxFee.isZero() && (
<div>
{showDetails && !isNaN(values.amount) ? (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you show the "details" all the time so that the "send" button doesn't jump?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean remove the 'Details' and 'Hide' buttons, and just show the details section all the time by default? Or retain the 'Details' and 'Hide' buttons functionality whilst preventing the "send" button from jumping when the user toggles one of the buttons?

Copy link
Contributor Author

@ltfschoen ltfschoen Dec 20, 2018

Choose a reason for hiding this comment

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

I'll keep the 'Details' and 'Hide' button functionality, and just fix it so it doesn't jump each time you click 'Details' or 'Hide'

const renderCalculation = values => {
return `Calcs: (${estimatedTxFee
.div(new BigNumber(values.gasPrice.toString()))
.div(10 ** 9)} GWEI * ${new BigNumber(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is in Wei

.div(new BigNumber(values.gasPrice.toString()))
.div(10 ** 9)} GWEI * ${new BigNumber(
values.gasPrice.toString()
)} GWEI) / 10**18`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd leave the / 10**18 because it makes things even more complex. Talking in ETH is fine.

@ltfschoen
Copy link
Contributor Author

@Tbaut I've pushed more commits to address your latest review comments

I still have to resolve the three issues shown in the description.

… by using async await

* Fixes error `Uncaught TypeError: Cannot read property 'resolve' of null at flush` that is generated after both valid amount and recipient values are entered
@ltfschoen
Copy link
Contributor Author

ltfschoen commented Dec 27, 2018

@Tbaut I've pushed commits that fix the bugs so I think we can remove the "A3-inprogress" label now. Suggest merging PR #326 before this one so we can double check that the second issue gets resolved by that PR

@ltfschoen ltfschoen changed the title WIP - Fixes #293. Shows tx fee estimate and total tx amount. See issues in commit details feat - Fixes #293. Shows tx fee estimate and total tx amount. See issues in commit details Dec 27, 2018
Copy link
Collaborator

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

I like the idea!

2 suggestions:

  • Can we make the details text selectable (nit)? It feels weird that it's not.
  • The text is not so clear to me right now, and there's a mistake: it's not 21,000 WEI, just 21,000 (units of gas).
    I propose:
Estimate amount of gas: 21000
Fee: 0.000840000 ETH (gas estimate * gas price)
Total amount: 1.2000840000 ETH

state = {
maxSelected: false
estimatedTxFee: ZERO,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this from state. The estimated fee is final-form's values.gas time values.gasPrice, so no need for another state variable.

componentWillUnmount () {
// Avoids encountering error `Can't call setState (or forceUpdate)
// on an unmounted component` when navigate from 'Send Ether' to 'Send THIBCoin'
this.isCancelled = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is we remove estimatedTxFee (see above), we don't need isCancelled anymore.

@@ -98,6 +125,56 @@ class Send extends Component {
token
} = this.props;

const { estimatedTxFee, showDetails } = this.state;

const renderFee = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

2 solutions here:

  • either create a variable called renderFee
  • or put this function as a class method.

Reason: now we're creating a new function on each render.

.toString()} ETH (Gas Limit * Gas Price)`;
};

const renderCalculation = values => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above.

return `Calcs: (${gasLimitBn} WEI * ${gasPriceBn} GWEI)`;
};

const renderTotalAmount = values => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above.

.toString()} ETH`;
};

const renderDetails = values => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above.

)}`;
};

const showHideLabel = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above.

);
};

const showDetailsLabel = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above.

@ltfschoen
Copy link
Contributor Author

@amaurymartiny I've addressed all your review comments

@Tbaut I've addressed all your review comments, except for:

The "send" button is still jumping when the "details" appears.

@Tbaut I just merged the latest changes from master and noticed that YJ has added an autoFocus on the Amount input field (which is now the second input field that is shown after re-ordering the input fields to match the wireframe you provided in this earlier comment #307 (comment)). I just wanted to confirm that this is correct?

@ltfschoen
Copy link
Contributor Author

@Tbaut I've just had a look at the following review comment but I can't replicate it.

The "send" button is still jumping when the "details" appears.

Could you please check if it's still an issue for you with the latest changes?

@Tbaut
Copy link
Collaborator

Tbaut commented Jan 4, 2019

Still happening on the latest iteration, the send button jumps when "details" appears.
There is also a slight horizontal jump of the whole windows (but this seems to be due to the automatic window size):
image

Copy link
Collaborator

@Tbaut Tbaut left a comment

Choose a reason for hiding this comment

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

nit

packages/fether-react/src/Send/TxForm/TxForm.js Outdated Show resolved Hide resolved
@ltfschoen
Copy link
Contributor Author

@Tbaut I've pushed commits addressing your issues. I noticed it on mine as well but hadn't looked close enough, and on closer inspection I found that it was the scroll bar appearing very briefly that caused the jumping effect. I found that I just needed to hide the scroll on the body element, which I've included in one of the commits

Copy link
Collaborator

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

lgtm! imo there's a script that is actually not needed, but I'll wait for @ltfschoen's answer.

),
'ether'
)
.toFixed(18)
Copy link
Collaborator

@amaury1093 amaury1093 Jan 4, 2019

Choose a reason for hiding this comment

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

If you remove this line, then .toString() actually already removes trailing zeroes, and I believe removeTrailingZeros is not needed then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes removing that script and removing .toFixed(18) fixed it

…oved into footer"

* Move "Details" / "Hide" buttons into the form-nav footer section

* TxDetails now appears above the footer area above other input fields without causing the screen height to increase

* Background of the TxDetails darkened so it stands out from surroudings

* Change "Details" arrow to point upwards since TxDetails now shown above

* Change "Hide" arrow to point downward since TxDetails now shown above

* Rename classnames to `_` or `-` more consistently

* Note: To quickly display the 'Details' button so you can click it change TxForm.js as follows:

```
{/* {valid && this.estimatedTxFee(values) ? ( */}
  <TxDetails
    // estimatedTxFee={this.estimatedTxFee(values)}
    estimatedTxFee={new BigNumber('8100000')}
    token={token}
    // values={values}
    values={ { amount: new BigNumber('0.1'), gasPrice: new BigNumber('21000') } }
  />
{/* ) : null} */}
@ltfschoen
Copy link
Contributor Author

ltfschoen commented Jan 4, 2019

Based on discussion with @Tbaut I've created a separate branch and this commit bd56db6 that includes:

  • Displays the "Details / Hide" buttons in the footer so when they appear they do not cause the height of the window to change (same horizontal alignment as the 'Send' / 'Checking...' button)
  • When "Details" button is clicked it displays the transaction details on top of the other fields so it doesn't cause the height of the window to change.

If we'd like this option then it's probably worth also refactoring the code to try and use a SUI popup/modal. What do you think?

Screenshot:

screen shot 2019-01-05 at 9 16 43 am

With the code in that branch/commit the only issue that appears to still need fixing is when it changes to 'Checking...' instead of 'Send' it causes both the "Details / Hide" buttons and the transaction details popup to shift to the left (since the text of 'Checking...' has more characters and makes the button wider requiring more space).

Screenshot with bug:

screen shot 2019-01-05 at 9 17 02 am

@Tbaut
Copy link
Collaborator

Tbaut commented Jan 6, 2019

I think there was a misunderstanding. My request was actually very small and most probably just needed a CSS trick. What you did before with a slide down was totally fine and matched the mockup we agreed on.

The only problem I saw was with the jump of the "Send" button when the details button appears.
An image is worth 1000 words.

  • We currently have a transition from 1 -> 2, the appearance of "Details" toggle button makes the windows longer, that's what I meant with the jump of the "Send" button.
  • I wish to make sure the space taken by the "Details" button is already reserved (green area hilighted in 3) so that we would have a transition from 3 -> 2 (the green area in 3 should obviously be white).

image

Please PM if that's not clear.
We could also simply show a disabled "Details" button when not available.

For the sake of completeness, here is my reasoning:

  • it's fine for things to change a lot (such as a window resize) when the user expects it, e.g user click on a "Details" button -> the windows shows a new section and resizes
  • it's not fine if the user doesn't expect it, e.g the user enters an amount and an unexpected "Details" button appears which makes the window resize.

…details buttons to footer

* Move toggle details buttons and associated methods and showDetails state into nav of TxForm component

* Pass showDetails down as props to TxDetails

* Remove previous attempt to display TxDetails like a popup above other fields
(i.e. remove form-details-wrapper and -details-value styles)
@ltfschoen
Copy link
Contributor Author

ltfschoen commented Jan 6, 2019

@Tbaut I've push a commit that's a slight alternative to what you've shown. It gets rid of the "green" area (shown in your image) all together so we don't have to unnecessarily reserve that entire space just for the little "Details / Hide" toggle button. It involves moving the "Details / Hide" toggle button div into the footer nav bar so it appears inline with the "Send / Checking..." button (so we're grouping our buttons together in the footer navbar). Whilst the form input fields aren't valid or it's still validating or if its still calculating the gas then it doesn't show the "Details / Hide" toggle buttons or the details section at all.

Screenshots:

screen shot 2019-01-07 at 5 44 06 am

screen shot 2019-01-07 at 5 44 18 am

@ltfschoen
Copy link
Contributor Author

ltfschoen commented Jan 6, 2019

@Tbaut If your not happy with the above alternative just let me know. It'd be a quick change to do as you've requested by reserving an area above the "Send / Checking..." button and move the "Details / Hide" toggle button there (but I was hoping that squeezing all the buttons together into the footer nav would be more appealing).

Currently it does not showing the "Details / Hide" toggle buttons or the details section at all when it's not "ready" (i.e. the form input fields aren't valid or it's still validating or if its still calculating the gas), and I'd suggest retaining this functionality

Copy link
Collaborator

@Tbaut Tbaut left a comment

Choose a reason for hiding this comment

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

Thanks a lot, that's fine like this.
We can improve the behaviour when the details section is shown and you change the amount, as the whole section gets hidden and shown again, but that can be addressed in another PR :)

@Tbaut Tbaut merged commit e7437e0 into master Jan 6, 2019
ltfschoen added a commit that referenced this pull request Jan 13, 2019
…etails.

* Add styled-components dependency to start introducing it to components instead of Sass

* Wrap App.js with styled-components ThemeProvider and inject `fetherTheme` prop colours so they are available to child components.

* Added styled-components' GlobalStyle https://www.styled-components.com/docs/faqs boilerplate as child of ThemeProvider so global styles may be defined here

* Replace assets/sass/layouts/_wrapper.scss with styled-components including:
  * DivContent is declared in App.js since it is only used here
  * DivWindow is declared in App.js since it is only used here
  * DivWindowContent is declared in shared folder since used by different components

* Removed assets/sass/layouts/_wrapper.scss. Noting that `.connector` class is not used

* Use styled-components in TxForm and TxDetails components (that were introduced in PR #307).

* Add a style.js file in the same directory of the component where styled-components are used

* Add styled-components theme animations folder with a SlideInLeft animation and introduce a theme to TxDetails

* Add keyframes animation to TxDetails component (i.e. slide-in animation that's used in the details section that appears when you click Details/Hide button on the Send Ether/THIBCoin page)

* Fix `faint` style implementation to use `rgba` with styled-components

* Note that I decided not to use defaultProps feature of styled-components as it bloats the code too much

* Note that currently we are using Sass _variables.scss for colour variables, and since many components still use some of the Sass variables we cannot remove them yet.

* Note that the original branch where this work was done is https://github.com/paritytech/fether/compare/luke-293-show-tx-fee-styled-components?expand=1, but since multiple PRs have since been merged it was easier to just code again using it as reference

* Disadvantage of styled-components appears to be when you go to debug components in Dev Tools > Elements. The classNames appear as a hash `<div class="sc-EHOje dGUdfn">` instead of the classname!!
@Tbaut Tbaut deleted the luke-293-show-tx-fee branch January 18, 2019 11:25
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.

None yet

3 participants