Skip to content

Commit 59b14c6

Browse files
committed
feat(staking): expose publisher names for pubs who wish to be public
1 parent 8cd4792 commit 59b14c6

File tree

7 files changed

+106
-50
lines changed

7 files changed

+106
-50
lines changed
149 KB
Loading

apps/staking/src/api.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
import { PublicKey } from "@solana/web3.js";
1313
import { z } from "zod";
1414

15+
import { KNOWN_PUBLISHERS } from "./known-publishers";
16+
1517
const publishersRankingSchema = z
1618
.object({
1719
publisher: z.string(),
@@ -47,7 +49,12 @@ type Data = {
4749
m: bigint;
4850
z: bigint;
4951
integrityStakingPublishers: {
50-
name: string | undefined;
52+
identity:
53+
| {
54+
name: string;
55+
icon: string;
56+
}
57+
| undefined;
5158
publicKey: PublicKey;
5259
stakeAccount: PublicKey | undefined;
5360
selfStake: bigint;
@@ -263,7 +270,9 @@ const loadPublisherData = async (
263270

264271
return {
265272
apyHistory,
266-
name: undefined, // TODO
273+
identity: (
274+
KNOWN_PUBLISHERS as Record<string, { name: string; icon: string }>
275+
)[publisher.pubkey.toBase58()],
267276
numFeeds: numberOfSymbols ?? 0,
268277
poolCapacity: getPublisherCap(publisherCaps, publisher.pubkey),
269278
poolUtilization: publisher.totalDelegation,

apps/staking/src/components/CopyButton/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ export const CopyButton = ({
5252
onPress={copy}
5353
isDisabled={isCopied}
5454
className={clsx(
55-
"group -mx-2 -mt-0.5 rounded-md px-2 py-0.5 align-middle transition hover:bg-white/10 focus:outline-none focus-visible:ring-1 focus-visible:ring-pythpurple-400",
55+
"group mx-[-0.25em] -mt-0.5 inline-block rounded-md px-[0.25em] py-0.5 transition hover:bg-white/10 focus:outline-none focus-visible:ring-1 focus-visible:ring-pythpurple-400",
5656
className,
5757
)}
5858
{...(isCopied && { "data-is-copied": true })}
5959
{...props}
6060
>
6161
{(...args) => (
6262
<>
63-
<span className="align-middle">
63+
<span>
6464
{typeof children === "function" ? children(...args) : children}
6565
</span>
66-
<span className="relative ml-[0.25em] inline-block align-middle">
66+
<span className="relative top-[0.125em] ml-[0.25em] inline-block">
6767
<span className="opacity-50 transition-opacity duration-100 group-data-[is-copied]:opacity-0">
6868
<ClipboardDocumentIcon className="size-[1em]" />
69-
<div className="sr-only">Copy code to clipboaord</div>
69+
<div className="sr-only">Copy to clipboard</div>
7070
</span>
7171
<CheckIcon className="absolute inset-0 text-green-600 opacity-0 transition-opacity duration-100 group-data-[is-copied]:opacity-100" />
7272
</span>

apps/staking/src/components/Header/current-stake-account.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const CurrentStakeAccount = ({
2828
<div className="font-semibold">Stake account:</div>
2929
<CopyButton
3030
text={api.account.toBase58()}
31-
className="-mr-2 text-pythpurple-400 md:ml-2 md:mr-0"
31+
className="text-pythpurple-400 xl:ml-2 xl:mr-0"
3232
>
3333
<TruncatedKey>{api.account}</TruncatedKey>
3434
</CopyButton>

apps/staking/src/components/OracleIntegrityStaking/index.tsx

Lines changed: 77 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { calculateApy } from "@pythnetwork/staking-sdk";
1111
import { PublicKey } from "@solana/web3.js";
1212
import clsx from "clsx";
13+
import Image from "next/image";
1314
import {
1415
useMemo,
1516
useCallback,
@@ -190,13 +191,13 @@ const SelfStaking = ({
190191
<div className="sticky left-0 mb-4 flex flex-row items-start justify-between px-4 sm:px-10 sm:pb-4 sm:pt-6 lg:items-center">
191192
<div>
192193
<h3 className="text-2xl font-light">Self Staking</h3>
193-
<PublisherName
194+
<PublisherIdentity
194195
truncatedClassName="2xl:hidden"
195196
fullClassName="hidden 2xl:inline"
196197
className="opacity-60"
197198
>
198199
{self}
199-
</PublisherName>
200+
</PublisherIdentity>
200201
</div>
201202
<div className="flex flex-row items-center gap-4">
202203
<MenuTrigger>
@@ -353,10 +354,12 @@ const ReassignStakeAccount = ({
353354
closeDisabled={closeDisabled}
354355
description={
355356
<>
356-
<span className="mr-3 align-middle">
357+
<span className="mr-[0.5em]">
357358
Designate a different stake account as the self-staking account for
358359
</span>
359-
<PublisherName className="font-semibold">{self}</PublisherName>
360+
<PublisherIdentity className="font-semibold">
361+
{self}
362+
</PublisherIdentity>
360363
</>
361364
}
362365
{...props}
@@ -613,8 +616,8 @@ const PublisherList = ({
613616
.filter(
614617
(publisher) =>
615618
filter.contains(publisher.publicKey.toBase58(), search) ||
616-
(publisher.name !== undefined &&
617-
filter.contains(publisher.name, search)),
619+
(publisher.identity !== undefined &&
620+
filter.contains(publisher.identity.name, search)),
618621
)
619622
.sort((a, b) => {
620623
if (yoursFirst) {
@@ -1027,8 +1030,8 @@ const compareName = (
10271030
) =>
10281031
(reverse ? -1 : 1) *
10291032
collator.compare(
1030-
a.name ?? a.publicKey.toBase58(),
1031-
b.name ?? b.publicKey.toBase58(),
1033+
a.identity?.name ?? a.publicKey.toBase58(),
1034+
b.identity?.name ?? b.publicKey.toBase58(),
10321035
);
10331036

10341037
const compareApy = (
@@ -1166,7 +1169,12 @@ type PublisherProps = {
11661169
totalStaked: bigint;
11671170
isSelf?: boolean | undefined;
11681171
publisher: {
1169-
name: string | undefined;
1172+
identity:
1173+
| {
1174+
name: string;
1175+
icon: string;
1176+
}
1177+
| undefined;
11701178
publicKey: PublicKey;
11711179
stakeAccount: PublicKey | undefined;
11721180
selfStake: bigint;
@@ -1247,6 +1255,7 @@ const Publisher = ({
12471255
publisher.poolCapacity,
12481256
publisher.poolUtilization,
12491257
publisher.poolUtilizationDelta,
1258+
publisher.delegationFee,
12501259
yieldRate,
12511260
],
12521261
);
@@ -1255,13 +1264,14 @@ const Publisher = ({
12551264
<div className="border-t border-neutral-600/50 p-4 sm:px-10 md:pt-8">
12561265
{!isSelf && (
12571266
<div className="flex flex-row items-center justify-between">
1258-
<PublisherName
1267+
<PublisherIdentity
12591268
className="font-semibold"
12601269
truncatedClassName="md:hidden"
12611270
fullClassName="hidden md:inline"
1271+
withNameClassName="flex flex-col items-start"
12621272
>
12631273
{publisher}
1264-
</PublisherName>
1274+
</PublisherIdentity>
12651275
<StakeToPublisherButton
12661276
api={api}
12671277
currentEpoch={currentEpoch}
@@ -1356,12 +1366,13 @@ const Publisher = ({
13561366
{!isSelf && (
13571367
<>
13581368
<PublisherTableCell className="truncate py-4 pl-4 font-medium sm:pl-10">
1359-
<PublisherName
1369+
<PublisherIdentity
13601370
truncatedClassName="3xl:hidden"
13611371
fullClassName="hidden 3xl:inline"
1372+
withNameClassName="flex flex-col items-start"
13621373
>
13631374
{publisher}
1364-
</PublisherName>
1375+
</PublisherIdentity>
13651376
</PublisherTableCell>
13661377
<PublisherTableCell className="text-center">
13671378
<Tokens>{publisher.selfStake + publisher.selfStakeDelta}</Tokens>
@@ -1526,12 +1537,12 @@ const YourPositionsTable = ({
15261537
className="w-28"
15271538
actionDescription={
15281539
<>
1529-
<span className="mr-3 align-middle">
1540+
<span className="mr-[0.5em]">
15301541
Cancel tokens that are in warmup for staking to
15311542
</span>
1532-
<PublisherName className="font-semibold">
1543+
<PublisherIdentity className="font-semibold">
15331544
{publisher}
1534-
</PublisherName>
1545+
</PublisherIdentity>
15351546
</>
15361547
}
15371548
actionName="Cancel"
@@ -1563,12 +1574,10 @@ const YourPositionsTable = ({
15631574
className="md:w-28"
15641575
actionDescription={
15651576
<>
1566-
<span className="mr-3 align-middle">
1567-
Unstake tokens from
1568-
</span>
1569-
<PublisherName className="font-semibold">
1577+
<span className="mr-[0.5em]">Unstake tokens from</span>
1578+
<PublisherIdentity className="font-semibold">
15701579
{publisher}
1571-
</PublisherName>
1580+
</PublisherIdentity>
15721581
</>
15731582
}
15741583
actionName="Unstake"
@@ -1615,8 +1624,10 @@ const StakeToPublisherButton = ({
16151624
size="small"
16161625
actionDescription={
16171626
<>
1618-
<span className="mr-3 align-middle">Stake to</span>
1619-
<PublisherName className="font-semibold">{publisher}</PublisherName>
1627+
<span className="mr-[0.5em]">Stake to</span>
1628+
<PublisherIdentity className="font-semibold">
1629+
{publisher}
1630+
</PublisherIdentity>
16201631
</>
16211632
}
16221633
actionName="Stake"
@@ -1690,41 +1701,66 @@ const NewApy = ({
16901701
publisher.selfStakeDelta,
16911702
publisher.poolUtilization,
16921703
publisher.poolUtilizationDelta,
1704+
publisher.delegationFee,
16931705
children,
16941706
],
16951707
);
16961708

16971709
return <div {...props}>{apy}%</div>;
16981710
};
16991711

1700-
type PublisherNameProps = {
1712+
type PublisherIdentityProps = PublisherKeyProps & {
1713+
withNameClassName?: string | undefined;
1714+
};
1715+
1716+
const PublisherIdentity = ({
1717+
className,
1718+
withNameClassName,
1719+
...props
1720+
}: PublisherIdentityProps) =>
1721+
props.children.identity ? (
1722+
<span className={clsx(className, withNameClassName)}>
1723+
<span>
1724+
<Image
1725+
alt={`${props.children.identity.name} icon`}
1726+
src={props.children.identity.icon}
1727+
className="mr-2 inline-block size-[20px] align-sub"
1728+
width={20}
1729+
height={20}
1730+
/>
1731+
<span className="mr-[0.5em]">{props.children.identity.name}</span>
1732+
</span>
1733+
<PublisherKey className="text-sm opacity-50" {...props} />
1734+
</span>
1735+
) : (
1736+
<PublisherKey className={className} {...props} />
1737+
);
1738+
1739+
type PublisherKeyProps = {
17011740
className?: string | undefined;
17021741
children: PublisherProps["publisher"];
17031742
fullClassName?: string;
17041743
truncatedClassName?: string;
17051744
};
17061745

1707-
const PublisherName = ({
1746+
const PublisherKey = ({
17081747
children,
17091748
fullClassName,
17101749
truncatedClassName,
17111750
className,
1712-
}: PublisherNameProps) =>
1713-
children.name ? (
1714-
<span className={className}>{children.name}</span>
1715-
) : (
1716-
<CopyButton
1717-
text={children.publicKey.toBase58()}
1718-
{...(className && { className })}
1719-
>
1720-
{fullClassName && (
1721-
<code className={fullClassName}>{children.publicKey.toBase58()}</code>
1722-
)}
1723-
<TruncatedKey className={truncatedClassName}>
1724-
{children.publicKey}
1725-
</TruncatedKey>
1726-
</CopyButton>
1727-
);
1751+
}: PublisherKeyProps) => (
1752+
<CopyButton
1753+
text={children.publicKey.toBase58()}
1754+
{...(className && { className })}
1755+
>
1756+
{fullClassName && (
1757+
<code className={fullClassName}>{children.publicKey.toBase58()}</code>
1758+
)}
1759+
<TruncatedKey className={truncatedClassName}>
1760+
{children.publicKey}
1761+
</TruncatedKey>
1762+
</CopyButton>
1763+
);
17281764

17291765
const useTransferActionForPublisher = (
17301766
action: ((publisher: PublicKey, amount: bigint) => Promise<void>) | undefined,

apps/staking/src/components/Tooltip/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ type Props = Omit<ComponentProps<typeof TooltipImpl>, "children"> & {
99
export const Tooltip = ({ children, className, offset, ...props }: Props) => (
1010
<TooltipImpl
1111
className={clsx(
12-
"border border-neutral-900 bg-neutral-200 px-2 py-1 text-sm text-neutral-900 shadow shadow-white/50 transition data-[entering]:animate-in data-[exiting]:animate-out data-[entering]:fade-in data-[exiting]:fade-out data-[entering]:slide-in-from-bottom",
12+
"group border border-neutral-900 bg-neutral-200 px-2 py-1 text-sm text-neutral-900 shadow shadow-white/50 transition data-[entering]:animate-in data-[exiting]:animate-out data-[entering]:fade-in data-[exiting]:fade-out data-[entering]:slide-in-from-bottom",
1313
className,
1414
)}
1515
offset={offset ?? 10}
1616
{...props}
1717
>
1818
<OverlayArrow>
19-
<svg width={8} height={8} viewBox="0 0 8 8" className="fill-neutral-200">
19+
<svg
20+
width={8}
21+
height={8}
22+
viewBox="0 0 8 8"
23+
className="fill-neutral-200 group-data-[placement=bottom]:rotate-180"
24+
>
2025
<path d="M0 0 L4 4 L8 0" />
2126
</svg>
2227
</OverlayArrow>

apps/staking/src/known-publishers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const KNOWN_PUBLISHERS = {
2+
CfVkYofcLC1iVBcYFzgdYPeiX25SVRmWvBQVHorP1A3y: {
3+
name: "BLOCKSIZE",
4+
icon: "/publisher-icons/blocksize.png",
5+
},
6+
};

0 commit comments

Comments
 (0)