[Xc admin] frontend to use server (#832)
* Import axios * Switch to axios * Fix * Error handling
This commit is contained in:
parent
01b54d2c58
commit
ddc0b48118
|
@ -6,6 +6,7 @@ import { useWallet } from '@solana/wallet-adapter-react'
|
||||||
import { WalletModalButton } from '@solana/wallet-adapter-react-ui'
|
import { WalletModalButton } from '@solana/wallet-adapter-react-ui'
|
||||||
import { Cluster, PublicKey, TransactionInstruction } from '@solana/web3.js'
|
import { Cluster, PublicKey, TransactionInstruction } from '@solana/web3.js'
|
||||||
import SquadsMesh from '@sqds/mesh'
|
import SquadsMesh from '@sqds/mesh'
|
||||||
|
import axios from 'axios'
|
||||||
import { Fragment, useContext, useEffect, useState } from 'react'
|
import { Fragment, useContext, useEffect, useState } from 'react'
|
||||||
import toast from 'react-hot-toast'
|
import toast from 'react-hot-toast'
|
||||||
import {
|
import {
|
||||||
|
@ -77,39 +78,46 @@ const PermissionDepermissionKey = ({
|
||||||
const fundingAccount = isRemote
|
const fundingAccount = isRemote
|
||||||
? mapKey(multisigAuthority)
|
? mapKey(multisigAuthority)
|
||||||
: multisigAuthority
|
: multisigAuthority
|
||||||
priceAccounts.map((priceAccount) => {
|
|
||||||
isPermission
|
for (const priceAccount of priceAccounts) {
|
||||||
? pythProgramClient.methods
|
if (isPermission) {
|
||||||
|
instructions.push(
|
||||||
|
await pythProgramClient.methods
|
||||||
.addPublisher(new PublicKey(publisherKey))
|
.addPublisher(new PublicKey(publisherKey))
|
||||||
.accounts({
|
.accounts({
|
||||||
fundingAccount,
|
fundingAccount,
|
||||||
priceAccount: priceAccount,
|
priceAccount: priceAccount,
|
||||||
})
|
})
|
||||||
.instruction()
|
.instruction()
|
||||||
.then((instruction) => instructions.push(instruction))
|
)
|
||||||
: pythProgramClient.methods
|
} else {
|
||||||
|
instructions.push(
|
||||||
|
await pythProgramClient.methods
|
||||||
.delPublisher(new PublicKey(publisherKey))
|
.delPublisher(new PublicKey(publisherKey))
|
||||||
.accounts({
|
.accounts({
|
||||||
fundingAccount,
|
fundingAccount,
|
||||||
priceAccount: priceAccount,
|
priceAccount: priceAccount,
|
||||||
})
|
})
|
||||||
.instruction()
|
.instruction()
|
||||||
.then((instruction) => instructions.push(instruction))
|
)
|
||||||
})
|
}
|
||||||
|
}
|
||||||
setIsSubmitButtonLoading(true)
|
setIsSubmitButtonLoading(true)
|
||||||
try {
|
try {
|
||||||
const proposalPubkey = await proposeInstructions(
|
const response = await axios.post(
|
||||||
squads,
|
process.env.NEXT_PUBLIC_PROPOSER_SERVER_URL + '/api/propose',
|
||||||
PRICE_FEED_MULTISIG[getMultisigCluster(cluster)],
|
{ instructions, cluster }
|
||||||
instructions,
|
|
||||||
isRemote,
|
|
||||||
wormholeAddress
|
|
||||||
)
|
)
|
||||||
|
const { proposalPubkey } = response.data
|
||||||
toast.success(`Proposal sent! 🚀 Proposal Pubkey: ${proposalPubkey}`)
|
toast.success(`Proposal sent! 🚀 Proposal Pubkey: ${proposalPubkey}`)
|
||||||
setIsSubmitButtonLoading(false)
|
setIsSubmitButtonLoading(false)
|
||||||
closeModal()
|
closeModal()
|
||||||
} catch (e: any) {
|
} catch (error: any) {
|
||||||
toast.error(capitalizeFirstLetter(e.message))
|
if (error.response) {
|
||||||
|
toast.error(capitalizeFirstLetter(error.response.data))
|
||||||
|
} else {
|
||||||
|
toast.error(capitalizeFirstLetter(error.message))
|
||||||
|
}
|
||||||
setIsSubmitButtonLoading(false)
|
setIsSubmitButtonLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { AccountType, getPythProgramKeyForCluster } from '@pythnetwork/client'
|
||||||
import { PythOracle, pythOracleProgram } from '@pythnetwork/client/lib/anchor'
|
import { PythOracle, pythOracleProgram } from '@pythnetwork/client/lib/anchor'
|
||||||
import { useWallet } from '@solana/wallet-adapter-react'
|
import { useWallet } from '@solana/wallet-adapter-react'
|
||||||
import { Cluster, PublicKey, TransactionInstruction } from '@solana/web3.js'
|
import { Cluster, PublicKey, TransactionInstruction } from '@solana/web3.js'
|
||||||
|
import axios from 'axios'
|
||||||
import { useCallback, useContext, useEffect, useState } from 'react'
|
import { useCallback, useContext, useEffect, useState } from 'react'
|
||||||
import toast from 'react-hot-toast'
|
import toast from 'react-hot-toast'
|
||||||
import {
|
import {
|
||||||
|
@ -464,18 +465,20 @@ const General = () => {
|
||||||
|
|
||||||
setIsSendProposalButtonLoading(true)
|
setIsSendProposalButtonLoading(true)
|
||||||
try {
|
try {
|
||||||
const proposalPubkey = await proposeInstructions(
|
const response = await axios.post(
|
||||||
proposeSquads,
|
process.env.NEXT_PUBLIC_PROPOSER_SERVER_URL + '/api/propose',
|
||||||
PRICE_FEED_MULTISIG[getMultisigCluster(cluster)],
|
{ instructions, cluster }
|
||||||
instructions,
|
|
||||||
isRemote,
|
|
||||||
wormholeAddress
|
|
||||||
)
|
)
|
||||||
|
const { proposalPubkey } = response.data
|
||||||
toast.success(`Proposal sent! 🚀 Proposal Pubkey: ${proposalPubkey}`)
|
toast.success(`Proposal sent! 🚀 Proposal Pubkey: ${proposalPubkey}`)
|
||||||
setIsSendProposalButtonLoading(false)
|
setIsSendProposalButtonLoading(false)
|
||||||
closeModal()
|
closeModal()
|
||||||
} catch (e: any) {
|
} catch (error: any) {
|
||||||
toast.error(capitalizeFirstLetter(e.message))
|
if (error.response) {
|
||||||
|
toast.error(capitalizeFirstLetter(error.response.data))
|
||||||
|
} else {
|
||||||
|
toast.error(capitalizeFirstLetter(error.message))
|
||||||
|
}
|
||||||
setIsSendProposalButtonLoading(false)
|
setIsSendProposalButtonLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
"@types/node": "^18.11.18",
|
"@types/node": "^18.11.18",
|
||||||
"@types/react": "18.0.26",
|
"@types/react": "18.0.26",
|
||||||
"@types/react-dom": "18.0.10",
|
"@types/react-dom": "18.0.10",
|
||||||
|
"axios": "^1.4.0",
|
||||||
"copy-to-clipboard": "^3.3.3",
|
"copy-to-clipboard": "^3.3.3",
|
||||||
"gsap": "^3.11.4",
|
"gsap": "^3.11.4",
|
||||||
"next": "12.2.5",
|
"next": "12.2.5",
|
||||||
|
|
|
@ -17,11 +17,6 @@ import { StatusFilterProvider } from '../contexts/StatusFilterContext'
|
||||||
import { classNames } from '../utils/classNames'
|
import { classNames } from '../utils/classNames'
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async () => {
|
export const getServerSideProps: GetServerSideProps = async () => {
|
||||||
const KEYPAIR_BASE_PATH = process.env.KEYPAIR_BASE_PATH || ''
|
|
||||||
const OPS_WALLET = fs.existsSync(`${KEYPAIR_BASE_PATH}/ops-key`)
|
|
||||||
? JSON.parse(fs.readFileSync(`${KEYPAIR_BASE_PATH}/ops-key`, 'ascii'))
|
|
||||||
: null
|
|
||||||
|
|
||||||
const MAPPINGS_BASE_PATH = process.env.MAPPINGS_BASE_PATH || ''
|
const MAPPINGS_BASE_PATH = process.env.MAPPINGS_BASE_PATH || ''
|
||||||
const PUBLISHER_PYTHNET_MAPPING_PATH = `${MAPPINGS_BASE_PATH}/publishers-pythnet.json`
|
const PUBLISHER_PYTHNET_MAPPING_PATH = `${MAPPINGS_BASE_PATH}/publishers-pythnet.json`
|
||||||
const PUBLISHER_PYTHTEST_MAPPING_PATH = `${MAPPINGS_BASE_PATH}/publishers-pythtest.json`
|
const PUBLISHER_PYTHTEST_MAPPING_PATH = `${MAPPINGS_BASE_PATH}/publishers-pythtest.json`
|
||||||
|
@ -53,7 +48,6 @@ export const getServerSideProps: GetServerSideProps = async () => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
OPS_WALLET,
|
|
||||||
publisherKeyToNameMapping,
|
publisherKeyToNameMapping,
|
||||||
multisigSignerKeyToNameMapping,
|
multisigSignerKeyToNameMapping,
|
||||||
},
|
},
|
||||||
|
@ -81,22 +75,13 @@ const TAB_INFO = {
|
||||||
const DEFAULT_TAB = 'general'
|
const DEFAULT_TAB = 'general'
|
||||||
|
|
||||||
const Home: NextPage<{
|
const Home: NextPage<{
|
||||||
OPS_WALLET: number[] | null
|
|
||||||
publisherKeyToNameMapping: Record<string, Record<string, string>>
|
publisherKeyToNameMapping: Record<string, Record<string, string>>
|
||||||
multisigSignerKeyToNameMapping: Record<string, string>
|
multisigSignerKeyToNameMapping: Record<string, string>
|
||||||
}> = ({
|
}> = ({ publisherKeyToNameMapping, multisigSignerKeyToNameMapping }) => {
|
||||||
OPS_WALLET,
|
|
||||||
publisherKeyToNameMapping,
|
|
||||||
multisigSignerKeyToNameMapping,
|
|
||||||
}) => {
|
|
||||||
const [currentTabIndex, setCurrentTabIndex] = useState(0)
|
const [currentTabIndex, setCurrentTabIndex] = useState(0)
|
||||||
const tabInfoArray = Object.values(TAB_INFO)
|
const tabInfoArray = Object.values(TAB_INFO)
|
||||||
const anchorWallet = useAnchorWallet()
|
const anchorWallet = useAnchorWallet()
|
||||||
const wallet = OPS_WALLET
|
const wallet = anchorWallet as Wallet
|
||||||
? (new NodeWallet(
|
|
||||||
Keypair.fromSecretKey(Uint8Array.from(OPS_WALLET))
|
|
||||||
) as Wallet)
|
|
||||||
: (anchorWallet as Wallet)
|
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
|
|
@ -1417,6 +1417,7 @@
|
||||||
"@types/node": "^18.11.18",
|
"@types/node": "^18.11.18",
|
||||||
"@types/react": "18.0.26",
|
"@types/react": "18.0.26",
|
||||||
"@types/react-dom": "18.0.10",
|
"@types/react-dom": "18.0.10",
|
||||||
|
"axios": "^1.4.0",
|
||||||
"copy-to-clipboard": "^3.3.3",
|
"copy-to-clipboard": "^3.3.3",
|
||||||
"gsap": "^3.11.4",
|
"gsap": "^3.11.4",
|
||||||
"next": "12.2.5",
|
"next": "12.2.5",
|
||||||
|
@ -21997,10 +21998,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/axios": {
|
"node_modules/axios": {
|
||||||
"version": "1.3.4",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz",
|
||||||
"integrity": "sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==",
|
"integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.15.0",
|
"follow-redirects": "^1.15.0",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
|
@ -78690,10 +78690,9 @@
|
||||||
"integrity": "sha512-/BQzOX780JhsxDnPpH4ZiyrJAzcd8AfzFPkv+89veFSr1rcMjuq2JDCwypKaPeB6ljHp9KjXhPpjgCvQlWYuqg=="
|
"integrity": "sha512-/BQzOX780JhsxDnPpH4ZiyrJAzcd8AfzFPkv+89veFSr1rcMjuq2JDCwypKaPeB6ljHp9KjXhPpjgCvQlWYuqg=="
|
||||||
},
|
},
|
||||||
"axios": {
|
"axios": {
|
||||||
"version": "1.3.4",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz",
|
||||||
"integrity": "sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==",
|
"integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"follow-redirects": "^1.15.0",
|
"follow-redirects": "^1.15.0",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
|
@ -105817,6 +105816,7 @@
|
||||||
"@types/react": "18.0.26",
|
"@types/react": "18.0.26",
|
||||||
"@types/react-dom": "18.0.10",
|
"@types/react-dom": "18.0.10",
|
||||||
"autoprefixer": "^10.4.8",
|
"autoprefixer": "^10.4.8",
|
||||||
|
"axios": "^1.4.0",
|
||||||
"copy-to-clipboard": "^3.3.3",
|
"copy-to-clipboard": "^3.3.3",
|
||||||
"eslint": "8.22.0",
|
"eslint": "8.22.0",
|
||||||
"eslint-config-next": "12.2.5",
|
"eslint-config-next": "12.2.5",
|
||||||
|
|
Loading…
Reference in New Issue