Skip to content

Commit ddc0b48

Browse files
authored
[Xc admin] frontend to use server (#832)
* Import axios * Switch to axios * Fix * Error handling
1 parent 01b54d2 commit ddc0b48

File tree

5 files changed

+45
-48
lines changed

5 files changed

+45
-48
lines changed

governance/xc_admin/packages/xc_admin_frontend/components/PermissionDepermissionKey.tsx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useWallet } from '@solana/wallet-adapter-react'
66
import { WalletModalButton } from '@solana/wallet-adapter-react-ui'
77
import { Cluster, PublicKey, TransactionInstruction } from '@solana/web3.js'
88
import SquadsMesh from '@sqds/mesh'
9+
import axios from 'axios'
910
import { Fragment, useContext, useEffect, useState } from 'react'
1011
import toast from 'react-hot-toast'
1112
import {
@@ -77,39 +78,46 @@ const PermissionDepermissionKey = ({
7778
const fundingAccount = isRemote
7879
? mapKey(multisigAuthority)
7980
: multisigAuthority
80-
priceAccounts.map((priceAccount) => {
81-
isPermission
82-
? pythProgramClient.methods
81+
82+
for (const priceAccount of priceAccounts) {
83+
if (isPermission) {
84+
instructions.push(
85+
await pythProgramClient.methods
8386
.addPublisher(new PublicKey(publisherKey))
8487
.accounts({
8588
fundingAccount,
8689
priceAccount: priceAccount,
8790
})
8891
.instruction()
89-
.then((instruction) => instructions.push(instruction))
90-
: pythProgramClient.methods
92+
)
93+
} else {
94+
instructions.push(
95+
await pythProgramClient.methods
9196
.delPublisher(new PublicKey(publisherKey))
9297
.accounts({
9398
fundingAccount,
9499
priceAccount: priceAccount,
95100
})
96101
.instruction()
97-
.then((instruction) => instructions.push(instruction))
98-
})
102+
)
103+
}
104+
}
99105
setIsSubmitButtonLoading(true)
100106
try {
101-
const proposalPubkey = await proposeInstructions(
102-
squads,
103-
PRICE_FEED_MULTISIG[getMultisigCluster(cluster)],
104-
instructions,
105-
isRemote,
106-
wormholeAddress
107+
const response = await axios.post(
108+
process.env.NEXT_PUBLIC_PROPOSER_SERVER_URL + '/api/propose',
109+
{ instructions, cluster }
107110
)
111+
const { proposalPubkey } = response.data
108112
toast.success(`Proposal sent! 🚀 Proposal Pubkey: ${proposalPubkey}`)
109113
setIsSubmitButtonLoading(false)
110114
closeModal()
111-
} catch (e: any) {
112-
toast.error(capitalizeFirstLetter(e.message))
115+
} catch (error: any) {
116+
if (error.response) {
117+
toast.error(capitalizeFirstLetter(error.response.data))
118+
} else {
119+
toast.error(capitalizeFirstLetter(error.message))
120+
}
113121
setIsSubmitButtonLoading(false)
114122
}
115123
}

governance/xc_admin/packages/xc_admin_frontend/components/tabs/General.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AccountType, getPythProgramKeyForCluster } from '@pythnetwork/client'
33
import { PythOracle, pythOracleProgram } from '@pythnetwork/client/lib/anchor'
44
import { useWallet } from '@solana/wallet-adapter-react'
55
import { Cluster, PublicKey, TransactionInstruction } from '@solana/web3.js'
6+
import axios from 'axios'
67
import { useCallback, useContext, useEffect, useState } from 'react'
78
import toast from 'react-hot-toast'
89
import {
@@ -464,18 +465,20 @@ const General = () => {
464465

465466
setIsSendProposalButtonLoading(true)
466467
try {
467-
const proposalPubkey = await proposeInstructions(
468-
proposeSquads,
469-
PRICE_FEED_MULTISIG[getMultisigCluster(cluster)],
470-
instructions,
471-
isRemote,
472-
wormholeAddress
468+
const response = await axios.post(
469+
process.env.NEXT_PUBLIC_PROPOSER_SERVER_URL + '/api/propose',
470+
{ instructions, cluster }
473471
)
472+
const { proposalPubkey } = response.data
474473
toast.success(`Proposal sent! 🚀 Proposal Pubkey: ${proposalPubkey}`)
475474
setIsSendProposalButtonLoading(false)
476475
closeModal()
477-
} catch (e: any) {
478-
toast.error(capitalizeFirstLetter(e.message))
476+
} catch (error: any) {
477+
if (error.response) {
478+
toast.error(capitalizeFirstLetter(error.response.data))
479+
} else {
480+
toast.error(capitalizeFirstLetter(error.message))
481+
}
479482
setIsSendProposalButtonLoading(false)
480483
}
481484
}

governance/xc_admin/packages/xc_admin_frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@types/node": "^18.11.18",
2626
"@types/react": "18.0.26",
2727
"@types/react-dom": "18.0.10",
28+
"axios": "^1.4.0",
2829
"copy-to-clipboard": "^3.3.3",
2930
"gsap": "^3.11.4",
3031
"next": "12.2.5",

governance/xc_admin/packages/xc_admin_frontend/pages/index.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ import { StatusFilterProvider } from '../contexts/StatusFilterContext'
1717
import { classNames } from '../utils/classNames'
1818

1919
export const getServerSideProps: GetServerSideProps = async () => {
20-
const KEYPAIR_BASE_PATH = process.env.KEYPAIR_BASE_PATH || ''
21-
const OPS_WALLET = fs.existsSync(`${KEYPAIR_BASE_PATH}/ops-key`)
22-
? JSON.parse(fs.readFileSync(`${KEYPAIR_BASE_PATH}/ops-key`, 'ascii'))
23-
: null
24-
2520
const MAPPINGS_BASE_PATH = process.env.MAPPINGS_BASE_PATH || ''
2621
const PUBLISHER_PYTHNET_MAPPING_PATH = `${MAPPINGS_BASE_PATH}/publishers-pythnet.json`
2722
const PUBLISHER_PYTHTEST_MAPPING_PATH = `${MAPPINGS_BASE_PATH}/publishers-pythtest.json`
@@ -53,7 +48,6 @@ export const getServerSideProps: GetServerSideProps = async () => {
5348

5449
return {
5550
props: {
56-
OPS_WALLET,
5751
publisherKeyToNameMapping,
5852
multisigSignerKeyToNameMapping,
5953
},
@@ -81,22 +75,13 @@ const TAB_INFO = {
8175
const DEFAULT_TAB = 'general'
8276

8377
const Home: NextPage<{
84-
OPS_WALLET: number[] | null
8578
publisherKeyToNameMapping: Record<string, Record<string, string>>
8679
multisigSignerKeyToNameMapping: Record<string, string>
87-
}> = ({
88-
OPS_WALLET,
89-
publisherKeyToNameMapping,
90-
multisigSignerKeyToNameMapping,
91-
}) => {
80+
}> = ({ publisherKeyToNameMapping, multisigSignerKeyToNameMapping }) => {
9281
const [currentTabIndex, setCurrentTabIndex] = useState(0)
9382
const tabInfoArray = Object.values(TAB_INFO)
9483
const anchorWallet = useAnchorWallet()
95-
const wallet = OPS_WALLET
96-
? (new NodeWallet(
97-
Keypair.fromSecretKey(Uint8Array.from(OPS_WALLET))
98-
) as Wallet)
99-
: (anchorWallet as Wallet)
84+
const wallet = anchorWallet as Wallet
10085

10186
const router = useRouter()
10287

package-lock.json

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

0 commit comments

Comments
 (0)