Compare commits

...

2 Commits

Author SHA1 Message Date
ekzyis fe8c55815d Limit y to 0..1 2024-10-03 09:23:35 -05:00
ekzyis 1e9c33bc89 Colorize potential earn 2024-10-02 16:40:58 -05:00
2 changed files with 27 additions and 11 deletions

View File

@ -20,7 +20,7 @@ const element = document.getElementById('chart')
function transformPoint({ X, Y }) {
return { x: new Date(X), y: Y * 100 }
return { x: new Date(X), y: Y }
}
const no = JSON.parse($("#chart-data").getAttribute("chart-data-p0")).map(transformPoint)
@ -55,8 +55,10 @@ const config = {
time: { unit: 'month' }
},
y: {
display: true,
text: 'price',
min: 0,
max: 100
max: 1
}
}
}

View File

@ -4,6 +4,7 @@ import (
"fmt"
"git.ekzyis.com/ekzyis/delphi.market/types"
"strconv"
"math"
)
templ MarketForm(m types.Market, outcome int, q types.MarketQuote, uQ int) {
@ -18,14 +19,16 @@ templ MarketForm(m types.Market, outcome int, q types.MarketQuote, uQ int) {
>
<input type="hidden" name="o" value={ fmt.Sprint(outcome) }/>
<div class="none col-span-2 htmx-request"></div>
<label for="p">avg price per share:</label>
<div id="p">{ formatPrice(q.AvgPrice) }</div>
<label for="q">how many?</label>
<label for="p">price:</label>
<div id="p">{ formatPrice(q.AvgPrice, 3) }</div>
<label for="q">shares:</label>
<input
id={ inputId(outcome) }
name="q"
class="text-black px-1"
type="number"
step="100"
min="0"
autofocus
hx-get={ fmt.Sprintf("/market/%d", m.Id) }
hx-replace-url="true"
@ -37,10 +40,10 @@ templ MarketForm(m types.Market, outcome int, q types.MarketQuote, uQ int) {
hx-disabled-elt="next button"
hx-indicator={ hxIndicator(outcome) }
/>
<label for="total">you pay:</label>
<div id="total">{ formatPrice(q.TotalPrice) }</div>
<label for="reward">{ "if you win:" }</label>
<div id="reward">+{ formatPrice(q.Reward) }</div>
<label for="total">total:</label>
<div id="total">{ formatPrice(q.TotalPrice, 3) }</div>
<label for="reward">{ "potential earn:" }</label>
<span id="reward" class={ colorize(q.Reward) }>+{ formatPrice(q.Reward, 3) }</span>
<label for="uQ">you have:</label>
<div id="uQ">{ fmt.Sprint(uQ) }</div>
<button type="submit" class="col-span-2">submit</button>
@ -61,6 +64,17 @@ func hxIndicator(outcome int) string {
formId(outcome), formId(outcome), formId(outcome))
}
func formatPrice(p float64) string {
return fmt.Sprintf("%v sats", strconv.FormatFloat(p, 'f', 3, 64))
func formatPrice(p float64, n int) string {
if p == 0 || math.IsNaN(p) {
return "0 sats"
}
return fmt.Sprintf("%v sats", strconv.FormatFloat(p, 'f', n, 64))
}
func colorize(f float64) string {
eps := 1e-5
if f-eps > 0 {
return "text-success"
}
return "text-reset"
}