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()
}
</script>
<body onload="load()">
<x-box id="main" style="visibility:hidden;">
- <x-button onclick="wallet().then(w => {console.log(w);showWallets()})">
+ <x-button onclick="createWallet().then(w => { console.log(w);showWallets() })">
<x-label>Create</x-label>
</x-button>
<x-card id="wallet">
</x-card>
- <x-button onclick="clear()">
+ <x-button onclick="clearStorage()">
<x-label>Clear</x-label>
</x-button>
</x-box>