Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/contexts/sales/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getCorePriceAt, getCurrentPhase } from '@/utils/sale';
import {
BrokerStatus,
ContextStatus,
NetworkType,
PhaseEndpoints,
RELAY_CHAIN_BLOCK_TIME,
SaleConfig,
Expand All @@ -14,7 +15,7 @@ import {
SalePhaseInfo,
} from '@/models';

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

interface SaleData {
Expand Down Expand Up @@ -90,10 +91,12 @@ interface Props {
const SaleInfoProvider = ({ children }: Props) => {
const { network } = useNetwork();
const {
state: { api: coretimeApi, isApiReady: isCoretimeReady, height },
state: { api: coretimeApi, isApiReady: isCoretimeReady },
timeslicePeriod,
} = useCoretimeApi();

const { state: { api: relayApi, isApiReady: isRelayReady, height } } = useRelayApi();

const [saleInfo, setSaleInfo] = useState<SaleInfo>(defaultSaleData.saleInfo);
const [saleStatus, setSaleStatus] = useState<BrokerStatus>(defaultSaleData.saleStatus);
const [config, setConfig] = useState<SaleConfig>(defaultSaleData.config);
Expand All @@ -117,7 +120,7 @@ const SaleInfoProvider = ({ children }: Props) => {
const fetchSaleInfo = async () => {
try {
setStatus(ContextStatus.LOADING);
if (!coretimeApi || !isCoretimeReady) {
if (!coretimeApi || !isCoretimeReady || !relayApi || !isRelayReady) {
setStatus(ContextStatus.UNINITIALIZED);
return;
}
Expand Down Expand Up @@ -149,10 +152,15 @@ const SaleInfoProvider = ({ children }: Props) => {

const saleStart = saleInfo.saleStart;
// Sale start != bulk phase start. sale_start = bulk_phase_start + interlude_length.
const saleStartTimestamp = await getBlockTimestamp(coretimeApi, saleStart, network);
let saleStartTimestamp;
if (network === NetworkType.WESTEND) {
saleStartTimestamp = await getBlockTimestamp(relayApi, saleStart, network);
} else {
saleStartTimestamp = await getBlockTimestamp(coretimeApi, saleStart, network);
}

const regionDuration = saleInfo.regionEnd - saleInfo.regionBegin;
const blockTime = getBlockTime(network); // Block time on the coretime chain
const blockTime = network === NetworkType.WESTEND ? RELAY_CHAIN_BLOCK_TIME : getBlockTime(network);

const saleEndTimestamp =
saleStartTimestamp -
Expand Down