-
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 #128 from NetSepio/rushikesh-peaq
add : save to walrus and download button
- Loading branch information
Showing
6 changed files
with
340 additions
and
52 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,45 @@ | ||
import React, { useState } from 'react'; | ||
import axios from 'axios'; | ||
|
||
interface DownloadFromWalrusButtonProps { | ||
blobId: string; | ||
clientName: string; | ||
} | ||
|
||
const DownloadFromWalrusButton: React.FC<DownloadFromWalrusButtonProps> = ({ blobId, clientName }) => { | ||
const [isDownloading, setIsDownloading] = useState(false); | ||
|
||
const downloadFromWalrus = async () => { | ||
setIsDownloading(true); | ||
try { | ||
const response = await axios.get(`https://aggregator-devnet.walrus.space/v1/${blobId}`, { | ||
responseType: 'blob' | ||
}); | ||
|
||
const url = window.URL.createObjectURL(new Blob([response.data])); | ||
const link = document.createElement('a'); | ||
link.href = url; | ||
link.setAttribute('download', `${clientName}.conf`); | ||
document.body.appendChild(link); | ||
link.click(); | ||
link.remove(); | ||
} catch (error) { | ||
console.error('Error downloading from Walrus:', error); | ||
alert('Failed to download the configuration file.'); | ||
} finally { | ||
setIsDownloading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<button | ||
onClick={downloadFromWalrus} | ||
disabled={isDownloading} | ||
className="text-sm px-2 py-1 rounded bg-blue-500 text-white hover:bg-blue-600 transition-colors duration-200 ease-in-out" | ||
> | ||
{isDownloading ? 'Downloading...' : 'Download'} | ||
</button> | ||
); | ||
}; | ||
|
||
export default DownloadFromWalrusButton; |
Oops, something went wrong.