Skip to content

Commit

Permalink
Merge pull request #1140 from givepraise/add/attestations
Browse files Browse the repository at this point in the history
Add/attestations
  • Loading branch information
kristoferlund authored Sep 4, 2023
2 parents 57ff6c8 + 383a920 commit 499f45c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import { Parser } from '@json2csv/plainjs';

import { Dialog } from '@headlessui/react';
Expand All @@ -9,11 +8,6 @@ import { faReceipt, faTimes } from '@fortawesome/free-solid-svg-icons';
import { Button } from '@/components/ui/Button';
import { useSafe } from '../../../model/safe/hooks/useSafe';
import {
getPeriodDatesConfig,
PeriodDates,
} from '../../../model/report/util/get-period-dates-config';
import {
AllPeriods,
PeriodPageParams,
useUpdatePeriod,
} from '../../../model/periods/periods';
Expand All @@ -33,25 +27,18 @@ export function CreateAttestationsDialog({
}: CreateAttestationsDialogProps): JSX.Element | null {
// Hooks
const { periodId } = useParams<PeriodPageParams>();
const periods = useRecoilValue(AllPeriods);
const { owners, threshold } = useSafe();

const { createAttestationsTransaction, safeTransactionState } = useEas();

const { updatePeriod } = useUpdatePeriod();

// Local state
const [periodDates, setPeriodDates] = useState<PeriodDates>();
const [attestationReportData, setAttestationReportData] =
useState<useReportRunReturn>();
const [attestationCsv, setAttestationCsv] = useState<string>();

// Effects
function loadPeriodDates(): void {
if (!periods) return;
setPeriodDates(getPeriodDatesConfig(periods, periodId));
}

function saveTransactionHash(): void {
if (
!safeTransactionState?.txHash ||
Expand Down Expand Up @@ -86,7 +73,6 @@ export function CreateAttestationsDialog({
setAttestationCsv(csv);
}

useEffect(loadPeriodDates, [periods, periodId]);
useEffect(saveTransactionHash, [
safeTransactionState?.txHash,
safeTransactionState?.status,
Expand All @@ -96,8 +82,6 @@ export function CreateAttestationsDialog({
]);
useEffect(createAttestationCsv, [attestationReportData, periodId]);

if (!periodDates) return null;

return (
<div className="flex items-center justify-center min-h-screen">
<Dialog.Overlay className="fixed inset-0 bg-black/30" />
Expand All @@ -120,7 +104,6 @@ export function CreateAttestationsDialog({
<div className="flex flex-col justify-center gap-5 p-10 text-center border border-black">
<GenerateAttestationsData
periodId={periodId}
periodDates={periodDates}
manifestUrl={ATTESTATION_REPORT_MANIFEST_URL}
done={(result): void => {
if (!result) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ import {
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { useEffect, useState } from 'react';
import { useReport } from '../../../model/report/hooks/use-report.hook';
import { PeriodDates } from '../../../model/report/util/get-period-dates-config';
import { useReportRunReturn } from '../../../model/report/types/use-report-run-return.type';
import { objectToQs } from '../../../utils/querystring';
import { Link } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import { SinglePeriod } from '../../../model/periods/periods';

type GenerateAttestationsDataProps = {
periodId: string;
periodDates: PeriodDates;
manifestUrl: string;
done: (result: useReportRunReturn | undefined) => void;
};

export function GenerateAttestationsData({
periodId,
periodDates,
manifestUrl,
done,
}: GenerateAttestationsDataProps): JSX.Element {
const period = useRecoilValue(SinglePeriod(periodId));
const report = useReport({
manifestUrl,
periodId,
startDate: periodDates.startDate,
endDate: periodDates.endDate,
startDate: period?.startDate,
endDate: period?.endDate,
});
const [data, setData] = useState<useReportRunReturn | undefined>(undefined);

Expand Down Expand Up @@ -60,8 +60,8 @@ export function GenerateAttestationsData({

const reportUrl = `/reports/run?${objectToQs({
manifestUrl,
startDate: periodDates.startDate,
endDate: periodDates.endDate,
startDate: period?.startDate || '',
endDate: period?.endDate || '',
})}`;

return (
Expand Down

0 comments on commit 499f45c

Please sign in to comment.