-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.mjs
49 lines (44 loc) · 1.28 KB
/
app.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { ECPrivateKeyBigints } from "./bitcoin/myCrypto.mjs";
import { bufToHex, parseHexToBuf } from "./bitcoin/utils/arraybuffer-hex.mjs";
import { parsePrefixedWif } from "./bitcoin/utils/wif.mjs";
import { html } from "./htm.mjs";
import { loadSavedKeysFromStorage, saveKeysToStorage } from "./keysStorage.mjs";
import { LoginView } from "./loginview.mjs";
import { useState } from "./thirdparty/hooks.mjs";
import { BitcoinWallet } from "./wallet.mjs";
import { WalletView } from "./walletview.mjs";
/**
*
* @param {{}} props
*/
export function App(props) {
const [wallet, setWallet] = useState(() => {
// todo read
const keys = loadSavedKeysFromStorage();
if (!keys) {
return;
}
return new BitcoinWallet(keys);
});
const onLogout = () => {
saveKeysToStorage(null);
document.location.reload();
};
const onLogin = (
/** @type {ReturnType<typeof parsePrefixedWif>[]} */ keys,
/** @type {boolean} */ isRemember
) => {
if (isRemember) {
saveKeysToStorage(keys);
}
setWallet(new BitcoinWallet(keys));
};
if (!wallet) {
return html`<div class="container">
<${LoginView} onLogin=${onLogin} />
</div>`;
}
return html`<div class="container">
<${WalletView} wallet=${wallet} onLogout=${onLogout} />
</div>`;
}