Skip to content

Commit 933d768

Browse files
Min Savings Deposit UI
1 parent d6b7c4c commit 933d768

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

packages/app/features/explore/rewards/activity/screen.tsx

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Card,
23
type CardProps,
34
FadeCard,
45
H3,
@@ -21,7 +22,7 @@ import {
2122
} from 'app/utils/distributions'
2223
import formatAmount from 'app/utils/formatAmount'
2324
import { formatUnits } from 'viem'
24-
import type { PropsWithChildren } from 'react'
25+
import { useMemo, type PropsWithChildren } from 'react'
2526
import { DistributionClaimButton } from '../components/DistributionClaimButton'
2627
import { useSendAccount } from 'app/utils/send-accounts'
2728
import { DistributionSelect } from '../components/DistributionSelect'
@@ -30,7 +31,8 @@ import { isEqualCalendarDate } from 'app/utils/dateHelper'
3031
import { toNiceError } from 'app/utils/toNiceError'
3132
import { min } from 'app/utils/bigint'
3233
import type { Json } from '@my/supabase/database.types'
33-
import { sendCoin } from 'app/data/coins'
34+
import { sendCoin, usdcCoin } from 'app/data/coins'
35+
import { useSendEarnBalances, useVaultConvertSharesToAssets } from 'app/features/earn/hooks'
3436

3537
//@todo get this from the db
3638
const verificationTypesAndTitles = {
@@ -165,6 +167,29 @@ const DistributionRequirementsCard = ({
165167
isLoading: isLoadingSnapshotBalance,
166168
error: snapshotBalanceError,
167169
} = useSnapshotBalance({ distribution, sendAccount })
170+
171+
const { data: sendEarnBalances, isLoading: isLoadingSendEarnBalances } = useSendEarnBalances()
172+
// Extract vaults and shares from balances for conversion
173+
const vaults =
174+
sendEarnBalances
175+
?.filter((balance) => balance.shares > 0n && balance.log_addr !== null)
176+
.map((balance) => balance.log_addr) || []
177+
178+
const shares =
179+
sendEarnBalances
180+
?.filter((balance) => balance.shares > 0n && balance.log_addr !== null)
181+
.map((balance) => balance.shares) || []
182+
183+
// Use the hook to get current asset values based on onchain rate
184+
const earnAssets = useVaultConvertSharesToAssets({ vaults, shares })
185+
186+
const totalAssets = useMemo(
187+
() => earnAssets.data?.reduce((sum, assets) => sum + assets, 0n) ?? 0n,
188+
[earnAssets.data]
189+
)
190+
191+
const hasMinSavings = BigInt(distribution.earn_min_balance) > 0n
192+
168193
if (verificationsQuery.isLoading || isLoadingSendAccount) {
169194
return (
170195
<FadeCard br={12} $gtMd={{ gap: '$4', p: '$7' }} p="$5">
@@ -223,7 +248,7 @@ const DistributionRequirementsCard = ({
223248
</XStack>
224249
<XStack ai="center" gap="$2">
225250
<Paragraph>
226-
Min. Balance{' '}
251+
Balance{' '}
227252
{formatAmount(
228253
formatUnits(
229254
BigInt(distribution.hodler_min_balance ?? 0n),
@@ -255,6 +280,39 @@ const DistributionRequirementsCard = ({
255280
}
256281
})()}
257282
</XStack>
283+
{hasMinSavings && (
284+
<XStack ai="center" gap="$2">
285+
<Paragraph>
286+
Savings Deposit $
287+
{formatAmount(
288+
formatUnits(BigInt(distribution.earn_min_balance ?? 0n), usdcCoin.decimals) ?? 0n,
289+
9,
290+
2
291+
)}{' '}
292+
</Paragraph>
293+
{(() => {
294+
switch (true) {
295+
case isLoadingSendEarnBalances:
296+
return <Spinner size="small" />
297+
case distribution.earn_min_balance === undefined ||
298+
BigInt(distribution.earn_min_balance) > (totalAssets ?? 0n):
299+
return (
300+
<Theme name="red">
301+
<IconInfoCircle color={'$color8'} size={'$2'} />
302+
</Theme>
303+
)
304+
default:
305+
return (
306+
<CheckCircle2
307+
$theme-light={{ color: '$color12' }}
308+
color="$primary"
309+
size={'$1.5'}
310+
/>
311+
)
312+
}
313+
})()}
314+
</XStack>
315+
)}
258316
</YStack>
259317
</Stack>
260318
</FadeCard>
@@ -275,11 +333,11 @@ const TaskCards = ({
275333
<H3 fontWeight={'600'} color={'$color12'}>
276334
Tasks
277335
</H3>
278-
<FadeCard br={12} $gtMd={{ gap: '$4', p: '$7' }} p="$5">
336+
<Card br={12} $gtMd={{ gap: '$4', p: '$7' }} p="$5">
279337
<Stack ai="center" jc="center" p="$4">
280338
<Spinner color="$color12" size="large" />
281339
</Stack>
282-
</FadeCard>
340+
</Card>
283341
</YStack>
284342
)
285343
}
@@ -381,7 +439,7 @@ const TaskCard = ({
381439
].includes(type)
382440

383441
return (
384-
<FadeCard br={12} gap="$4" p="$6" jc={'space-between'} $gtSm={{ maw: 331 }} w={'100%'}>
442+
<Card br={12} gap="$4" p="$6" jc={'space-between'} $gtSm={{ maw: 331 }} w={'100%'}>
385443
<XStack ai={'center'} jc="space-between">
386444
{status}
387445
{shouldShowValue && (
@@ -399,7 +457,7 @@ const TaskCard = ({
399457
)}
400458
</XStack>
401459
{children}
402-
</FadeCard>
460+
</Card>
403461
)
404462
}
405463

packages/app/utils/distributions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function fetchDistributions(supabase: SupabaseClient<Database>) {
6666
token_addr,
6767
token_decimals,
6868
updated_at,
69+
earn_min_balance::text,
6970
distribution_shares(
7071
address,
7172
amount::text,

0 commit comments

Comments
 (0)