|
1 | | -import LicenseRewardsPoA from '@/app/server-components/Licenses/LicenseRewardsPoA'; |
2 | | -import { BorderedCard } from '@/app/server-components/shared/cards/BorderedCard'; |
3 | | -import { CardHorizontal } from '@/app/server-components/shared/cards/CardHorizontal'; |
4 | | -import ClientWrapper from '@/components/shared/ClientWrapper'; |
5 | | -import { CopyableAddress } from '@/components/shared/CopyableValue'; |
6 | | -import config from '@/config'; |
7 | | -import { routePath } from '@/lib/routes'; |
8 | | -import { fBI } from '@/lib/utils'; |
9 | | -import * as types from '@/typedefs/blockchain'; |
10 | | -import { Skeleton } from '@heroui/skeleton'; |
11 | | -import clsx from 'clsx'; |
12 | | -import Link from 'next/link'; |
13 | | -import { Suspense } from 'react'; |
14 | | -import { formatUnits } from 'viem'; |
15 | | -import PoA from '../Licenses/PoA'; |
16 | | -import TreasuryWallets from '../Licenses/TreasuryWallets'; |
17 | | -import { CardTitle } from '../shared/CardTitle'; |
18 | | -import { LargeTag } from '../shared/LargeTag'; |
19 | | -import UsageStats from '../shared/Licenses/UsageStats'; |
20 | | - |
21 | | -interface Props { |
22 | | - license: types.License; |
23 | | - licenseType: 'ND' | 'MND' | 'GND'; |
24 | | - licenseId: string; |
25 | | - owner: types.EthAddress; |
26 | | - getNodeAvailability: () => Promise<(types.OraclesAvailabilityResult & types.OraclesDefaultResult) | undefined>; |
27 | | - hasLink?: boolean; // If it has a link to it, it means it's not the main card (displayed on top of the page) |
28 | | -} |
29 | | - |
30 | | -export default async function LicenseCard({ license, licenseType, licenseId, owner, getNodeAvailability, hasLink }: Props) { |
31 | | - const environment = config.environment; |
32 | | - const awbBalance = license.awbBalance; |
33 | | - |
34 | | - const getTitle = () => <CardTitle hasLink={hasLink}>License #{licenseId}</CardTitle>; |
35 | | - |
36 | | - return ( |
37 | | - <BorderedCard> |
38 | | - <div className="row gap-3"> |
39 | | - {!hasLink ? ( |
40 | | - getTitle() |
41 | | - ) : ( |
42 | | - <Link href={`${routePath.license}/${licenseType}/${licenseId}`} className="hover:text-primary"> |
43 | | - {getTitle()} |
44 | | - </Link> |
45 | | - )} |
46 | | - |
47 | | - {license.isBanned && <LargeTag variant="banned">Banned</LargeTag>} |
48 | | - </div> |
49 | | - |
50 | | - <div className="flexible-row"> |
51 | | - {!!licenseType && ( |
52 | | - <CardHorizontal |
53 | | - label="Type" |
54 | | - value={ |
55 | | - <div |
56 | | - className={clsx({ |
57 | | - 'text-primary': licenseType === 'ND', |
58 | | - 'text-purple-600': licenseType === 'MND', |
59 | | - 'text-orange-600': licenseType === 'GND', |
60 | | - })} |
61 | | - > |
62 | | - {licenseType} |
63 | | - </div> |
64 | | - } |
65 | | - isSmall |
66 | | - isFlexible |
67 | | - /> |
68 | | - )} |
69 | | - |
70 | | - {!!owner && ( |
71 | | - <CardHorizontal |
72 | | - label="Owner" |
73 | | - value={ |
74 | | - <ClientWrapper> |
75 | | - <CopyableAddress value={owner} size={4} isLarge link={`${routePath.account}/${owner}`} /> |
76 | | - </ClientWrapper> |
77 | | - } |
78 | | - isSmall |
79 | | - isFlexible |
80 | | - /> |
81 | | - )} |
82 | | - |
83 | | - {!!license.assignTimestamp && ( |
84 | | - <CardHorizontal |
85 | | - label="Assign timestamp" |
86 | | - value={new Date(Number(license.assignTimestamp) * 1000).toLocaleString()} |
87 | | - isSmaller |
88 | | - isFlexible |
89 | | - widthClasses="min-w-[310px] md:min-w-[420px]" |
90 | | - /> |
91 | | - )} |
92 | | - |
93 | | - {!!license.lastClaimEpoch && ( |
94 | | - <CardHorizontal |
95 | | - label="Last claim epoch" |
96 | | - value={license.lastClaimEpoch.toString()} |
97 | | - isSmall |
98 | | - isFlexible |
99 | | - widthClasses="min-w-[274px]" |
100 | | - /> |
101 | | - )} |
102 | | - |
103 | | - <CardHorizontal |
104 | | - label="Usage" |
105 | | - value={ |
106 | | - <div className="w-full min-w-52 xs:min-w-56 md:min-w-60"> |
107 | | - <UsageStats |
108 | | - totalClaimedAmount={license.totalClaimedAmount} |
109 | | - totalAssignedAmount={license.totalAssignedAmount} |
110 | | - awbBalance={license.awbBalance} |
111 | | - /> |
112 | | - </div> |
113 | | - } |
114 | | - isSmall |
115 | | - isFlexible |
116 | | - /> |
117 | | - |
118 | | - <PoA totalAssignedAmount={license.totalAssignedAmount} totalClaimedAmount={license.totalClaimedAmount} /> |
119 | | - |
120 | | - {licenseType !== 'ND' && ( |
121 | | - <CardHorizontal |
122 | | - label="Adoption Withheld Buffer" |
123 | | - value={<div className="text-orange-500">{fBI(awbBalance, 18)} $R1</div>} |
124 | | - isSmall |
125 | | - isFlexible |
126 | | - widthClasses="min-w-[360px]" |
127 | | - /> |
128 | | - )} |
129 | | - |
130 | | - <Suspense fallback={<Skeleton className="min-h-[76px] w-full rounded-xl md:max-w-[258px]" />}> |
131 | | - <LicenseRewardsPoA |
132 | | - license={license} |
133 | | - licenseType={licenseType as 'ND' | 'MND' | 'GND'} |
134 | | - licenseId={licenseId} |
135 | | - getNodeAvailability={getNodeAvailability} |
136 | | - /> |
137 | | - </Suspense> |
138 | | - |
139 | | - {licenseType === 'ND' && ( |
140 | | - <CardHorizontal |
141 | | - label="Rewards (PoAI)" |
142 | | - value={ |
143 | | - <div className="text-primary"> |
144 | | - {license.r1PoaiRewards === undefined |
145 | | - ? '...' |
146 | | - : parseFloat( |
147 | | - Number(formatUnits(license.r1PoaiRewards ?? 0n, 18)).toFixed(2), |
148 | | - ).toLocaleString()} |
149 | | - {!!license.r1PoaiRewards ? ' $R1' : ''} |
150 | | - </div> |
151 | | - } |
152 | | - isSmall |
153 | | - /> |
154 | | - )} |
155 | | - </div> |
156 | | - |
157 | | - {environment === 'mainnet' && licenseId === '1' && licenseType === 'GND' && <TreasuryWallets license={license} />} |
158 | | - </BorderedCard> |
159 | | - ); |
160 | | -} |
| 1 | +import LicenseRewardsPoA from '@/app/server-components/Licenses/LicenseRewardsPoA'; |
| 2 | +import { BorderedCard } from '@/app/server-components/shared/cards/BorderedCard'; |
| 3 | +import { CardHorizontal } from '@/app/server-components/shared/cards/CardHorizontal'; |
| 4 | +import ClientWrapper from '@/components/shared/ClientWrapper'; |
| 5 | +import { CopyableAddress } from '@/components/shared/CopyableValue'; |
| 6 | +import { routePath } from '@/lib/routes'; |
| 7 | +import { fBI } from '@/lib/utils'; |
| 8 | +import * as types from '@/typedefs/blockchain'; |
| 9 | +import { Skeleton } from '@heroui/skeleton'; |
| 10 | +import clsx from 'clsx'; |
| 11 | +import Link from 'next/link'; |
| 12 | +import { Suspense } from 'react'; |
| 13 | +import { formatUnits } from 'viem'; |
| 14 | +import PoA from '../Licenses/PoA'; |
| 15 | +import { CardTitle } from '../shared/CardTitle'; |
| 16 | +import { LargeTag } from '../shared/LargeTag'; |
| 17 | +import UsageStats from '../shared/Licenses/UsageStats'; |
| 18 | + |
| 19 | +interface Props { |
| 20 | + license: types.License; |
| 21 | + licenseType: 'ND' | 'MND' | 'GND'; |
| 22 | + licenseId: string; |
| 23 | + owner: types.EthAddress; |
| 24 | + getNodeAvailability: () => Promise<(types.OraclesAvailabilityResult & types.OraclesDefaultResult) | undefined>; |
| 25 | + hasLink?: boolean; // If it has a link to it, it means it's not the main card (displayed on top of the page) |
| 26 | +} |
| 27 | + |
| 28 | +export default async function LicenseCard({ license, licenseType, licenseId, owner, getNodeAvailability, hasLink }: Props) { |
| 29 | + const awbBalance = license.awbBalance; |
| 30 | + |
| 31 | + const getTitle = () => <CardTitle hasLink={hasLink}>License #{licenseId}</CardTitle>; |
| 32 | + |
| 33 | + return ( |
| 34 | + <BorderedCard> |
| 35 | + <div className="row gap-3"> |
| 36 | + {!hasLink ? ( |
| 37 | + getTitle() |
| 38 | + ) : ( |
| 39 | + <Link href={`${routePath.license}/${licenseType}/${licenseId}`} className="hover:text-primary"> |
| 40 | + {getTitle()} |
| 41 | + </Link> |
| 42 | + )} |
| 43 | + |
| 44 | + {license.isBanned && <LargeTag variant="banned">Banned</LargeTag>} |
| 45 | + </div> |
| 46 | + |
| 47 | + <div className="flexible-row"> |
| 48 | + {!!licenseType && ( |
| 49 | + <CardHorizontal |
| 50 | + label="Type" |
| 51 | + value={ |
| 52 | + <div |
| 53 | + className={clsx({ |
| 54 | + 'text-primary': licenseType === 'ND', |
| 55 | + 'text-purple-600': licenseType === 'MND', |
| 56 | + 'text-orange-600': licenseType === 'GND', |
| 57 | + })} |
| 58 | + > |
| 59 | + {licenseType} |
| 60 | + </div> |
| 61 | + } |
| 62 | + isSmall |
| 63 | + isFlexible |
| 64 | + /> |
| 65 | + )} |
| 66 | + |
| 67 | + {!!owner && ( |
| 68 | + <CardHorizontal |
| 69 | + label="Owner" |
| 70 | + value={ |
| 71 | + <ClientWrapper> |
| 72 | + <CopyableAddress value={owner} size={4} isLarge link={`${routePath.account}/${owner}`} /> |
| 73 | + </ClientWrapper> |
| 74 | + } |
| 75 | + isSmall |
| 76 | + isFlexible |
| 77 | + /> |
| 78 | + )} |
| 79 | + |
| 80 | + {!!license.assignTimestamp && ( |
| 81 | + <CardHorizontal |
| 82 | + label="Assign timestamp" |
| 83 | + value={new Date(Number(license.assignTimestamp) * 1000).toLocaleString()} |
| 84 | + isSmaller |
| 85 | + isFlexible |
| 86 | + widthClasses="min-w-[310px] md:min-w-[420px]" |
| 87 | + /> |
| 88 | + )} |
| 89 | + |
| 90 | + {!!license.lastClaimEpoch && ( |
| 91 | + <CardHorizontal |
| 92 | + label="Last claim epoch" |
| 93 | + value={license.lastClaimEpoch.toString()} |
| 94 | + isSmall |
| 95 | + isFlexible |
| 96 | + widthClasses="min-w-[274px]" |
| 97 | + /> |
| 98 | + )} |
| 99 | + |
| 100 | + <CardHorizontal |
| 101 | + label="Usage" |
| 102 | + value={ |
| 103 | + <div className="w-full min-w-52 xs:min-w-56 md:min-w-60"> |
| 104 | + <UsageStats |
| 105 | + totalClaimedAmount={license.totalClaimedAmount} |
| 106 | + totalAssignedAmount={license.totalAssignedAmount} |
| 107 | + awbBalance={license.awbBalance} |
| 108 | + /> |
| 109 | + </div> |
| 110 | + } |
| 111 | + isSmall |
| 112 | + isFlexible |
| 113 | + /> |
| 114 | + |
| 115 | + <PoA totalAssignedAmount={license.totalAssignedAmount} totalClaimedAmount={license.totalClaimedAmount} /> |
| 116 | + |
| 117 | + {licenseType !== 'ND' && ( |
| 118 | + <CardHorizontal |
| 119 | + label="Adoption Withheld Buffer" |
| 120 | + value={<div className="text-orange-500">{fBI(awbBalance, 18)} $R1</div>} |
| 121 | + isSmall |
| 122 | + isFlexible |
| 123 | + widthClasses="min-w-[360px]" |
| 124 | + /> |
| 125 | + )} |
| 126 | + |
| 127 | + <Suspense fallback={<Skeleton className="min-h-[76px] w-full rounded-xl md:max-w-[258px]" />}> |
| 128 | + <LicenseRewardsPoA |
| 129 | + license={license} |
| 130 | + licenseType={licenseType as 'ND' | 'MND' | 'GND'} |
| 131 | + licenseId={licenseId} |
| 132 | + getNodeAvailability={getNodeAvailability} |
| 133 | + /> |
| 134 | + </Suspense> |
| 135 | + |
| 136 | + {licenseType === 'ND' && ( |
| 137 | + <CardHorizontal |
| 138 | + label="Rewards (PoAI)" |
| 139 | + value={ |
| 140 | + <div className="text-primary"> |
| 141 | + {license.r1PoaiRewards === undefined |
| 142 | + ? '...' |
| 143 | + : parseFloat( |
| 144 | + Number(formatUnits(license.r1PoaiRewards ?? 0n, 18)).toFixed(2), |
| 145 | + ).toLocaleString()} |
| 146 | + {!!license.r1PoaiRewards ? ' $R1' : ''} |
| 147 | + </div> |
| 148 | + } |
| 149 | + isSmall |
| 150 | + /> |
| 151 | + )} |
| 152 | + </div> |
| 153 | + </BorderedCard> |
| 154 | + ); |
| 155 | +} |
0 commit comments