From ffd1e233c88b8ded4a5737ebd3a886bece0776a5 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Thu, 2 Dec 2021 01:37:15 -0600 Subject: [PATCH] Preview bid return before submission --- market-simulator/src/components/EntryRow.vue | 40 ++++++++++++++++ market-simulator/src/components/Simulator.vue | 47 +++++++++++-------- market-simulator/src/components/entries.ts | 2 +- 3 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 market-simulator/src/components/EntryRow.vue diff --git a/market-simulator/src/components/EntryRow.vue b/market-simulator/src/components/EntryRow.vue new file mode 100644 index 00000000..e18622dc --- /dev/null +++ b/market-simulator/src/components/EntryRow.vue @@ -0,0 +1,40 @@ + + + + diff --git a/market-simulator/src/components/Simulator.vue b/market-simulator/src/components/Simulator.vue index af74ad14..8d8ae021 100644 --- a/market-simulator/src/components/Simulator.vue +++ b/market-simulator/src/components/Simulator.vue @@ -58,14 +58,16 @@ placeholder="0" class="input input-bordered" @focus="$event.target.select()" + @keyup.enter="submitBid" /> - X - X - X - X + - @@ -92,27 +94,16 @@ + @@ -142,6 +133,7 @@ import { bids as sampleBids } from './sample-bids' import { makeEntries } from './entries' import { ref, computed } from '@vue/reactivity' import { onMounted, watch } from '@vue/runtime-core' +import EntryRow from './EntryRow.vue' // Copy over the sample bids to seed the simulation const bids = sampleBids.slice() @@ -197,12 +189,29 @@ function toggleBidType() { newBidType.value = newBidType.value === 'YES' ? 'NO' : 'YES' } -function submitBid() { - const bid = { +function makeBid(type: string, bid: number) { + return { yesBid: newBidType.value == 'YES' ? newBid.value : 0, noBid: newBidType.value == 'YES' ? 0 : newBid.value, } +} + +function submitBid() { + if (newBid.value <= 0) return + const bid = makeBid(newBidType.value, newBid.value) bids.splice(steps.value, 0, bid) steps.value++ + newBid.value = 0 } + +// Preview the next bid before it's added +const nextEntry = computed(() => { + if (newBid.value) { + const nextBid = makeBid(newBidType.value, newBid.value) + const fakeBids = [...bids.slice(0, steps.value), nextBid] + const entries = makeEntries(fakeBids) + return entries[entries.length - 1] + } + return null +}) diff --git a/market-simulator/src/components/entries.ts b/market-simulator/src/components/entries.ts index dc907fe6..6f9103bf 100644 --- a/market-simulator/src/components/entries.ts +++ b/market-simulator/src/components/entries.ts @@ -1,7 +1,7 @@ type Bid = { yesBid: number; noBid: number } // An entry has a yes/no for bid, weight, payout, return. Also a current probability -type Entry = { +export type Entry = { yesBid: number noBid: number yesWeight: number