From 75b39cbf6f00d032edc648d6bf29610cc3101633 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 13 Apr 2022 12:52:12 -0500 Subject: [PATCH] Remove loans: no new loans --- functions/src/create-answer.ts | 2 +- functions/src/place-bet.ts | 4 +- web/components/amount-input.tsx | 55 +------------------ web/components/answers/answer-bet-panel.tsx | 4 -- .../answers/create-answer-panel.tsx | 1 - web/components/bet-panel.tsx | 2 - web/pages/make-predictions.tsx | 1 - 7 files changed, 6 insertions(+), 63 deletions(-) diff --git a/functions/src/create-answer.ts b/functions/src/create-answer.ts index fbde2666..4bbfb089 100644 --- a/functions/src/create-answer.ts +++ b/functions/src/create-answer.ts @@ -103,7 +103,7 @@ export const createAnswer = functions.runWith({ minInstances: 1 }).https.onCall( .collection(`contracts/${contractId}/bets`) .doc() - const loanAmount = getLoanAmount(yourBets, amount) + const loanAmount = 0 // getLoanAmount(yourBets, amount) const { newBet, newPool, newTotalShares, newTotalBets, newBalance } = getNewMultiBetInfo( diff --git a/functions/src/place-bet.ts b/functions/src/place-bet.ts index 68789096..74487126 100644 --- a/functions/src/place-bet.ts +++ b/functions/src/place-bet.ts @@ -59,8 +59,8 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall( ) const yourBets = yourBetsSnap.docs.map((doc) => doc.data() as Bet) - const loanAmount = getLoanAmount(yourBets, amount) - if (user.balance < amount - loanAmount) + const loanAmount = 0 // getLoanAmount(yourBets, amount) + if (user.balance < amount) return { status: 'error', message: 'Insufficient balance' } if (outcomeType === 'FREE_RESPONSE') { diff --git a/web/components/amount-input.tsx b/web/components/amount-input.tsx index 3ea4d2d9..79bd32ad 100644 --- a/web/components/amount-input.tsx +++ b/web/components/amount-input.tsx @@ -4,8 +4,7 @@ import { useUser } from '../hooks/use-user' import { formatMoney, formatWithCommas } from '../../common/util/format' import { Col } from './layout/col' import { Row } from './layout/row' -import { Bet, MAX_LOAN_PER_CONTRACT } from '../../common/bet' -import { InfoTooltip } from './info-tooltip' +import { Bet } from '../../common/bet' import { Spacer } from './layout/spacer' import { calculateCpmmSale } from '../../common/calculate-cpmm' import { Binary, CPMM, FullContract } from '../../common/contract' @@ -80,8 +79,6 @@ export function BuyAmountInput(props: { onChange: (newAmount: number | undefined) => void error: string | undefined setError: (error: string | undefined) => void - contractIdForLoan: string | undefined - userBets?: Bet[] minimumAmount?: number disabled?: boolean className?: string @@ -92,10 +89,8 @@ export function BuyAmountInput(props: { const { amount, onChange, - userBets, error, setError, - contractIdForLoan, disabled, className, inputClassName, @@ -105,23 +100,12 @@ export function BuyAmountInput(props: { 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) => { onChange(amount) // Check for errors. if (amount !== undefined) { - const amountNetLoan = amount - loanAmount - - if (user && user.balance < amountNetLoan) { + if (user && user.balance < amount) { setError('Insufficient balance') } else if (minimumAmount && amount < minimumAmount) { setError('Minimum amount: ' + formatMoney(minimumAmount)) @@ -141,25 +125,7 @@ export function BuyAmountInput(props: { className={className} inputClassName={inputClassName} inputRef={inputRef} - > - {user && ( - - {contractIdForLoan && ( - - - Amount loaned{' '} - - - {formatMoney(loanAmount)}{' '} - - )} - - )} - + /> ) } @@ -204,8 +170,6 @@ export function SellAmountInput(props: { const sellOutcome = yesShares ? 'YES' : noShares ? 'NO' : undefined const shares = yesShares || noShares - const prevLoanAmount = _.sumBy(openUserBets, (bet) => bet.loanAmount ?? 0) - const sharesSold = Math.min(amount ?? 0, yesShares || noShares) const { saleValue } = calculateCpmmSale( contract, @@ -213,8 +177,6 @@ export function SellAmountInput(props: { sellOutcome as 'YES' | 'NO' ) - const loanRepaid = Math.min(prevLoanAmount, saleValue) - const onAmountChange = (amount: number | undefined) => { onChange(amount) @@ -245,17 +207,6 @@ export function SellAmountInput(props: { Sale proceeds{' '} {formatMoney(saleValue)} - {!!prevLoanAmount && ( - - - Loan repaid{' '} - - - {formatMoney(loanRepaid)}{' '} - - )} )} diff --git a/web/components/answers/answer-bet-panel.tsx b/web/components/answers/answer-bet-panel.tsx index 5470d0e3..e1ecfab4 100644 --- a/web/components/answers/answer-bet-panel.tsx +++ b/web/components/answers/answer-bet-panel.tsx @@ -25,7 +25,6 @@ import { } from '../../../common/calculate-dpm' import { firebaseLogin } from '../../lib/firebase/users' import { Bet } from '../../../common/bet' -import { useUserContractBets } from '../../hooks/use-user-bets' export function AnswerBetPanel(props: { answer: Answer @@ -38,7 +37,6 @@ export function AnswerBetPanel(props: { const { id: answerId } = answer const user = useUser() - const userBets = useUserContractBets(user?.id, contract.id) const [betAmount, setBetAmount] = useState(undefined) const [error, setError] = useState() @@ -124,8 +122,6 @@ export function AnswerBetPanel(props: { setError={setError} disabled={isSubmitting} inputRef={inputRef} - contractIdForLoan={contract.id} - userBets={userBets} /> diff --git a/web/components/answers/create-answer-panel.tsx b/web/components/answers/create-answer-panel.tsx index c140e0be..3aa3c0cd 100644 --- a/web/components/answers/create-answer-panel.tsx +++ b/web/components/answers/create-answer-panel.tsx @@ -104,7 +104,6 @@ export function CreateAnswerPanel(props: { setError={setAmountError} minimumAmount={1} disabled={isSubmitting} - contractIdForLoan={contract.id} /> diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx index d196e410..4828913c 100644 --- a/web/components/bet-panel.tsx +++ b/web/components/bet-panel.tsx @@ -327,12 +327,10 @@ function BuyPanel(props: { inputClassName="w-full" amount={betAmount} onChange={onBetChange} - userBets={userBets} error={error} setError={setError} disabled={isSubmitting} inputRef={inputRef} - contractIdForLoan={contract.id} /> diff --git a/web/pages/make-predictions.tsx b/web/pages/make-predictions.tsx index 60144386..fa7ef5c7 100644 --- a/web/pages/make-predictions.tsx +++ b/web/pages/make-predictions.tsx @@ -248,7 +248,6 @@ ${TEST_VALUE} error={anteError} setError={setAnteError} disabled={isSubmitting} - contractIdForLoan={undefined} />