diff --git a/src/contexts/sales/index.tsx b/src/contexts/sales/index.tsx index ae069f43..c16cbadd 100644 --- a/src/contexts/sales/index.tsx +++ b/src/contexts/sales/index.tsx @@ -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'; @@ -95,10 +95,6 @@ const SaleInfoProvider = ({ children }: Props) => { timeslicePeriod, } = useCoretimeApi(); - const { - state: { api: relayApi, apiState: relayApiState }, - } = useRelayApi(); - const [saleInfo, setSaleInfo] = useState(defaultSaleData.saleInfo); const [saleStatus, setSaleStatus] = useState( defaultSaleData.saleStatus diff --git a/src/pages/orders/index.tsx b/src/pages/orders/index.tsx index 47fd2ba6..6b3a3552 100644 --- a/src/pages/orders/index.tsx +++ b/src/pages/orders/index.tsx @@ -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 }, @@ -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 = orders.filter(({ processed }) => !processed); + + if (saleInfoStatus === ContextStatus.LOADED) { + _orders = _orders.filter( + ({ end }) => end > saleStatus.lastCommittedTimeslice + ); + } + setOrdersToShow(_orders); + }, [orders, saleInfoStatus, saleStatus]); return ( <> @@ -96,11 +105,11 @@ const OrderDashboard = () => { /> - {status === ContextStatus.ERROR ? ( + {orderStatus === ContextStatus.ERROR ? ( An error occured while fetching the orders. - ) : status !== ContextStatus.LOADED ? ( + ) : orderStatus !== ContextStatus.LOADED ? ( diff --git a/src/pages/paras/renewal.tsx b/src/pages/paras/renewal.tsx index 589d60d4..66ea00a6 100644 --- a/src/pages/paras/renewal.tsx +++ b/src/pages/paras/renewal.tsx @@ -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(); @@ -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 }, @@ -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( @@ -131,6 +129,8 @@ const Renewal = () => { activeIdx, parachains, timeslicePeriod, + saleInfoStatus, + saleStatus, ]); useEffect(() => {