forked from SmartDropLabs/smartdrop-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEarningRow.tsx
More file actions
198 lines (191 loc) · 5.94 KB
/
Copy pathEarningRow.tsx
File metadata and controls
198 lines (191 loc) · 5.94 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
"use client";
import { stellarNetwork } from "@/config";
import { useStellarWallet } from "@/context/StellarWalletContext";
import { useCountdown } from "@/hooks/useCountdown";
import { formatCredits } from "@/lib/soroban";
import { useFarmStore } from "@/store/farmStore";
import {
type FarmPosition,
unlockAvailableAt,
} from "@/types/farm";
import {
Box,
Button,
Flex,
Text,
Tooltip,
} from "@chakra-ui/react";
import { memo, type ReactNode } from "react";
export function MetricColumn({
label,
value,
minW = "110px",
}: {
label: string;
value: ReactNode;
minW?: string;
}) {
return (
<Flex
direction="column"
minW={{ base: 0, md: minW }}
w={{ base: "full", md: "auto" }}
align={{ base: "stretch", md: "flex-start" }}
gap={1}
>
<Text fontSize="2xs" color="app.muted" textTransform="uppercase">
{label}
</Text>
<Text fontWeight={{ base: "semibold", md: "normal" }} overflowWrap="anywhere">
{value}
</Text>
</Flex>
);
}
type EarningRowProps = {
position: FarmPosition;
};
function earningRowPropsAreEqual(
previous: EarningRowProps,
next: EarningRowProps,
) {
const previousPosition = previous.position;
const nextPosition = next.position;
return (
previousPosition.id === nextPosition.id &&
previousPosition.contractAddress === nextPosition.contractAddress &&
previousPosition.name === nextPosition.name &&
previousPosition.img === nextPosition.img &&
previousPosition.earned === nextPosition.earned &&
previousPosition.stake === nextPosition.stake &&
previousPosition.dailyRate === nextPosition.dailyRate &&
previousPosition.totalStakedLiquidity === nextPosition.totalStakedLiquidity &&
previousPosition.symbol === nextPosition.symbol &&
previousPosition.lockedAmount === nextPosition.lockedAmount &&
previousPosition.lockedAt === nextPosition.lockedAt &&
previousPosition.lockPeriodSeconds === nextPosition.lockPeriodSeconds
);
}
export const EarningRow = memo(function EarningRow({
position,
}: EarningRowProps) {
const openUnlock = useFarmStore((s) => s.openUnlock);
const openBoost = useFarmStore((s) => s.openBoost);
const { isNetworkMismatch } = useStellarWallet();
const countdown = useCountdown(unlockAvailableAt(position));
const hasStake = position.lockedAmount > 0;
const canUnlock = hasStake && countdown.isElapsed;
const boostDisabled = !hasStake || isNetworkMismatch;
const unlockDisabled = !canUnlock || isNetworkMismatch;
const boostTooltipLabel = isNetworkMismatch
? `Switch Freighter to ${stellarNetwork} to set boost.`
: !hasStake
? "Deposit first to enable boost"
: undefined;
const unlockTooltipLabel = isNetworkMismatch
? `Switch Freighter to ${stellarNetwork} to unlock.`
: !hasStake
? "No locked assets in this position"
: `Locked for another ${countdown.label}`;
return (
<Flex
display={{ base: "flex", md: "flex" }}
flexDirection={{ base: "column", md: "row" }}
w="full"
minH={20}
align={{ base: "stretch", md: "center" }}
justify={{ base: "flex-start", md: "space-between" }}
gap={{ base: 4, md: 0 }}
border="1px solid"
borderColor="app.border"
borderRadius="card"
bg="app.surface"
boxShadow="card"
transition="all 0.2s ease"
_hover={{ borderColor: "app.borderHover", boxShadow: "cardHover" }}
px={5}
py={{ base: 4, md: 0 }}
>
<Text fontWeight="bold" w={{ base: "full", md: "auto" }}>
{position.name}
</Text>
<MetricColumn label="Earned" value={formatCredits(position.earned)} />
<MetricColumn label="My Stake" value={position.stake} />
<MetricColumn label="Daily Rate" value={position.dailyRate} />
<MetricColumn
label="Total Staked Liquidity"
value={position.totalStakedLiquidity}
minW="180px"
/>
{hasStake && (
<Box
display="block"
w={{ base: "full", md: "auto" }}
minW={{ md: "150px" }}
textAlign="center"
border="1px solid"
borderColor="app.border"
borderRadius="2xl"
bg="app.inputBg"
px={3}
py={3}
>
<Text fontSize="2xs" color="app.muted" textTransform="uppercase">
Unlock status
</Text>
<Text fontSize="lg" fontWeight="bold">
{countdown.label}
</Text>
</Box>
)}
<Flex
gap={{ base: 3, md: 4 }}
direction={{ base: "column", md: "row" }}
w={{ base: "full", md: "auto" }}
>
<Tooltip
label={boostTooltipLabel}
isDisabled={!boostDisabled}
hasArrow
bg="app.tooltipBg"
color="app.tooltipFg"
>
<Box w={{ base: "full", md: "auto" }}>
<Button
borderRadius="3xl"
variant="outline"
borderColor="app.border"
color={position.boostAllocation ? "app.accent" : "app.muted"}
isDisabled={boostDisabled}
onClick={() => openBoost(position)}
w={{ base: "full", md: "auto" }}
>
{position.boostAllocation ? `Boost (${position.boostAllocation}%)` : "Boost"}
</Button>
</Box>
</Tooltip>
<Tooltip
label={unlockTooltipLabel}
isDisabled={!unlockDisabled}
hasArrow
bg="app.tooltipBg"
color="app.tooltipFg"
>
<Box w={{ base: "full", md: "auto" }}>
<Button
borderRadius="3xl"
bg="app.accent"
color="app.onAccent"
_hover={{ opacity: 0.9 }}
onClick={() => openUnlock(position)}
isDisabled={unlockDisabled}
w={{ base: "full", md: "auto" }}
>
Unlock
</Button>
</Box>
</Tooltip>
</Flex>
</Flex>
);
}, earningRowPropsAreEqual);