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: SIP-10 balances on mobile #820

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

pete-watters
Copy link
Contributor

@pete-watters pete-watters commented Jan 17, 2025

This PR:

  • Integrates the SIP-10 balances service to mobile: LEA-1832
  • Adds boiler plate code for Runes: LEA-1981

I didn't add the icons yet as Tigran will add update icon component to accept URLs LEA-1909

For the Tokens Widget we have a hard cap to show only 5 tokens so I added some code to cap it:

  • BTC
  • STX
  • 3 SIP tokens

This is OK for now but we need to revisit this. You can see a demo here:

SIP-10-less.mp4

I did more testing before this cap to make sure we are showing the correct aggregate balances on the homepage:

SIP-10.mp4

Copy link

linear bot commented Jan 17, 2025

Copy link

codecov bot commented Jan 17, 2025

Codecov Report

Attention: Patch coverage is 97.77778% with 1 line in your changes missing coverage. Please review.

Project coverage is 29.53%. Comparing base (711449b) to head (737562a).

Files with missing lines Patch % Lines
packages/services/src/index.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #820      +/-   ##
==========================================
+ Coverage   29.15%   29.53%   +0.37%     
==========================================
  Files         205      206       +1     
  Lines        8159     8204      +45     
  Branches      560      567       +7     
==========================================
+ Hits         2379     2423      +44     
- Misses       5780     5781       +1     
Files with missing lines Coverage Δ
...es/services/src/balances/sip10-balances.service.ts 100.00% <100.00%> (ø)
...ages/services/src/balances/sip10-balances.utils.ts 100.00% <100.00%> (ø)
packages/services/src/index.ts 0.00% <0.00%> (ø)
Components Coverage Δ
bitcoin 64.15% <ø> (ø)
query 12.60% <ø> (ø)
utils 42.64% <ø> (ø)
crypto 68.21% <ø> (ø)
stacks 71.78% <ø> (ø)

@pete-watters pete-watters force-pushed the feat/LEA-1832/stacks-sip10 branch 3 times, most recently from 728e6d5 to 4810561 Compare January 17, 2025 15:41
@pete-watters pete-watters changed the base branch from feat/LEA-1726/sip10-balances to dev January 17, 2025 15:42
import { BitcoinAccountIdentifier, getRunesBalancesService } from '@leather.io/services';

export function useRunesTotalBalance() {
// TODO LEA-1982: check with Alex once we have xpub-based runes endpoint from BIS
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexp3y I just stubbed out this Runes code, we can revisit it once the BIS endpoint is ready and probably refactor this

@pete-watters pete-watters force-pushed the feat/LEA-1832/stacks-sip10 branch from 4810561 to 737562a Compare January 17, 2025 15:44
@@ -55,6 +57,7 @@ export function createSip10BalancesService(
return {
usd: totalUsdBalance,
addressBalances,
aggregateBalances: getAggregateSip10Balances(addressBalances),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexp3y I added aggregateBalances as that's what we need on the homepage.

We don't use addressBalances from this service but it could be useful? I'm not sure. I think it has a different query cache than account specific balances anyway?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Yeah having an aggregateBalances field here makes perfect sense. Definitely more so than the addressBalances array, which I thought could be useful but in retrospect it does stretch the responsibility of the call and bloats the query cache unnecessarily. If we're not going to use it then it might be best to just remove.

@pete-watters pete-watters marked this pull request as ready for review January 17, 2025 15:49

import { TokenBalance } from '../token-balance';

const sip10MaxDisplay = 3;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm adding this hard cap of 3 SIP-10 tokens until we figure out what we want to do here


// TODO LEA-1726: handle balance loading & error states
if (data.state !== 'success') return;
return data.value?.runes.map((balance: any, index: any) => (
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't it typed such that values is definitely defined when state !== 'success'?

@@ -25,6 +27,9 @@ export function AllAccountBalances() {
<>
<BitcoinBalance />
<StacksBalance />
<Sip10Balance />
Copy link
Contributor Author

@pete-watters pete-watters Jan 17, 2025

Choose a reason for hiding this comment

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

@kyranjamie : do you have some good ideas about how to handle this best? I asked about it in the design channel.

In the accounts widget, we only have space for 5 tokens as we want to show other widgets also. For now I have prioritised:

  • BTX
  • STX
  • 3 others SIPs

We load tokens from different places so if we only want to show 5 and prioritise some it gets messy quickly. At the moment users will also have no way to see all of their SIP-10s as work on that is ongoing.

I added a hard cap of 3 SIP-10's in the interim but there is no sorting there yet. This will also not work if there are 0 balances for STX or BTC as we will still only show 3 SIP-10's 😢

@alexp3y maybe we could use a balance wrapper service to wrap and curate the balances?

That would move us away from this coding style though of separate balance components which we favour

Copy link
Contributor

@alexp3y alexp3y left a comment

Choose a reason for hiding this comment

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

Looks great 🔥

@@ -55,6 +57,7 @@ export function createSip10BalancesService(
return {
usd: totalUsdBalance,
addressBalances,
aggregateBalances: getAggregateSip10Balances(addressBalances),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Yeah having an aggregateBalances field here makes perfect sense. Definitely more so than the addressBalances array, which I thought could be useful but in retrospect it does stretch the responsibility of the call and bloats the query cache unnecessarily. If we're not going to use it then it might be best to just remove.

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