feat - Fixes #293. Shows tx fee estimate and total tx amount. See issues in commit details #307
Conversation
…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!
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. |
Here is the most simple way to show what you've built, but only to interested users. |
@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. |
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.
that's cool, some nits
{estimatedTxFee && | ||
!estimatedTxFee.isZero() && ( | ||
<div> | ||
{showDetails && !isNaN(values.amount) ? ( |
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.
Could you show the "details" all the time so that the "send" button doesn't jump?
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.
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?
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'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( |
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 is in Wei
.div(new BigNumber(values.gasPrice.toString())) | ||
.div(10 ** 9)} GWEI * ${new BigNumber( | ||
values.gasPrice.toString() | ||
)} GWEI) / 10**18`; |
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'd leave the / 10**18
because it makes things even more complex. Talking in ETH is fine.
@Tbaut I've pushed more commits to address your latest review comments I still have to resolve the three issues shown in the description. |
…prevent wrapping in UI
… 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
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 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, |
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.
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; |
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.
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 = () => { |
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.
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 => { |
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.
same as above.
return `Calcs: (${gasLimitBn} WEI * ${gasPriceBn} GWEI)`; | ||
}; | ||
|
||
const renderTotalAmount = values => { |
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.
same as above.
.toString()} ETH`; | ||
}; | ||
|
||
const renderDetails = values => { |
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.
same as above.
)}`; | ||
}; | ||
|
||
const showHideLabel = () => { |
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.
same as above.
); | ||
}; | ||
|
||
const showDetailsLabel = () => { |
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.
same as above.
… prop to TxDetails
…textarea focus opacity
…iling 0's for say 0.0000000001
…l point in string
@amaurymartiny I've addressed all your review comments @Tbaut I've addressed all your review comments, except for:
@Tbaut I just merged the latest changes from master and noticed that YJ has added an |
@Tbaut I've just had a look at the following review comment but I can't replicate it.
Could you please check if it's still an issue for you with the latest changes? |
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.
nit
@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 |
…licker on/off when TxDetails toggled
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! imo there's a script that is actually not needed, but I'll wait for @ltfschoen's answer.
), | ||
'ether' | ||
) | ||
.toFixed(18) |
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.
If you remove this line, then .toString()
actually already removes trailing zeroes, and I believe removeTrailingZeros
is not needed then?
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.
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} */}
Based on discussion with @Tbaut I've created a separate branch and this commit bd56db6 that includes:
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: 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: |
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.
Please PM if that's not clear. For the sake of completeness, here is my reasoning:
|
…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)
@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: |
@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 |
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.
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 :)
…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!!
Update (28 Dec 2018): RESOLVED in commit 13fd9f6 - 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)
Update (28 Dec 2018): REQUIRES this PR to be merged fix: Fixes #320. Memoize form field values in state to prevent reseting on sync #326 - After I've enter a recipient and an amount and the Transaction Details have been calculated, then if the page refreshes (likely due to syncing) then the input values clear but the Transaction Details are still shown. Update: Note that I have raised this PR to prevent the input values from being cleared due to syncing fix: Fixes #320. Memoize form field values in state to prevent reseting on sync #326 so that this will no longer be an issue
Screenshot: