From 8098daab8c75036f7ce127cd70fdfb2d094a4572 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 28 Nov 2023 22:10:16 +0100 Subject: [PATCH] Highlight matching orders --- db/market.go | 4 ++-- db/types.go | 1 + vue/src/components/MarketOrders.vue | 15 ++++++++++++++- vue/src/components/OrderRow.vue | 25 +++++++++++++++++++++++-- vue/src/components/UserInvoices.vue | 4 ++++ 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/db/market.go b/db/market.go index d35bd32..87d2f1d 100644 --- a/db/market.go +++ b/db/market.go @@ -149,7 +149,7 @@ func (db *DB) FetchUserOrders(pubkey string, orders *[]Order) error { func (db *DB) FetchMarketOrders(marketId int64, orders *[]Order) error { query := "" + "SELECT o.id, share_id, o.pubkey, o.side, o.quantity, o.price, o.invoice_id, o.created_at, s.description, s.market_id, " + - "CASE WHEN o.order_id IS NOT NULL THEN 'EXECUTED' ELSE 'PENDING' END AS status " + + "CASE WHEN o.order_id IS NOT NULL THEN 'EXECUTED' ELSE 'PENDING' END AS status, o.order_id " + "FROM orders o " + "JOIN shares s ON o.share_id = s.id " + "JOIN invoices i ON i.id = o.invoice_id " + @@ -162,7 +162,7 @@ func (db *DB) FetchMarketOrders(marketId int64, orders *[]Order) error { defer rows.Close() for rows.Next() { var order Order - rows.Scan(&order.Id, &order.ShareId, &order.Pubkey, &order.Side, &order.Quantity, &order.Price, &order.InvoiceId, &order.CreatedAt, &order.ShareDescription, &order.Share.MarketId, &order.Status) + rows.Scan(&order.Id, &order.ShareId, &order.Pubkey, &order.Side, &order.Quantity, &order.Price, &order.InvoiceId, &order.CreatedAt, &order.ShareDescription, &order.Share.MarketId, &order.Status, &order.OrderId) *orders = append(*orders, order) } return nil diff --git a/db/types.go b/db/types.go index 9e64896..80ae160 100644 --- a/db/types.go +++ b/db/types.go @@ -61,5 +61,6 @@ type ( Price int64 `json:"price"` InvoiceId UUID Invoice + OrderId UUID } ) diff --git a/vue/src/components/MarketOrders.vue b/vue/src/components/MarketOrders.vue index 2a728f8..5b33714 100644 --- a/vue/src/components/MarketOrders.vue +++ b/vue/src/components/MarketOrders.vue @@ -7,7 +7,8 @@ status - + @@ -21,6 +22,18 @@ import OrderRow from './OrderRow.vue' const route = useRoute() const marketId = route.params.id +const selected = ref([]) + +function mouseover (oid) { + const o2id = orders.value.find(i => i.OrderId === oid)?.Id + if (o2id) { + selected.value = [oid, o2id] + } else { + // reset selection + selected.value = [] + } +} + const orders = ref([]) const url = `/api/market/${marketId}/orders` await fetch(url) diff --git a/vue/src/components/OrderRow.vue b/vue/src/components/OrderRow.vue index 19d305c..a64867e 100644 --- a/vue/src/components/OrderRow.vue +++ b/vue/src/components/OrderRow.vue @@ -4,7 +4,7 @@ {{ order.side }} {{ order.quantity }} {{ order.ShareDescription }} @ {{ order.price }} sats {{ ago(new Date(order.CreatedAt)) }} - {{ order.Status }} + {{ order.Status }} @@ -12,7 +12,7 @@ import { ref, defineProps, computed } from 'vue' import ago from 's-ago' -const props = defineProps(['order']) +const props = defineProps(['order', 'selected']) const order = ref(props.order) @@ -23,4 +23,25 @@ const statusClassName = computed(() => { return 'error' }) +const selectedClassName = computed(() => { + if (typeof props.selected === 'boolean') { + return props.selected ? 'selected' : '' + } + if (Array.isArray(props.selected)) { + return props.selected.some(id => id === order.value.Id) ? 'selected' : '' + } + return '' +}) + + + diff --git a/vue/src/components/UserInvoices.vue b/vue/src/components/UserInvoices.vue index b6dbf4f..6ad3d55 100644 --- a/vue/src/components/UserInvoices.vue +++ b/vue/src/components/UserInvoices.vue @@ -46,6 +46,10 @@ table { align-items: center; } +td { + padding: 0 0.5em; +} + th { padding: 0 2rem; }