From 4e4ffe8e20179fb4646483a4f974adbafa295137 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Fri, 22 Apr 2022 04:43:34 -0600 Subject: [PATCH] Sell either type of share for dpm market --- web/components/bet-row.tsx | 19 ++++++++++++++++--- web/components/sell-button.tsx | 21 +++++---------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/web/components/bet-row.tsx b/web/components/bet-row.tsx index dd1ba496..3deec388 100644 --- a/web/components/bet-row.tsx +++ b/web/components/bet-row.tsx @@ -23,7 +23,10 @@ export default function BetRow(props: { ) const user = useUser() const userBets = useUserContractBets(user?.id, contract.id) - const { yesFloorShares, noFloorShares } = useSaveShares(contract, userBets) + const { yesFloorShares, noFloorShares, yesShares, noShares } = useSaveShares( + contract, + userBets + ) return ( <> @@ -40,12 +43,22 @@ export default function BetRow(props: { }} replaceNoButton={ yesFloorShares > 0 ? ( - + ) : undefined } replaceYesButton={ noFloorShares > 0 ? ( - + ) : undefined } /> diff --git a/web/components/sell-button.tsx b/web/components/sell-button.tsx index 3b66d46a..0bccb631 100644 --- a/web/components/sell-button.tsx +++ b/web/components/sell-button.tsx @@ -2,7 +2,6 @@ import { Binary, CPMM, DPM, FullContract } from '../../common/contract' import { User } from '../../common/user' import { useUserContractBets } from '../hooks/use-user-bets' import { useState } from 'react' -import { useSaveShares } from './use-save-shares' import { Col } from './layout/col' import clsx from 'clsx' import { SellSharesModal } from './sell-modal' @@ -10,23 +9,13 @@ import { SellSharesModal } from './sell-modal' export function SellButton(props: { contract: FullContract user: User | null | undefined + sharesOutcome: 'YES' | 'NO' | undefined + shares: number }) { - const { contract, user } = props - + const { contract, user, sharesOutcome, shares } = props const userBets = useUserContractBets(user?.id, contract.id) const [showSellModal, setShowSellModal] = useState(false) - const { mechanism } = contract - const { yesFloorShares, noFloorShares, yesShares, noShares } = useSaveShares( - contract, - userBets - ) - const floorShares = yesFloorShares || noFloorShares - const sharesOutcome = yesFloorShares - ? 'YES' - : noFloorShares - ? 'NO' - : undefined if (sharesOutcome && user && mechanism === 'cpmm-1') { return ( @@ -45,14 +34,14 @@ export function SellButton(props: { {'Sell ' + sharesOutcome}
- {'(' + floorShares + ' shares)'} + {'(' + Math.floor(shares) + ' shares)'}
{showSellModal && ( } user={user} userBets={userBets ?? []} - shares={yesShares || noShares} + shares={shares} sharesOutcome={sharesOutcome} setOpen={setShowSellModal} />