diff --git a/web/cashtab/src/components/Configure/Configure.js b/web/cashtab/src/components/Configure/Configure.js --- a/web/cashtab/src/components/Configure/Configure.js +++ b/web/cashtab/src/components/Configure/Configure.js @@ -1151,6 +1151,40 @@ setSavedWalletContactModal(true); }; + const exportWallet = savedWallets => { + let walletExport = { + wallets: [], + }; + // retireve only what's needed from saved wallet objects + for (let i = 0; i < savedWallets.length; i++) { + const walletSummary = { + // Store all wallet info except state and unused deriv paths + mnemonic: savedWallets[i].mnemonic, + name: savedWallets[i].name, + Path1899: savedWallets[i].Path1899, + }; + walletExport.wallets.push(walletSummary); + } + // add the activate wallet to export + walletExport.wallets.push({ + // Store all wallet info except state and unused deriv paths + mnemonic: wallet.mnemonic, + name: wallet.name, + Path1899: wallet.Path1899, + }); + + // convert and export wallet summary array into json format + let walletDataStr = JSON.stringify(walletExport, null, 4); + let walletDataUri = + 'data:application/json;charset=utf-8,' + + encodeURIComponent(walletDataStr); + let exportFileName = 'CashtabExport_' + new Date().toString() + '.json'; + let linkElement = document.createElement('a'); + linkElement.setAttribute('href', walletDataUri); + linkElement.setAttribute('download', exportFileName); + linkElement.click(); + }; + const handleManualAddContactModalOk = async () => { // if either inputs are invalid then go no further if (!manualContactNameIsValid || !manualContactAddressIsValid) { @@ -1574,6 +1608,9 @@ )} )} + exportWallet(savedWallets)}> + Export Cashtab Data + {savedWallets && savedWallets.length > 0 && ( <> diff --git a/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap b/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap --- a/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap +++ b/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap @@ -149,6 +149,31 @@ Import Wallet +
Import Wallet +