Resolve "WIP: UTXO Selection and Storage"

This commit is contained in:
Jim Hamill
2025-01-11 08:39:24 +00:00
parent f934216d68
commit 33fd9bac4d
156 changed files with 13304 additions and 4595 deletions
+4 -4
View File
@@ -13,7 +13,7 @@ class WalletHDReact extends WalletHD<WalletP2PKHReact> {
node: HdPrivateNodeValid,
electrum: Blockchain,
walletFactory = (privateKeyBytes: Uint8Array, electrum: Blockchain) =>
new WalletP2PKHReact(privateKeyBytes, electrum)
new WalletP2PKHReact(privateKeyBytes, electrum),
) {
super(node, electrum, walletFactory);
@@ -66,17 +66,17 @@ class WalletHDReact extends WalletHD<WalletP2PKHReact> {
export function useWalletHD(node: HdPrivateNodeValid, electrum: Blockchain) {
const walletHD = useMemo(
() => new WalletHDReact(node, electrum),
[node, electrum]
[node, electrum],
);
const wallets = useSyncExternalStore(
walletHD.subscribeToWallets,
walletHD.getWallets
walletHD.getWallets,
);
const shouldMonitor = useSyncExternalStore(
walletHD.subscribeToShouldMonitor,
walletHD.getShouldMonitor
walletHD.getShouldMonitor,
);
const balance = useMemo(() => {
+4 -4
View File
@@ -8,21 +8,21 @@ import {
export function useWalletP2PKH(
privateKeyBytes: Uint8Array,
electrum: Blockchain
electrum: Blockchain,
) {
const wallet = React.useMemo(
() => new WalletP2PKHReact(privateKeyBytes, electrum),
[privateKeyBytes, electrum]
[privateKeyBytes, electrum],
);
const unspents = useSyncExternalStore(
wallet.subscribeToUnspents,
wallet.getUnspents
wallet.getUnspents,
);
const transactions = useSyncExternalStore(
wallet.subscribeToTransactions,
wallet.getTransactions
wallet.getTransactions,
);
const balance = React.useMemo(() => {
+5 -5
View File
@@ -12,7 +12,7 @@ export class WalletP2PKHSvelte extends WalletP2PKH {
// Derived store for balance
public balance: Readable<number> = derived(this.unspents, ($unspents) =>
$unspents.reduce((total, unspent) => total + unspent.value, 0)
$unspents.reduce((total, unspent) => total + unspent.value, 0),
);
constructor(privateKeyBytes: Uint8Array, electrum: Blockchain) {
@@ -28,7 +28,7 @@ export class WalletP2PKHSvelte extends WalletP2PKH {
export function useWalletP2PKHSvelte(
privateKeyBytes: Uint8Array,
electrum: Blockchain
electrum: Blockchain,
): WalletP2PKHSvelte {
return new WalletP2PKHSvelte(privateKeyBytes, electrum);
}
@@ -44,18 +44,18 @@ export class WalletHDSvelte extends WalletHD<WalletP2PKHSvelte> {
let walletBalance = 0;
wallet.balance.subscribe((value) => (walletBalance = value))();
return total + walletBalance;
}, 0)
}, 0),
);
constructor(
node: HdPrivateNodeValid,
electrum: Blockchain,
walletFactory = useWalletP2PKHSvelte
walletFactory = useWalletP2PKHSvelte,
) {
super(node, electrum, walletFactory);
this.events.on('walletsUpdated', (wallets) => this.wallets.set(wallets));
this.events.on('shouldMonitorUpdated', (shouldMonitor) =>
this.shouldMonitor.set(shouldMonitor)
this.shouldMonitor.set(shouldMonitor),
);
}
}