Skip to content

Commit 3ccdf24

Browse files
committed
feat: support fiat currency setting, ref LEA-2032
1 parent b2084b7 commit 3ccdf24

39 files changed

+454
-321
lines changed

apps/mobile/src/features/balances/bitcoin/bitcoin-balance.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function BitcoinBalance() {
4141
return (
4242
<BitcoinTokenBalance
4343
availableBalance={balance.value.btc.availableBalance}
44-
fiatBalance={balance.value.usd.availableBalance}
44+
fiatBalance={balance.value.fiat.availableBalance}
4545
px="5"
4646
py="3"
4747
/>
@@ -64,7 +64,7 @@ export function BitcoinBalanceByAccount({
6464
return (
6565
<BitcoinTokenBalance
6666
availableBalance={balance.value.btc.availableBalance}
67-
fiatBalance={balance.value.usd.availableBalance}
67+
fiatBalance={balance.value.fiat.availableBalance}
6868
onPress={onPress}
6969
px="5"
7070
py="3"

apps/mobile/src/features/balances/bitcoin/runes-balance.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function RunesBalance() {
4747
symbol={balance.asset.symbol}
4848
name={balance.asset.runeName}
4949
availableBalance={balance.crypto.availableBalance}
50-
fiatBalance={balance.usd.totalBalance}
50+
fiatBalance={balance.fiat.totalBalance}
5151
px="5"
5252
py="3"
5353
/>
@@ -65,7 +65,7 @@ export function RunesBalanceByAccount({ fingerprint, accountIndex }: AccountId)
6565
symbol={balance.asset.symbol}
6666
name={balance.asset.spacedRuneName}
6767
availableBalance={balance.crypto.availableBalance}
68-
fiatBalance={balance.usd.availableBalance}
68+
fiatBalance={balance.fiat.availableBalance}
6969
px="5"
7070
py="3"
7171
/>

apps/mobile/src/features/balances/stacks/sip10-balance.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function Sip10Balance() {
4949
symbol={balance.asset.symbol}
5050
name={balance.asset.name}
5151
availableBalance={balance.crypto.availableBalance}
52-
fiatBalance={balance.usd.totalBalance}
52+
fiatBalance={balance.fiat.totalBalance}
5353
px="5"
5454
py="3"
5555
/>
@@ -73,7 +73,7 @@ export function Sip10BalanceByAccount({ accountIndex, fingerprint }: Sip10Balanc
7373
symbol={balance.asset.symbol}
7474
name={balance.asset.name}
7575
availableBalance={balance.crypto.availableBalance}
76-
fiatBalance={balance.usd.totalBalance}
76+
fiatBalance={balance.fiat.totalBalance}
7777
px="5"
7878
py="3"
7979
/>

apps/mobile/src/features/balances/stacks/stacks-balance.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function StacksBalance() {
3939
return (
4040
<StacksTokenBalance
4141
availableBalance={balance.value.stx.availableBalance}
42-
fiatBalance={balance.value.usd.availableBalance}
42+
fiatBalance={balance.value.fiat.availableBalance}
4343
px="5"
4444
py="3"
4545
/>
@@ -62,7 +62,7 @@ export function StacksBalanceByAccount({
6262
return (
6363
<StacksTokenBalance
6464
availableBalance={balance.value.stx.availableBalance}
65-
fiatBalance={balance.value.usd.availableBalance}
65+
fiatBalance={balance.value.fiat.availableBalance}
6666
onPress={onPress}
6767
px="5"
6868
py="3"

apps/mobile/src/features/send/send-form/loaders/send-form-btc-loader.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function SendFormBtcLoader({ account, children }: SendFormBtcLoaderProps)
3636

3737
return children({
3838
availableBalance: btcBalance.value.btc.availableBalance,
39-
fiatBalance: btcBalance.value.usd.availableBalance,
39+
fiatBalance: btcBalance.value.fiat.availableBalance,
4040
feeRates: feeRates || zeroFees,
4141
utxos: accountUtxos.value.available,
4242
});

apps/mobile/src/features/send/send-form/loaders/send-form-stx-loader.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function SendFormStxLoader({ account, children }: SendFormStxLoaderProps)
3131

3232
return children({
3333
availableBalance: balance!.stx.availableBalance,
34-
fiatBalance: balance!.usd.availableBalance,
34+
fiatBalance: balance!.fiat.availableBalance,
3535
nonce: nextNonce?.nonce ?? '',
3636
});
3737
}

apps/mobile/src/queries/balance/account-balance.query.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AccountId } from '@/models/domain.model';
22
import { useStxAccountBalance } from '@/queries/balance/stx-balance.query';
33
import { FetchState, toFetchState } from '@/shared/fetch-state';
4+
import { useSettings } from '@/store/settings/settings';
45

56
import { Money } from '@leather.io/models';
67
import {
@@ -23,10 +24,10 @@ interface AccountBalance {
2324
totalBalance: FetchState<Money>;
2425
}
2526

26-
const zeroMoneyUsd = createMoney(0, 'USD');
27-
2827
export function useAccountBalance(accountId: AccountId): AccountBalance {
2928
const { fingerprint, accountIndex } = accountId;
29+
const { fiatCurrencyPreference } = useSettings();
30+
const zeroMoneyFiat = createMoney(0, fiatCurrencyPreference);
3031

3132
const btcAccountBalance = useBtcAccountBalance(fingerprint, accountIndex);
3233
const stxAccountBalance = useStxAccountBalance(fingerprint, accountIndex);
@@ -45,11 +46,11 @@ export function useAccountBalance(accountId: AccountId): AccountBalance {
4546
runesAccountBalance.state === 'error';
4647
const accountBalance = sumMoney(
4748
[
48-
zeroMoneyUsd,
49-
btcAccountBalance.value?.usd.availableBalance,
50-
stxAccountBalance.value?.usd.availableBalance,
51-
sip10AccountBalance.value?.usd.availableBalance,
52-
runesAccountBalance.value?.usd.availableBalance,
49+
zeroMoneyFiat,
50+
btcAccountBalance.value?.fiat.availableBalance,
51+
stxAccountBalance.value?.fiat.availableBalance,
52+
sip10AccountBalance.value?.fiat.availableBalance,
53+
runesAccountBalance.value?.fiat.availableBalance,
5354
].filter(isDefined)
5455
);
5556

apps/mobile/src/queries/balance/btc-balance.query.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
useWalletBitcoinAccountServiceRequests,
55
} from '@/hooks/use-bitcoin-account-service-requests';
66
import { toFetchState } from '@/shared/fetch-state';
7+
import { useSettings } from '@/store/settings/settings';
78
import { QueryFunctionContext, useQuery } from '@tanstack/react-query';
89

910
import { BitcoinAccountServiceRequest, getBtcBalancesService } from '@leather.io/services';
@@ -24,8 +25,13 @@ export function useBtcAccountBalance(fingerprint: string, accountIndex: number)
2425
}
2526

2627
export function useBtcAccountBalanceQuery(serviceRequest: BitcoinAccountServiceRequest) {
28+
const { fiatCurrencyPreference } = useSettings();
2729
return useQuery({
28-
queryKey: ['btc-balance-service-get-btc-account-balance', serviceRequest],
30+
queryKey: [
31+
'btc-balance-service-get-btc-account-balance',
32+
serviceRequest,
33+
fiatCurrencyPreference,
34+
],
2935
queryFn: ({ signal }: QueryFunctionContext) =>
3036
getBtcBalancesService().getBtcAccountBalance(serviceRequest, signal),
3137
refetchOnReconnect: false,
@@ -38,8 +44,13 @@ export function useBtcAccountBalanceQuery(serviceRequest: BitcoinAccountServiceR
3844
}
3945

4046
export function useBtcAggregateBalanceQuery(serviceRequests: BitcoinAccountServiceRequest[]) {
47+
const { fiatCurrencyPreference } = useSettings();
4148
return useQuery({
42-
queryKey: ['btc-balance-service-get-btc-aggregate-balance', serviceRequests],
49+
queryKey: [
50+
'btc-balance-service-get-btc-aggregate-balance',
51+
serviceRequests,
52+
fiatCurrencyPreference,
53+
],
4354
queryFn: ({ signal }: QueryFunctionContext) =>
4455
getBtcBalancesService().getBtcAggregateBalance(serviceRequests, signal),
4556
refetchOnReconnect: false,

apps/mobile/src/queries/balance/runes-balance.query.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
useWalletBitcoinAccountServiceRequests,
55
} from '@/hooks/use-bitcoin-account-service-requests';
66
import { toFetchState } from '@/shared/fetch-state';
7+
import { useSettings } from '@/store/settings/settings';
78
import { QueryFunctionContext, useQuery } from '@tanstack/react-query';
89

910
import { BitcoinAccountIdentifier, getRunesBalancesService } from '@leather.io/services';
@@ -25,8 +26,13 @@ export function useRunesAccountBalance(fingerprint: string, accountIndex: number
2526
}
2627

2728
export function useRunesAggregateBalanceQuery(accounts: BitcoinAccountIdentifier[]) {
29+
const { fiatCurrencyPreference } = useSettings();
2830
return useQuery({
29-
queryKey: ['runes-balances-service-get-runes-aggregate-balance', accounts],
31+
queryKey: [
32+
'runes-balances-service-get-runes-aggregate-balance',
33+
accounts,
34+
fiatCurrencyPreference,
35+
],
3036
queryFn: ({ signal }: QueryFunctionContext) =>
3137
getRunesBalancesService().getRunesAggregateBalance(accounts, signal),
3238
refetchOnReconnect: false,
@@ -39,8 +45,9 @@ export function useRunesAggregateBalanceQuery(accounts: BitcoinAccountIdentifier
3945
}
4046

4147
export function useRunesAccountBalanceQuery(account: BitcoinAccountIdentifier) {
48+
const { fiatCurrencyPreference } = useSettings();
4249
return useQuery({
43-
queryKey: ['runes-balances-service-get-runes-account-balance', account],
50+
queryKey: ['runes-balances-service-get-runes-account-balance', account, fiatCurrencyPreference],
4451
queryFn: ({ signal }: QueryFunctionContext) =>
4552
getRunesBalancesService().getRunesAccountBalance(account, signal),
4653
refetchOnReconnect: false,

apps/mobile/src/queries/balance/sip10-balance.query.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
useStacksSignerAddressFromAccountIndex,
44
useStacksSignerAddresses,
55
} from '@/store/keychains/stacks/stacks-keychains.read';
6+
import { useSettings } from '@/store/settings/settings';
67
import { QueryFunctionContext, useQuery } from '@tanstack/react-query';
78

89
import { getSip10BalancesService } from '@leather.io/services';
@@ -25,8 +26,13 @@ export function useSip10AccountBalance(fingerprint: string, accountIndex: number
2526
}
2627

2728
export function useSip10AggregateBalanceQuery(addresses: string[]) {
29+
const { fiatCurrencyPreference } = useSettings();
2830
return useQuery({
29-
queryKey: ['sip10-balances-service-get-sip10-aggregate-balance', addresses],
31+
queryKey: [
32+
'sip10-balances-service-get-sip10-aggregate-balance',
33+
addresses,
34+
fiatCurrencyPreference,
35+
],
3036
queryFn: ({ signal }: QueryFunctionContext) =>
3137
getSip10BalancesService().getSip10AggregateBalance(addresses, signal),
3238
refetchOnReconnect: false,
@@ -39,8 +45,9 @@ export function useSip10AggregateBalanceQuery(addresses: string[]) {
3945
}
4046

4147
export function useSip10AddressBalanceQuery(address: string) {
48+
const { fiatCurrencyPreference } = useSettings();
4249
return useQuery({
43-
queryKey: ['sip10-balances-service-get-sip10-address-balance', address],
50+
queryKey: ['sip10-balances-service-get-sip10-address-balance', address, fiatCurrencyPreference],
4451
queryFn: ({ signal }: QueryFunctionContext) =>
4552
getSip10BalancesService().getSip10AddressBalance(address, signal),
4653
refetchOnReconnect: false,

apps/mobile/src/queries/balance/stx-balance.query.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
useStacksSignerAddressFromAccountIndex,
44
useStacksSignerAddresses,
55
} from '@/store/keychains/stacks/stacks-keychains.read';
6+
import { useSettings } from '@/store/settings/settings';
67
import { QueryFunctionContext, useQuery } from '@tanstack/react-query';
78

89
import { getStxBalancesService } from '@leather.io/services';
@@ -21,8 +22,9 @@ export function useStxAccountBalance(fingerprint: string, accountIndex: number)
2122
}
2223

2324
export function useStxAggregateBalanceQuery(addresses: string[]) {
25+
const { fiatCurrencyPreference } = useSettings();
2426
return useQuery({
25-
queryKey: ['stx-balances-service-get-stx-aggregate-balance', addresses],
27+
queryKey: ['stx-balances-service-get-stx-aggregate-balance', addresses, fiatCurrencyPreference],
2628
queryFn: ({ signal }: QueryFunctionContext) =>
2729
getStxBalancesService().getStxAggregateBalance(addresses, signal),
2830
refetchOnReconnect: false,
@@ -35,8 +37,9 @@ export function useStxAggregateBalanceQuery(addresses: string[]) {
3537
}
3638

3739
export function useStxAddressBalanceQuery(address: string) {
40+
const { fiatCurrencyPreference } = useSettings();
3841
return useQuery({
39-
queryKey: ['stx-balances-service-get-stx-address-balance', address],
42+
queryKey: ['stx-balances-service-get-stx-address-balance', address, fiatCurrencyPreference],
4043
queryFn: ({ signal }: QueryFunctionContext) =>
4144
getStxBalancesService().getStxAddressBalance(address, signal),
4245
refetchOnReconnect: false,

apps/mobile/src/queries/balance/total-balance.query.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { useStxTotalBalance } from '@/queries/balance/stx-balance.query';
22
import { FetchState, toFetchState } from '@/shared/fetch-state';
3+
import { useSettings } from '@/store/settings/settings';
34

45
import { Money } from '@leather.io/models';
56
import {
6-
BtcAggregateBalance,
7+
BtcBalance,
78
RunesAggregateBalance,
89
Sip10AggregateBalance,
9-
StxAggregateBalance,
10+
StxBalance,
1011
} from '@leather.io/services';
1112
import { createMoney, isDefined, sumMoney } from '@leather.io/utils';
1213

@@ -15,16 +16,17 @@ import { useRunesTotalBalance } from './runes-balance.query';
1516
import { useSip10TotalBalance } from './sip10-balance.query';
1617

1718
interface TotalBalance {
18-
btc: FetchState<BtcAggregateBalance>;
19-
stx: FetchState<StxAggregateBalance>;
19+
btc: FetchState<BtcBalance>;
20+
stx: FetchState<StxBalance>;
2021
sip10: FetchState<Sip10AggregateBalance>;
2122
runes: FetchState<RunesAggregateBalance>;
2223
totalBalance: FetchState<Money>;
2324
}
2425

25-
const zeroMoneyUsd = createMoney(0, 'USD');
26-
2726
export function useTotalBalance(): TotalBalance {
27+
const { fiatCurrencyPreference } = useSettings();
28+
const zeroMoneyFiat = createMoney(0, fiatCurrencyPreference);
29+
2830
const btcTotalBalance = useBtcTotalBalance();
2931
const stxTotalBalance = useStxTotalBalance();
3032
const sip10TotalBalance = useSip10TotalBalance();
@@ -42,11 +44,11 @@ export function useTotalBalance(): TotalBalance {
4244
runesTotalBalance.state === 'error';
4345
const accountBalance = sumMoney(
4446
[
45-
zeroMoneyUsd,
46-
btcTotalBalance.value?.usd.availableBalance,
47-
stxTotalBalance.value?.usd.availableBalance,
48-
sip10TotalBalance.value?.usd.availableBalance,
49-
runesTotalBalance.value?.usd.availableBalance,
47+
zeroMoneyFiat,
48+
btcTotalBalance.value?.fiat.availableBalance,
49+
stxTotalBalance.value?.fiat.availableBalance,
50+
sip10TotalBalance.value?.fiat.availableBalance,
51+
runesTotalBalance.value?.fiat.availableBalance,
5052
].filter(isDefined)
5153
);
5254

Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import { useSettings } from '@/store/settings/settings';
22
import { QueryFunctionContext, useQueries, useQuery } from '@tanstack/react-query';
33

4-
import { bitcoinNetworkModeToCoreNetworkMode } from '@leather.io/bitcoin';
5-
import { FungibleCryptoAssetInfo, NetworkModes } from '@leather.io/models';
4+
import { FiatCurrency, FungibleCryptoAssetInfo } from '@leather.io/models';
65
import { getMarketDataService } from '@leather.io/services';
76
import { oneMinInMs } from '@leather.io/utils';
87

98
export function createMarketDataQueryOptions(
109
token: FungibleCryptoAssetInfo,
11-
network: NetworkModes
10+
currency: FiatCurrency
1211
) {
1312
return {
14-
queryKey: ['market-data-service-get-market-data', network, token],
13+
queryKey: ['market-data-service-get-market-data', token, currency],
1514
queryFn: ({ signal }: QueryFunctionContext) =>
1615
getMarketDataService().getMarketData(token, signal),
1716
refetchOnReconnect: false,
@@ -24,23 +23,13 @@ export function createMarketDataQueryOptions(
2423
}
2524

2625
export function useMarketDataQuery(token: FungibleCryptoAssetInfo) {
27-
const { networkPreference } = useSettings();
28-
return useQuery(
29-
createMarketDataQueryOptions(
30-
token,
31-
bitcoinNetworkModeToCoreNetworkMode(networkPreference.chain.bitcoin.mode)
32-
)
33-
);
26+
const { fiatCurrencyPreference } = useSettings();
27+
return useQuery(createMarketDataQueryOptions(token, fiatCurrencyPreference));
3428
}
3529

3630
export function useMarketDataQueries(tokens: FungibleCryptoAssetInfo[]) {
37-
const { networkPreference } = useSettings();
31+
const { fiatCurrencyPreference } = useSettings();
3832
return useQueries({
39-
queries: tokens.map(token =>
40-
createMarketDataQueryOptions(
41-
token,
42-
bitcoinNetworkModeToCoreNetworkMode(networkPreference.chain.bitcoin.mode)
43-
)
44-
),
33+
queries: tokens.map(token => createMarketDataQueryOptions(token, fiatCurrencyPreference)),
4534
});
4635
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { initializeServiceContainers } from '@leather.io/services';
22

33
import { createMobileHttpCacheService } from './mobile-http-cache.service';
4-
import { createMobileNetworkSettingsService } from './mobile-network-settings.service';
4+
import { createMobileSettingsService } from './mobile-settings.service';
55

66
export function initAppServices() {
7-
initializeServiceContainers(createMobileNetworkSettingsService(), createMobileHttpCacheService());
7+
initializeServiceContainers(createMobileSettingsService(), createMobileHttpCacheService());
88
}

apps/mobile/src/services/mobile-network-settings.service.ts

-20
This file was deleted.

0 commit comments

Comments
 (0)