-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/dOrgTech/homebase-app in…
…to develop
- Loading branch information
Showing
7 changed files
with
4,985 additions
and
3,986 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
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
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,75 @@ | ||
import React, { useEffect, useState } from "react" | ||
import { Button, Typography } from "@material-ui/core" | ||
import { ReactComponent as DownloadCSVIcon } from "assets/img/download_csv.svg" | ||
import { Choice, WalletAddress } from "models/Choice" | ||
import { mkConfig, generateCsv, download, asString } from "export-to-csv" | ||
import { writeFile } from "node:fs" | ||
import { useNotification } from "modules/lite/components/hooks/useNotification" | ||
|
||
type DownloadCsvFileProps = { | ||
data: Choice[] | ||
pollId: string | undefined | ||
symbol: string | ||
} | ||
|
||
export const DownloadCsvFile: React.FC<DownloadCsvFileProps> = ({ data, pollId, symbol }) => { | ||
const [votesDetails, setVotesDetails] = useState<any>() | ||
const openNotification = useNotification() | ||
|
||
useEffect(() => { | ||
const arr: any = [] | ||
data.map(item => { | ||
item.walletAddresses.map(vote => { | ||
const formattedVote = { | ||
address: vote.address, | ||
choice: item.name, | ||
balance: vote.balanceAtReferenceBlock, | ||
signature: vote.signature, | ||
ipfsStorage: vote.cidLink | ||
} | ||
return arr.push(formattedVote) | ||
}) | ||
}) | ||
setVotesDetails(arr) | ||
}, [data]) | ||
|
||
const downloadCvs = () => { | ||
console.log(votesDetails) | ||
const csvConfig = mkConfig({ | ||
useKeysAsHeaders: true, | ||
filename: `proposal-${pollId}`, | ||
showTitle: false | ||
}) | ||
|
||
const votesData = votesDetails.map((row: any) => { | ||
return { | ||
"Address": row.address, | ||
"Choice": row.choice, | ||
"Token": symbol, | ||
"Vote Weight": row.balance, | ||
"Signature": row.signature, | ||
"IPFS Storage Link": row.ipfsStorage | ||
} | ||
}) | ||
try { | ||
const csv = generateCsv(csvConfig)(votesData) | ||
download(csvConfig)(csv) | ||
} catch (error) { | ||
openNotification({ | ||
message: `Error downloading csv file`, | ||
autoHideDuration: 3000, | ||
variant: "error" | ||
}) | ||
} | ||
} | ||
|
||
return ( | ||
<Button> | ||
<DownloadCSVIcon style={{ marginRight: 8 }} /> | ||
<Typography color="secondary" onClick={downloadCvs}> | ||
{" "} | ||
Download CSV | ||
</Typography> | ||
</Button> | ||
) | ||
} |
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
Oops, something went wrong.