forked from koshikraj/ottopus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol-labels.ts
More file actions
71 lines (68 loc) · 2.2 KB
/
Copy pathprotocol-labels.ts
File metadata and controls
71 lines (68 loc) · 2.2 KB
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
import type { PositionGroup, ProtocolModule, ProtocolPositionType } from '@/lib/api'
import type { Tone } from '@/components/ui'
/**
* The tag on a protocol row: how this asset is held, in one word. Debt gets
* the block tone because it is the one row that makes the card smaller; the
* rest are facts and stay neutral.
*/
export function heldTag(
positionType: ProtocolPositionType,
module: ProtocolModule | null,
): { label: string; tone: Tone } {
if (positionType === 'loan') return { label: 'Debt', tone: 'block' }
if (module === 'vesting' && positionType !== 'reward') return { label: 'Vesting', tone: 'neutral' }
switch (positionType) {
case 'deposit':
return { label: 'Deposited', tone: 'neutral' }
case 'staked':
return { label: 'Staked', tone: 'neutral' }
case 'locked':
return { label: 'Locked', tone: 'neutral' }
case 'reward':
return { label: 'Reward', tone: 'ok' }
case 'investment':
return { label: 'Investment', tone: 'neutral' }
}
}
/** What kind of thing a group is, for its header. Null when the provider did not say. */
export function moduleLabel(module: ProtocolModule | null): string | null {
switch (module) {
case 'deposit':
return 'Deposit'
case 'lending':
return 'Lending'
case 'yield':
return 'Yield'
case 'liquidity_pool':
return 'Liquidity pool'
case 'staked':
return 'Staking'
case 'leveraged_farming':
return 'Leveraged farming'
case 'nft_staked':
return 'NFT staking'
case 'farming':
return 'Farming'
case 'locked':
return 'Locked'
case 'vesting':
return 'Vesting'
case 'rewards':
return 'Rewards'
case 'investment':
return 'Investment'
case null:
return null
}
}
/**
* The group's header line: its module when the name does not already say it.
* "Fluid Lending (#9468)" needs no "Lending" beside it; "USDC/WETH" needs
* "Liquidity pool".
*/
export function groupKind(group: Pick<PositionGroup, 'name' | 'module'>): string | null {
const label = moduleLabel(group.module)
if (!label) return null
const first = label.split(' ')[0]!.toLowerCase()
return group.name.toLowerCase().includes(first) ? null : label
}