Skip to content

Commit

Permalink
feat: offer
Browse files Browse the repository at this point in the history
  • Loading branch information
HuberTRoy committed Jan 25, 2024
1 parent bd4176c commit 9607cb3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@sentry/react": "^7.57.0",
"@subql/apollo-links": "^1.3.0",
"@subql/components": "1.0.3-27",
"@subql/contract-sdk": "0.114.0",
"@subql/contract-sdk": "0.115.0",
"@subql/network-clients": "^0.114.0",
"@subql/network-config": "^0.114.1-0",
"@subql/network-query": "0.112.1-2",
Expand Down
16 changes: 16 additions & 0 deletions src/pages/consumer/MyOffers/MyOffers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
useGetOwnOpenOffersLazyQuery,
} from '@subql/react-hooks';
import { ROUTES, URLS } from '@utils';
import { EVENT_TYPE, EventBus } from '@utils/eventBus';
import { retry } from '@utils/retry';
import dayjs from 'dayjs';
import i18next from 'i18next';

Expand Down Expand Up @@ -152,10 +154,24 @@ export const MyOffers: React.FC = () => {
const requiresTokenApproval = offerAllowance.result.data?.isZero();
const offers = useGetOfferCountQuery({
variables: { consumer: account ?? '' },
fetchPolicy: 'network-only',
});

const title = match?.pathname ? t('myOffers.createOffer') : t('myOffers.title');

React.useEffect(() => {
const refresh = () => {
retry(() => {
offers.refetch();
});
};
EventBus.on(EVENT_TYPE.CREATED_CONSUMER_OFFER, refresh);

return () => {
EventBus.off(EVENT_TYPE.CREATED_CONSUMER_OFFER, refresh);
};
}, []);

return renderAsync(offers, {
loading: () => <Spinner />,
error: (e) => <Typography>{`Failed to load offers: ${e}`}</Typography>,
Expand Down
10 changes: 6 additions & 4 deletions src/pages/consumer/OfferMarketplace/AcceptOffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ export const AcceptOffer: React.FC<Props> = ({ deployment, offer, requiredBlockH
description: 'Please confirm your metadata can be reach',
});
}
return contracts.purchaseOfferMarket.acceptPurchaseOffer(offer?.id ?? '', deploymentMeta.data?.poiHash || '');

const tempMmrRoot = '0xab3921276c8067fe0c82def3e5ecfd8447f1961bc85768c2a56e6bd26d3c0c55';
return contracts.purchaseOfferMarket.acceptPurchaseOffer(
offer?.id ?? '',
deploymentMeta.data?.poiHash || tempMmrRoot,
);
};

return (
Expand Down Expand Up @@ -229,9 +234,6 @@ export const AcceptOffer: React.FC<Props> = ({ deployment, offer, requiredBlockH
status={deployment.status}
deploymentId={deployment.deploymentId}
proxyEndpoint={indexerMetadata.url ?? ''}
offerId={offer?.id}
rewardPerIndexer={offer?.deposit.toString()}
planDuration={offer?.planTemplate?.period.toString()}
requiredBlockHeight={requiredBlockHeight}
onSubmit={onSubmit}
isLoading={isLoading}
Expand Down
11 changes: 1 addition & 10 deletions src/pages/consumer/OfferMarketplace/CheckList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import { ServiceStatus } from '@subql/network-query';
import { AsyncMemoReturn, renderAsync } from '@subql/react-hooks';
import { Button, Typography } from 'antd';
import clsx from 'clsx';
import dayjs from 'dayjs';

import { Spinner, Status as AppStatus } from '../../../components';
import { deploymentStatus } from '../../../components/Status/Status';
import { COLORS, convertStringToNumber, formatEther, isUndefined, Metadata, parseError } from '../../../utils';
import { COLORS, isUndefined, Metadata, parseError } from '../../../utils';
import styles from './AcceptOffer.module.css';

const RequirementCheckListTitle = () => {
Expand Down Expand Up @@ -86,9 +85,6 @@ interface ICheckList {
status: string | undefined;
deploymentId: string;
proxyEndpoint: string | undefined;
offerId: string;
planDuration: string | undefined;
rewardPerIndexer: string;
requiredBlockHeight: number; //TODO: or should use bigInt?
onSubmit: (params: unknown) => void;
error?: unknown;
Expand All @@ -105,9 +101,6 @@ interface ICheckList {
export const CheckList: React.FC<ICheckList> = ({
status,
requiredBlockHeight,
offerId,
rewardPerIndexer,
planDuration,
onSubmit,
error,
isLoading,
Expand All @@ -118,8 +111,6 @@ export const CheckList: React.FC<ICheckList> = ({

const REQUIRED_STATUS = ServiceStatus.READY;
const REQUIRED_BLOCKHEIGHT = requiredBlockHeight;
const daysOfPlan = dayjs.duration(+(planDuration || 0), 'seconds').asDays();
const REQUIRED_DAILY_REWARD_CAP = convertStringToNumber(formatEther(rewardPerIndexer)) / Math.ceil(daysOfPlan);

return renderAsync(deploymentMeta, {
loading: () => <Spinner />,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4556,10 +4556,10 @@
string-width "4.2.3"
use-screen "^1.1.3"

"@subql/contract-sdk@0.114.0":
version "0.114.0"
resolved "https://registry.npmjs.org/@subql/contract-sdk/-/contract-sdk-0.114.0.tgz#b3c4f43f35ed680321f082371c7d4268187e9990"
integrity sha512-jnlN4w7pNl7beCzG112Dk/7vxX9n1mdPvaGVNUUeQmpl4aEdSv9Z1B4YD6Wq0dezFejTsrGCkNo5IPZPBlLu0Q==
"@subql/contract-sdk@0.115.0":
version "0.115.0"
resolved "https://registry.npmjs.org/@subql/contract-sdk/-/contract-sdk-0.115.0.tgz#16e787a6630e97e676521b2174d41e19115b5f75"
integrity sha512-F58qy0cBqAM3KNgcDfa1IWPIe/SUEGTmAU44SGR/8ru2YxT8Ws7oFMMNDhsXelNq27/P4MK99P5WxSCTyhctMw==

"@subql/network-clients@^0.114.0":
version "0.114.0"
Expand Down

0 comments on commit 9607cb3

Please sign in to comment.