From 47972819415911f0ebd382f7048abf7f8a73a6e6 Mon Sep 17 00:00:00 2001
From: Ali Ebrahimi <65724329+ae2079@users.noreply.github.com>
Date: Thu, 11 Jul 2024 17:25:30 +0330
Subject: [PATCH] Merge pull request #14 from Giveth/10-multisig-sessions-count
Add MultisigSessionsCount section to the dashboard
---
src/components/views/home/Home.index.tsx | 3 +
.../views/home/MultisigSessionsCount.tsx | 86 +++++++++++++++++++
src/configuration.ts | 5 ++
src/hooks/useMultisigSessionsCount.ts | 46 ++++++++++
4 files changed, 140 insertions(+)
create mode 100644 src/components/views/home/MultisigSessionsCount.tsx
create mode 100644 src/hooks/useMultisigSessionsCount.ts
diff --git a/src/components/views/home/Home.index.tsx b/src/components/views/home/Home.index.tsx
index f5f3a6e..a9e59c9 100644
--- a/src/components/views/home/Home.index.tsx
+++ b/src/components/views/home/Home.index.tsx
@@ -6,6 +6,7 @@ import TotalDonations from './TotalDonations';
import DonationsCount from './DonationsCount';
import NewDonorsCount from './NewDonorsCount';
import NewDonorsDonationTotalUsd from './NewDonorsDonationTotalUsd';
+import MultisigSessionsCount from './MultisigSessionsCount';
const HomeIndex = () => {
return (
@@ -22,6 +23,8 @@ const HomeIndex = () => {
+
+
);
};
diff --git a/src/components/views/home/MultisigSessionsCount.tsx b/src/components/views/home/MultisigSessionsCount.tsx
new file mode 100644
index 0000000..60aa9a5
--- /dev/null
+++ b/src/components/views/home/MultisigSessionsCount.tsx
@@ -0,0 +1,86 @@
+import React, { useState } from 'react';
+import {
+ H2,
+ H4,
+ H6,
+ IconHelpFilled16,
+ neutralColors,
+ Subline,
+} from '@giveth/ui-design-system';
+import styled from 'styled-components';
+import {
+ firstOfNextMonth,
+ firstOfGiveth,
+ thousandsSeparator,
+} from '../../../lib/helpers';
+import { Col, Row } from '../../styled-components/grid';
+import { FlexCenter } from '../../styled-components/flex';
+import { IconWithTooltip } from '../../IconWithTooltip';
+import Spinner from '../../Spinner';
+import DatePicker from '../../DatePicker';
+import useMultisigSessionsCount from '../../../hooks/useMultisigSessionsCount';
+
+const MultisigSessionsCount = () => {
+ const [fromDate, setFromDate] = useState(firstOfGiveth());
+ const [toDate, setToDate] = useState(firstOfNextMonth());
+ const { multisigSessionsCount, loading, error } = useMultisigSessionsCount(
+ fromDate,
+ toDate,
+ );
+
+ return (
+
+
+
+ Multisig Sessions Count
+ }
+ direction={'top'}
+ >
+
+ Total number of multisig sessions during the
+ selected timeframe.
+
+
+
+
+
+
+ From:
+
+
+
+ To:
+
+
+
+
+
+ Total:
+ {loading ? (
+
+ ) : (
+
+ {multisigSessionsCount !== null
+ ? thousandsSeparator(multisigSessionsCount)
+ : 'N/A'}
+
+ )}
+ {error && {error}
}
+
+
+ );
+};
+
+const TooltipBody = styled(Subline)`
+ color: ${neutralColors.gray[100]};
+ width: 270px;
+`;
+
+const RowStyled = styled(Row)`
+ margin-top: 40px;
+ align-items: center;
+ margin-bottom: 40px;
+`;
+
+export default MultisigSessionsCount;
diff --git a/src/configuration.ts b/src/configuration.ts
index e1b45a2..08313a4 100644
--- a/src/configuration.ts
+++ b/src/configuration.ts
@@ -4,8 +4,13 @@ const BASE_ROUTE = isDevelopment
? 'https://impact-graph.serve.giveth.io'
: 'https://mainnet.serve.giveth.io';
+const SWIE_AUTH_ROUTE = isDevelopment
+ ? 'https://auth.serve.giveth.io'
+ : 'https://auth.giveth.io';
+
const config = {
BACKEND_LINK: `${BASE_ROUTE}/graphql`,
+ SWIE_AUTH_MICROSERVICE_URL: SWIE_AUTH_ROUTE,
};
export default config;
diff --git a/src/hooks/useMultisigSessionsCount.ts b/src/hooks/useMultisigSessionsCount.ts
new file mode 100644
index 0000000..bbfed5a
--- /dev/null
+++ b/src/hooks/useMultisigSessionsCount.ts
@@ -0,0 +1,46 @@
+import { useEffect, useState } from 'react';
+import config from '../configuration';
+
+const useMultisigSessionsCount = (fromDate: Date, toDate: Date) => {
+ const [multisigSessionsCount, setMultisigSessionsCount] = useState<
+ number | null
+ >(null);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState(null);
+
+ useEffect(() => {
+ const fetchData = async () => {
+ setLoading(true);
+ setError(null);
+ try {
+ const url = new URL(
+ `${config.SWIE_AUTH_MICROSERVICE_URL}/v1/multisigSessionCount`,
+ );
+ url.searchParams.append(
+ 'from',
+ fromDate.toISOString().split('T')[0],
+ );
+ url.searchParams.append(
+ 'to',
+ toDate.toISOString().split('T')[0],
+ );
+
+ const response = await fetch(url.toString(), {
+ method: 'GET',
+ });
+ const data = await response.json();
+ setMultisigSessionsCount(data.count);
+ } catch (err) {
+ setError('Failed to fetch data');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ fetchData();
+ }, [fromDate, toDate]);
+
+ return { multisigSessionsCount, loading, error };
+};
+
+export default useMultisigSessionsCount;