Skip to content

Commit 2943fc7

Browse files
committed
feat: adds locale to token description service call
1 parent 1bb8f58 commit 2943fc7

File tree

5 files changed

+73
-21
lines changed

5 files changed

+73
-21
lines changed

apps/mobile/src/queries/assets/fungible-asset-info.query.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import { QueryFunctionContext, useQuery } from '@tanstack/react-query';
44
import { FungibleCryptoAsset } from '@leather.io/models';
55
import { getFungibleAssetInfoService } from '@leather.io/services';
66

7+
const DEFAULT_LOCALE = 'en';
8+
const DEFAULT_PRICE_HISTORY_INTERVAL = '24h';
9+
710
export function useAssetDescriptionQuery(asset: FungibleCryptoAsset) {
811
return useQuery({
912
queryKey: ['fungible-asset-info-service-get-asset-description', asset],
1013
queryFn: ({ signal }: QueryFunctionContext) =>
11-
getFungibleAssetInfoService().getAssetDescription(asset, signal),
14+
getFungibleAssetInfoService().getAssetDescription(asset, DEFAULT_LOCALE, signal),
1215
refetchOnReconnect: false,
1316
refetchOnWindowFocus: false,
1417
refetchOnMount: true,
@@ -22,7 +25,11 @@ export function useAssetPriceChangeQuery(asset: FungibleCryptoAsset) {
2225
return useQuery({
2326
queryKey: ['fungible-asset-info-service-get-asset-price-change', asset],
2427
queryFn: ({ signal }: QueryFunctionContext) =>
25-
getFungibleAssetInfoService().getAssetPriceChange(asset, '24h', signal),
28+
getFungibleAssetInfoService().getAssetPriceChange(
29+
asset,
30+
DEFAULT_PRICE_HISTORY_INTERVAL,
31+
signal
32+
),
2633
refetchOnReconnect: false,
2734
refetchOnWindowFocus: false,
2835
refetchOnMount: true,
@@ -41,7 +48,11 @@ export function useAssetPriceHistoryQuery(asset: FungibleCryptoAsset) {
4148
fiatCurrencyPreference,
4249
],
4350
queryFn: ({ signal }: QueryFunctionContext) =>
44-
getFungibleAssetInfoService().getAssetPriceHistory(asset, '24h', signal),
51+
getFungibleAssetInfoService().getAssetPriceHistory(
52+
asset,
53+
DEFAULT_PRICE_HISTORY_INTERVAL,
54+
signal
55+
),
4556
refetchOnReconnect: false,
4657
refetchOnWindowFocus: false,
4758
refetchOnMount: true,

packages/services/src/assets/fungible-asset-info.service.spec.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@ describe(FungibleAssetInfoService.name, () => {
8585
describe('getAssetDescription', () => {
8686
it('should return native asset descriptions from Leather API', async () => {
8787
const signal = new AbortController().signal;
88-
const description = await fungibleAssetInfoService.getAssetDescription(btcAsset, signal);
88+
const description = await fungibleAssetInfoService.getAssetDescription(
89+
btcAsset,
90+
'en',
91+
signal
92+
);
8993

9094
expect(mockLeatherApiClient.fetchNativeTokenDescription).toHaveBeenCalledWith(
9195
btcAsset.symbol,
96+
'en',
9297
signal
9398
);
9499
expect(description).toEqual({
@@ -102,11 +107,13 @@ describe(FungibleAssetInfoService.name, () => {
102107
const signal = new AbortController().signal;
103108
const description = await fungibleAssetInfoService.getAssetDescription(
104109
{ contractId, protocol: CryptoAssetProtocols.sip10 } as Sip10Asset,
110+
'en',
105111
signal
106112
);
107113

108114
expect(mockLeatherApiClient.fetchSip10TokenDescription).toHaveBeenCalledWith(
109115
contractId,
116+
'en',
110117
signal
111118
);
112119
expect(description).toEqual({
@@ -120,10 +127,15 @@ describe(FungibleAssetInfoService.name, () => {
120127
const signal = new AbortController().signal;
121128
const description = await fungibleAssetInfoService.getAssetDescription(
122129
{ runeName, protocol: CryptoAssetProtocols.rune } as RuneAsset,
130+
'en',
123131
signal
124132
);
125133

126-
expect(mockLeatherApiClient.fetchRuneDescription).toHaveBeenCalledWith(runeName, signal);
134+
expect(mockLeatherApiClient.fetchRuneDescription).toHaveBeenCalledWith(
135+
runeName,
136+
'en',
137+
signal
138+
);
127139
expect(description).toEqual({
128140
description: runeDescription,
129141
});
@@ -132,7 +144,9 @@ describe(FungibleAssetInfoService.name, () => {
132144
it('should throw an error if the asset protocol is not supported', async () => {
133145
const signal = new AbortController().signal;
134146
const asset = { protocol: 'unsupported' } as unknown as FungibleCryptoAsset;
135-
await expect(fungibleAssetInfoService.getAssetDescription(asset, signal)).rejects.toThrow();
147+
await expect(
148+
fungibleAssetInfoService.getAssetDescription(asset, 'en', signal)
149+
).rejects.toThrow();
136150
});
137151
});
138152

packages/services/src/assets/fungible-asset-info.service.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { quoteCurrencyAmountToBase } from '@leather.io/utils';
55

66
import {
77
LeatherApiClient,
8+
LeatherApiLocale,
89
LeatherApiTokenPriceHistory,
910
} from '../infrastructure/api/leather/leather-api.client';
1011
import type { SettingsService } from '../infrastructure/settings/settings.service';
@@ -28,16 +29,25 @@ export class FungibleAssetInfoService {
2829

2930
public async getAssetDescription(
3031
asset: FungibleCryptoAsset,
32+
locale: LeatherApiLocale,
3133
signal?: AbortSignal
3234
): Promise<AssetDescription> {
3335
switch (asset.protocol) {
3436
case CryptoAssetProtocols.nativeBtc:
3537
case CryptoAssetProtocols.nativeStx:
36-
return await this.leatherApiClient.fetchNativeTokenDescription(asset.symbol, signal);
38+
return await this.leatherApiClient.fetchNativeTokenDescription(
39+
asset.symbol,
40+
locale,
41+
signal
42+
);
3743
case CryptoAssetProtocols.sip10:
38-
return await this.leatherApiClient.fetchSip10TokenDescription(asset.contractId, signal);
44+
return await this.leatherApiClient.fetchSip10TokenDescription(
45+
asset.contractId,
46+
locale,
47+
signal
48+
);
3949
case CryptoAssetProtocols.rune:
40-
return await this.leatherApiClient.fetchRuneDescription(asset.runeName, signal);
50+
return await this.leatherApiClient.fetchRuneDescription(asset.runeName, locale, signal);
4151
default:
4252
throw Error('Asset descriptions not supported for asset type: ' + asset.protocol);
4353
}

packages/services/src/infrastructure/api/leather/leather-api.client.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export type LeatherApiUtxo =
2424
paths['/v1/utxos/{descriptor}']['get']['responses'][200]['content']['application/json'][number];
2525
export type LeatherApiTokenPriceHistory =
2626
paths['/v1/market/prices/native/{symbol}/history']['get']['responses'][200]['content']['application/json'];
27+
export type LeatherApiLocale = Required<
28+
NonNullable<paths['/v1/tokens/native/{symbol}/description']['get']['parameters']['query']>
29+
>['locale'];
2730

2831
@injectable()
2932
export class LeatherApiClient {
@@ -192,16 +195,20 @@ export class LeatherApiClient {
192195
);
193196
}
194197

195-
async fetchNativeTokenDescription(symbol: string, signal?: AbortSignal) {
198+
async fetchNativeTokenDescription(
199+
symbol: string,
200+
locale: LeatherApiLocale,
201+
signal?: AbortSignal
202+
) {
196203
return await this.cacheService.fetchWithCache(
197-
['leather-api-native-token-description', symbol],
204+
['leather-api-native-token-description', symbol, locale],
198205
async () => {
199206
const { data } = await this.rateLimiter.add(
200207
RateLimiterType.Leather,
201208
() =>
202209
this.client.GET('/v1/tokens/native/{symbol}/description', {
203210
signal,
204-
params: { path: { symbol } },
211+
params: { path: { symbol }, query: { locale } },
205212
}),
206213
{
207214
priority: leatherApiPriorities.nativeTokenDescription,
@@ -349,16 +356,16 @@ export class LeatherApiClient {
349356
});
350357
}
351358

352-
async fetchRuneDescription(runeName: string, signal?: AbortSignal) {
359+
async fetchRuneDescription(runeName: string, locale: LeatherApiLocale, signal?: AbortSignal) {
353360
return await this.cacheService.fetchWithCache(
354-
['leather-api-rune-description', runeName],
361+
['leather-api-rune-description', runeName, locale],
355362
async () => {
356363
const { data } = await this.rateLimiter.add(
357364
RateLimiterType.Leather,
358365
() =>
359366
this.client.GET('/v1/tokens/runes/{runeName}/description', {
360367
signal,
361-
params: { path: { runeName } },
368+
params: { path: { runeName }, query: { locale } },
362369
}),
363370
{
364371
priority: leatherApiPriorities.runeDescription,
@@ -513,16 +520,20 @@ export class LeatherApiClient {
513520
);
514521
}
515522

516-
async fetchSip10TokenDescription(principal: string, signal?: AbortSignal) {
523+
async fetchSip10TokenDescription(
524+
principal: string,
525+
locale: LeatherApiLocale,
526+
signal?: AbortSignal
527+
) {
517528
return await this.cacheService.fetchWithCache(
518-
['leather-api-sip10-token-description', principal],
529+
['leather-api-sip10-token-description', principal, locale],
519530
async () => {
520531
const { data } = await this.rateLimiter.add(
521532
RateLimiterType.Leather,
522533
() =>
523534
this.client.GET('/v1/tokens/sip10s/{principal}/description', {
524535
signal,
525-
params: { path: { principal } },
536+
params: { path: { principal }, query: { locale } },
526537
}),
527538
{
528539
priority: leatherApiPriorities.sip10TokenDescription,

packages/services/src/infrastructure/api/leather/leather-api.types.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,9 @@ export interface paths {
14301430
/** @description Get SIP-10 Token Description */
14311431
get: {
14321432
parameters: {
1433-
query?: never;
1433+
query?: {
1434+
locale?: 'en' | 'es' | 'ru' | 'zh';
1435+
};
14341436
header?: never;
14351437
path: {
14361438
principal: string;
@@ -1670,7 +1672,9 @@ export interface paths {
16701672
/** @description Get Rune Description */
16711673
get: {
16721674
parameters: {
1673-
query?: never;
1675+
query?: {
1676+
locale?: 'en' | 'es' | 'ru' | 'zh';
1677+
};
16741678
header?: never;
16751679
path: {
16761680
runeName: string;
@@ -1743,7 +1747,9 @@ export interface paths {
17431747
/** @description Get Native token description */
17441748
get: {
17451749
parameters: {
1746-
query?: never;
1750+
query?: {
1751+
locale?: 'en' | 'es' | 'ru' | 'zh';
1752+
};
17471753
header?: never;
17481754
path: {
17491755
symbol: string;

0 commit comments

Comments
 (0)