From 521b9763ab64f8077b079e758392304f17f41ef1 Mon Sep 17 00:00:00 2001 From: klepi21 Date: Wed, 11 Oct 2023 18:22:19 +0300 Subject: [PATCH] from jsoncontent to download button --- .../components/NewUserForm/CreateWallet.tsx | 85 ++++++++++++++++--- 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/src/views/Home/components/NewUserForm/CreateWallet.tsx b/src/views/Home/components/NewUserForm/CreateWallet.tsx index b0aaed6..ac5195b 100644 --- a/src/views/Home/components/NewUserForm/CreateWallet.tsx +++ b/src/views/Home/components/NewUserForm/CreateWallet.tsx @@ -3,6 +3,8 @@ import { Mnemonic, UserWallet } from "@multiversx/sdk-wallet"; import { getShardOfAddress } from "@multiversx/sdk-dapp/utils/account" import { useState } from "react"; import { createUser } from "../../services/calls"; +import React from 'react'; + export default function CreateWallet({formData, email, platform, handleReset}: {formData: any, email: string, platform: string, handleReset: any}) { @@ -24,6 +26,31 @@ export default function CreateWallet({formData, email, platform, handleReset}: { type WalletInfoType = keyof typeof walletInfoTypes; + const [jsonFileDownloaded, setJsonFileDownloaded] = useState(false); + + const downloadJsonFile = () => { + // Create a Blob from the JSON content + const blob = new Blob([jsonFileContent], { type: 'application/json' }); + + // Create a data URL for the Blob + const url = URL.createObjectURL(blob); + + // Create an anchor element for downloading + const a = document.createElement('a'); + a.href = url; + a.download = 'mywallet.json'; + + // Trigger a click event on the anchor element + a.click(); + + // Clean up by revoking the URL + URL.revokeObjectURL(url); + + // Set the state to indicate that the file has been downloaded + setJsonFileDownloaded(true); + }; + + // Create a null wallet info object const nullWalletInfo = Object.fromEntries( Object.entries(walletInfoTypes).map(([key, value]) => [value, null]) @@ -149,19 +176,51 @@ export default function CreateWallet({formData, email, platform, handleReset}: { } - {jsonFileContent != "" && - <> - - JSON File: {jsonFileContent} - - - Congratsulations! Now you can save the JSON file in a safe place and connect using it (password is "password" 😎). - - - Wait a few seconds and refresh the page. You should see your information if everything run successfully. - - - } + {jsonFileContent != "" && !jsonFileDownloaded && ( + + + + + + +)} + +{jsonFileContent != "" && jsonFileDownloaded && ( + <> + {/* + + JSON File: {jsonFileContent} + +*/} + + + + Congratulations! Now you can save the JSON file in a safe place and connect using it (password is "password" 😎). + + + Wait a few seconds and refresh the page. You should see your information if everything ran successfully. + + +)} + }