forked from DA0-DA0/dao-dao-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoken.ts
169 lines (151 loc) · 4.23 KB
/
token.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { ComponentType } from 'react'
import { Account } from './account'
import { ChainId, Validator } from './chain'
import {
ButtonLinkProps,
ButtonPopupSection,
ButtonPopupSectionButton,
LoadingData,
LoadingDataWithError,
StatefulEntityDisplayProps,
} from './components'
export enum TokenType {
Native = 'native',
Cw20 = 'cw20',
Cw721 = 'cw721',
}
export type GenericTokenSource = Pick<
GenericToken,
'chainId' | 'type' | 'denomOrAddress'
>
// A native or CW20 token.
export type GenericToken = {
// What chain this token lives on.
chainId: string
type: TokenType
denomOrAddress: string
symbol: string
decimals: number
imageUrl: string | undefined
// The source chain and base denom. For IBC assets, this should differ from
// the main fields.
source: GenericTokenSource
}
export type GenericTokenWithUsdPrice = {
token: GenericToken
usdPrice?: number
timestamp?: Date
}
export type GenericTokenBalance = {
token: GenericToken
balance: string
// Whether or not this is the governance token in the related context.
isGovernanceToken?: boolean
// Whether or not this is staked.
staked?: boolean
}
export type GenericTokenBalanceWithOwner = GenericTokenBalance & {
owner: Account
}
export type LooseGenericToken = Pick<
GenericToken,
'chainId' | 'denomOrAddress'
> & {
type: TokenType | string
}
export enum UnstakingTaskStatus {
Unstaking = 'unstaking',
ReadyToClaim = 'readyToClaim',
Claimed = 'claimed',
}
export type UnstakingTask = {
token: GenericToken
status: UnstakingTaskStatus
amount: number
// If unstaking or ready to claim, date it will be/was unstaked.
// If claimed, date it was claimed.
date?: Date
}
export type TokenStake = {
token: GenericToken
validator: Validator
amount: number
rewards: number
}
export type TokenCardLazyInfo = {
usdUnitPrice: GenericTokenWithUsdPrice | undefined
stakingInfo:
| {
unstakingTasks: UnstakingTask[]
unstakingDurationSeconds: number | undefined
stakes: TokenStake[]
totalStaked: number
totalPendingRewards: number
totalUnstaking: number
}
| undefined
// unstakedBalance + totalStaked + totalUnstaking
totalBalance: number
// Display DAOs that the token is used as governance in, and optionally an
// amount of staked tokens. This is used to display how much a wallet has
// staked.
daosGoverned?: {
coreAddress: string
stakingContractAddress: string
stakedBalance?: number
}[]
}
export type TokenCardInfo = {
owner: Account
token: GenericToken
isGovernanceToken: boolean
subtitle?: string
unstakedBalance: number
// Only native tokens load staking info for now, so let's show a nice loader.
hasStakingInfo: boolean
lazyInfo: LoadingData<TokenCardLazyInfo>
// If defined, adds a color indicator.
color?: string
}
export type TokenCardProps = TokenCardInfo & {
refreshUnstakingTasks?: () => void
onClaim?: () => void
ButtonLink: ComponentType<ButtonLinkProps>
EntityDisplay: ComponentType<StatefulEntityDisplayProps>
// Actions to display in the button popup.
actions?: {
// Actions to add in the token section. By default, this will include copy
// address and add to wallet, if a cw20 token.
token?: ButtonPopupSectionButton[]
// Extra sections to add to the action popup.
extraSections?: ButtonPopupSection[]
}
}
export type TokenLineProps<T extends TokenCardInfo = TokenCardInfo> = T & {
transparentBackground?: boolean
TokenCard: ComponentType<T>
}
// Map chain ID to loading tokens on that chain.
export type LoadingTokens<T extends TokenCardInfo = TokenCardInfo> = Partial<
Record<ChainId | string, LoadingDataWithError<T[]>>
>
export type DaoTokenCardProps = TokenCardInfo & {
// Hide extra actions, like stake, unstake, and claim.
noExtraActions?: boolean
}
/**
* Packet-forward-middleware memo field for transfer messages.
* (https://github.com/cosmos/ibc-apps/tree/main/middleware/packet-forward-middleware#intermediate-receivers)
*/
export type PfmMemo = {
forward: {
receiver: string
port: string
channel: string
timeout?: string
retries?: number
// Parsed from JSON-stringified PfmMemo if needed (field can be a JSON
// string or an object).
next?: PfmMemo
}
}