Skip to content

Commit 61edf51

Browse files
committed
Update index.tsx
1 parent 9186441 commit 61edf51

File tree

8 files changed

+174
-69
lines changed

8 files changed

+174
-69
lines changed

server/client/mongo/schema.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const db = require("./");
33
const {
44
EXPIRE_1M,
55
EXPIRE_48H,
6-
EXPIRE_1W,
7-
EXPIRE_2W,
6+
EXPIRE_7D,
7+
EXPIRE_14D,
88
TOTAL_CONFIRMATIONS_COLLECTION,
99
TOTAL_VOLUME_COLLECTION,
1010
LARGE_TRANSACTIONS,
@@ -24,7 +24,7 @@ async function createIndexes() {
2424
if (!indexExists1) {
2525
database
2626
.collection(LARGE_TRANSACTIONS)
27-
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_1W, ...extraOptions });
27+
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_7D, ...extraOptions });
2828
console.log("Index LARGE_TRANSACTIONS createdAt created successfully");
2929
}
3030

@@ -42,15 +42,15 @@ async function createIndexes() {
4242
if (!indexExists3) {
4343
database
4444
.collection(TOTAL_CONFIRMATIONS_COLLECTION)
45-
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_2W, ...extraOptions });
45+
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_14D, ...extraOptions });
4646
console.log("Index TOTAL_CONFIRMATIONS_COLLECTION createdAt created successfully");
4747
}
4848

4949
const indexExists4 = await database.collection(TOTAL_VOLUME_COLLECTION).indexExists("createdAt");
5050
if (!indexExists4) {
5151
database
5252
.collection(TOTAL_VOLUME_COLLECTION)
53-
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_48H, ...extraOptions });
53+
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_14D, ...extraOptions });
5454
console.log("Index TOTAL_VOLUME_COLLECTION createdAt created successfully");
5555
}
5656

server/constants.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const EXPIRE_1H = 3600;
55
const EXPIRE_6H = 3600 * 6;
66
const EXPIRE_24H = EXPIRE_1H * 24;
77
const EXPIRE_48H = EXPIRE_24H * 2;
8-
const EXPIRE_1W = EXPIRE_24H * 7;
9-
const EXPIRE_2W = EXPIRE_24H * 14;
8+
const EXPIRE_7D = EXPIRE_24H * 7;
9+
const EXPIRE_14D = EXPIRE_24H * 14;
1010
const EXPIRE_1Y = EXPIRE_24H * 365;
1111
const EXPIRE_5Y = EXPIRE_24H * 365 * 5;
1212
const TOTAL_CONFIRMATIONS_COLLECTION = "TOTAL_CONFIRMATIONS";
@@ -18,6 +18,7 @@ const TOTAL_VOLUME_COLLECTION = "TOTAL_VOLUME";
1818
const TOTAL_VOLUME_24H = "TOTAL_VOLUME_24H";
1919
const TOTAL_VOLUME_7D = "TOTAL_VOLUME_7D";
2020
const TOTAL_VOLUME_48H = "TOTAL_VOLUME_48H";
21+
const TOTAL_VOLUME_14D = "TOTAL_VOLUME_14D";
2122
const MARKET_CAP_RANK_COLLECTION = "MARKET_CAP_RANK";
2223
const MARKET_CAP_STATS_COLLECTION = "MARKET_CAP_STATS";
2324
const MARKET_CAP_RANK = "MARKET_CAP_RANK";
@@ -78,8 +79,8 @@ module.exports = {
7879
EXPIRE_6H,
7980
EXPIRE_24H,
8081
EXPIRE_48H,
81-
EXPIRE_1W,
82-
EXPIRE_2W,
82+
EXPIRE_7D,
83+
EXPIRE_14D,
8384
EXPIRE_1Y,
8485
EXPIRE_5Y,
8586
TOTAL_CONFIRMATIONS_COLLECTION,
@@ -91,6 +92,7 @@ module.exports = {
9192
TOTAL_VOLUME_24H,
9293
TOTAL_VOLUME_7D,
9394
TOTAL_VOLUME_48H,
95+
TOTAL_VOLUME_14D,
9496
MARKET_CAP_RANK_COLLECTION,
9597
MARKET_CAP_STATS_COLLECTION,
9698
MARKET_CAP_RANK,

server/cron/ws.js

Lines changed: 97 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const {
88
EXPIRE_1M,
99
EXPIRE_24H,
1010
EXPIRE_1W,
11+
EXPIRE_7D,
12+
EXPIRE_14D,
1113
EXPIRE_48H,
1214
TOTAL_CONFIRMATIONS_COLLECTION,
1315
TOTAL_CONFIRMATIONS_24H,
@@ -16,7 +18,9 @@ const {
1618
TOTAL_CONFIRMATIONS_14D,
1719
TOTAL_VOLUME_COLLECTION,
1820
TOTAL_VOLUME_24H,
21+
TOTAL_VOLUME_7D,
1922
TOTAL_VOLUME_48H,
23+
TOTAL_VOLUME_14D,
2024
CONFIRMATIONS_PER_SECOND,
2125
} = require("../constants");
2226
const { rawToRai } = require("../utils");
@@ -36,7 +40,7 @@ cron.schedule("*/3 * * * * *", async () => {
3640
{
3741
$match: {
3842
createdAt: {
39-
$lt: new Date(Date.now() - EXPIRE_1M * 1000),
43+
$gte: new Date(Date.now() - EXPIRE_1M * 1000),
4044
},
4145
},
4246
},
@@ -71,32 +75,32 @@ cron.schedule("*/10 * * * * *", async () => {
7175
{
7276
$match: {
7377
createdAt: {
74-
$lt: new Date(Date.now() - EXPIRE_24H * 1000),
78+
$gte: new Date(Date.now() - EXPIRE_24H * 1000),
7579
},
7680
},
7781
},
78-
{ $group: { _id: null, totalConfirmations: { $sum: "$value" } } },
82+
{ $group: { _id: null, totalConfirmations24h: { $sum: "$value" } } },
7983
])
8084
.toArray()
81-
.then(([{ totalConfirmations = 0 } = {}]) => {
82-
nodeCache.set(TOTAL_CONFIRMATIONS_24H, totalConfirmations);
85+
.then(([{ totalConfirmations24h = 0 } = {}]) => {
86+
nodeCache.set(TOTAL_CONFIRMATIONS_24H, totalConfirmations24h);
8387
});
84-
// conf 7d
85-
database
88+
// conf 7d
89+
database
8690
.collection(TOTAL_CONFIRMATIONS_COLLECTION)
8791
.aggregate([
8892
{
8993
$match: {
9094
createdAt: {
91-
$lt: new Date(Date.now() - EXPIRE_1W * 1000),
95+
$gte: new Date(Date.now() - EXPIRE_1W * 1000),
9296
},
9397
},
9498
},
95-
{ $group: { _id: null, totalConfirmations14d: { $sum: "$value" } } },
99+
{ $group: { _id: null, totalConfirmations7d: { $sum: "$value" } } },
96100
])
97101
.toArray()
98-
.then(([{ totalConfirmations14d = 0 } = {}]) => {
99-
nodeCache.set(TOTAL_CONFIRMATIONS_7D, totalConfirmations14d);
102+
.then(([{ totalConfirmations7d = 0 } = {}]) => {
103+
nodeCache.set(TOTAL_CONFIRMATIONS_7D, totalConfirmations7d);
100104
});
101105

102106
database
@@ -105,25 +109,25 @@ cron.schedule("*/10 * * * * *", async () => {
105109
{
106110
$match: {
107111
createdAt: {
108-
$lt: new Date(Date.now() - EXPIRE_48H * 1000),
112+
$gte: new Date(Date.now() - EXPIRE_48H * 1000),
109113
},
110114
},
111115
},
112-
{ $group: { _id: null, totalConfirmations: { $sum: "$value" } } },
116+
{ $group: { _id: null, totalConfirmations48h: { $sum: "$value" } } },
113117
])
114118
.toArray()
115-
.then(([{ totalConfirmations = 0 } = {}]) => {
116-
nodeCache.set(TOTAL_CONFIRMATIONS_48H, totalConfirmations);
119+
.then(([{ totalConfirmations48h = 0 } = {}]) => {
120+
nodeCache.set(TOTAL_CONFIRMATIONS_48H, totalConfirmations48h);
117121
});
118122

119-
//conf 1w
120-
database
123+
//conf 1w
124+
database
121125
.collection(TOTAL_CONFIRMATIONS_COLLECTION)
122126
.aggregate([
123127
{
124128
$match: {
125129
createdAt: {
126-
$lt: new Date(Date.now() - EXPIRE_1W * 1000),
130+
$gte: new Date(Date.now() - EXPIRE_14D * 1000),
127131
},
128132
},
129133
},
@@ -140,15 +144,32 @@ cron.schedule("*/10 * * * * *", async () => {
140144
{
141145
$match: {
142146
createdAt: {
143-
$lt: new Date(Date.now() - EXPIRE_24H * 1000),
147+
$gte: new Date(Date.now() - EXPIRE_24H * 1000),
148+
},
149+
},
150+
},
151+
{ $group: { _id: null, totalVolume24h: { $sum: "$value" } } },
152+
])
153+
.toArray()
154+
.then(([{ totalVolume24h = 0 } = {}]) => {
155+
nodeCache.set(TOTAL_VOLUME_24H, rawToRai(totalVolume24h));
156+
});
157+
158+
database
159+
.collection(TOTAL_VOLUME_COLLECTION)
160+
.aggregate([
161+
{
162+
$match: {
163+
createdAt: {
164+
$gte: new Date(Date.now() - EXPIRE_7D * 1000),
144165
},
145166
},
146167
},
147-
{ $group: { _id: null, totalVolume: { $sum: "$value" } } },
168+
{ $group: { _id: null, totalVolume7d: { $sum: "$value" } } },
148169
])
149170
.toArray()
150-
.then(([{ totalVolume = 0 } = {}]) => {
151-
nodeCache.set(TOTAL_VOLUME_24H, rawToRai(totalVolume));
171+
.then(([{ totalVolume7d = 0 } = {}]) => {
172+
nodeCache.set(TOTAL_VOLUME_7D, rawToRai(totalVolume7d));
152173
});
153174

154175
database
@@ -157,15 +178,65 @@ cron.schedule("*/10 * * * * *", async () => {
157178
{
158179
$match: {
159180
createdAt: {
160-
$lt: new Date(Date.now() - EXPIRE_48H * 1000),
181+
$gte: new Date(Date.now() - TOTAL_VOLUME_14D * 1000),
182+
},
183+
},
184+
},
185+
{ $group: { _id: null, totalVolume14d: { $sum: "$value" } } },
186+
])
187+
.toArray()
188+
.then(([{ totalVolume14d = 0 } = {}]) => {
189+
nodeCache.set(TOTAL_VOLUME_14D, rawToRai(totalVolume14d));
190+
});
191+
192+
database
193+
.collection(TOTAL_VOLUME_COLLECTION)
194+
.aggregate([
195+
{
196+
$match: {
197+
createdAt: {
198+
$gte: new Date(Date.now() - EXPIRE_48H * 1000),
199+
},
200+
},
201+
},
202+
{ $group: { _id: null, totalVolume48h: { $sum: "$value" } } },
203+
])
204+
.toArray()
205+
.then(([{ totalVolume48h = 0 } = {}]) => {
206+
nodeCache.set(TOTAL_VOLUME_48H, rawToRai(totalVolume48h));
207+
});
208+
209+
database
210+
.collection(TOTAL_VOLUME_COLLECTION)
211+
.aggregate([
212+
{
213+
$match: {
214+
createdAt: {
215+
$gte: new Date(Date.now() - EXPIRE_7D * 1000),
216+
},
217+
},
218+
},
219+
{ $group: { _id: null, totalVolume7d: { $sum: "$value" } } },
220+
])
221+
.toArray()
222+
.then(([{ totalVolume7d = 0 } = {}]) => {
223+
nodeCache.set(TOTAL_VOLUME_7D, rawToRai(totalVolume7d));
224+
});
225+
database
226+
.collection(TOTAL_VOLUME_COLLECTION)
227+
.aggregate([
228+
{
229+
$match: {
230+
createdAt: {
231+
$gte: new Date(Date.now() - EXPIRE_14D * 1000),
161232
},
162233
},
163234
},
164-
{ $group: { _id: null, totalVolume: { $sum: "$value" } } },
235+
{ $group: { _id: null, totalVolume14d: { $sum: "$value" } } },
165236
])
166237
.toArray()
167-
.then(([{ totalVolume = 0 } = {}]) => {
168-
nodeCache.set(TOTAL_VOLUME_48H, rawToRai(totalVolume));
238+
.then(([{ totalVolume14d = 0 } = {}]) => {
239+
nodeCache.set(TOTAL_VOLUME_14D, rawToRai(totalVolume14d));
169240
});
170241
} catch (err) {
171242
Sentry.captureException(err, {

server/utils/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const BigNumber = require("bignumber.js");
22

33
const rawToRai = raw => {
44
const value = new BigNumber(raw.toString());
5-
return value.shiftedBy(30 * -1).toNumber();
5+
return value.shiftedBy(30 * -1).toNumber() || 0;
66
};
77

88
const raiToRaw = rai => {

server/ws/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ws.onmessage = msg => {
6161

6262
if (topic === "confirmation") {
6363
accumulatedConfirmations = accumulatedConfirmations + 1;
64+
6465

6566
// 10,000 NANO
6667
if (subtype === "send" && amount.length >= 35) {

src/api/contexts/MarketStatistics.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const TOTAL_CONFIRMATIONS_7D = "TOTAL_CONFIRMATIONS_7D";
99
export const TOTAL_CONFIRMATIONS_14D = "TOTAL_CONFIRMATIONS_14D";
1010
export const TOTAL_VOLUME_24H = "TOTAL_VOLUME_24H";
1111
export const TOTAL_VOLUME_7D = "TOTAL_VOLUME_7D";
12+
export const TOTAL_VOLUME_14D = "TOTAL_VOLUME_14D";
1213
export const TOTAL_CONFIRMATIONS_48H = "TOTAL_CONFIRMATIONS_48H";
1314
export const TOTAL_VOLUME_48H = "TOTAL_VOLUME_48H";
1415
export const BITCOIN_TOTAL_TRANSACTION_FEES_24H = "BITCOIN_TOTAL_TRANSACTION_FEES_24H";
@@ -26,6 +27,7 @@ export interface Response {
2627
[TOTAL_CONFIRMATIONS_48H]: number;
2728
[TOTAL_CONFIRMATIONS_14D]: number;
2829
[TOTAL_VOLUME_48H]: number;
30+
[TOTAL_VOLUME_14D]: number;
2931
[BITCOIN_TOTAL_TRANSACTION_FEES_24H]: number;
3032
[BITCOIN_TOTAL_TRANSACTION_FEES_7D]: number;
3133
[BITCOIN_TOTAL_TRANSACTION_FEES_14D]: number;
@@ -70,6 +72,7 @@ export const MarketStatisticsContext = React.createContext<Context>({
7072
[TOTAL_VOLUME_7D]: 0,
7173
[TOTAL_CONFIRMATIONS_48H]: 0,
7274
[TOTAL_VOLUME_48H]: 0,
75+
[TOTAL_VOLUME_14D]: 0,
7376
[BITCOIN_TOTAL_TRANSACTION_FEES_24H]: 0,
7477
[BITCOIN_TOTAL_TRANSACTION_FEES_7D]: 0,
7578
[BITCOIN_TOTAL_TRANSACTION_FEES_14D]: 0,

src/i18n/locales/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@
9999
"senderFilter": "Filter blocks to include only or exclude all send transactions from a specific address. To filter multiple addresses, separate them with a comma.",
100100
"receiverFilter": "Filter blocks to include only or exclude all send transactions from a specific address. To filter multiple addresses, separate them with a comma.",
101101
"filterTransactions": "Only accounts with equal or less than 5,000 confirmed transactions can be filtered",
102-
"averageTps": "On {{date}}, {{block_count}} {{block_type}} blocks were broadcasted at a rate of {{bps}} BPS (blocks per second) to measure the network efficiency. The network reached a P90 of {{cps_p90}} CPS (confirmations per seconds) across the nodes. For more details visit https://nanotps.net/."
102+
"averageTps": "On {{date}}, {{block_count}} {{block_type}} blocks were broadcasted at a rate of {{bps}} BPS (blocks per second) to measure the network efficiency. The network reached a P90 of {{cps_p90}} CPS (confirmations per seconds) across the nodes. For more details visit https://nanotps.net/.",
103+
"last24Hours": "Displays a comparison of data trends and metrics from the last 24 hours against those from the preceding 48 hours, providing insights into recent changes and patterns.",
104+
"last7days": "Shows a comparative analysis of data and trends over the past 7 days against the previous 14 days, highlighting shifts and patterns over a broader time frame for a comprehensive view."
103105
},
104106
"search": {
105107
"searchBy": "Search by Address / Block / Known Account",

0 commit comments

Comments
 (0)