@@ -14,7 +14,7 @@ import { FunctionComponent, PropsWithChildren, useEffect, useMemo, useState } fr
1414import toast from 'react-hot-toast' ;
1515import { RiCpuLine , RiExchange2Line , RiFireLine , RiLink , RiLinkUnlink , RiMoreFill , RiTimeLine } from 'react-icons/ri' ;
1616import { Link } from 'react-router-dom' ;
17- import { License } from 'typedefs/blockchain' ;
17+ import { License , MndRewardsBreakdown } from 'typedefs/blockchain' ;
1818import { formatUnits } from 'viem' ;
1919import { useAccount , usePublicClient } from 'wagmi' ;
2020import { LicenseCardNode } from './LicenseCardNode' ;
@@ -42,6 +42,7 @@ export const LicenseCardHeader = ({
4242 // Rewards
4343 const [ rewardsTotal , setRewardsTotal ] = useState < bigint | undefined > ( ) ;
4444 const [ licenseRewardsPoA , setLicenseRewardsPoA ] = useState < bigint | undefined > ( ) ;
45+ const [ licenseRewardsBreakdown , setLicenseRewardsBreakdown ] = useState < MndRewardsBreakdown | undefined > ( ) ;
4546 const licenseRewardsPoAI : bigint | undefined = license . type === 'ND' ? license . r1PoaiRewards || undefined : undefined ;
4647
4748 // Used to restrict actions until all data is loaded
@@ -74,8 +75,12 @@ export const LicenseCardHeader = ({
7475 if ( license . isLinked ) {
7576 ( async ( ) => {
7677 try {
77- const rewardsPoA = await license . rewards ;
78+ const [ rewardsPoA , rewardsBreakdown ] = await Promise . all ( [
79+ license . rewards ,
80+ license . type !== 'ND' ? license . rewardsBreakdown : Promise . resolve ( undefined ) ,
81+ ] ) ;
7882 setLicenseRewardsPoA ( rewardsPoA ) ;
83+ setLicenseRewardsBreakdown ( rewardsBreakdown ) ;
7984
8085 setRewardsTotal (
8186 rewardsPoA !== undefined || licenseRewardsPoAI !== undefined
@@ -109,37 +114,41 @@ export const LicenseCardHeader = ({
109114 </ Link >
110115 ) ;
111116
112- const getLicenseUsageStats = ( ) => (
113- < div className = "row gap-2.5 text-sm leading-none font-medium" >
114- < div >
115- { fBI ( license . totalClaimedAmount , 18 ) } /{ fBI ( license . totalAssignedAmount , 18 ) }
116- </ div >
117+ const getLicenseUsageStats = ( ) => {
118+ const walletClaimedAmount =
119+ license . type === 'ND'
120+ ? license . totalClaimedAmount
121+ : license . totalClaimedAmount > license . awbBalance
122+ ? license . totalClaimedAmount - license . awbBalance
123+ : 0n ;
124+
125+ return (
126+ < div className = "row gap-2.5 text-sm leading-none font-medium" >
127+ < div >
128+ { fBI ( walletClaimedAmount , 18 ) } /{ fBI ( license . totalAssignedAmount , 18 ) }
129+ </ div >
117130
118- < div className = "flex h-1 w-full overflow-hidden rounded-full bg-gray-300" >
119- < div
120- className = "bg-primary rounded-full transition-all"
121- style = { {
122- width : `${ Number (
123- ( ( license . totalClaimedAmount - ( license . type !== 'ND' ? license . awbBalance : 0n ) ) * 100n ) /
124- license . totalAssignedAmount ,
125- ) } %`,
126- } }
127- > </ div >
128- { license . type !== 'ND' && (
131+ < div className = "flex h-1 w-full overflow-hidden rounded-full bg-gray-300" >
129132 < div
130- className = "rounded-end bg-orange-500 transition-all"
133+ className = "bg-primary rounded-full transition-all"
131134 style = { {
132- width : `${ Number ( ( license . awbBalance * 100n ) / license . totalAssignedAmount ) } %` ,
135+ width : `${ Number ( ( walletClaimedAmount * 100n ) / license . totalAssignedAmount ) } %` ,
133136 } }
134137 > </ div >
135- ) }
136- </ div >
138+ { license . type !== 'ND' && (
139+ < div
140+ className = "rounded-end bg-orange-500 transition-all"
141+ style = { {
142+ width : `${ Number ( ( license . awbBalance * 100n ) / license . totalAssignedAmount ) } %` ,
143+ } }
144+ > </ div >
145+ ) }
146+ </ div >
137147
138- < div >
139- { parseFloat ( ( ( Number ( license . totalClaimedAmount ) / Number ( license . totalAssignedAmount ) ) * 100 ) . toFixed ( 2 ) ) } %
148+ < div > { parseFloat ( ( ( Number ( walletClaimedAmount ) / Number ( license . totalAssignedAmount ) ) * 100 ) . toFixed ( 2 ) ) } %</ div >
140149 </ div >
141- </ div >
142- ) ;
150+ ) ;
151+ } ;
143152
144153 const getLicenseCard = ( ) => (
145154 < LicenseSmallCard >
@@ -163,8 +172,10 @@ export const LicenseCardHeader = ({
163172
164173 const nRewardsPoA : number = Number ( formatUnits ( licenseRewardsPoA ?? 0n , 18 ) ) ;
165174 const nRewardsPoAI : number = Number ( formatUnits ( licenseRewardsPoAI ?? 0n , 18 ) ) ;
175+ const nCarryover : number = Number ( formatUnits ( licenseRewardsBreakdown ?. carryoverAmount ?? 0n , 18 ) ) ;
166176
167177 const hasRewards = nRewardsPoA > 0 || nRewardsPoAI > 0 ;
178+ const showMndBreakdown = license . type !== 'ND' && nCarryover > 0 ;
168179
169180 if ( ! isLoadingRewards && ! hasRewards ) {
170181 return undefined ;
@@ -187,6 +198,11 @@ export const LicenseCardHeader = ({
187198 < div className = "col gap-1.5 text-sm" >
188199 < div className = "leading-none font-medium text-slate-500" > PoA</ div >
189200 < div className = "text-primary leading-none font-semibold" > { fN ( nRewardsPoA ) } </ div >
201+ { showMndBreakdown && (
202+ < div className = "text-[11px] leading-none text-slate-500" >
203+ includes { fN ( nCarryover ) } carryover
204+ </ div >
205+ ) }
190206 </ div >
191207 ) }
192208
0 commit comments