Skip to content

Commit

Permalink
Merge pull request #2294 from zeitgeistpm/#2134-filter-parimutuel
Browse files Browse the repository at this point in the history
Filter parimituel apps
  • Loading branch information
yornaath authored Mar 1, 2024
2 parents e67eb02 + bbabdf8 commit 20b5bb1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
5 changes: 5 additions & 0 deletions lib/constants/whitelisted-trusted-creators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { tryCatch } from "@zeitgeistpm/utility/dist/either";

export const WHITELISTED_TRUSTED_CREATORS: string[] = tryCatch(() =>
JSON.parse(process.env.NEXT_PUBLIC_WHITELISTED_TRUSTED_CREATORS as string),
).unwrapOr([]);
4 changes: 2 additions & 2 deletions lib/gql/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isWSX, wsxID } from "lib/constants";

export const marketMetaFilter = isWSX
? `question_not_eq: "", question_isNull: false, categories_isNull: false, hasValidMetaCategories_eq: true, baseAsset_eq: "{\\"foreignAsset\\":${wsxID}}"`
: `question_not_eq: "", question_isNull: false, categories_isNull: false, hasValidMetaCategories_eq: true, baseAsset_not_eq: "{\\"foreignAsset\\":${wsxID}}"`;
? `question_not_eq: "", question_isNull: false, categories_isNull: false, hasValidMetaCategories_eq: true, scoringRule_not_eq: Parimutuel, baseAsset_eq: "{\\"foreignAsset\\":${wsxID}}"`
: `question_not_eq: "", question_isNull: false, categories_isNull: false, hasValidMetaCategories_eq: true, scoringRule_not_eq: Parimutuel, baseAsset_not_eq: "{\\"foreignAsset\\":${wsxID}}"`;
6 changes: 2 additions & 4 deletions lib/hooks/queries/useInfiniteMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { marketMetaFilter } from "./constants";
import { marketsRootQuery } from "./useMarket";

import { tryCatch } from "@zeitgeistpm/utility/dist/either";
import { WHITELISTED_TRUSTED_CREATORS } from "lib/constants/whitelisted-trusted-creators";

export const rootKey = "markets-filtered";

Expand All @@ -40,10 +41,6 @@ export type QueryMarketData = Market<IndexerContext> & {
prediction: { name: string; price: number };
};

const WHITELISTED_TRUSTED_CREATORS: string[] = tryCatch(() =>
JSON.parse(process.env.NEXT_PUBLIC_WHITELISTED_TRUSTED_CREATORS as string),
).unwrapOr([]);

export const useInfiniteMarkets = (
orderBy: MarketsOrderBy,
withLiquidityOnly = false,
Expand Down Expand Up @@ -81,6 +78,7 @@ export const useInfiniteMarkets = (
status_in: statuses.length === 0 ? undefined : statuses,
tags_containsAny: tags?.length === 0 ? undefined : tags,
baseAsset_in: currencies?.length !== 0 ? currencies : undefined,
scoringRule_not_eq: ScoringRule.Parimutuel,
},
{
disputeMechanism_isNull: false,
Expand Down
26 changes: 22 additions & 4 deletions lib/hooks/queries/useRecommendedMarkets.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { useQuery } from "@tanstack/react-query";
import { MarketOrderByInput, MarketStatus } from "@zeitgeistpm/indexer";
import {
MarketOrderByInput,
MarketStatus,
ScoringRule,
} from "@zeitgeistpm/indexer";
import { isIndexedSdk } from "@zeitgeistpm/sdk";
import { useSdkv2 } from "../useSdkv2";
import { useMarket } from "./useMarket";
import { searchMarketsText } from "./useMarketSearch";
import { WHITELISTED_TRUSTED_CREATORS } from "lib/constants/whitelisted-trusted-creators";

export const recommendedMarketsRootKey = "recommended-markets";

Expand Down Expand Up @@ -34,9 +39,22 @@ export const useRecommendedMarkets = (marketId?: number, limit = 2) => {
limit,
order: [MarketOrderByInput.VolumeDesc],
where: {
status_eq: MarketStatus.Active,
marketId_not_eq: marketId,
volume_gt: "0",
AND: [
{
status_eq: MarketStatus.Active,
marketId_not_eq: marketId,
volume_gt: "0",
scoringRule_not_eq: ScoringRule.Parimutuel,
},
{
disputeMechanism_isNull: false,
OR: [
{
creator_in: WHITELISTED_TRUSTED_CREATORS,
},
],
},
],
},
});
return {
Expand Down

0 comments on commit 20b5bb1

Please sign in to comment.