Last active
December 28, 2022 09:13
-
-
Save shreyakupadhyay/f933eab68e92de308e3f021a63e79a92 to your computer and use it in GitHub Desktop.
Beginner level typescript implementation of API response handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- common payload: stats associated with data --> | |
type StatsRange = { | |
max: number, min: number | |
} | |
type StatsKeys = 'count' | 'aum' | 'priceusd' | 'value' | |
type PartialStats = { | |
stats?: { | |
[key in StatsKeys]?: StatsRange | |
} | |
} | |
<!-- common payload: pagination info --> | |
type Pagination = { | |
pagination?: { | |
currentPage: number, | |
perPage: number, | |
total: number, | |
totalPages: number | |
} | |
} | |
<!-- api: onboarding data --> | |
type APIResponseOnboards = { | |
count: number, | |
unixTimeStamp: number, | |
timestamp: string, | |
} | |
<!-- api: historical data --> | |
type APIResponseHistorical = { | |
aum: number, | |
unixTimeStamp: number, | |
} | |
<!-- api: wallets data --> | |
type APIResponseWallets = { | |
wid: number, | |
tenant: number, | |
portfolioValue: number, | |
address: string, | |
} | |
<!-- all api data handling --> | |
interface APIResponseData extends PartialStats, Pagination { | |
data : { | |
data: APIResponseOnboards[] | APIResponseHistorical[], | |
field?: string, | |
grouping?: string | |
}[] | APIResponseWallets[], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment