Skip to content

Commit

Permalink
search based on core & paraId
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Sep 21, 2024
1 parent f2b3738 commit 1e73548
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/components/Renew/renewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions src/components/Renew/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});
};

Expand All @@ -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) => (
Expand Down
8 changes: 5 additions & 3 deletions src/components/Tables/ParachainTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => (
<StyledTableRow key={index}>
<StyledTableCell style={{ width: '10%' }} align='center'>
<Link href={`${SUSBCAN_RELAY_URL[network]}/parachain/${id}`}>{id}</Link>
Expand Down Expand Up @@ -219,7 +219,9 @@ export const ParachainTable = ({
) : state === ParaState.IDLE_PARA ? (
<ParaActionButton onClick={onBuy}>Buy Coretime</ParaActionButton>
) : state === ParaState.ACTIVE_RENEWABLE_PARA ? (
<ParaActionButton onClick={() => onRenew(id)}>Renew Coretime</ParaActionButton>
<ParaActionButton onClick={() => onRenew(id, core)}>
Renew Coretime
</ParaActionButton>
) : (
<Typography>No action required</Typography>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/parasInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -141,6 +141,7 @@ export const useParasInfo = () => {
if (manager === activeAccount?.address) {
paras.push({
id,
core: 0,
state: ParaState.RESERVED,
name: '',
});
Expand Down
1 change: 1 addition & 0 deletions src/models/paras/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export enum ParaState {
}
export type ParachainInfo = {
id: number;
core: number;
state: ParaState;
name: string;
watching?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/paras/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});
};

Expand Down

0 comments on commit 1e73548

Please sign in to comment.