fix: issue with fee UI react rendering loop #65
Closed
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.
The bug happens when you stake amount + fee > funds avaiable:
This is a high-risk change, but it’s the least invasive approach I could think of without breaking other functionality.
What’s wrong with the current implementation?
The three components are currently tangled together:
The stakingFeeSat is derived in staking.tsx, but it’s passed as a prop to stakingFee.tsx and is affected by selectedFeeRate, which is also set within stakingFee.tsx. This results in two different places determining the fee values.
To make it more complex, stakingAmount.tsx handles input validation and decides the value that will determine UTXOs, which in turn affects the fees. As a result, these three components create a very complex interdependent React data flow through props and state.
I didn’t attempt to fix these interdependencies in this PR because doing so would require much larger changes. The ideal state I envision is:
As a result of this PR, you’ll notice that the StakingFee component re-renders with each amount input. This isn’t avoidable unless we untangle the three components mentioned above. While it’s not ideal, it’s something we can live with for now until we refactor.