Merge branch 'vscode_files' into automated-market-resolution
# Conflicts: # .vscode/settings.json
This commit is contained in:
commit
b1532f766a
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Attach to Chrome",
|
||||
"type": "chrome",
|
||||
"request": "attach",
|
||||
"port": 9222, // chrome needs to be started with the parameter "--remote-debugging-port=9222"
|
||||
"urlFilter": "http://localhost:3000/*",
|
||||
"webRoot": "${workspaceFolder}/web"
|
||||
}
|
||||
]
|
||||
}
|
11
.vscode/settings.json
vendored
11
.vscode/settings.json
vendored
|
@ -2,4 +2,15 @@
|
|||
"javascript.preferences.importModuleSpecifier": "shortest",
|
||||
"typescript.preferences.importModuleSpecifier": "shortest",
|
||||
"files.eol": "\r\n",
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
"search.exclude": {
|
||||
"**/node_modules": true,
|
||||
"**/package-lock.json": true,
|
||||
"**/yarn.lock": true
|
||||
},
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnPaste": true,
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
>>>>>>> vscode_files
|
||||
}
|
||||
|
|
|
@ -22,11 +22,14 @@ import TriangleFillIcon from 'web/lib/icons/triangle-fill-icon'
|
|||
import { Col } from '../layout/col'
|
||||
import { OUTCOME_TO_COLOR } from '../outcome-label'
|
||||
import { useSaveShares } from '../use-save-shares'
|
||||
import { sellShares } from 'web/lib/firebase/fn-call'
|
||||
import { calculateCpmmSale, getCpmmProbability } from 'common/calculate-cpmm'
|
||||
|
||||
const BET_SIZE = 10
|
||||
|
||||
export function QuickBet(props: { contract: Contract; user: User }) {
|
||||
const { contract, user } = props
|
||||
const isCpmm = contract.mechanism === 'cpmm-1'
|
||||
|
||||
const userBets = useUserContractBets(user.id, contract.id)
|
||||
const topAnswer =
|
||||
|
@ -35,7 +38,7 @@ export function QuickBet(props: { contract: Contract; user: User }) {
|
|||
: undefined
|
||||
|
||||
// TODO: yes/no from useSaveShares doesn't work on numeric contracts
|
||||
const { yesFloorShares, noFloorShares } = useSaveShares(
|
||||
const { yesFloorShares, noFloorShares, yesShares, noShares } = useSaveShares(
|
||||
contract,
|
||||
userBets,
|
||||
topAnswer?.number.toString() || undefined
|
||||
|
@ -68,8 +71,38 @@ export function QuickBet(props: { contract: Contract; user: User }) {
|
|||
// Catch any errors from hovering on an invalid option
|
||||
}
|
||||
|
||||
let sharesSold: number | undefined
|
||||
let sellOutcome: 'YES' | 'NO' | undefined
|
||||
let saleAmount: number | undefined
|
||||
if (isCpmm && (upHover || downHover)) {
|
||||
const oppositeShares = upHover ? noShares : yesShares
|
||||
if (oppositeShares) {
|
||||
sellOutcome = upHover ? 'NO' : 'YES'
|
||||
|
||||
const prob = getProb(contract)
|
||||
const maxSharesSold = BET_SIZE / (sellOutcome === 'YES' ? prob : 1 - prob)
|
||||
sharesSold = Math.min(oppositeShares, maxSharesSold)
|
||||
|
||||
const { newPool, saleValue } = calculateCpmmSale(
|
||||
contract,
|
||||
sharesSold,
|
||||
sellOutcome
|
||||
)
|
||||
saleAmount = saleValue
|
||||
previewProb = getCpmmProbability(newPool, contract.p)
|
||||
}
|
||||
}
|
||||
|
||||
async function placeQuickBet(direction: 'UP' | 'DOWN') {
|
||||
const betPromise = async () => {
|
||||
if (sharesSold && sellOutcome) {
|
||||
return await sellShares({
|
||||
shares: sharesSold,
|
||||
outcome: sellOutcome,
|
||||
contractId: contract.id,
|
||||
})
|
||||
}
|
||||
|
||||
const outcome = quickOutcome(contract, direction)
|
||||
return await placeBet({
|
||||
amount: BET_SIZE,
|
||||
|
@ -78,9 +111,14 @@ export function QuickBet(props: { contract: Contract; user: User }) {
|
|||
})
|
||||
}
|
||||
const shortQ = contract.question.slice(0, 20)
|
||||
const message =
|
||||
sellOutcome && saleAmount
|
||||
? `${formatMoney(saleAmount)} sold of "${shortQ}"...`
|
||||
: `${formatMoney(BET_SIZE)} on "${shortQ}"...`
|
||||
|
||||
toast.promise(betPromise(), {
|
||||
loading: `${formatMoney(BET_SIZE)} on "${shortQ}"...`,
|
||||
success: `${formatMoney(BET_SIZE)} on "${shortQ}"...`,
|
||||
loading: message,
|
||||
success: message,
|
||||
error: (err) => `${err.message}`,
|
||||
})
|
||||
}
|
||||
|
@ -142,6 +180,14 @@ export function QuickBet(props: { contract: Contract; user: User }) {
|
|||
<QuickOutcomeView contract={contract} previewProb={previewProb} />
|
||||
|
||||
{/* Down bet triangle */}
|
||||
{contract.outcomeType !== 'BINARY' ? (
|
||||
<div>
|
||||
<div className="peer absolute bottom-0 left-0 right-0 h-[50%] cursor-default"></div>
|
||||
<TriangleDownFillIcon
|
||||
className={clsx('mx-auto h-5 w-5 text-gray-200')}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<div
|
||||
className="peer absolute bottom-0 left-0 right-0 h-[50%]"
|
||||
|
@ -168,6 +214,7 @@ export function QuickBet(props: { contract: Contract; user: User }) {
|
|||
{formatMoney(10)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Col>
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user