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

New asset systems fixes + New indexer schema #2383

Merged
merged 10 commits into from
Apr 18, 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
59 changes: 17 additions & 42 deletions components/assets/AssetActionButtons/PoolShareButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import LiquidityModal from "components/liquidity/LiquidityModal";
import SecondaryButton from "components/ui/SecondaryButton";
import { usePool } from "lib/hooks/queries/usePool";
import { useState } from "react";
import { MarketStatus, FullMarketFragment } from "@zeitgeistpm/indexer";
import { useExtrinsic } from "lib/hooks/useExtrinsic";
import { useNotifications } from "lib/state/notifications";
import { useSdkv2 } from "lib/hooks/useSdkv2";
import { FullMarketFragment } from "@zeitgeistpm/indexer";
import {
IOBaseAssetId,
IOCategoricalAssetId,
getIndexOf,
isRpcSdk,
parseAssetId,
} from "@zeitgeistpm/sdk";
import { useChainConstants } from "lib/hooks/queries/useChainConstants";
import { useBalance } from "lib/hooks/queries/useBalance";
import { useWallet } from "lib/state/wallet";
import SecondaryButton from "components/ui/SecondaryButton";
import Decimal from "decimal.js";
import { DEFAULT_SLIPPAGE_PERCENTAGE } from "lib/constants";
import { useAccountPoolAssetBalances } from "lib/hooks/queries/useAccountPoolAssetBalances";
import { useBalance } from "lib/hooks/queries/useBalance";
import { useChainConstants } from "lib/hooks/queries/useChainConstants";
import { usePool } from "lib/hooks/queries/usePool";
import { usePoolBaseBalance } from "lib/hooks/queries/usePoolBaseBalance";
import { DEFAULT_SLIPPAGE_PERCENTAGE } from "lib/constants";
import { useTotalIssuance } from "lib/hooks/queries/useTotalIssuance";
import Decimal from "decimal.js";
import { useTotalIssuanceForPools } from "lib/hooks/queries/useTotalIssuanceForPools";
import { useExtrinsic } from "lib/hooks/useExtrinsic";
import { useSdkv2 } from "lib/hooks/useSdkv2";
import { useNotifications } from "lib/state/notifications";
import { useWallet } from "lib/state/wallet";
import { parseAssetIdString } from "lib/util/parse-asset-id";

const RedeemPoolButton = ({
Expand All @@ -43,12 +41,11 @@ const RedeemPoolButton = ({
pool,
);
const { data: poolBaseBalance } = usePoolBaseBalance(poolId);
const { data: totalPoolSharesIssuance } = useTotalIssuance({
PoolShare: poolId,
});
const poolsTotalIssuance = useTotalIssuanceForPools([poolId]);
const { data: totalPoolSharesIssuance } = poolsTotalIssuance[poolId];
const userPercentageOwnership =
userPoolShares && totalPoolSharesIssuance
? userPoolShares.div(totalPoolSharesIssuance)
userPoolShares && totalPoolSharesIssuance?.totalIssuance
? userPoolShares.div(totalPoolSharesIssuance.totalIssuance.toNumber())
: new Decimal(0);

// filter out non-winning assets as they are deleted on chain
Expand Down Expand Up @@ -144,29 +141,7 @@ const PoolShareButtons = ({
poolId: number;
market: FullMarketFragment;
}) => {
const [manageLiquidityOpen, setManageLiquidityOpen] = useState(false);

return (
<>
{market.status === MarketStatus.Resolved ? (
<RedeemPoolButton poolId={poolId} market={market} />
) : (
<>
<SecondaryButton
onClick={() => setManageLiquidityOpen(true)}
className="ml-auto max-w-[160px]"
>
Manage Liquidity
</SecondaryButton>
<LiquidityModal
poolId={poolId}
open={manageLiquidityOpen}
onClose={() => setManageLiquidityOpen(false)}
/>
</>
)}
</>
);
return <RedeemPoolButton poolId={poolId} market={market} />;
};

export default PoolShareButtons;
10 changes: 6 additions & 4 deletions components/assets/AssetActionButtons/RedeemButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const RedeemButtonByAssetId = ({

const balance = getAccountAssetBalance(realAddress, resolvedAssetId)?.data
?.balance;
return new Decimal(balance?.free.toString() ?? 0).div(ZTG);
return balance?.div(ZTG);
} else {
const shortBalance = getAccountAssetBalance(realAddress, {
ScalarOutcome: [market.marketId as MarketId, "Short"],
Expand All @@ -107,13 +107,15 @@ export const RedeemButtonByAssetId = ({
lowerBound,
upperBound,
new Decimal(resolvedNumber).div(ZTG),
new Decimal(shortBalance.free.toNumber()).div(ZTG),
new Decimal(longBalance.free.toNumber()).div(ZTG),
shortBalance.div(ZTG),
longBalance.div(ZTG),
);
}
}, [market, assetId, isLoadingAssetBalance, getAccountAssetBalance]);

return <RedeemButtonByValue market={market} value={value} />;
return (
<RedeemButtonByValue market={market} value={value ?? new Decimal(0)} />
);
};

const RedeemButtonByValue = ({
Expand Down
274 changes: 0 additions & 274 deletions components/liquidity/ExitPoolForm.tsx

This file was deleted.

Loading
Loading