From: Chris Duncan Date: Mon, 14 Oct 2024 10:51:17 +0000 (-0700) Subject: Refactor wallet function to save wallet IDs for later. Fix weird function naming... X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=01dee28ccdcecb1068c90c55c5810e1caf6ca550;p=nemo-wallet.git Refactor wallet function to save wallet IDs for later. Fix weird function naming conflict with clear(). --- 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 @@