Skip to content

Commit

Permalink
test json data
Browse files Browse the repository at this point in the history
  • Loading branch information
nikos-koukis committed Oct 13, 2023
1 parent 10bceb8 commit ac51e14
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/views/Home/components/NewUserForm/ViewWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';

import { useEffect } from 'react';
interface UserInfo {
address: string;
secretWords: string[];
Expand All @@ -14,24 +14,23 @@ interface ViewWalletProps {
const ViewWallet: React.FC<ViewWalletProps> = ({ userInfo, isLoadingUserInfo, jsonPrettyData }) => {
const [parsedData, setParsedData] = useState<any | null>(null);

if (jsonPrettyData !== '') {
setParsedData(JSON.parse(jsonPrettyData));
}
useEffect(() => {
if (jsonPrettyData !== '') {
setParsedData(JSON.parse(jsonPrettyData));
}
}, [jsonPrettyData]);

const handleDownload = () => {
if (parsedData) {
const jsonContent = JSON.stringify(parsedData, null, 2);

const blob = new Blob([jsonContent], { type: 'application/json' });

const url = window.URL.createObjectURL(blob);

const a = document.createElement('a');
a.href = url;
a.download = 'file.json';

a.click();

window.URL.revokeObjectURL(url);
}
};
Expand All @@ -44,7 +43,7 @@ const ViewWallet: React.FC<ViewWalletProps> = ({ userInfo, isLoadingUserInfo, js
<div>
<h1>View Wallet</h1>
<p>Address: {userInfo.address}</p>
{parsedData !== '' && (
{parsedData !== null && (
<div>
<button onClick={handleDownload}>Download JSON</button>
</div>
Expand All @@ -53,6 +52,4 @@ const ViewWallet: React.FC<ViewWalletProps> = ({ userInfo, isLoadingUserInfo, js
)}
</div>
);
};

export default ViewWallet;
};

0 comments on commit ac51e14

Please sign in to comment.