-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from Giveth/release-multisig-sessions-count
Release multisig sessions count
- Loading branch information
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<RowStyled> | ||
<Col md={4}> | ||
<FlexCenter gap='10px'> | ||
<H4>Multisig Sessions Count</H4> | ||
<IconWithTooltip | ||
icon={<IconHelpFilled16 />} | ||
direction={'top'} | ||
> | ||
<TooltipBody> | ||
Total number of multisig sessions during the | ||
selected timeframe. | ||
</TooltipBody> | ||
</IconWithTooltip> | ||
</FlexCenter> | ||
</Col> | ||
<Col md={4}> | ||
<div> | ||
From: <DatePicker date={fromDate} setDate={setFromDate} /> | ||
</div> | ||
<br /> | ||
<div> | ||
To: <DatePicker date={toDate} setDate={setToDate} /> | ||
</div> | ||
<br /> | ||
</Col> | ||
<Col md={1} /> | ||
<Col md={2}> | ||
<H6>Total:</H6> | ||
{loading ? ( | ||
<Spinner /> | ||
) : ( | ||
<H2> | ||
{multisigSessionsCount !== null | ||
? thousandsSeparator(multisigSessionsCount) | ||
: 'N/A'} | ||
</H2> | ||
)} | ||
{error && <p style={{ color: 'red' }}>{error}</p>} | ||
</Col> | ||
</RowStyled> | ||
); | ||
}; | ||
|
||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<boolean>(true); | ||
const [error, setError] = useState<string | null>(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; |