Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release fixes #2441

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading