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