Skip to content

Commit

Permalink
Merge pull request #2089 from zeitgeistpm/tr-filter-invalid-categories
Browse files Browse the repository at this point in the history
Filter markets with invalid categories
  • Loading branch information
yornaath authored Dec 13, 2023
2 parents 7eddc1c + 4735134 commit ff43d9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import resolveTailwindConfig from "tailwindcss/resolveConfig";
import tailwindConfig from "../../tailwind.config";
import { EndpointOption, Environment } from "../types";

export const isWSX = process.env.NEXT_PUBLIC_CLIENT === "wsx";
// IMPORTANT: this should be false for all other branches other than the wsx branch.
export const isWSX = false;

export const wsxID = process.env.NEXT_PUBLIC_VERCEL_ENV === "staging" ? 3 : 3;
export const wsxAssetIdString = `{"foreignAsset":${wsxID}}`;

Expand Down
15 changes: 14 additions & 1 deletion lib/gql/trending-markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getCurrentPrediction } from "lib/util/assets";
import { fetchAllPages } from "lib/util/fetch-all-pages";
import { parseAssetIdString } from "lib/util/parse-asset-id";
import { marketMetaFilter } from "./constants";
import { isNotNull } from "@zeitgeistpm/utility/dist/null";

const poolChangesQuery = gql`
query PoolChanges($start: DateTime, $end: DateTime) {
Expand All @@ -45,6 +46,8 @@ const marketQuery = gql`
where: {
pool: { poolId_eq: $poolId }
marketId_not_in: ${hiddenMarketIds}
hasValidMetaCategories_eq: true
categories_isNull: false
${marketMetaFilter}
}
) {
Expand Down Expand Up @@ -149,6 +152,11 @@ const getTrendingMarkets = async (

const market = marketsRes.markets[0];

if (!market) {
console.log("No market");
return null;
}

const assetsRes = await client.request<{
assets: {
pool: { poolId: number };
Expand All @@ -163,6 +171,11 @@ const getTrendingMarkets = async (

const prediction = getCurrentPrediction(assets, market);

if (!market.categories) {
console.log("No categories for market", market.marketId);
return null;
}

const marketCategories: MarketOutcomes = market.categories.map(
(category, index) => {
const asset = assets[index];
Expand Down Expand Up @@ -198,7 +211,7 @@ const getTrendingMarkets = async (
}),
);

return trendingMarkets;
return trendingMarkets.filter(isNotNull);
};

const lookupPrice = (
Expand Down

0 comments on commit ff43d9d

Please sign in to comment.