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

feat: migrate bitcoin generate txs, closes LEA-1735 #668

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

fbwoolf
Copy link
Contributor

@fbwoolf fbwoolf commented Nov 28, 2024

This PR migrates code to generate the unsigned psbt for btc sends.

I did some refactoring here using generic types so we can extend our form context to accommodate diff form data in each form flow. I needed to do this to handle loading feeRates and utxos for bitcoin specifically. I spent a lot of time trying to rethink this and hope it is a good solution. I've created a few more loaders to get rid of some undefined returns we had in the code I ported over from the extension.

I've also spent some time making sure to write tests that were missing, and refactoring bitcoin fees code as I migrated it over.

As mentioned in Slack, I'd like to standardize our Fees model type after this work.

Copy link

linear bot commented Nov 28, 2024

@fbwoolf fbwoolf force-pushed the feat/migrate-bitcoin-generate-txs branch from 7f3c7d2 to 77c5ff7 Compare November 28, 2024 19:05
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 88.33333% with 14 lines in your changes missing coverage. Please review.

Project coverage is 30.25%. Comparing base (0cad7aa) to head (e085851).
Report is 17 commits behind head on dev.

Files with missing lines Patch % Lines
packages/bitcoin/src/index.ts 0.00% 6 Missing ⚠️
packages/stacks/src/index.ts 0.00% 4 Missing ⚠️
...ages/query/src/bitcoin/fees/fee-estimates.hooks.ts 0.00% 2 Missing ⚠️
.../src/transactions/generate-unsigned-transaction.ts 97.61% 1 Missing ⚠️
.../src/transactions/generate-unsigned-transaction.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #668      +/-   ##
==========================================
+ Coverage   29.41%   30.25%   +0.83%     
==========================================
  Files         175      177       +2     
  Lines        6836     6924      +88     
  Branches      457      471      +14     
==========================================
+ Hits         2011     2095      +84     
- Misses       4825     4829       +4     
Files with missing lines Coverage Δ
packages/bitcoin/src/bitcoin-error.ts 100.00% <100.00%> (ø)
.../bitcoin/src/coin-selection/calculate-max-spend.ts 86.66% <ø> (ø)
...bitcoin/src/coin-selection/coin-selection.mocks.ts 100.00% <100.00%> (ø)
...kages/bitcoin/src/coin-selection/coin-selection.ts 100.00% <100.00%> (+2.06%) ⬆️
...bitcoin/src/coin-selection/coin-selection.utils.ts 100.00% <100.00%> (ø)
packages/bitcoin/src/fees/bitcoin-fees.ts 100.00% <100.00%> (ø)
.../src/transactions/generate-unsigned-transaction.ts 97.61% <97.61%> (ø)
.../src/transactions/generate-unsigned-transaction.ts 73.33% <0.00%> (ø)
...ages/query/src/bitcoin/fees/fee-estimates.hooks.ts 0.00% <0.00%> (ø)
packages/stacks/src/index.ts 0.00% <0.00%> (ø)
... and 1 more
Components Coverage Δ
bitcoin 72.90% <93.80%> (+1.64%) ⬆️
query 12.65% <0.00%> (ø)
utils 49.19% <ø> (ø)
crypto 68.21% <ø> (ø)
stacks 72.68% <0.00%> (+0.30%) ⬆️

Copy link
Collaborator

@kyranjamie kyranjamie left a comment

Choose a reason for hiding this comment

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

Great work @fbwoolf, like the component generic 👍🏼

Copy link
Collaborator

@edgarkhanzadian edgarkhanzadian left a comment

Choose a reason for hiding this comment

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

Amazing work!! 🚀

values: BitcoinTransactionValues;
}

export function useGenerateBtcUnsignedTransactionNativeSegwit(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: i think it's better to keep this function as a pure function and then wrap it in useCallback in the component when we need it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 this doesn't need to be a hook as it's not using any state. useCallback isn't needed if it's defined outside of react

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, thanks, will change.

@fbwoolf fbwoolf force-pushed the feat/migrate-bitcoin-generate-txs branch 2 times, most recently from b8bec60 to a08eb22 Compare November 29, 2024 20:01
@fbwoolf fbwoolf force-pushed the feat/migrate-bitcoin-generate-txs branch from a08eb22 to e085851 Compare November 29, 2024 20:08
@fbwoolf fbwoolf added this pull request to the merge queue Nov 29, 2024
Merged via the queue into dev with commit 44fd6cf Nov 29, 2024
13 checks passed
@fbwoolf fbwoolf deleted the feat/migrate-bitcoin-generate-txs branch November 29, 2024 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants