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: add psbt functionality #641

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open

feat: add psbt functionality #641

wants to merge 23 commits into from

Conversation

edgarkhanzadian
Copy link
Collaborator

@edgarkhanzadian edgarkhanzadian commented Nov 20, 2024

  • Add PsbtSigner component.
  • Hook up PsbtSigner to send flow
  • Create a basic psbt with 1 input utxo for psbt testing
  • Market data should be returned in cents, not dollars
  • Fix flaky balances using unique react query keys for btc balance
  • Update api to the leather-hosted api
  • Fix encryption compliance in Info.plist so appstore doesn't require manual submission for every build

Note: I'll leave the commits unsquashed for now until right before the merge, just in case i need to revert some of the changes.

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.

Thanks @edgarkhanzadian, just dropping some comments in here. Main thoughts is that I think it isn't necessary to pass around addresses the way being done here.

apps/mobile/src/features/send/send-sheets/sign-psbt.tsx Outdated Show resolved Hide resolved
apps/mobile/src/features/send/send-sheets/sign-psbt.tsx Outdated Show resolved Hide resolved
packages/bitcoin/src/psbt/psbt-details.ts Outdated Show resolved Hide resolved
packages/bitcoin/src/psbt/psbt-details.ts Outdated Show resolved Hide resolved
packages/bitcoin/src/psbt/psbt-inputs.ts Outdated Show resolved Hide resolved
packages/bitcoin/src/psbt/psbt-inscriptions.ts Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 0.57143% with 174 lines in your changes missing coverage. Please review.

Project coverage is 28.71%. Comparing base (1a71396) to head (da5ade0).
Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
packages/bitcoin/src/psbt/psbt-details.ts 0.00% 43 Missing ⚠️
packages/bitcoin/src/psbt/psbt-totals.ts 0.00% 41 Missing ⚠️
packages/bitcoin/src/psbt/psbt-inputs.ts 0.00% 33 Missing ⚠️
packages/bitcoin/src/psbt/psbt-outputs.ts 0.00% 24 Missing ⚠️
packages/bitcoin/src/psbt/utils.ts 0.00% 17 Missing ⚠️
packages/bitcoin/src/index.ts 0.00% 6 Missing ⚠️
packages/bitcoin/src/bitcoin.utils.ts 16.66% 5 Missing ⚠️
...es/services/src/market-data/market-data.service.ts 0.00% 4 Missing ⚠️
...s/query/src/bitcoin/balance/btc-blockbook-utxos.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #641      +/-   ##
==========================================
- Coverage   29.41%   28.71%   -0.71%     
==========================================
  Files         175      180       +5     
  Lines        6836     7008     +172     
  Branches      457      462       +5     
==========================================
+ Hits         2011     2012       +1     
- Misses       4825     4996     +171     
Files with missing lines Coverage Δ
...s/query/src/bitcoin/balance/btc-blockbook-utxos.ts 0.00% <0.00%> (ø)
...es/services/src/market-data/market-data.service.ts 0.00% <0.00%> (ø)
packages/bitcoin/src/bitcoin.utils.ts 41.55% <16.66%> (-0.67%) ⬇️
packages/bitcoin/src/index.ts 0.00% <0.00%> (ø)
packages/bitcoin/src/psbt/utils.ts 0.00% <0.00%> (ø)
packages/bitcoin/src/psbt/psbt-outputs.ts 0.00% <0.00%> (ø)
packages/bitcoin/src/psbt/psbt-inputs.ts 0.00% <0.00%> (ø)
packages/bitcoin/src/psbt/psbt-totals.ts 0.00% <0.00%> (ø)
packages/bitcoin/src/psbt/psbt-details.ts 0.00% <0.00%> (ø)
Components Coverage Δ
bitcoin 62.23% <0.58%> (-9.02%) ⬇️
query 12.65% <0.00%> (ø)
utils 49.19% <ø> (ø)
crypto 68.21% <ø> (ø)
stacks 72.38% <ø> (ø)

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 @edgarkhanzadian this is coming together 👌🏼

Comment on lines +5 to +6
<key>ITSAppUsesNonExemptEncryption</key>
<false />
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixing the appstore connect deployment, s.t. appstore connect does not ask for manual approval every time we upload a build to testflight

@@ -28,7 +28,7 @@ const accountUtxoResponseSchema = z.array(utxoSchema);
export type Utxo = z.infer<typeof utxoSchema>;

export function createUtxoAccountCacheKey(network: string, descriptor: string) {
return ['btc-utxos', network, descriptor.substring(0, 10)];
return ['btc-utxos', network, descriptor.substring(0, 35)];
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

10 characters were not enough to make a unique xpub key for multiple accounts, extending it to 35 fixed it

Copy link
Collaborator

Choose a reason for hiding this comment

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

yep I saw a similar bug elsewhere

@@ -78,9 +79,13 @@ export function createMarketDataService(
.map(r => r.value)
.filter(isDefined);
if (prices.length === 0) throw new Error('Unable to fetch price data: ' + currency);

const meanPrice = calculateMeanAverage(prices);
const meanPriceFractional = convertAmountToFractionalUnit(meanPrice, currencyDecimalsMap.USD);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Services should return cents, not dollars

}

function selectByAccountIds(accountIds: string[]) {
return createSelector(selectors.selectEntities, entities => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

selectors.selectAll does the mapping you do here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

selectAll returns an array of accounts which i'd need to filter up using accountIds array. In this case, entities is a map from which i can select only the accounts that i need, without going through all accounts accountIds.length times. Thought to include a small optimization for big wallets

apps/mobile/src/components/spinner-icon.tsx Outdated Show resolved Hide resolved
const btcBalance = createMoney(Number(inputOutput.value), 'BTC');
const usdBalance = btcMarketData
? baseCurrencyAmountInQuote(btcBalance, btcMarketData)
: createMoney(0, 'USD');
Copy link
Contributor

Choose a reason for hiding this comment

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

I've seen this used in few other places, and it can potentially cause flicker from 0 to actual balance, unless the relevant query happens to be in cache and fresh. Is there anything we're missing design-wise to avoid this?
Couple things I can think of:

  1. Loading state (if applicable)
  2. Making shared data like market queries globally available upon app startup

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree, we need to think of that but we might need to handle it as a part of a separate PR


export function FeeCard({ feeType }: { feeType: FeeTypes }) {
export function FeeCard({ feeType, amount }: { feeType: FeeTypes; amount: Money }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use a props interface?


export function OutcomesCard() {
Copy link
Contributor

Choose a reason for hiding this comment

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

What does OutcomesCard refer to? Not sure I understand what this is exactly?

// eslint-disable-next-line no-console, lingui/no-unlocalized-strings
console.log('Send form data:', values);
async onInitSendTransfer(values: SendFormBtcSchema) {
if (!sortedUtxos[0]) throw new Error('no utxo');
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this all just for testing? Please don't merge over my work in latest btc send form PR to gen the unsigned psbt.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeap! i created a very basic psbt here just for testing purposes until your changes get merged.

Great work @edgarkhanzadian, can you rebase on my latest merge before I approve? My changes in onInitSendTransfer in use-send-form.tsx should generate the unsigned psbt to pass to your work.

Sounds awesome! Will update the PR

@fbwoolf
Copy link
Contributor

fbwoolf commented Nov 29, 2024

Great work @edgarkhanzadian, can you rebase on my latest merge before I approve? My changes in onInitSendTransfer in use-send-form.tsx should generate the unsigned psbt to pass to your work.

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.

4 participants