Skip to content
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

Conversation

dhriaznov
Copy link
Contributor

@dhriaznov dhriaznov commented Dec 13, 2023

🔘 PR Type

What kind of change does this PR introduce?

  • Refactoring (no functional changes, no API changes)

📜 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

  • Moved Speed Up tx custom fee component to a separate folder and created a separate file for its styles
  • Removed the initialFeeRate property of the custom fee component that had the same value as minimumRbfFee
  • Fixed typing for the Speed Up tx screen
  • Moved the handleKeyDownFeeRateInput function to helpers to reuse it
  • Added EMPTY_LABEL constant
  • Used the FiatAmountText component instead of duplicating the getFiatAmountString function
  • Moved the copy related to estimated RBF completion time to translations

Impact:

  • This PR makes the RBF code more clean and robust, and shouldn't break any logic

🖼 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:

  • Code Style is consistent with the project guidelines.
  • Code is readable and well-commented.
  • No unnecessary or debugging code has been added.
  • Security considerations have been taken into account.
  • The change has been manually tested and works as expected.
  • Breaking changes and their impacts have been considered and documented.
  • Code does not introduce new technical debt or issues.

@dhriaznov dhriaznov self-assigned this Dec 13, 2023
@dhriaznov dhriaznov requested a review from teebszet December 13, 2023 20:11
@dhriaznov dhriaznov marked this pull request as ready for review December 13, 2023 20:15
Comment on lines +54 to +64
const fetchTotalFee = async () => {
const response = await calculateTotalFee(feeRateInput);

if (response) {
setTotalFee(response.toString());
}
};

useEffect(() => {
fetchTotalFee();
}, [feeRateInput]);
Copy link
Member

@teebszet teebszet Dec 14, 2023

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Contributor Author

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

Comment on lines +77 to +81
export const ControlsContainer = styled.div`
display: flex;
gap: 12px;
margin: 24px 16px 40px;
`;
Copy link
Member

@teebszet teebszet Dec 14, 2023

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 😄

Copy link
Member

Choose a reason for hiding this comment

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

very clean, thank you!

Copy link
Member

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')) {
Copy link
Member

@teebszet teebszet Dec 14, 2023

Choose a reason for hiding this comment

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

Suggested change
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 {
Copy link
Member

@teebszet teebszet Dec 14, 2023

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

Copy link
Contributor Author

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

Comment on lines 376 to 378
const priorityOrder = ['highest', 'higher', 'high', 'medium'];
return priorityOrder.indexOf(a[0]) - priorityOrder.indexOf(b[0]);
})
Copy link
Member

@teebszet teebszet Dec 14, 2023

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

teebszet
teebszet previously approved these changes Dec 14, 2023
Copy link
Member

@teebszet teebszet left a 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

@dhriaznov
Copy link
Contributor Author

Thanks for the review @teebszet! I updated the PR, and also included the fix from #713 you created since it's related and would be better to test those 2 PRs together. Could you approve it again pls? 🙂

@dhriaznov
Copy link
Contributor Author

It would make sense to test and merge this PR together with #727 in the next release (0.28.0)

Copy link

@DuskaT021 DuskaT021 added testing QA testing in progress and removed ready for test labels Jan 9, 2024
@DuskaT021
Copy link
Contributor

@dhriaznov this can be merged, tested per agreement

@DuskaT021 DuskaT021 added ready for release and removed testing QA testing in progress labels Jan 9, 2024
@DuskaT021 DuskaT021 merged commit e279511 into develop Jan 9, 2024
2 checks passed
@teebszet teebszet deleted the denys/eng-3436-make-some-code-refactoring-for-rbf-in-the-extension branch January 10, 2024 07:37
This was referenced Jan 11, 2024
teebszet added a commit that referenced this pull request Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants