Skip to content

Commit 47c9993

Browse files
cctdanielguibescos
andauthored
[xc-admin] permission accounts (#494)
* Rework pyth hooks * xc admin/add min pub page (#492) * add min pubs page * add wallet * update connect wallet button * fix header * add ClusterSwitch * fix header css * add update permissions tab * fix default tab * show default value when permission account does not exists * use table and add copy text function * update package-lock.json * update package-lock.json * trigger deployment * remove unused icon * capitalize tabInfo * remove -1 index check * refactor * refactor TabInfo to TAB_INFO * trigger deployment * remove unused icon Co-authored-by: Guillermo Bescos Alapont <gbescos@stanford.edu>
1 parent d2d8213 commit 47c9993

20 files changed

+930
-126
lines changed

governance/xc-admin/package-lock.json

Lines changed: 648 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

governance/xc-admin/packages/xc-admin-frontend/components/MinPublishers.tsx renamed to governance/xc-admin/packages/xc-admin-frontend/components/tabs/MinPublishers.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { usePythContext } from '../contexts/PythContext'
2-
import ClusterSwitch from './ClusterSwitch'
3-
import Loadbar from './loaders/Loadbar'
1+
import { usePythContext } from '../../contexts/PythContext'
2+
import ClusterSwitch from '../ClusterSwitch'
3+
import Loadbar from '../loaders/Loadbar'
44

5-
function MinPublishers() {
5+
const MinPublishers = () => {
66
const { rawConfig, dataIsLoading } = usePythContext()
77

88
return (
9-
<div className="pt-15 relative lg:pt-20">
10-
<div className="container flex flex-col items-center justify-between pt-32 lg:flex-row ">
11-
<div className="mb-10 w-full text-left lg:mb-0">
12-
<h1 className="h1 mb-3">Min Publishers</h1>
9+
<div className="relative">
10+
<div className="container flex flex-col items-center justify-between lg:flex-row">
11+
<div className="mb-4 w-full text-left lg:mb-0">
12+
<h1 className="h1 mb-4">Min Publishers</h1>
1313
</div>
1414
</div>
1515
<div className="container">
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { PublicKey } from '@solana/web3.js'
2+
import copy from 'copy-to-clipboard'
3+
import React from 'react'
4+
import { usePythContext } from '../../contexts/PythContext'
5+
import CopyIcon from '../../images/icons/copy.inline.svg'
6+
import ClusterSwitch from '../ClusterSwitch'
7+
import Loadbar from '../loaders/Loadbar'
8+
9+
interface UpdatePermissionsProps {
10+
account: string
11+
pubkey?: PublicKey
12+
}
13+
14+
const UpdatePermissionsRow: React.FunctionComponent<UpdatePermissionsProps> = ({
15+
account,
16+
pubkey = new PublicKey(0),
17+
}) => {
18+
return (
19+
<tr key={account} className="border-t border-beige-300">
20+
<td className="py-3 pl-4 pr-2 lg:pl-14">{account}</td>
21+
<td className="py-3 pl-1 lg:pl-14">
22+
<div
23+
className="-ml-1 inline-flex cursor-pointer items-center px-1 hover:bg-dark hover:text-white active:bg-darkGray3"
24+
onClick={() => {
25+
copy(pubkey.toBase58())
26+
}}
27+
>
28+
<span className="mr-2 hidden lg:block">{pubkey.toBase58()}</span>
29+
<span className="mr-2 lg:hidden">
30+
{pubkey.toBase58().slice(0, 6) +
31+
'...' +
32+
pubkey.toBase58().slice(-6)}
33+
</span>{' '}
34+
<CopyIcon className="shrink-0" />
35+
</div>
36+
</td>
37+
</tr>
38+
)
39+
}
40+
41+
const UpdatePermissions = () => {
42+
const { rawConfig, dataIsLoading } = usePythContext()
43+
44+
return (
45+
<div className="relative">
46+
<div className="container flex flex-col items-center justify-between lg:flex-row">
47+
<div className="mb-4 w-full text-left lg:mb-0">
48+
<h1 className="h1 mb-4">Update Permissions</h1>
49+
</div>
50+
</div>
51+
<div className="container">
52+
<div className="mb-4 md:mb-0">
53+
<ClusterSwitch />
54+
</div>
55+
<div className="table-responsive relative mt-6">
56+
{dataIsLoading ? (
57+
<div className="mt-3">
58+
<Loadbar theme="light" />
59+
</div>
60+
) : (
61+
<div className="table-responsive mb-10">
62+
<table className="w-full bg-darkGray text-left">
63+
<thead>
64+
<tr>
65+
<th className="base16 pt-8 pb-6 pl-4 pr-2 font-semibold opacity-60 lg:pl-14">
66+
Account
67+
</th>
68+
<th className="base16 pt-8 pb-6 pl-1 pr-2 font-semibold opacity-60 lg:pl-14">
69+
Public Key
70+
</th>
71+
</tr>
72+
</thead>
73+
<tbody>
74+
<UpdatePermissionsRow
75+
account="Master Authority"
76+
pubkey={rawConfig.permissionAccount?.masterAuthority}
77+
/>
78+
<UpdatePermissionsRow
79+
account="Data Curation Authority"
80+
pubkey={rawConfig.permissionAccount?.dataCurationAuthority}
81+
/>
82+
<UpdatePermissionsRow
83+
account="Security Authority"
84+
pubkey={rawConfig.permissionAccount?.securityAuthority}
85+
/>
86+
</tbody>
87+
</table>
88+
</div>
89+
)}
90+
</div>
91+
</div>
92+
</div>
93+
)
94+
}
95+
96+
export default UpdatePermissions

governance/xc-admin/packages/xc-admin-frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@types/node": "18.11.18",
2020
"@types/react": "18.0.26",
2121
"@types/react-dom": "18.0.10",
22+
"copy-to-clipboard": "^3.3.3",
2223
"gsap": "^3.11.4",
2324
"next": "12.2.5",
2425
"next-seo": "^5.15.0",

governance/xc-admin/packages/xc-admin-frontend/pages/_document.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default function Document() {
3232
sizes="16x16"
3333
href="/favicon-16x16.png"
3434
/>
35+
<link rel="manifest" href="/site.webmanifest" />
3536
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#242235" />
3637
<meta name="msapplication-TileColor" content="#242235" />
3738
<meta name="theme-color" content="#242235"></meta>

governance/xc-admin/packages/xc-admin-frontend/pages/index.tsx

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,97 @@
1+
import { Tab } from '@headlessui/react'
12
import type { NextPage } from 'next'
3+
import { useRouter } from 'next/router'
4+
import { useEffect, useState } from 'react'
25
import Layout from '../components/layout/Layout'
3-
import MinPublishers from '../components/MinPublishers'
6+
import MinPublishers from '../components/tabs/MinPublishers'
7+
import UpdatePermissions from '../components/tabs/UpdatePermissions'
48
import { PythContextProvider } from '../contexts/PythContext'
9+
import { classNames } from '../utils/classNames'
10+
11+
const TAB_INFO = {
12+
MinPublishers: {
13+
title: 'Min Publishers',
14+
description:
15+
'Set the minimum number of publishers required to publish a price.',
16+
queryString: 'min-publishers',
17+
},
18+
UpdatePermissions: {
19+
title: 'Update Permissions',
20+
description: 'Update the permissions of the program.',
21+
queryString: 'update-permissions',
22+
},
23+
}
24+
25+
const DEFAULT_TAB = 'min-publishers'
526

627
const Home: NextPage = () => {
28+
const [currentTabIndex, setCurrentTabIndex] = useState(0)
29+
const tabInfoArray = Object.values(TAB_INFO)
30+
31+
const router = useRouter()
32+
33+
// set current tab value when tab is clicked
34+
const handleChangeTab = (index: number) => {
35+
router.query.tab = tabInfoArray[index].queryString
36+
setCurrentTabIndex(index)
37+
router.push(
38+
{
39+
pathname: router.pathname,
40+
query: router.query,
41+
},
42+
undefined,
43+
{ scroll: false }
44+
)
45+
}
46+
47+
// set current tab value when page is loaded
48+
useEffect(() => {
49+
router.query && router.query.tab
50+
? setCurrentTabIndex(
51+
tabInfoArray.findIndex((v) => v.queryString === router.query.tab)
52+
)
53+
: setCurrentTabIndex(
54+
tabInfoArray.findIndex((v) => v.queryString === DEFAULT_TAB)
55+
)
56+
}, [router, tabInfoArray])
57+
758
return (
859
<Layout>
960
<PythContextProvider>
10-
<MinPublishers />
61+
<div className="relative pt-16 md:pt-20">
62+
<div className="py-8 md:py-16">
63+
<Tab.Group
64+
selectedIndex={currentTabIndex}
65+
onChange={handleChangeTab}
66+
>
67+
<Tab.List className="mx-auto max-w-[526px] gap-1 space-x-4 text-center sm:gap-2.5 md:space-x-8">
68+
{Object.entries(TAB_INFO).map((tab, idx) => (
69+
<Tab
70+
key={idx}
71+
className={({ selected }) =>
72+
classNames(
73+
'p-3 text-xs font-semibold uppercase outline-none transition-colors md:text-base',
74+
currentTabIndex === idx
75+
? 'bg-darkGray3'
76+
: 'bg-darkGray2',
77+
selected ? 'bg-darkGray3' : 'hover:bg-darkGray3'
78+
)
79+
}
80+
>
81+
{tab[1].title}
82+
</Tab>
83+
))}
84+
</Tab.List>
85+
</Tab.Group>
86+
</div>
87+
</div>
88+
{tabInfoArray[currentTabIndex].queryString ===
89+
TAB_INFO.MinPublishers.queryString ? (
90+
<MinPublishers />
91+
) : tabInfoArray[currentTabIndex].queryString ===
92+
TAB_INFO.UpdatePermissions.queryString ? (
93+
<UpdatePermissions />
94+
) : null}
1195
</PythContextProvider>
1296
</Layout>
1397
)
Loading
Loading
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<browserconfig>
3+
<msapplication>
4+
<tile>
5+
<square150x150logo src="/mstile-150x150.png"/>
6+
<TileColor>#242235</TileColor>
7+
</tile>
8+
</msapplication>
9+
</browserconfig>

0 commit comments

Comments
 (0)