Skip to content

Commit

Permalink
sort the order book
Browse files Browse the repository at this point in the history
  • Loading branch information
vilterp committed Nov 24, 2024
1 parent 1f5b12a commit d42e57d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions apps/actors/systems/kvSync/examples/commodityMarket/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,18 @@ function useOrders(client: Client): [OrderWithState[], QueryStatus] {
prefix: "/orders/",
});

const orders = Object.entries(rawOrders).map(
([id, rawOrder]): OrderWithState => {
const cmpKey = (a: OrderWithState) => (a.side === "buy" ? a.price : -a.price);

const orders = Object.entries(rawOrders)
.map(([id, rawOrder]): OrderWithState => {
const order = rawOrder.value as any;
const mapped = readOrder(order);
return {
...mapped,
state: client.state.transactions[rawOrder.transactionID]?.state,
};
}
);
})
.sort((a, b) => cmpKey(a) - cmpKey(b));

return [orders, queryStatus];
}
Expand Down

0 comments on commit d42e57d

Please sign in to comment.