- {props.buttonOnly ? (
-
+
+
+
+ You have {formatWithCommas(floorShares)}{' '}
+ {' '}
+ shares
+
+
-
- {'(' + shares + ' shares)'}
-
-
- ) : (
-
-
-
- You have {formatWithCommas(shares)}{' '}
- {' '}
- shares
-
-
-
-
-
- )}
+
+
{showSellModal && (
}
- user={props.user}
+ contract={contract as FullContract}
+ user={user}
userBets={userBets ?? []}
- shares={shares}
+ shares={yesShares || noShares}
sharesOutcome={sharesOutcome}
setOpen={setShowSellModal}
/>
@@ -98,7 +77,63 @@ export function SellRow(props: {
)
}
- return
+ return
+}
+
+export function SellButton(props: {
+ contract: FullContract
+ user: User | null | undefined
+}) {
+ const { contract, user } = 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 (
+
+
+
+ {'(' + floorShares + ' shares)'}
+
+ {showSellModal && (
+ }
+ user={user}
+ userBets={userBets ?? []}
+ shares={yesShares || noShares}
+ sharesOutcome={sharesOutcome}
+ setOpen={setShowSellModal}
+ />
+ )}
+
+ )
+ }
+ return
}
function SellSharesModal(props: {
@@ -120,7 +155,7 @@ function SellSharesModal(props: {
You have {formatWithCommas(Math.floor(shares))}{' '}
{' '}
shares