Show market outcome
This commit is contained in:
parent
79e2cbefdc
commit
0ea0cecfc3
|
@ -39,6 +39,7 @@ CREATE EXTENSION "uuid-ossp";
|
|||
CREATE TABLE shares(
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
market_id INTEGER REFERENCES markets(id),
|
||||
win BOOLEAN,
|
||||
description TEXT NOT NULL
|
||||
);
|
||||
CREATE TYPE order_side AS ENUM ('BUY', 'SELL');
|
||||
|
|
|
@ -54,14 +54,14 @@ func (db *DB) FetchActiveMarkets(markets *[]Market) error {
|
|||
}
|
||||
|
||||
func (db *DB) FetchShares(marketId int, shares *[]Share) error {
|
||||
rows, err := db.Query("SELECT id, market_id, description FROM shares WHERE market_id = $1 ORDER BY description DESC", marketId)
|
||||
rows, err := db.Query("SELECT id, market_id, description, win FROM shares WHERE market_id = $1 ORDER BY description DESC", marketId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var share Share
|
||||
rows.Scan(&share.Id, &share.MarketId, &share.Description)
|
||||
rows.Scan(&share.Id, &share.MarketId, &share.Description, &share.Win)
|
||||
*shares = append(*shares, share)
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -37,6 +37,7 @@ type (
|
|||
Id UUID `json:"sid"`
|
||||
MarketId int
|
||||
Description string
|
||||
Win bool
|
||||
}
|
||||
Invoice struct {
|
||||
Id UUID
|
||||
|
|
|
@ -457,6 +457,11 @@ func HandleMarketSettlement(sc context.ServerContext) echo.HandlerFunc {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err = tx.ExecContext(ctx, "UPDATE shares SET win = (id = $1) WHERE market_id = $2", s.Id, marketId); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
|
||||
return c.JSON(http.StatusOK, nil)
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
|_| |_| |_|\__,_|_| |_|\_\___|\__|</pre>
|
||||
</div>
|
||||
<div class="font-mono">{{ market.Description }}</div>
|
||||
<div v-if="!!market.SettledAt" class="label error font-mono m-auto my-3">
|
||||
<div>Settled</div>
|
||||
<div v-if="!!market.SettledAt" class="label info font-mono m-auto my-3">
|
||||
<div>Settled: {{ winShareDescription }}</div>
|
||||
</div>
|
||||
<!-- eslint-enable -->
|
||||
<header class="flex flex-row text-center justify-center pt-1">
|
||||
|
@ -38,6 +38,7 @@ const marketId = route.params.id
|
|||
|
||||
const market = ref(null)
|
||||
const mine = ref(false)
|
||||
const winShareDescription = ref(null)
|
||||
const url = '/api/market/' + marketId
|
||||
await fetch(url)
|
||||
.then(r => r.json())
|
||||
|
@ -45,6 +46,11 @@ await fetch(url)
|
|||
market.value = body
|
||||
mine.value = market.value.Pubkey === session.pubkey
|
||||
})
|
||||
.then(() => {
|
||||
if (market.value.SettledAt) {
|
||||
winShareDescription.value = market.value.Shares.find(({ Win }) => Win).Description
|
||||
}
|
||||
})
|
||||
.catch(console.error)
|
||||
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue