-
Notifications
You must be signed in to change notification settings - Fork 104
Improve Fee UX: Bidirectional Fee/Rate Input & Better Rebalance Button #447
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
Closed
Legend101Zz
wants to merge
15
commits into
caravan-bitcoin:main
from
Legend101Zz:feat/fees-based-change-in-tx
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f10e416
feat: add rebalance button for better UX
Legend101Zz c392346
Merge branch 'main' into feat/fees-based-change-in-tx
Legend101Zz 6b1663a
Merge branch 'main' into feat/fees-based-change-in-tx
25577ac
Merge branch 'main' into feat/fees-based-change-in-tx
Legend101Zz 9deae58
fix: sync issues and styling for fees and feeRate
Legend101Zz 7dbe572
fix: bump fees button and some UI changes
Legend101Zz 9f3b381
chore: add changeset
Legend101Zz 900977d
fix: restrict rebalance to change output and apply EPSILON rounding
Legend101Zz 1f3be1a
fix: bump fee-rate step to 1 sat/vB and stabilize output row layout
Legend101Zz 29cbcc3
fix: always re-derive fee rate from fee amount when inputs are known
Legend101Zz 8614494
test(e2e): target rebalance button by stable test id
Legend101Zz ecd6904
fix: wrap bitcoinsToSatoshis result in BigNumber so fee→rate back-cal…
Legend101Zz c2a983a
Merge remote-tracking branch 'upstream/main' into feat/fees-based-cha…
Legend101Zz a62473c
style: apply prettier formatting to fix CI lint
Legend101Zz a61f963
fix: e2e
Legend101Zz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "caravan-coordinator": patch | ||
| --- | ||
|
|
||
| Feat: add func to edit fees in manual mode | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ import { | |
| InputAdornment, | ||
| FormHelperText, | ||
| Typography, | ||
| Box, | ||
| Button, | ||
| } from "@mui/material"; | ||
| import AccountBalanceWalletOutlinedIcon from "@mui/icons-material/AccountBalanceWallet"; | ||
| import { Delete, AddCircle, RemoveCircle } from "@mui/icons-material"; | ||
|
|
@@ -133,12 +135,14 @@ class OutputEntry extends React.Component { | |
| } | ||
| const newAmount = this.autoBalancedAmount(); | ||
| if ( | ||
| !BigNumber.isBigNumber(newAmount) || | ||
| newAmount.isNaN() || | ||
| validateOutputAmount(bitcoinsToSatoshis(newAmount), inputsTotalSats) !== | ||
| "" | ||
| "" | ||
| ) { | ||
| return true; | ||
| } | ||
| return amountError === "" && newAmount === new BigNumber(amount); | ||
| return amountError === "" && newAmount.isEqualTo(new BigNumber(amount)); | ||
| }; | ||
|
|
||
| isBalanceable = () => !this.isNotBalanceable(); | ||
|
|
@@ -152,15 +156,17 @@ class OutputEntry extends React.Component { | |
| const { number, fee, inputsTotalSats, outputs } = this.props; | ||
| const outputTotalSats = outputs | ||
| .filter((output, i) => i !== number - 1) | ||
| .map((output) => output.amountSats) | ||
| .map((output) => new BigNumber(output.amountSats || 0)) | ||
| .reduce( | ||
| (accumulator, currentValue) => accumulator.plus(currentValue), | ||
| new BigNumber(0), | ||
| ); | ||
| const feeSats = bitcoinsToSatoshis(new BigNumber(fee)); | ||
| return satoshisToBitcoins( | ||
| const result = satoshisToBitcoins( | ||
| inputsTotalSats.minus(outputTotalSats.plus(feeSats)), | ||
| ); | ||
| // Guarantee we always return a BigNumber so .toFixed() never crashes | ||
| return BigNumber.isBigNumber(result) ? result : new BigNumber(result || 0); | ||
| }; | ||
|
|
||
| balanceAction = () => { | ||
|
|
@@ -210,10 +216,18 @@ class OutputEntry extends React.Component { | |
| } = this.props; | ||
|
|
||
| const gridSpacing = isWallet ? 10 : 1; | ||
| // Only show the rebalance button on the change output when one is set, | ||
| // not on recipient outputs. | ||
| const isChangeOutput = | ||
| changeOutputIndex > 0 && number === changeOutputIndex; | ||
| const showRebalance = | ||
| this.displayBalanceAction() && | ||
| this.balanceAction() !== null && | ||
| (changeOutputIndex === 0 || isChangeOutput); | ||
|
|
||
| return ( | ||
| <Grid container spacing={gridSpacing}> | ||
| <Grid item xs={7}> | ||
| <Grid container spacing={gridSpacing} alignItems="flex-start"> | ||
| <Grid item xs={6}> | ||
| <TextField | ||
| fullWidth | ||
| placeholder="Address" | ||
|
|
@@ -266,35 +280,61 @@ class OutputEntry extends React.Component { | |
| }} | ||
| /> | ||
| </Grid> | ||
| {this.displayBalanceAction() && ( | ||
| <Grid item xs={1}> | ||
| <Tooltip | ||
| title={`${this.balanceAction()} to ${this.autoBalancedAmount().toString()}`} | ||
| placement="top" | ||
| > | ||
| <small> | ||
| <IconButton onClick={this.handleBalance}> | ||
| {this.balanceAction() === "Increase" ? ( | ||
| <Grid item xs={2} sx={{ minHeight: 64 }}> | ||
| {showRebalance && ( | ||
| <Box> | ||
| <Button | ||
| data-testid="rebalance-button" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| variant="outlined" | ||
| color="primary" | ||
| size="small" | ||
| onClick={this.handleBalance} | ||
| startIcon={ | ||
| this.balanceAction() === "Increase" ? ( | ||
| <AddCircle /> | ||
| ) : ( | ||
| <RemoveCircle /> | ||
| )} | ||
| </IconButton> | ||
| </small> | ||
| </Tooltip> | ||
| </Grid> | ||
| )} | ||
| ) | ||
| } | ||
| sx={{ | ||
| textTransform: "none", | ||
| fontSize: "0.75rem", | ||
| whiteSpace: "nowrap", | ||
| minWidth: "auto", | ||
| }} | ||
| > | ||
| Rebalance | ||
| </Button> | ||
| <Typography | ||
| variant="caption" | ||
| color="textSecondary" | ||
| noWrap | ||
| sx={{ | ||
| display: "block", | ||
| mt: 0.5, | ||
| fontSize: "0.65rem", | ||
| overflow: "hidden", | ||
| textOverflow: "ellipsis", | ||
| }} | ||
| title={`${this.balanceAction()} to ${this.autoBalancedAmount().toFixed(8)} BTC`} | ||
| > | ||
| {this.balanceAction()} to {this.autoBalancedAmount().toFixed(8)}{" "} | ||
| BTC | ||
| </Typography> | ||
| </Box> | ||
| )} | ||
| </Grid> | ||
|
|
||
| {!finalizedOutputs && | ||
| outputs.length > (changeOutputIndex > 0 && autoSpend ? 2 : 1) && ( | ||
| <Grid item xs={1}> | ||
| <Grid item xs={1}> | ||
| {!finalizedOutputs && | ||
| outputs.length > (changeOutputIndex > 0 && autoSpend ? 2 : 1) && ( | ||
| <Tooltip title="Remove Output" placement="top"> | ||
| <IconButton onClick={this.handleDelete}> | ||
| <Delete /> | ||
| </IconButton> | ||
| </Tooltip> | ||
| </Grid> | ||
| )} | ||
| )} | ||
| </Grid> | ||
| </Grid> | ||
| ); | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: This should be a minor bump since it's a new feature and does change how rebalance looks.