-
Notifications
You must be signed in to change notification settings - Fork 27
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
[ENG-3436] chore: Make some code refactoring for RBF in the extension #712
[ENG-3436] chore: Make some code refactoring for RBF in the extension #712
Conversation
…-for-rbf-in-the-extension
const fetchTotalFee = async () => { | ||
const response = await calculateTotalFee(feeRateInput); | ||
|
||
if (response) { | ||
setTotalFee(response.toString()); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchTotalFee(); | ||
}, [feeRateInput]); |
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.
const fetchTotalFee = async () => { | |
const response = await calculateTotalFee(feeRateInput); | |
if (response) { | |
setTotalFee(response.toString()); | |
} | |
}; | |
useEffect(() => { | |
fetchTotalFee(); | |
}, [feeRateInput]); | |
useEffect(() => { | |
const fetchTotalFee = async () => { | |
const response = await calculateTotalFee(feeRateInput); | |
if (response) { | |
setTotalFee(response.toString()); | |
} | |
}; | |
fetchTotalFee(); | |
}, [feeRateInput, calculateTotalFee]); |
nit: I think if fetchTotalFee is not a function used anywhere but this useEffect, it should go inside. then it will only recreate this function on change of the useEffect deps array
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.
When I apply the code you suggested, it starts lagging for some reason 🤔 let's probably keep the original version for now
export const ControlsContainer = styled.div` | ||
display: flex; | ||
gap: 12px; | ||
margin: 24px 16px 40px; | ||
`; |
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.
fyi: I have started moving some common layouts (defined in zeroheight) into common.styled.ts 😄
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.
very clean, thank you!
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.
👏 👏
@@ -195,7 +206,7 @@ function SpeedUpTransactionScreen() { | |||
} catch (err: any) { | |||
console.error(err); | |||
|
|||
if (err?.response?.data && err?.response?.data.includes('insufficient fee')) { | |||
if (err?.response?.data && err.response.data.includes('insufficient fee')) { |
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 (err?.response?.data && err.response.data.includes('insufficient fee')) { | |
if (err?.response?.data?.includes('insufficient fee')) { |
yeah or this 😄
a matter of code aesthetics I guess
@@ -128,7 +131,7 @@ function SpeedUpTransactionScreen() { | |||
} finally { |
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.
L124-125: is there a hook we can use for mempoolApi.getRecommendedFees?
L130: I wonder if we need a toast error here too?
L108-128: could abstract all this logic into a hook like:
const useRbfTransactionData: (transaction: ReturnType<useTransaction>) => {
rbfTransaction?: rbf.RbfTransaction,
rbfTxSummary?: {
currentFee: number;
currentFeeRate: number;
minimumRbfFee: number;
minimumRbfFeeRate: number;
},
rbfRecommendedFees?: RbfRecommendedFees
} = (transaction) => {
const { selectedAccount, accountType, network } = useWalletSelector();
const seedVault = useSeedVault();
const btcClient = useBtcClient();
// logic here
}
// in SpeedUpTransaction:
const {rbfTransaction, rbfTxSummary, rbfRecommendedFees} = useRbfTransactionData(transaction)
or even wrap it in a useQuery, and get the isLoading and error states too
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.
makes sense! I added a todo comment for this
const priorityOrder = ['highest', 'higher', 'high', 'medium']; | ||
return priorityOrder.indexOf(a[0]) - priorityOrder.indexOf(b[0]); | ||
}) |
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: maybe you could sort this before setRbfRecommendedFees()? here it will sort again on every render
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 for taking the time to tidy the code! I had some more code style suggestions, but only suggestions.
and a couple of nits on (probably insignificant) react optimisations
…-for-rbf-in-the-extension
…-for-rbf-in-the-extension
It would make sense to test and merge this PR together with #727 in the next release (0.28.0) |
…-for-rbf-in-the-extension
|
@dhriaznov this can be merged, tested per agreement |
…re not unique across ledger devices (#712)
🔘 PR Type
What kind of change does this PR introduce?
📜 Background
After the RBF UI & logic were added to the web-extension, we also developed it for the mobile app. And some things could be improved in its code like constants, typing, etc. (kudos to @fedeerbes for the mobile app PR review)
This PR is made to address those things for the web extension as well.
Issue Link: #[ENG-3436]
Context Link (if applicable):
🔄 Changes
initialFeeRate
property of the custom fee component that had the same value asminimumRbfFee
handleKeyDownFeeRateInput
function to helpers to reuse itEMPTY_LABEL
constantFiatAmountText
component instead of duplicating thegetFiatAmountString
functionImpact:
🖼 Screenshot / 📹 Video
Include screenshots or a video demonstrating the changes. This is especially helpful for UI changes.
✅ Review checklist
Please ensure the following are true before merging: