const currentPage = props.page; const instance = "treasury-testing.near"; // props.instance; // if (!instance) { // return <></>; // } const { treasuryDaoID } = VM.require(`${instance}/widget/config.data`); const [csvUrl, setCsvUrl] = useState(""); // To store the Blob URL // Hardcoded CSV data (for testing) const hardcodedCsvData = `id,proposer,description,kind,status 1,megha19.near,Update policy,ChangePolicy,Approved 2,john.doe.near,Add new feature,AddFeature,Pending 3,jane.doe.near,Fix bug,FixBug,Rejected`; // Create a Blob and generate the URL for download const generateCsvUrl = () => { let endpoint = `https://sputnik-indexer-divine-fog-3863.fly.dev/proposals/${treasuryDaoID}`; switch (currentPage) { case "payments": { endpoint += `?proposal_type=Transfer`; break; } case "stake-delegation": { endpoint += `?proposal_type=FunctionCall&keyword=stake`; break; } case "asset-exchange": { endpoint += `?proposal_type=FunctionCall&keyword=asset-exchange`; break; } case "lockup": { endpoint += `?proposal_type=FunctionCall&keyword=lockup`; break; } default: { break; } } console.log(endpoint); const blob = new Blob([hardcodedCsvData], { type: "text/csv" }); const url = URL.createObjectURL(blob); console.log(url); setCsvUrl(url); // asyncFetch(endpoint, { // headers: { // Accept: "text/csv", // }, // }).then((response) => { // if (!response.ok) { // console.log("Error occured while fetching csv"); // } else { // const blob = new Blob([response.body], { type: "text/csv" }); // const url = URL.createObjectURL(blob); // setCsvUrl(url); // } // }); }; useEffect(() => { generateCsvUrl(); }, []); return ( <div> {csvUrl && ( <a href={csvUrl} download="data.csv" // target="_blank" // rel="noopener noreferrer" > <button className="btn btn-outline-secondary d-flex gap-1 align-items-center"> <i class="bi bi-download h6 mb-0"></i> Export </button> </a> )} </div> );