From 1e73548e232eb467e77f99232bb4efd01122a71a Mon Sep 17 00:00:00 2001 From: Szegoo Date: Sat, 21 Sep 2024 16:40:19 +0200 Subject: [PATCH] search based on core & paraId --- src/components/Renew/renewPage.tsx | 4 +++- src/components/Renew/select.tsx | 9 +++++++-- src/components/Tables/ParachainTable/index.tsx | 8 +++++--- src/hooks/parasInfo.ts | 3 ++- src/models/paras/index.ts | 1 + src/pages/paras/index.tsx | 4 ++-- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/components/Renew/renewPage.tsx b/src/components/Renew/renewPage.tsx index 4ee3a3d3..ab006fc9 100644 --- a/src/components/Renew/renewPage.tsx +++ b/src/components/Renew/renewPage.tsx @@ -27,7 +27,9 @@ const Renewal = () => { // Intentionally set to -1 so that the user gets rerouted if core is not set. const core = router.query.core ? Number(router.query.core) : -1; - const index = parachains.findIndex((p) => p.core === core); + const paraId = router.query.paraId ? Number(router.query.paraId) : -1; + + const index = parachains.findIndex((p) => p.core === core && p.paraId === paraId); if (index >= 0) { setActiveIndex(index); diff --git a/src/components/Renew/select.tsx b/src/components/Renew/select.tsx index f48d678d..746ea6e2 100644 --- a/src/components/Renew/select.tsx +++ b/src/components/Renew/select.tsx @@ -26,14 +26,19 @@ export const SelectParachain = ({ parachains }: SelectParachainProps) => { // Get coreId from query params. const core = router.query.core ? Number(router.query.core) : null; + const paraId = router.query.paraId ? Number(router.query.paraId) : null; const onParaChange = (e: SelectChangeEvent) => { const selectedCoreId = core ? parachains[Number(e.target.value)].core : parachains[0].core; + const selectedParaId = paraId + ? parachains[Number(e.target.value)].paraId + : parachains[0].paraId; + // Update the URL with the new `core` query param router.push({ pathname: '/renew', - query: { network, core: selectedCoreId }, + query: { network, paraId: selectedParaId, core: selectedCoreId }, }); }; @@ -52,7 +57,7 @@ export const SelectParachain = ({ parachains }: SelectParachainProps) => { sx={{ borderRadius: '1rem' }} labelId='label-parachain-select' label='Parachain' - value={parachains.findIndex((p) => p.core === core).toString()} + value={parachains.findIndex((p) => p.core === core && p.paraId === paraId).toString()} onChange={onParaChange} > {parachains.map(({ paraId, core }, index) => ( diff --git a/src/components/Tables/ParachainTable/index.tsx b/src/components/Tables/ParachainTable/index.tsx index 7135c857..888ed469 100644 --- a/src/components/Tables/ParachainTable/index.tsx +++ b/src/components/Tables/ParachainTable/index.tsx @@ -43,7 +43,7 @@ interface ParachainTableProps { onUpgrade: (_id: number) => void; onBuy: () => void; onWatch: (_id: number, _watching: boolean) => void; - onRenew: (_id: number) => void; + onRenew: (_id: number, _core: number) => void; }; orderBy: string; direction: Order; @@ -151,7 +151,7 @@ export const ParachainTable = ({ {(rowsPerPage > 0 ? parachains.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) : parachains - ).map(({ id, name, state, watching, logo, homepage }, index) => ( + ).map(({ id, core, name, state, watching, logo, homepage }, index) => ( {id} @@ -219,7 +219,9 @@ export const ParachainTable = ({ ) : state === ParaState.IDLE_PARA ? ( Buy Coretime ) : state === ParaState.ACTIVE_RENEWABLE_PARA ? ( - onRenew(id)}>Renew Coretime + onRenew(id, core)}> + Renew Coretime + ) : ( No action required )} diff --git a/src/hooks/parasInfo.ts b/src/hooks/parasInfo.ts index d6c138e9..ae85e77e 100644 --- a/src/hooks/parasInfo.ts +++ b/src/hooks/parasInfo.ts @@ -125,7 +125,7 @@ export const useParasInfo = () => { ? ParaState.ONDEMAND_PARACHAIN : ParaState.IDLE_PARA; - paras.push({ id, state, name, logo, homepage } as ParachainInfo); + paras.push({ id, core: isRenewable?.core, state, name, logo, homepage } as ParachainInfo); } return paras; }; @@ -141,6 +141,7 @@ export const useParasInfo = () => { if (manager === activeAccount?.address) { paras.push({ id, + core: 0, state: ParaState.RESERVED, name: '', }); diff --git a/src/models/paras/index.ts b/src/models/paras/index.ts index 87aaab88..e38e2c75 100644 --- a/src/models/paras/index.ts +++ b/src/models/paras/index.ts @@ -20,6 +20,7 @@ export enum ParaState { } export type ParachainInfo = { id: number; + core: number; state: ParaState; name: string; watching?: boolean; diff --git a/src/pages/paras/index.tsx b/src/pages/paras/index.tsx index 22310ca6..60875e9f 100644 --- a/src/pages/paras/index.tsx +++ b/src/pages/paras/index.tsx @@ -67,10 +67,10 @@ const ParachainManagement = () => { }; // Renew coretime with the given para id - const onRenew = (paraId: number) => { + const onRenew = (paraId: number, core: number) => { router.push({ pathname: 'renew', - query: { network, paraId }, + query: { network, paraId, core }, }); };