Remove loans: no new loans
This commit is contained in:
parent
6ac361fdb9
commit
75b39cbf6f
|
@ -103,7 +103,7 @@ export const createAnswer = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
.collection(`contracts/${contractId}/bets`)
|
.collection(`contracts/${contractId}/bets`)
|
||||||
.doc()
|
.doc()
|
||||||
|
|
||||||
const loanAmount = getLoanAmount(yourBets, amount)
|
const loanAmount = 0 // getLoanAmount(yourBets, amount)
|
||||||
|
|
||||||
const { newBet, newPool, newTotalShares, newTotalBets, newBalance } =
|
const { newBet, newPool, newTotalShares, newTotalBets, newBalance } =
|
||||||
getNewMultiBetInfo(
|
getNewMultiBetInfo(
|
||||||
|
|
|
@ -59,8 +59,8 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
)
|
)
|
||||||
const yourBets = yourBetsSnap.docs.map((doc) => doc.data() as Bet)
|
const yourBets = yourBetsSnap.docs.map((doc) => doc.data() as Bet)
|
||||||
|
|
||||||
const loanAmount = getLoanAmount(yourBets, amount)
|
const loanAmount = 0 // getLoanAmount(yourBets, amount)
|
||||||
if (user.balance < amount - loanAmount)
|
if (user.balance < amount)
|
||||||
return { status: 'error', message: 'Insufficient balance' }
|
return { status: 'error', message: 'Insufficient balance' }
|
||||||
|
|
||||||
if (outcomeType === 'FREE_RESPONSE') {
|
if (outcomeType === 'FREE_RESPONSE') {
|
||||||
|
|
|
@ -4,8 +4,7 @@ import { useUser } from '../hooks/use-user'
|
||||||
import { formatMoney, formatWithCommas } from '../../common/util/format'
|
import { formatMoney, formatWithCommas } from '../../common/util/format'
|
||||||
import { Col } from './layout/col'
|
import { Col } from './layout/col'
|
||||||
import { Row } from './layout/row'
|
import { Row } from './layout/row'
|
||||||
import { Bet, MAX_LOAN_PER_CONTRACT } from '../../common/bet'
|
import { Bet } from '../../common/bet'
|
||||||
import { InfoTooltip } from './info-tooltip'
|
|
||||||
import { Spacer } from './layout/spacer'
|
import { Spacer } from './layout/spacer'
|
||||||
import { calculateCpmmSale } from '../../common/calculate-cpmm'
|
import { calculateCpmmSale } from '../../common/calculate-cpmm'
|
||||||
import { Binary, CPMM, FullContract } from '../../common/contract'
|
import { Binary, CPMM, FullContract } from '../../common/contract'
|
||||||
|
@ -80,8 +79,6 @@ export function BuyAmountInput(props: {
|
||||||
onChange: (newAmount: number | undefined) => void
|
onChange: (newAmount: number | undefined) => void
|
||||||
error: string | undefined
|
error: string | undefined
|
||||||
setError: (error: string | undefined) => void
|
setError: (error: string | undefined) => void
|
||||||
contractIdForLoan: string | undefined
|
|
||||||
userBets?: Bet[]
|
|
||||||
minimumAmount?: number
|
minimumAmount?: number
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
className?: string
|
className?: string
|
||||||
|
@ -92,10 +89,8 @@ export function BuyAmountInput(props: {
|
||||||
const {
|
const {
|
||||||
amount,
|
amount,
|
||||||
onChange,
|
onChange,
|
||||||
userBets,
|
|
||||||
error,
|
error,
|
||||||
setError,
|
setError,
|
||||||
contractIdForLoan,
|
|
||||||
disabled,
|
disabled,
|
||||||
className,
|
className,
|
||||||
inputClassName,
|
inputClassName,
|
||||||
|
@ -105,23 +100,12 @@ export function BuyAmountInput(props: {
|
||||||
|
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
|
|
||||||
const openUserBets = (userBets ?? []).filter(
|
|
||||||
(bet) => !bet.isSold && !bet.sale
|
|
||||||
)
|
|
||||||
const prevLoanAmount = _.sumBy(openUserBets, (bet) => bet.loanAmount ?? 0)
|
|
||||||
|
|
||||||
const loanAmount = contractIdForLoan
|
|
||||||
? Math.min(amount ?? 0, MAX_LOAN_PER_CONTRACT - prevLoanAmount)
|
|
||||||
: 0
|
|
||||||
|
|
||||||
const onAmountChange = (amount: number | undefined) => {
|
const onAmountChange = (amount: number | undefined) => {
|
||||||
onChange(amount)
|
onChange(amount)
|
||||||
|
|
||||||
// Check for errors.
|
// Check for errors.
|
||||||
if (amount !== undefined) {
|
if (amount !== undefined) {
|
||||||
const amountNetLoan = amount - loanAmount
|
if (user && user.balance < amount) {
|
||||||
|
|
||||||
if (user && user.balance < amountNetLoan) {
|
|
||||||
setError('Insufficient balance')
|
setError('Insufficient balance')
|
||||||
} else if (minimumAmount && amount < minimumAmount) {
|
} else if (minimumAmount && amount < minimumAmount) {
|
||||||
setError('Minimum amount: ' + formatMoney(minimumAmount))
|
setError('Minimum amount: ' + formatMoney(minimumAmount))
|
||||||
|
@ -141,25 +125,7 @@ export function BuyAmountInput(props: {
|
||||||
className={className}
|
className={className}
|
||||||
inputClassName={inputClassName}
|
inputClassName={inputClassName}
|
||||||
inputRef={inputRef}
|
inputRef={inputRef}
|
||||||
>
|
|
||||||
{user && (
|
|
||||||
<Col className="gap-3 text-sm">
|
|
||||||
{contractIdForLoan && (
|
|
||||||
<Row className="items-center justify-between gap-2 text-gray-500">
|
|
||||||
<Row className="items-center gap-2">
|
|
||||||
Amount loaned{' '}
|
|
||||||
<InfoTooltip
|
|
||||||
text={`In every market, you get an interest-free loan on the first ${formatMoney(
|
|
||||||
MAX_LOAN_PER_CONTRACT
|
|
||||||
)}.`}
|
|
||||||
/>
|
/>
|
||||||
</Row>
|
|
||||||
<span className="text-neutral">{formatMoney(loanAmount)}</span>{' '}
|
|
||||||
</Row>
|
|
||||||
)}
|
|
||||||
</Col>
|
|
||||||
)}
|
|
||||||
</AmountInput>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,8 +170,6 @@ export function SellAmountInput(props: {
|
||||||
const sellOutcome = yesShares ? 'YES' : noShares ? 'NO' : undefined
|
const sellOutcome = yesShares ? 'YES' : noShares ? 'NO' : undefined
|
||||||
const shares = yesShares || noShares
|
const shares = yesShares || noShares
|
||||||
|
|
||||||
const prevLoanAmount = _.sumBy(openUserBets, (bet) => bet.loanAmount ?? 0)
|
|
||||||
|
|
||||||
const sharesSold = Math.min(amount ?? 0, yesShares || noShares)
|
const sharesSold = Math.min(amount ?? 0, yesShares || noShares)
|
||||||
const { saleValue } = calculateCpmmSale(
|
const { saleValue } = calculateCpmmSale(
|
||||||
contract,
|
contract,
|
||||||
|
@ -213,8 +177,6 @@ export function SellAmountInput(props: {
|
||||||
sellOutcome as 'YES' | 'NO'
|
sellOutcome as 'YES' | 'NO'
|
||||||
)
|
)
|
||||||
|
|
||||||
const loanRepaid = Math.min(prevLoanAmount, saleValue)
|
|
||||||
|
|
||||||
const onAmountChange = (amount: number | undefined) => {
|
const onAmountChange = (amount: number | undefined) => {
|
||||||
onChange(amount)
|
onChange(amount)
|
||||||
|
|
||||||
|
@ -245,17 +207,6 @@ export function SellAmountInput(props: {
|
||||||
Sale proceeds{' '}
|
Sale proceeds{' '}
|
||||||
<span className="text-neutral">{formatMoney(saleValue)}</span>
|
<span className="text-neutral">{formatMoney(saleValue)}</span>
|
||||||
</Row>
|
</Row>
|
||||||
{!!prevLoanAmount && (
|
|
||||||
<Row className="items-center justify-between gap-2 text-gray-500">
|
|
||||||
<Row className="items-center gap-2">
|
|
||||||
Loan repaid{' '}
|
|
||||||
<InfoTooltip
|
|
||||||
text={`Sold shares go toward paying off loans first.`}
|
|
||||||
/>
|
|
||||||
</Row>
|
|
||||||
<span className="text-neutral">{formatMoney(loanRepaid)}</span>{' '}
|
|
||||||
</Row>
|
|
||||||
)}
|
|
||||||
</Col>
|
</Col>
|
||||||
)}
|
)}
|
||||||
</AmountInput>
|
</AmountInput>
|
||||||
|
|
|
@ -25,7 +25,6 @@ import {
|
||||||
} from '../../../common/calculate-dpm'
|
} from '../../../common/calculate-dpm'
|
||||||
import { firebaseLogin } from '../../lib/firebase/users'
|
import { firebaseLogin } from '../../lib/firebase/users'
|
||||||
import { Bet } from '../../../common/bet'
|
import { Bet } from '../../../common/bet'
|
||||||
import { useUserContractBets } from '../../hooks/use-user-bets'
|
|
||||||
|
|
||||||
export function AnswerBetPanel(props: {
|
export function AnswerBetPanel(props: {
|
||||||
answer: Answer
|
answer: Answer
|
||||||
|
@ -38,7 +37,6 @@ export function AnswerBetPanel(props: {
|
||||||
const { id: answerId } = answer
|
const { id: answerId } = answer
|
||||||
|
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
const userBets = useUserContractBets(user?.id, contract.id)
|
|
||||||
const [betAmount, setBetAmount] = useState<number | undefined>(undefined)
|
const [betAmount, setBetAmount] = useState<number | undefined>(undefined)
|
||||||
|
|
||||||
const [error, setError] = useState<string | undefined>()
|
const [error, setError] = useState<string | undefined>()
|
||||||
|
@ -124,8 +122,6 @@ export function AnswerBetPanel(props: {
|
||||||
setError={setError}
|
setError={setError}
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
inputRef={inputRef}
|
inputRef={inputRef}
|
||||||
contractIdForLoan={contract.id}
|
|
||||||
userBets={userBets}
|
|
||||||
/>
|
/>
|
||||||
<Col className="mt-3 w-full gap-3">
|
<Col className="mt-3 w-full gap-3">
|
||||||
<Row className="items-center justify-between text-sm">
|
<Row className="items-center justify-between text-sm">
|
||||||
|
|
|
@ -104,7 +104,6 @@ export function CreateAnswerPanel(props: {
|
||||||
setError={setAmountError}
|
setError={setAmountError}
|
||||||
minimumAmount={1}
|
minimumAmount={1}
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
contractIdForLoan={contract.id}
|
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
<Col className="gap-3">
|
<Col className="gap-3">
|
||||||
|
|
|
@ -327,12 +327,10 @@ function BuyPanel(props: {
|
||||||
inputClassName="w-full"
|
inputClassName="w-full"
|
||||||
amount={betAmount}
|
amount={betAmount}
|
||||||
onChange={onBetChange}
|
onChange={onBetChange}
|
||||||
userBets={userBets}
|
|
||||||
error={error}
|
error={error}
|
||||||
setError={setError}
|
setError={setError}
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
inputRef={inputRef}
|
inputRef={inputRef}
|
||||||
contractIdForLoan={contract.id}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Col className="mt-3 w-full gap-3">
|
<Col className="mt-3 w-full gap-3">
|
||||||
|
|
|
@ -248,7 +248,6 @@ ${TEST_VALUE}
|
||||||
error={anteError}
|
error={anteError}
|
||||||
setError={setAnteError}
|
setError={setAnteError}
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
contractIdForLoan={undefined}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user