Skip to content

Commit

Permalink
getting ready to release the 7-14 days feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tombertrand committed Jan 16, 2024
1 parent 2796222 commit c7b9de6
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 54 deletions.
12 changes: 6 additions & 6 deletions server/cron/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ cron.schedule("*/10 * * * * *", async () => {
{
$match: {
createdAt: {
$gte: new Date(Date.now() - EXPIRE_14D * 1000),
$gte: new Date(Date.now() - EXPIRE_7D * 1000),
},
},
},
Expand All @@ -126,7 +126,7 @@ cron.schedule("*/10 * * * * *", async () => {
{
$match: {
createdAt: {
$lt: new Date(Date.now() + EXPIRE_14D * 1000),
$gte: new Date(Date.now() - EXPIRE_14D * 1000),
},
},
},
Expand Down Expand Up @@ -160,7 +160,7 @@ cron.schedule("*/10 * * * * *", async () => {
{
$match: {
createdAt: {
$lt: new Date(Date.now() + EXPIRE_7D * 1000),
$gte: new Date(Date.now() - EXPIRE_7D * 1000),
},
},
},
Expand All @@ -177,7 +177,7 @@ cron.schedule("*/10 * * * * *", async () => {
{
$match: {
createdAt: {
$lt: new Date(Date.now() + TOTAL_VOLUME_14D * 1000),
$gte: new Date(Date.now() - TOTAL_VOLUME_14D * 1000),
},
},
},
Expand Down Expand Up @@ -211,7 +211,7 @@ cron.schedule("*/10 * * * * *", async () => {
{
$match: {
createdAt: {
$lt: new Date(Date.now() + EXPIRE_7D * 1000),
$gte: new Date(Date.now() - EXPIRE_7D * 1000),
},
},
},
Expand All @@ -227,7 +227,7 @@ cron.schedule("*/10 * * * * *", async () => {
{
$match: {
createdAt: {
$lt: new Date(Date.now() + EXPIRE_14D * 1000),
$gte: new Date(Date.now() - EXPIRE_14D * 1000),
},
},
},
Expand Down
124 changes: 76 additions & 48 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { useTranslation } from "react-i18next";
import { useMediaQuery } from "react-responsive";
import { Link } from "react-router-dom";

import { CheckOutlined, CloseOutlined } from "@ant-design/icons";
import { Card, Col, Row, Switch, Tooltip } from "antd";
import { Card, Col, Row, Select, Tooltip } from "antd";
import BigNumber from "bignumber.js";

import { BlockCountContext } from "api/contexts/BlockCount";
Expand All @@ -16,11 +15,11 @@ import {
BITCOIN_TOTAL_TRANSACTION_FEES_48H,
MarketStatisticsContext,
TOTAL_CONFIRMATIONS_7D,
// TOTAL_CONFIRMATIONS_14D,
TOTAL_CONFIRMATIONS_14D,
TOTAL_CONFIRMATIONS_24H,
TOTAL_CONFIRMATIONS_48H,
TOTAL_VOLUME_7D,
// TOTAL_VOLUME_14D,
TOTAL_VOLUME_14D,
TOTAL_VOLUME_24H,
TOTAL_VOLUME_48H,
} from "api/contexts/MarketStatistics";
Expand All @@ -36,6 +35,8 @@ import { formatBytes } from "components/utils";
import Banner from "./Banner";
import RecentTransactions from "./RecentTransactions";

const { Option } = Select;

const HomePage = () => {
const { t } = useTranslation();
const isSmallAndLower = !useMediaQuery({ query: "(min-width: 576px)" });
Expand Down Expand Up @@ -117,31 +118,57 @@ const HomePage = () => {
.times(100)
.toNumber()
: 0;
let onChainVolume48hAgo = 0;
let onChainVolumeChange24h = 0;
if (marketStatistics[TOTAL_VOLUME_24H] && marketStatistics[TOTAL_VOLUME_48H]) {
onChainVolume48hAgo = new BigNumber(marketStatistics[TOTAL_VOLUME_48H])
.minus(marketStatistics[TOTAL_VOLUME_24H])
.toNumber();
onChainVolumeChange24h = new BigNumber(marketStatistics[TOTAL_VOLUME_24H])
.minus(onChainVolume48hAgo)
.dividedBy(onChainVolume48hAgo)
.times(100)
.toNumber();
}

let totalConfirmations48hAgo = 0;
let confirmationChange24h = 0;
if (marketStatistics[TOTAL_CONFIRMATIONS_24H] && marketStatistics[TOTAL_CONFIRMATIONS_48H]) {
totalConfirmations48hAgo = new BigNumber(marketStatistics[TOTAL_CONFIRMATIONS_48H])
.minus(marketStatistics[TOTAL_CONFIRMATIONS_24H])
.toNumber();
confirmationChange24h = new BigNumber(marketStatistics[TOTAL_CONFIRMATIONS_24H])
.minus(totalConfirmations48hAgo)
.dividedBy(totalConfirmations48hAgo)
.times(100)
.toNumber();
}
let onChainVolume48hAgo = 0;
let onChainVolumeChange24h = 0;
if (marketStatistics[TOTAL_VOLUME_24H] && marketStatistics[TOTAL_VOLUME_48H]) {
onChainVolume48hAgo = new BigNumber(marketStatistics[TOTAL_VOLUME_48H])
.minus(marketStatistics[TOTAL_VOLUME_24H])
.toNumber();
onChainVolumeChange24h = new BigNumber(marketStatistics[TOTAL_VOLUME_24H])
.minus(onChainVolume48hAgo)
.dividedBy(onChainVolume48hAgo)
.times(100)
.toNumber();
}

let onChainVolume14dAgo = 0;
let onChainVolumeChange7d = 0;
if (marketStatistics[TOTAL_VOLUME_7D] && marketStatistics[TOTAL_VOLUME_14D]) {
onChainVolume14dAgo = new BigNumber(marketStatistics[TOTAL_VOLUME_14D])
.minus(marketStatistics[TOTAL_VOLUME_7D])
.toNumber();
onChainVolumeChange7d = new BigNumber(marketStatistics[TOTAL_VOLUME_7D])
.minus(onChainVolume14dAgo)
.dividedBy(onChainVolume14dAgo)
.times(100)
.toNumber();
}

let totalConfirmations48hAgo = 0;
let confirmationChange24h = 0;
if (marketStatistics[TOTAL_CONFIRMATIONS_24H] && marketStatistics[TOTAL_CONFIRMATIONS_48H]) {
totalConfirmations48hAgo = new BigNumber(marketStatistics[TOTAL_CONFIRMATIONS_48H])
.minus(marketStatistics[TOTAL_CONFIRMATIONS_24H])
.toNumber();
confirmationChange24h = new BigNumber(marketStatistics[TOTAL_CONFIRMATIONS_24H])
.minus(totalConfirmations48hAgo)
.dividedBy(totalConfirmations48hAgo)
.times(100)
.toNumber();
}

let totalConfirmations14dAgo = 0;
let confirmationChange7d = 0;
if (marketStatistics[TOTAL_CONFIRMATIONS_7D] && marketStatistics[TOTAL_CONFIRMATIONS_14D]) {
totalConfirmations14dAgo = new BigNumber(marketStatistics[TOTAL_CONFIRMATIONS_14D])
.minus(marketStatistics[TOTAL_CONFIRMATIONS_7D])
.toNumber();
confirmationChange7d = new BigNumber(marketStatistics[TOTAL_CONFIRMATIONS_7D])
.minus(totalConfirmations14dAgo)
.dividedBy(totalConfirmations14dAgo)
.times(100)
.toNumber();
}

React.useEffect(() => {
setFormattedLedgerSize(formatBytes(ledgerSize));
Expand Down Expand Up @@ -235,26 +262,27 @@ const HomePage = () => {
<Card
size="small"
title={
<span>
{is24Hours ? t("pages.home.last24Hours") : t("pages.home.last7Days")}
<Tooltip
placement="right"
title={is24Hours ? t("tooltips.last24Hours") : t("tooltips.last7days")}
>
<QuestionCircle />
</Tooltip>
</span>
}
extra={
isFeatureActive ? (
<Switch
checkedChildren={<CheckOutlined />}
unCheckedChildren={<CloseOutlined />}
onChange={(checked: boolean) => {
setIs24Hours(checked);
}}
checked={is24Hours}
/>
<>
<Select
value={is24Hours}
onChange={(value: boolean) => {
console.log("~~~value", value);
setIs24Hours(value);
}}
>
<Option value={true}>{t("pages.home.last24Hours")}</Option>
<Option value={false}>{t("pages.home.last7Days")}</Option>
</Select>
<span>
<Tooltip
placement="right"
title={is24Hours ? t("tooltips.last24Hours") : t("tooltips.last7days")}
>
<QuestionCircle />
</Tooltip>
</span>
</>
) : null
}
>
Expand Down

0 comments on commit c7b9de6

Please sign in to comment.