Browse Source

Make proposer server url a serverside prop (#840)

* Make proposer server url a serverside prop

* Make low caps
guibescos 2 years ago
parent
commit
479a2d8b09

+ 1 - 1
governance/xc_admin/packages/proposer_server/src/index.ts

@@ -20,7 +20,7 @@ import { getPythClusterApiUrl, PythCluster } from "@pythnetwork/client";
 import SquadsMesh from "@sqds/mesh";
 import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
 
-const PORT: number = Number(process.env.PORT ?? "3000");
+const PORT: number = Number(process.env.PORT ?? "4000");
 const KEYPAIR: Keypair = Keypair.fromSecretKey(
   Uint8Array.from(JSON.parse(fs.readFileSync(envOrErr("WALLET"), "ascii")))
 );

+ 6 - 4
governance/xc_admin/packages/xc_admin_frontend/components/PermissionDepermissionKey.tsx

@@ -31,10 +31,12 @@ const PermissionDepermissionKey = ({
   isPermission,
   pythProgramClient,
   squads,
+  proposerServerUrl,
 }: {
   isPermission: boolean
   pythProgramClient?: Program<PythOracle>
   squads?: SquadsMesh
+  proposerServerUrl: string
 }) => {
   const [publisherKey, setPublisherKey] = useState(
     'JTmFx5zX9mM94itfk2nQcJnQQDPjcv4UPD7SYj6xDCV'
@@ -104,10 +106,10 @@ const PermissionDepermissionKey = ({
       }
       setIsSubmitButtonLoading(true)
       try {
-        const response = await axios.post(
-          process.env.NEXT_PUBLIC_PROPOSER_SERVER_URL + '/api/propose',
-          { instructions, cluster }
-        )
+        const response = await axios.post(proposerServerUrl + '/api/propose', {
+          instructions,
+          cluster,
+        })
         const { proposalPubkey } = response.data
         toast.success(`Proposal sent! 🚀 Proposal Pubkey: ${proposalPubkey}`)
         setIsSubmitButtonLoading(false)

+ 7 - 5
governance/xc_admin/packages/xc_admin_frontend/components/tabs/General.tsx

@@ -25,7 +25,7 @@ import Spinner from '../common/Spinner'
 import Loadbar from '../loaders/Loadbar'
 import PermissionDepermissionKey from '../PermissionDepermissionKey'
 
-const General = () => {
+const General = ({ proposerServerUrl }: { proposerServerUrl: string }) => {
   const [data, setData] = useState<any>({})
   const [dataChanges, setDataChanges] = useState<Record<string, any>>()
   const [existingSymbols, setExistingSymbols] = useState<Set<string>>(new Set())
@@ -465,10 +465,10 @@ const General = () => {
 
       setIsSendProposalButtonLoading(true)
       try {
-        const response = await axios.post(
-          process.env.NEXT_PUBLIC_PROPOSER_SERVER_URL + '/api/propose',
-          { instructions, cluster }
-        )
+        const response = await axios.post(proposerServerUrl + '/api/propose', {
+          instructions,
+          cluster,
+        })
         const { proposalPubkey } = response.data
         toast.success(`Proposal sent! 🚀 Proposal Pubkey: ${proposalPubkey}`)
         setIsSendProposalButtonLoading(false)
@@ -767,11 +767,13 @@ const General = () => {
             isPermission={true}
             pythProgramClient={pythProgramClient}
             squads={proposeSquads}
+            proposerServerUrl={proposerServerUrl}
           />
           <PermissionDepermissionKey
             isPermission={false}
             pythProgramClient={pythProgramClient}
             squads={proposeSquads}
+            proposerServerUrl={proposerServerUrl}
           />
         </div>
         <div className="relative mt-6">

+ 10 - 2
governance/xc_admin/packages/xc_admin_frontend/pages/index.tsx

@@ -46,8 +46,11 @@ export const getServerSideProps: GetServerSideProps = async () => {
       )
     : {}
 
+  const proposerServerUrl =
+    process.env.PROPOSER_SERVER_URL || 'http://localhost:4000'
   return {
     props: {
+      proposerServerUrl,
       publisherKeyToNameMapping,
       multisigSignerKeyToNameMapping,
     },
@@ -77,7 +80,12 @@ const DEFAULT_TAB = 'general'
 const Home: NextPage<{
   publisherKeyToNameMapping: Record<string, Record<string, string>>
   multisigSignerKeyToNameMapping: Record<string, string>
-}> = ({ publisherKeyToNameMapping, multisigSignerKeyToNameMapping }) => {
+  proposerServerUrl: string
+}> = ({
+  publisherKeyToNameMapping,
+  multisigSignerKeyToNameMapping,
+  proposerServerUrl,
+}) => {
   const [currentTabIndex, setCurrentTabIndex] = useState(0)
   const tabInfoArray = Object.values(TAB_INFO)
   const anchorWallet = useAnchorWallet()
@@ -143,7 +151,7 @@ const Home: NextPage<{
           </div>
           {tabInfoArray[currentTabIndex].queryString ===
           TAB_INFO.General.queryString ? (
-            <General />
+            <General proposerServerUrl={proposerServerUrl} />
           ) : tabInfoArray[currentTabIndex].queryString ===
             TAB_INFO.UpdatePermissions.queryString ? (
             <UpdatePermissions />