-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.tsx
49 lines (40 loc) · 1.26 KB
/
Home.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React, { useEffect, useState } from 'react';
import { orderbookWebocketClient } from 'core/webSocketClients';
import OrderList from 'components/OrderList';
import Navbar from 'components/Navbar';
import Spinner from 'components/Spinner';
import { Orders } from 'core/models';
const Home: React.FC = () => {
const [orders, setOrders] = useState<Orders | undefined>(undefined);
/**
* Subscribe to orders observable
*/
const subscribeToOrders = () => {
// Start websocket communication
orderbookWebocketClient.start();
// Subscribe to Orders observable
return orderbookWebocketClient.ordersFeed
.subscribe({
next: (newOrders) => setOrders(newOrders)
});
};
useEffect(() => {
// Subscribe to Orders observable
const ordersSubscription = subscribeToOrders();
// Unsubscribe from observable on componenent unmount
return () => ordersSubscription.unsubscribe();
}, []);
return (
<div className="container-fluid p-0">
<Navbar />
<div className="container my-5 text-center">
<h2 className="mb-4">XBT/USD Orderbook</h2>
{ orders
? <OrderList data={orders} />
: <Spinner className="center-fixed" />
}
</div>
</div>
);
};
export default Home;