From 01dee28ccdcecb1068c90c55c5810e1caf6ca550 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 14 Oct 2024 03:51:17 -0700 Subject: [PATCH] Refactor wallet function to save wallet IDs for later. Fix weird function naming conflict with clear(). --- app/pages/nemo-wallet.html | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/pages/nemo-wallet.html b/app/pages/nemo-wallet.html index a3ad906..f92c95e 100644 --- a/app/pages/nemo-wallet.html +++ b/app/pages/nemo-wallet.html @@ -23,23 +23,31 @@ Bip44Wallet = libnemo.Bip44Wallet console.log('loaded libnemo') } - async function wallet () { + async function createWallet () { const wallet = await Bip44Wallet.create('password') - await wallet.unlock('password') + const bip44WalletIds = JSON.parse(sessionStorage.getItem('Bip44Wallets') ?? '[]') + bip44WalletIds.push(wallet.id) + sessionStorage.setItem('Bip44Wallets', JSON.stringify(bip44WalletIds)) return wallet } async function showWallets () { + console.log(`showWallets()`) const card = document.getElementById('wallet') - for (let i = 0; i < sessionStorage.length; i++) { - const name = sessionStorage.key(i) - const item = sessionStorage.getItem(name) - console.log(item) + const bip44WalletIds = JSON.parse(sessionStorage.getItem('Bip44Wallets') ?? '[]') + console.log(`bip44WalletIds: ${bip44WalletIds}`) + for (const id of bip44WalletIds) { + console.log(`id: ${id}`) + const wallet = await Bip44Wallet.restore(id) const walletElement = document.createElement('x-label') - walletElement.innerText = item + await wallet.unlock('password') + console.log(`wallet: ${wallet}`) + walletElement.innerText = wallet.mnemonic + wallet.lock('password') card.appendChild(walletElement) } } - function clear () { + async function clearStorage () { + console.log('clear()') sessionStorage.clear() } @@ -51,12 +59,12 @@ -- 2.34.1