@@ -27,6 +27,7 @@ import formatAmount from 'app/utils/formatAmount'
27
27
import { zeroAddress } from 'viem'
28
28
import { type PropsWithChildren , useRef , useId , useState } from 'react'
29
29
import { DistributionClaimButton } from '../components/DistributionClaimButton'
30
+ import { useSendAccount } from 'app/utils/send-accounts'
30
31
31
32
//@todo get this from the db
32
33
const verificationTypesAndTitles = {
@@ -226,7 +227,10 @@ export function ActivityRewardsScreen() {
226
227
< DistributionRequirementsCard distribution = { distributions [ selectedDistributionIndex ] } />
227
228
< SendPerksCards distribution = { distributions [ selectedDistributionIndex ] } />
228
229
< MultiplierCards distribution = { distributions [ selectedDistributionIndex ] } />
229
- < RewardsProgressCard distribution = { distributions [ selectedDistributionIndex ] } />
230
+ < RewardsProgressCard
231
+ distribution = { distributions [ selectedDistributionIndex ] }
232
+ previousDistribution = { distributions [ selectedDistributionIndex - 1 ] }
233
+ />
230
234
< ClaimableRewardsCard distribution = { distributions [ selectedDistributionIndex ] } />
231
235
</ YStack >
232
236
) }
@@ -318,19 +322,29 @@ const Header = () => (
318
322
319
323
const DistributionRequirementsCard = ( {
320
324
distribution,
321
- } : { distribution : UseDistributionsResultData [ number ] } ) => {
325
+ previousDistribution,
326
+ } : {
327
+ distribution : UseDistributionsResultData [ number ]
328
+ previousDistribution ?: UseDistributionsResultData [ number ]
329
+ } ) => {
330
+ const hasSent = Boolean (
331
+ distribution . distribution_verifications_summary
332
+ . at ( 0 )
333
+ ?. verification_values ?. find ( ( { type } ) => type === 'send_ten' )
334
+ )
335
+ const { data : sendAccount } = useSendAccount ( )
322
336
const {
323
337
data : snapshotBalance ,
324
338
isLoading : isLoadingSnapshotBalance ,
325
339
error : snapshotBalanceError ,
326
340
} = useReadSendTokenBalanceOf ( {
327
341
chainId : distribution . chain_id as keyof typeof sendTokenAddress ,
328
- args : [ distribution . distribution_shares . at ( 0 ) ?. address ?? zeroAddress ] ,
342
+ args : [ sendAccount ?. address ?? zeroAddress ] ,
329
343
blockNumber : distribution . snapshot_block_num
330
344
? BigInt ( distribution . snapshot_block_num )
331
345
: undefined ,
332
346
query : {
333
- enabled : ! ! distribution . distribution_shares . at ( 0 ) ?. address ,
347
+ enabled : hasSent && Boolean ( sendAccount ?. address ) ,
334
348
} ,
335
349
} )
336
350
@@ -340,13 +354,36 @@ const DistributionRequirementsCard = ({
340
354
. at ( 0 )
341
355
?. verification_values ?. find ( ( { type } ) => type === 'tag_registration' ) ?. weight
342
356
357
+ const sendCeiling = distribution . distribution_verifications_summary [ 0 ] ?. verification_values ?. find (
358
+ ( { type } ) => type === 'send_ceiling'
359
+ )
360
+
361
+ const previousReward =
362
+ previousDistribution ?. distribution_shares ?. [ 0 ] ?. amount_after_slash ??
363
+ distribution . hodler_min_balance
364
+
365
+ let percent = 0
366
+ let balanceAfterSlash = 0n
367
+
368
+ if ( sendCeiling ?. weight && distribution . send_slash ?. scaling_divisor ) {
369
+ const scaledPreviousReward = previousReward / distribution . send_slash . scaling_divisor
370
+ // Multiply by 10000 to get 4 decimal places of precision
371
+ percent = Math . min ( ( sendCeiling . weight / scaledPreviousReward ) * 10000 , 10000 )
372
+ balanceAfterSlash = snapshotBalance
373
+ ? percent === 10000
374
+ ? snapshotBalance
375
+ : ( BigInt ( snapshotBalance ) * BigInt ( Math . round ( percent ) ) ) / BigInt ( 10000 )
376
+ : 0n
377
+ }
378
+
343
379
return (
344
380
< Card br = { 12 } $gtMd = { { gap : '$4' , p : '$7' } } p = "$5" >
345
381
< Stack ai = "center" jc = "space-between" gap = "$5" $gtXs = { { flexDirection : 'row' } } >
346
382
< YStack gap = "$2" >
347
383
< Label fontSize = { '$5' } col = { '$color10' } >
348
- Your SEND Balance
384
+ Your Qualifying Balance
349
385
</ Label >
386
+
350
387
{ isLoadingSnapshotBalance ? (
351
388
< Spinner size = "small" color = { '$color11' } />
352
389
) : (
@@ -359,7 +396,7 @@ const DistributionRequirementsCard = ({
359
396
fontSize = { '$9' }
360
397
$gtXl = { { fontSize : '$10' } }
361
398
>
362
- { `${ formatAmount ( snapshotBalance ?. toString ( ) ?? 0 , 9 , 0 ) } SEND` }
399
+ { `${ formatAmount ( balanceAfterSlash ?. toString ( ) ?? 0 , 9 , 0 ) } SEND` }
363
400
</ Paragraph >
364
401
</ Theme >
365
402
) }
@@ -591,25 +628,33 @@ const MultiplierCard = ({ children }: PropsWithChildren<CardProps>) => {
591
628
592
629
const RewardsProgressCard = ( {
593
630
distribution,
631
+ previousDistribution,
594
632
} : {
595
633
distribution : UseDistributionsResultData [ number ]
634
+ previousDistribution ?: UseDistributionsResultData [ number ]
596
635
} ) => {
597
- const shareAmount = distribution . distribution_shares ?. [ 0 ] ?. amount
598
- const slashedAmount = distribution . distribution_shares ?. [ 0 ] ?. amount_after_slash
636
+ const sendCeiling = distribution . distribution_verifications_summary [ 0 ] ?. verification_values ?. find (
637
+ ( { type } ) => type === 'send_ceiling'
638
+ )
639
+
640
+ if ( ! sendCeiling || ! distribution . send_slash ) return null
641
+
642
+ const previousReward =
643
+ previousDistribution ?. distribution_shares ?. [ 0 ] ?. amount_after_slash ??
644
+ distribution . hodler_min_balance
599
645
600
- if ( ! shareAmount || ! slashedAmount ) return null
646
+ const scaledPreviousReward = previousReward / distribution . send_slash . scaling_divisor
601
647
602
- const percentage = Math . floor ( ( Number ( slashedAmount ) / Number ( shareAmount ) ) * 100 )
648
+ const progress = Math . min ( Math . floor ( ( sendCeiling . weight / scaledPreviousReward ) * 100 ) , 100 )
603
649
604
650
return (
605
651
< YStack f = { 1 } w = { '100%' } gap = "$5" >
606
652
< H3 fontWeight = { '600' } color = { '$color12' } >
607
- Progress
653
+ Send Progress
608
654
</ H3 >
609
- < Card br = { '$6' } p = "$7" w = { '100%' } >
655
+ < Card br = { '$6' } p = "$7" $xs = { { p : '$5' } } w = { '100%' } maw = { 500 } >
610
656
< YStack gap = "$4" w = "100%" >
611
- < XStack jc = "space-between" ai = "center" >
612
- < Paragraph color = "$color11" > Current Rewards</ Paragraph >
657
+ < XStack jc = "flex-end" >
613
658
< Paragraph
614
659
ff = { '$mono' }
615
660
py = { '$size.0.5' }
@@ -619,13 +664,12 @@ const RewardsProgressCard = ({
619
664
$theme-light = { { borderColor : '$color12' } }
620
665
borderRadius = { '$4' }
621
666
>
622
- { percentage } %
667
+ { progress } %
623
668
</ Paragraph >
624
669
</ XStack >
625
-
626
- < Stack w = "100%" h = "$1" br = "$10" bc = "$color3" overflow = "hidden" >
670
+ < Stack w = "100%" h = "$1" br = "$10" bc = "$color3" >
627
671
< Stack
628
- w = { `${ percentage } %` }
672
+ w = { `${ progress } %` }
629
673
h = "100%"
630
674
br = "$10"
631
675
animation = "quick"
@@ -637,25 +681,6 @@ const RewardsProgressCard = ({
637
681
} }
638
682
/>
639
683
</ Stack >
640
-
641
- < XStack jc = "space-between" ai = "center" >
642
- < YStack >
643
- < Paragraph color = "$color10" size = "$3" >
644
- Current
645
- </ Paragraph >
646
- < Paragraph fontFamily = "$mono" color = "$color12" >
647
- { formatAmount ( slashedAmount , 9 , 0 ) } SEND
648
- </ Paragraph >
649
- </ YStack >
650
- < YStack ai = "flex-end" >
651
- < Paragraph color = "$color10" size = "$3" >
652
- Estimated Maximum
653
- </ Paragraph >
654
- < Paragraph fontFamily = "$mono" color = "$color12" >
655
- { formatAmount ( shareAmount , 9 , 0 ) } SEND
656
- </ Paragraph >
657
- </ YStack >
658
- </ XStack >
659
684
</ YStack >
660
685
</ Card >
661
686
</ YStack >
@@ -680,7 +705,7 @@ const ClaimableRewardsCard = ({
680
705
return (
681
706
< YStack f = { 1 } w = { '100%' } gap = "$5" $sm = { { display : 'none' } } >
682
707
< H3 fontWeight = { '600' } color = { '$color12' } >
683
- { isQualificationOver ? `Total ${ distributionMonth } ` : `Estimated ${ distributionMonth } ` }
708
+ { isQualificationOver ? `Total ${ distributionMonth } ` : ` ${ distributionMonth } Rewards ` }
684
709
</ H3 >
685
710
< Card br = { '$6' } p = "$7" ai = { 'center' } w = { '100%' } >
686
711
< Stack ai = "center" jc = "space-between" fd = "row" w = "100%" >
0 commit comments