Skip to content

Commit

Permalink
filter orders
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Aug 20, 2024
1 parent bec562d commit eede322
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
6 changes: 1 addition & 5 deletions src/contexts/sales/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
SalePhaseInfo,
} from '@/models';

import { useCoretimeApi, useRelayApi } from '../apis';
import { useCoretimeApi } from '../apis';
import { ApiState } from '../apis/types';
import { useNetwork } from '../network';

Expand Down Expand Up @@ -95,10 +95,6 @@ const SaleInfoProvider = ({ children }: Props) => {
timeslicePeriod,
} = useCoretimeApi();

const {
state: { api: relayApi, apiState: relayApiState },
} = useRelayApi();

const [saleInfo, setSaleInfo] = useState<SaleInfo>(defaultSaleData.saleInfo);
const [saleStatus, setSaleStatus] = useState<BrokerStatus>(
defaultSaleData.saleStatus
Expand Down
19 changes: 14 additions & 5 deletions src/pages/orders/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import { OrderProcessorModal } from '@/components/Orders/Modals/OrderProcessor';
import { useAccounts } from '@/contexts/account';
import { useOrders } from '@/contexts/orders';
import { useRegions } from '@/contexts/regions';
import { useSaleInfo } from '@/contexts/sales';
import { ContextStatus, Order } from '@/models';

const OrderDashboard = () => {
const theme = useTheme();

const { orders, status } = useOrders();
const { orders, status: orderStatus } = useOrders();
const { regions } = useRegions();
const {
state: { activeAccount },
Expand All @@ -42,10 +43,18 @@ const OrderDashboard = () => {
const [orderCreationModalOpen, openOrderCreationModal] = useState(false);
const [contributionModal, openContributionModal] = useState(false);
const [processorModal, openProcessorModal] = useState(false);
const { saleStatus, status: saleInfoStatus } = useSaleInfo();

useEffect(() => {
setOrdersToShow(orders.filter(({ processed }) => !processed));
}, [orders]);
let _orders: Array<Order> = orders.filter(({ processed }) => !processed);

if (saleInfoStatus === ContextStatus.LOADED) {
_orders = _orders.filter(
({ end }) => end > saleStatus.lastCommittedTimeslice
);
}
setOrdersToShow(_orders);
}, [orders, saleInfoStatus, saleStatus]);

return (
<>
Expand Down Expand Up @@ -96,11 +105,11 @@ const OrderDashboard = () => {
/>
</Box>
</Box>
{status === ContextStatus.ERROR ? (
{orderStatus === ContextStatus.ERROR ? (
<Box mt='1rem'>
<Typography>An error occured while fetching the orders.</Typography>
</Box>
) : status !== ContextStatus.LOADED ? (
) : orderStatus !== ContextStatus.LOADED ? (
<Backdrop open>
<CircularProgress />
</Backdrop>
Expand Down
14 changes: 7 additions & 7 deletions src/pages/paras/renewal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ApiState } from '@/contexts/apis/types';
import { useNetwork } from '@/contexts/network';
import { useSaleInfo } from '@/contexts/sales';
import { useToast } from '@/contexts/toast';
import { BrokerStatus, ContextStatus } from '@/models';
import { ContextStatus } from '@/models';

const Renewal = () => {
const router = useRouter();
Expand All @@ -38,7 +38,7 @@ const Renewal = () => {
state: { activeAccount, activeSigner },
} = useAccounts();
const { status, parachains } = useRenewableParachains();
const { saleInfo } = useSaleInfo();
const { saleInfo, saleStatus, status: saleInfoStatus } = useSaleInfo();

const {
state: { api: relayApi, apiState: relayApiState },
Expand Down Expand Up @@ -101,16 +101,14 @@ const Renewal = () => {
coretimeApiState !== ApiState.READY ||
!relayApi ||
relayApiState !== ApiState.READY ||
!parachains[activeIdx]
!parachains[activeIdx] ||
saleInfoStatus !== ContextStatus.LOADED
)
return;

const { lastCommittedTimeslice } = (
await coretimeApi.query.broker.status()
).toJSON() as BrokerStatus;
const now = await timesliceToTimestamp(
relayApi,
lastCommittedTimeslice,
saleStatus.lastCommittedTimeslice,
timeslicePeriod
);
const expiry = await timesliceToTimestamp(
Expand All @@ -131,6 +129,8 @@ const Renewal = () => {
activeIdx,
parachains,
timeslicePeriod,
saleInfoStatus,
saleStatus,
]);

useEffect(() => {
Expand Down

0 comments on commit eede322

Please sign in to comment.