Skip to content

Commit c64dfdd

Browse files
committed
refactor: update currency handling to use UsdCurrencyAmount across analytics models
- Replaced instances of TonCurrencyAmount with UsdCurrencyAmount in various analytics models and interfaces to standardize currency handling. - Updated related mapping functions and interfaces to ensure compatibility with the new currency type. - Removed deprecated analytics-payment interface as it is no longer needed. These changes enhance consistency in currency representation throughout the analytics feature set.
1 parent ac373be commit c64dfdd

13 files changed

+55
-79
lines changed

src/features/analytics/model/analytics-gpt-generation.store.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { makeAutoObservable } from 'mobx';
2-
import { Loadable, TonCurrencyAmount } from 'src/shared';
2+
import { Loadable, UsdCurrencyAmount } from 'src/shared';
33
import {
44
getStatsChatGptPrice,
55
statsChatGptRequest,
@@ -65,9 +65,6 @@ function mapStatsChatGptPriceToGptGenerationPricing(
6565
return {
6666
freeRequestsNumber: value.free_requests,
6767
usedFreeRequest: value.used,
68-
// TODO: PRICES remove this after backend will be updated
69-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
70-
// @ts-ignore
71-
requestPrice: value.price ? new TonCurrencyAmount(value.price) : value.usd_price
68+
requestPrice: new UsdCurrencyAmount(value.usd_price)
7269
};
7370
}

src/features/analytics/model/analytics-graph-query.store.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
import { makeAutoObservable } from 'mobx';
2-
import {
3-
createReaction,
4-
Loadable,
5-
TonAddress,
6-
TonCurrencyAmount
7-
} from 'src/shared';
8-
import {
9-
getGraphFromStats,
10-
getSqlResultFromStats,
11-
DTOStatsQueryResult
12-
} from 'src/shared/api';
2+
import { createReaction, Loadable, TonAddress, UsdCurrencyAmount } from 'src/shared';
3+
import { getGraphFromStats, getSqlResultFromStats, DTOStatsQueryResult } from 'src/shared/api';
134
import { AnalyticsGraphQuery, AnalyticsGraphQueryBasic } from './interfaces';
145
import { Project } from 'src/entities/project';
156

@@ -104,10 +95,7 @@ export function mapDTOStatsGraphResultToAnalyticsGraphQuery(
10495
value.url!
10596
)}&meta=${encodeURIComponent(value.meta_url!)}`,
10697
spentTimeMS: value.spent_time!,
107-
// TODO: PRICES remove this after backend will be updated
108-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
109-
// @ts-ignore
110-
cost: new TonCurrencyAmount(value.cost!)
98+
cost: value.usd_cost ? new UsdCurrencyAmount(value.usd_cost) : new UsdCurrencyAmount(0)
11199
};
112100
}
113101

@@ -123,9 +111,6 @@ export function mapDTOStatsGraphResultToAnalyticsGraphQuery(
123111
status: 'error',
124112
errorReason: value.error!,
125113
spentTimeMS: value.spent_time!,
126-
// TODO: PRICES remove this after backend will be updated
127-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
128-
// @ts-ignore
129-
cost: new TonCurrencyAmount(value.cost!)
114+
cost: value.usd_cost ? new UsdCurrencyAmount(value.usd_cost) : undefined
130115
};
131116
}

src/features/analytics/model/analytics-history-table.store.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { makeAutoObservable, reaction } from 'mobx';
2-
import { Loadable, TonCurrencyAmount } from 'src/shared';
2+
import { Loadable, UsdCurrencyAmount } from 'src/shared';
33
import { getSqlHistoryFromStats, DTOStatsQueryResult, DTOStatsQueryType } from 'src/shared/api';
44
import {
55
AnalyticsGraphQuery,
@@ -143,10 +143,9 @@ function mapDTOStatsQueryResultToAnalyticsQueryAggregated(
143143
lastQuery: mapDTOStatsSqlResultToAnalyticsQuery(value),
144144
lastQueryDate: new Date(value.last_repeat_date!),
145145
repeatFrequencyMs: value.query!.repeat_interval! * 1000,
146-
// TODO: PRICES remove this after backend will be updated
147-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
148-
// @ts-ignore
149-
totalCost: new TonCurrencyAmount(value.total_cost!),
146+
totalCost: value.total_usd_cost
147+
? new UsdCurrencyAmount(value.total_usd_cost)
148+
: new UsdCurrencyAmount(0),
150149
totalRepetitions: value.total_repetitions!
151150
};
152151
}

src/features/analytics/model/analytics-query-request.store.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { makeAutoObservable } from 'mobx';
2-
import { createReaction, Loadable, Network, TonCurrencyAmount } from 'src/shared';
2+
import { createReaction, Loadable, Network, UsdCurrencyAmount } from 'src/shared';
33
import { estimateStatsQuery, DTOChain, DTOStatsEstimateQuery } from 'src/shared/api';
44
import { AnalyticsQueryTemplate } from './interfaces';
55
import { DTOChainNetworkMap } from 'src/shared/lib/blockchain/network';
@@ -110,14 +110,13 @@ function mapDTOStatsEstimateSQLToAnalyticsQuery(
110110
network: DTOChain,
111111
value: DTOStatsEstimateQuery
112112
): AnalyticsQueryTemplate {
113+
console.log(value.approximate_usd_cost);
113114
return {
114115
request,
115116
network: DTOChainNetworkMap[network],
116117
estimatedTimeMS: value.approximate_time,
117-
// TODO: PRICES remove this after backend will be updated
118-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
119-
// @ts-ignore
120-
estimatedCost: new TonCurrencyAmount(value.approximate_cost),
118+
119+
estimatedCost: new UsdCurrencyAmount(value.approximate_usd_cost),
121120
explanation: value.explain!
122121
};
123122
}

src/features/analytics/model/analytics-query.store.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { makeAutoObservable } from 'mobx';
2-
import { createReaction, Loadable, Network, TonCurrencyAmount } from 'src/shared';
2+
import { createReaction, Loadable, Network, UsdCurrencyAmount } from 'src/shared';
33
import {
44
getStatsDdl,
55
sendQueryToStats,
@@ -36,7 +36,10 @@ export class AnalyticsQueryStore {
3636
return this.setRepeatOnQuery.isLoading || this.removeRepeatOnQuery.isLoading;
3737
}
3838

39-
constructor(analyticsGPTGenerationStore: AnalyticsGPTGenerationStore, private readonly project: Project) {
39+
constructor(
40+
analyticsGPTGenerationStore: AnalyticsGPTGenerationStore,
41+
private readonly project: Project
42+
) {
4043
this.analyticsGPTGenerationStore = analyticsGPTGenerationStore;
4144
makeAutoObservable(this);
4245

@@ -247,17 +250,18 @@ export class AnalyticsQueryStore {
247250
}
248251

249252
export function mapDTOStatsSqlResultToAnalyticsQuery(value: DTOStatsQueryResult): AnalyticsQuery {
253+
if (!value.estimate) {
254+
throw new Error('Estimate is required');
255+
}
256+
250257
const basicQuery = {
251258
type: 'query',
252259
id: value.id,
253260
creationDate: new Date(value.date_create),
254261
gptPrompt: value.query?.gpt_message,
255262
request: value.query!.sql!,
256263
estimatedTimeMS: value.estimate!.approximate_time,
257-
// TODO: PRICES remove this after backend will be updated
258-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
259-
// @ts-ignore
260-
estimatedCost: new TonCurrencyAmount(value.estimate!.approximate_cost),
264+
estimatedCost: new UsdCurrencyAmount(value.estimate.approximate_usd_cost),
261265
explanation: value.estimate!.explain!,
262266
name: value.name,
263267
...(value.query?.repeat_interval && {
@@ -277,10 +281,7 @@ export function mapDTOStatsSqlResultToAnalyticsQuery(value: DTOStatsQueryResult)
277281
return {
278282
...basicQuery,
279283
status: 'success',
280-
// TODO: PRICES remove this after backend will be updated
281-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
282-
// @ts-ignore
283-
cost: new TonCurrencyAmount(value.cost!),
284+
cost: new UsdCurrencyAmount(value.usd_cost!),
284285
spentTimeMS: value.spent_time!,
285286
csvUrl: value.url!,
286287
preview: parsePreview(value.preview!, !!value.all_data_in_preview),
@@ -290,11 +291,8 @@ export function mapDTOStatsSqlResultToAnalyticsQuery(value: DTOStatsQueryResult)
290291

291292
return {
292293
...basicQuery,
293-
status: 'error',
294-
// TODO: PRICES remove this after backend will be updated
295-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
296-
// @ts-ignore
297-
cost: new TonCurrencyAmount(value.cost!),
294+
status: 'error',
295+
cost: new UsdCurrencyAmount(value.usd_cost!),
298296
spentTimeMS: value.spent_time!,
299297
errorReason: value.error!
300298
};

src/features/analytics/model/interfaces/analytics-graph-query.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TonAddress, TonCurrencyAmount } from 'src/shared';
1+
import { TonAddress, UsdCurrencyAmount } from 'src/shared';
22

33
export interface AnalyticsGraphQueryBasic {
44
type: 'graph';
@@ -12,7 +12,7 @@ export interface AnalyticsGraphQuerySuccess extends AnalyticsGraphQueryBasic {
1212
status: 'success';
1313
resultUrl: string;
1414
spentTimeMS: number;
15-
cost: TonCurrencyAmount;
15+
cost: UsdCurrencyAmount;
1616
}
1717

1818
export interface AnalyticsGraphQueryPending extends AnalyticsGraphQueryBasic {
@@ -23,7 +23,7 @@ export interface AnalyticsGraphQueryError extends AnalyticsGraphQueryBasic {
2323
status: 'error';
2424
errorReason: string;
2525
spentTimeMS: number;
26-
cost: TonCurrencyAmount;
26+
cost?: UsdCurrencyAmount;
2727
}
2828

2929
export type AnalyticsGraphQuery =

src/features/analytics/model/interfaces/analytics-payment.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/features/analytics/model/interfaces/analytics-query.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Network, TonCurrencyAmount } from 'src/shared';
1+
import { Network, UsdCurrencyAmount } from 'src/shared';
22
import { AnalyticsChartsConfig } from './charts';
33
import { AnalyticsGraphQuery } from './analytics-graph-query';
44

@@ -11,7 +11,7 @@ export interface AnalyticsTableSource {
1111
export interface AnalyticsQueryTemplate {
1212
request: string;
1313
estimatedTimeMS: number;
14-
estimatedCost: TonCurrencyAmount;
14+
estimatedCost: UsdCurrencyAmount;
1515
explanation: string;
1616
network: Network;
1717
}
@@ -29,7 +29,7 @@ export interface AnalyticsQueryBasic extends AnalyticsQueryTemplate {
2929
export interface AnalyticsQueryCompleted extends AnalyticsQueryBasic {
3030
status: 'success' | 'error';
3131
spentTimeMS: number;
32-
cost: TonCurrencyAmount;
32+
cost: UsdCurrencyAmount;
3333
}
3434

3535
export interface AnalyticsQuerySuccessful extends AnalyticsQueryCompleted {
@@ -76,5 +76,5 @@ export type AnalyticsRepeatingQueryAggregated = {
7676
lastQueryDate: Date;
7777
repeatFrequencyMs: number;
7878
totalRepetitions: number;
79-
totalCost: TonCurrencyAmount;
79+
totalCost: UsdCurrencyAmount;
8080
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { TonCurrencyAmount } from 'src/shared';
1+
import { UsdCurrencyAmount } from 'src/shared';
22

33
export interface GptGenerationPricing {
44
freeRequestsNumber: number;
55
usedFreeRequest: number;
6-
requestPrice: TonCurrencyAmount;
6+
requestPrice: UsdCurrencyAmount;
77
}

src/features/analytics/model/interfaces/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from './analytics-query';
22
export * from './analytics-graph-query';
3-
export * from './analytics-payment';
43
export * from './analytics-tables-schema';
54
export * from './gpt-generation-pricing';
65
export * from './charts';

0 commit comments

Comments
 (0)