Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 4b71e04

Browse files
authored
feat: added functions into token-api module (#35)
* feat: added functions into token-api module * fix: lint code
1 parent 74f5024 commit 4b71e04

2 files changed

Lines changed: 75 additions & 11 deletions

File tree

‎packages/sdk-core/src/modules/token-api/index.ts‎

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,58 @@ export interface XvmAssetsTransferHistory {
2222
}
2323

2424
export interface StatsDetail {
25-
era: string;
26-
timestamp: string;
27-
numberOfCalls: string;
28-
uniqueActiveUsers: string;
25+
timestamp: number;
26+
date: string;
27+
value: number;
2928
}
3029

3130
export type StatsType = 'uniqueActiveUsers' | 'numberOfCalls';
3231
export type Duration = '7 days' | '30 days' | '90 days' | '1 year';
32+
export type Category = 'defi' | 'gamefi' | 'infra' | 'nft' | 'others';
33+
34+
export interface LooseObject {
35+
[key: string]: any;
36+
}
37+
38+
export interface Developer {
39+
githubAccountUrl: string;
40+
twitterAccountUrl: string;
41+
linkedInAccountUrl: string;
42+
iconFile: string;
43+
name: string;
44+
}
45+
46+
export enum CommunityType {
47+
Twitter = 'Twitter',
48+
Reddit = 'Reddit',
49+
Facebook = 'Facebook',
50+
TikTok = 'TikTok',
51+
YouTube = 'YouTube',
52+
Instagram = 'Instagram',
53+
Discord = 'Discord',
54+
}
55+
56+
export interface Community {
57+
type: CommunityType;
58+
handle: string;
59+
}
60+
61+
export interface DappItem extends LooseObject {
62+
name: string;
63+
iconUrl: string;
64+
description: string;
65+
descriptionMarkdown: string;
66+
url: string;
67+
address: string;
68+
license: string;
69+
videoUrl: string;
70+
tags: string[];
71+
forumUrl: string;
72+
authorContact: string;
73+
gitHubUrl: string;
74+
imagesUrl: string[];
75+
developers: Developer[];
76+
communities: Community[];
77+
contractType: string;
78+
mainCategory: Category;
79+
}

‎packages/sdk-core/src/modules/token-api/utils/index.ts‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChartData, TOKEN_API_URL, Duration, XvmAssetsTransferHistory, StatsDetail, StatsType, TransferDetail } from '@astar-network/astar-sdk-core/modules/token-api';
1+
import { ChartData, TOKEN_API_URL, Duration, XvmAssetsTransferHistory, StatsDetail, StatsType, TransferDetail, DappItem } from '@astar-network/astar-sdk-core/modules/token-api';
22
import { formatNumber } from '@astar-network/astar-sdk-core/modules/units';
33
import axios from 'axios';
44

@@ -182,15 +182,32 @@ export const filterStatsData = ({ data,
182182
currentFilter: Duration;
183183
property: StatsType;
184184
}): number[][] => {
185-
const filteredResult = data.filter(
186-
(it) => Number(it.numberOfCalls) !== 0 && Number(it[property]) !== 0
187-
);
188185
const oneDayMilli = 3600000 * 24;
189-
return filteredResult
190-
.map((it) => [Number(it.timestamp) * 1000, Number(it[property])])
186+
return data
187+
.map((it) => [Number(it.timestamp) * 1000, Number(it.value)])
191188
.filter((it) => {
192-
const latestTs = Number(filteredResult[filteredResult.length - 1].timestamp) * 1000;
189+
const latestTs = Number(data[data.length - 1].timestamp) * 1000;
193190
const cutoff = latestTs - oneDayMilli * castDurationToDaysNumber(currentFilter);
194191
return it[0] > cutoff;
195192
});
196193
};
194+
195+
export const fetchDappTransactions = async ({ dapp,
196+
network }: {
197+
dapp: DappItem;
198+
network: string;
199+
}): Promise<StatsDetail[]> => {
200+
const url = `${TOKEN_API_URL}/v1/${network}/dapps-staking/stats/transactions?dappName=${dapp.name}&dappUrl=${dapp.url}`;
201+
const result = await axios.get<StatsDetail[]>(url);
202+
return result.data;
203+
};
204+
205+
export const fetchDappUAW = async ({ dapp,
206+
network }: {
207+
dapp: DappItem;
208+
network: string;
209+
}): Promise<StatsDetail[]> => {
210+
const url = `${TOKEN_API_URL}/v1/${network}/dapps-staking/stats/uaw?dappName=${dapp.name}&dappUrl=${dapp.url}`;
211+
const result = await axios.get<StatsDetail[]>(url);
212+
return result.data;
213+
};

0 commit comments

Comments
 (0)