Skip to content

Commit

Permalink
Merge pull request #2442 from zeitgeistpm/staging
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Jun 10, 2024
2 parents ede758e + 8e9a7d6 commit eed02b2
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 113 deletions.
196 changes: 98 additions & 98 deletions components/portfolio/MarketPositions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,104 +170,104 @@ export const MarketPositions = ({
);
};

if (positions.some(displayBalance)) {
return (
<div className={`${className}`}>
<MarketPositionHeader
marketId={market.marketId}
question={market.question ?? undefined}
baseAsset={market.baseAsset}
/>
<Table
showHighlight={false}
columns={isLiquidityMarket ? COLUMNS_LIQUIDITY : COLUMNS}
data={positions
.filter((pos) => displayBalance(pos))
.map<TableData>(
({
assetId,
price,
userBalance,
outcome,
changePercentage,
market,
avgCost,
rpnl,
upnl,
}) => {
const baseAssetUsdPrice = lookUpAssetPrice(
market.baseAsset,
foreignAssetPrices,
usdZtgPrice,
);
return {
outcome: outcome,
userBalance: userBalance.div(ZTG).toNumber(),
price: {
value: price.toNumber(),
usdValue: price.mul(baseAssetUsdPrice ?? 0).toNumber(),
},
cost: {
value: avgCost,
usdValue: new Decimal(avgCost)
.mul(baseAssetUsdPrice ?? 0)
.toNumber(),
},
upnl: {
value: upnl,
usdValue: new Decimal(upnl)
.mul(baseAssetUsdPrice ?? 0)
.toNumber(),
},
rpnl: {
value: rpnl,
usdValue: new Decimal(rpnl)
.mul(baseAssetUsdPrice ?? 0)
.toNumber(),
},
value: {
value: userBalance.mul(price).div(ZTG).toNumber(),
usdValue: userBalance
.mul(price)
.mul(baseAssetUsdPrice ?? 0)
.div(ZTG)
.toNumber(),
},
change: isNaN(changePercentage)
? 0
: changePercentage.toFixed(1),
actions: (
<div className="text-right">
{IOPoolShareAssetId.is(assetId) ? (
<PoolShareButtons
poolId={assetId.PoolShare}
market={market}
/>
) : marketStage?.type === "Trading" &&
IOMarketOutcomeAssetId.is(assetId) ? (
<AssetTradingButtons assetId={assetId} />
) : marketStage?.type === "Resolved" ? (
<RedeemButton market={market} assetId={assetId} />
) : IOMarketOutcomeAssetId.is(assetId) &&
marketStage?.type === "Reported" ? (
<DisputeButton market={market} assetId={assetId} />
) : IOMarketOutcomeAssetId.is(assetId) &&
(marketStage?.type === "OpenReportingPeriod" ||
(marketStage?.type === "OracleReportingPeriod" &&
isOracle)) ? (
<ReportButton market={market} assetId={assetId} />
) : (
""
)}
</div>
),
};
},
)}
/>
</div>
);
}
// if (positions.some(displayBalance)) {
return (
<div className={`${className}`}>
<MarketPositionHeader
marketId={market.marketId}
question={market.question ?? undefined}
baseAsset={market.baseAsset}
/>
<Table
showHighlight={false}
columns={isLiquidityMarket ? COLUMNS_LIQUIDITY : COLUMNS}
data={positions
// .filter((pos) => displayBalance(pos))
.map<TableData>(
({
assetId,
price,
userBalance,
outcome,
changePercentage,
market,
avgCost,
rpnl,
upnl,
}) => {
const baseAssetUsdPrice = lookUpAssetPrice(
market.baseAsset,
foreignAssetPrices,
usdZtgPrice,
);
return {
outcome: outcome,
userBalance: userBalance.div(ZTG).toNumber(),
price: {
value: price.toNumber(),
usdValue: price.mul(baseAssetUsdPrice ?? 0).toNumber(),
},
cost: {
value: avgCost,
usdValue: new Decimal(avgCost)
.mul(baseAssetUsdPrice ?? 0)
.toNumber(),
},
upnl: {
value: upnl,
usdValue: new Decimal(upnl)
.mul(baseAssetUsdPrice ?? 0)
.toNumber(),
},
rpnl: {
value: rpnl,
usdValue: new Decimal(rpnl)
.mul(baseAssetUsdPrice ?? 0)
.toNumber(),
},
value: {
value: userBalance.mul(price).div(ZTG).toNumber(),
usdValue: userBalance
.mul(price)
.mul(baseAssetUsdPrice ?? 0)
.div(ZTG)
.toNumber(),
},
change: isNaN(changePercentage)
? 0
: changePercentage.toFixed(1),
actions: (
<div className="text-right">
{IOPoolShareAssetId.is(assetId) ? (
<PoolShareButtons
poolId={assetId.PoolShare}
market={market}
/>
) : marketStage?.type === "Trading" &&
IOMarketOutcomeAssetId.is(assetId) ? (
<AssetTradingButtons assetId={assetId} />
) : marketStage?.type === "Resolved" ? (
<RedeemButton market={market} assetId={assetId} />
) : IOMarketOutcomeAssetId.is(assetId) &&
marketStage?.type === "Reported" ? (
<DisputeButton market={market} assetId={assetId} />
) : IOMarketOutcomeAssetId.is(assetId) &&
(marketStage?.type === "OpenReportingPeriod" ||
(marketStage?.type === "OracleReportingPeriod" &&
isOracle)) ? (
<ReportButton market={market} assetId={assetId} />
) : (
""
)}
</div>
),
};
},
)}
/>
</div>
);
// }

return <></>;
};
Expand Down
13 changes: 4 additions & 9 deletions lib/util/calc-resolved-market-prices.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FullMarketFragment, ScoringRule } from "@zeitgeistpm/indexer";
import { FullMarketFragment } from "@zeitgeistpm/indexer";
import Decimal from "decimal.js";
import { MarketPrices } from "lib/hooks/queries/useMarketSpotPrices";
import { calcScalarResolvedPrices } from "./calc-scalar-winnings";
Expand All @@ -8,14 +8,9 @@ import { IOBaseAssetId, MarketId } from "@zeitgeistpm/sdk";
export const calcResolvedMarketPrices = (
market: FullMarketFragment,
): MarketPrices => {
const assetIds = (
market.scoringRule === ScoringRule.AmmCdaHybrid ||
market.scoringRule === ScoringRule.Lmsr
? market.neoPool?.account.balances.map((b) =>
parseAssetIdString(b.assetId),
)
: market?.assets.map((a) => parseAssetIdString(a.assetId))
)?.filter((assetId) => IOBaseAssetId.is(assetId) === false);
const assetIds = market.assets
.map((a) => parseAssetIdString(a.assetId))
.filter((assetId) => IOBaseAssetId.is(assetId) === false);

const spotPrices: MarketPrices = new Map();

Expand Down
15 changes: 9 additions & 6 deletions pages/portfolio/[address].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ const Portfolio: NextPageWithLayout = () => {
(marketPositions) => {
const market = marketPositions[0].market;

marketPositions = marketPositions.filter((position) =>
position.userBalance.gt(0),
);
// marketPositions = marketPositions.filter((position) =>
// position.userBalance.gt(0),
// );

if (
market.status === "Resolved" &&
Expand All @@ -156,9 +156,12 @@ const Portfolio: NextPageWithLayout = () => {
className="mb-8"
market={market}
usdZtgPrice={ztgPrice}
positions={marketPositions.filter((position) =>
position.userBalance.gt(0),
)}
positions={
marketPositions
// .filter((position) =>
// position.userBalance.gt(0),
// )
}
/>
);
},
Expand Down

0 comments on commit eed02b2

Please sign in to comment.