From 66506c720a2ff89394d0e8daa2e0c92f37a38f49 Mon Sep 17 00:00:00 2001 From: Tom Robiquet Date: Thu, 16 Nov 2023 14:32:39 +0100 Subject: [PATCH 1/3] misc amm2 fixes for market list and page --- .../liquidity/MarketLiquiditySection.tsx | 4 ++-- components/markets/MarketChart.tsx | 2 +- components/markets/MarketHeader.tsx | 18 +++++++++++++----- components/markets/market-card/index.tsx | 10 ++++------ lib/gql/markets-stats.ts | 4 ++-- lib/gql/markets.ts | 12 +++++++++++- pages/markets/[marketid].tsx | 15 ++++++++++++--- 7 files changed, 45 insertions(+), 20 deletions(-) diff --git a/components/liquidity/MarketLiquiditySection.tsx b/components/liquidity/MarketLiquiditySection.tsx index c228b6f7b..14f10f7f7 100644 --- a/components/liquidity/MarketLiquiditySection.tsx +++ b/components/liquidity/MarketLiquiditySection.tsx @@ -88,12 +88,12 @@ const LiquidityHeaderButtonItem: FC> = }; const LiquidityHeader = ({ market }: { market: FullMarketFragment }) => { - const { pool } = market; + const { pool, neoPool } = market; const { data: liquidity } = usePoolLiquidity( pool?.poolId ? { poolId: pool.poolId } : undefined, ); - const swapFee = new Decimal(Number(pool?.swapFee) ?? 0) + const swapFee = new Decimal(Number(pool?.swapFee ?? neoPool?.swapFee) ?? 0) .div(ZTG) .mul(100) .toNumber(); diff --git a/components/markets/MarketChart.tsx b/components/markets/MarketChart.tsx index 1c6788b97..549b5d786 100644 --- a/components/markets/MarketChart.tsx +++ b/components/markets/MarketChart.tsx @@ -27,7 +27,7 @@ const MarketChart = ({ }: { marketId: number; chartSeries: ChartSeries[]; - baseAsset: string; + baseAsset?: string; poolCreationDate: Date; marketStatus: MarketStatus; resolutionDate: Date; diff --git a/components/markets/MarketHeader.tsx b/components/markets/MarketHeader.tsx index 63f992c31..175c8af10 100644 --- a/components/markets/MarketHeader.tsx +++ b/components/markets/MarketHeader.tsx @@ -322,14 +322,22 @@ const MarketHeader: FC<{ rejectReason, promotionData, }) => { - const { categories, status, question, period, marketType, pool, scalarType } = - market; + const { + categories, + status, + question, + period, + marketType, + pool, + scalarType, + neoPool, + } = market; const [showMarketHistory, setShowMarketHistory] = useState(false); const starts = Number(period.start); const ends = Number(period.end); - const volume = pool?.volume - ? new Decimal(pool?.volume).div(ZTG).toNumber() - : 0; + const volume = new Decimal(pool?.volume ?? neoPool?.volume ?? 0) + .div(ZTG) + .toNumber(); const { outcome, by } = getMarketStatusDetails( marketType, diff --git a/components/markets/market-card/index.tsx b/components/markets/market-card/index.tsx index 74a2c9865..9567ad105 100644 --- a/components/markets/market-card/index.tsx +++ b/components/markets/market-card/index.tsx @@ -50,13 +50,11 @@ export interface MarketCardProps extends IndexedMarketCardData { const MarketCardPredictionBar = ({ prediction: { name, price }, - pool, }: { prediction: { name: string; price: number }; - pool: {}; }) => { // check if market has liquidity - if (Object.keys(pool).length !== 0) { + if (price != null) { const impliedPercentage = Math.round(Number(price) * 100); return ( @@ -257,9 +255,9 @@ export const MarketCard = ({ : formatNumberCompact(Number(prediction.name))} - ) : pool && marketType?.categorical ? ( - - ) : pool && scalarType && Object.keys(pool).length !== 0 ? ( + ) : liquidity && marketType?.categorical ? ( + + ) : liquidity && scalarType ? ( => { if (ids.length === 0) return []; - const response = await client.request<{ + const { marketStats } = await client.request<{ marketStats: MarketStats[]; }>(query, { ids }); - return response.marketStats; + return marketStats; }; diff --git a/lib/gql/markets.ts b/lib/gql/markets.ts index 56ae827a4..a7b373e93 100644 --- a/lib/gql/markets.ts +++ b/lib/gql/markets.ts @@ -30,6 +30,11 @@ const marketQuery = gql` volume baseAsset } + neoPool { + createdAt + collateral + volume + } question slug status @@ -97,12 +102,17 @@ export interface MarketPageIndexedData { categories: { name: string; color: string }[]; outcomeAssets: string[]; resolvedOutcome: string; - pool: { + pool?: { poolId: number; volume: string; createdAt: string; baseAsset: string; }; + neoPool?: { + collateral: string; + createdAt: string; + volume: string; + }; scalarType: ScalarRangeType; marketType: { scalar: string[]; diff --git a/pages/markets/[marketid].tsx b/pages/markets/[marketid].tsx index c73101d82..7b48b66d3 100644 --- a/pages/markets/[marketid].tsx +++ b/pages/markets/[marketid].tsx @@ -278,13 +278,22 @@ const Market: NextPage = ({ )} - {chartSeries && indexedMarket?.pool?.poolId ? ( + {chartSeries && (indexedMarket?.pool || indexedMarket.neoPool) ? (
From ffb706da93cddef02adab4d5ed9ee559f311f41a Mon Sep 17 00:00:00 2001 From: Tom Robiquet Date: Thu, 16 Nov 2023 14:47:52 +0100 Subject: [PATCH 2/3] fix regressions --- components/liquidity/MarketLiquiditySection.tsx | 2 +- pages/markets/[marketid].tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/liquidity/MarketLiquiditySection.tsx b/components/liquidity/MarketLiquiditySection.tsx index 14f10f7f7..f5a34654c 100644 --- a/components/liquidity/MarketLiquiditySection.tsx +++ b/components/liquidity/MarketLiquiditySection.tsx @@ -93,7 +93,7 @@ const LiquidityHeader = ({ market }: { market: FullMarketFragment }) => { pool?.poolId ? { poolId: pool.poolId } : undefined, ); - const swapFee = new Decimal(Number(pool?.swapFee ?? neoPool?.swapFee) ?? 0) + const swapFee = new Decimal(Number(pool?.swapFee ?? neoPool?.swapFee ?? 0)) .div(ZTG) .mul(100) .toNumber(); diff --git a/pages/markets/[marketid].tsx b/pages/markets/[marketid].tsx index 7b48b66d3..145c85e9c 100644 --- a/pages/markets/[marketid].tsx +++ b/pages/markets/[marketid].tsx @@ -301,7 +301,7 @@ const Market: NextPage = ({ ) : ( <> )} - {marketHasPool && market.neoPool == null && ( + {marketHasPool === false && (
From daa5e0c8ed4d28d9e89ec5d2bb6b62774d0a1efd Mon Sep 17 00:00:00 2001 From: Tom Robiquet Date: Fri, 17 Nov 2023 11:43:34 +0100 Subject: [PATCH 3/3] fix flicker --- components/markets/MarketsList.tsx | 1 + components/markets/SimilarMarketsSection.tsx | 1 + components/markets/market-card/index.tsx | 7 +++++-- lib/gql/featured-markets.ts | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/markets/MarketsList.tsx b/components/markets/MarketsList.tsx index aca8d36d7..38fa8991f 100644 --- a/components/markets/MarketsList.tsx +++ b/components/markets/MarketsList.tsx @@ -133,6 +133,7 @@ const MarketsList = ({ className = "" }: MarketsListProps) => { marketType={marketType} scalarType={scalarType} pool={pool} + neoPool={market.neoPool} status={market.status} baseAsset={market.baseAsset} volume={new Decimal(volume).div(ZTG).toNumber()} diff --git a/components/markets/SimilarMarketsSection.tsx b/components/markets/SimilarMarketsSection.tsx index be9a3c351..c2dfe8e98 100644 --- a/components/markets/SimilarMarketsSection.tsx +++ b/components/markets/SimilarMarketsSection.tsx @@ -71,6 +71,7 @@ export const SimilarMarketsSection = ({ marketType={marketType} scalarType={scalarType} pool={market.pool ?? null} + neoPool={market?.neoPool} status={market.status} baseAsset={market.baseAsset} volume={new Decimal(market.pool?.volume ?? 0) diff --git a/components/markets/market-card/index.tsx b/components/markets/market-card/index.tsx index 24251c2e6..5640baab8 100644 --- a/components/markets/market-card/index.tsx +++ b/components/markets/market-card/index.tsx @@ -17,6 +17,7 @@ import { } from "@zeitgeistpm/sdk"; import { lookupAssetImagePath } from "lib/constants/foreign-asset"; import Image from "next/image"; +import { FullMarketFragment } from "@zeitgeistpm/indexer"; export interface IndexedMarketCardData { marketId: number; @@ -30,6 +31,7 @@ export interface IndexedMarketCardData { prediction: { name: string; price: number }; volume: number; pool?: { poolId?: number; volume: string } | null; + neoPool?: FullMarketFragment["neoPool"] | null; baseAsset: string; tags?: string[]; status: string; @@ -178,6 +180,7 @@ export const MarketCard = ({ marketType, prediction, pool, + neoPool, scalarType, volume, baseAsset, @@ -255,9 +258,9 @@ export const MarketCard = ({ : formatNumberCompact(Number(prediction.name))} - ) : liquidity && marketType?.categorical ? ( + ) : (pool || neoPool) && marketType?.categorical ? ( - ) : liquidity && scalarType ? ( + ) : (pool || neoPool) && scalarType ? (