diff --git a/src/components/SettingsView.vue b/src/components/SettingsView.vue index de38f1e..b644913 100644 --- a/src/components/SettingsView.vue +++ b/src/components/SettingsView.vue @@ -1164,11 +1164,12 @@ To avoid double-spending attempts, this wallet marks - ecash as reserved so you don't reuse it. This button will - unset all reserved tokens so they can be used again. If - you do this, your wallet might include spent proofs. Press - the "Remove spent proofs" button to get rid of them. + >This wallet marks pending outgoing ecash as reserved (and + subtracts it from your balance) to prevent double-spend + attempts. This button will unset all reserved tokens so + they can be used again. If you do this, your wallet might + include spent proofs. Press the "Remove spent proofs" + button to get rid of them. @@ -1335,12 +1336,7 @@ export default defineComponent({ "showP2PkButtonInDrawer", ]), ...mapWritableState(useNWCStore, ["showNWCDialog", "showNWCData"]), - ...mapState(useMintsStore, [ - "activeMintUrl", - "mints", - "activeProofs", - "proofs", - ]), + ...mapState(useMintsStore, ["activeMintUrl", "mints", "activeProofs"]), ...mapState(useNPCStore, ["npcLoading"]), ...mapState(useNostrStore, [ "pubkey", @@ -1464,11 +1460,9 @@ export default defineComponent({ }, unsetAllReservedProofs: async function () { // mark all this.proofs as reserved=false - for (let proof of this.proofs) { - proof.reserved = false; - proof.quote = undefined; - } - this.notifySuccess("No reserved proofs left"); + const proofsStore = useProofsStore(); + await proofsStore.setReserved(await proofsStore.getProofs(), false); + this.notifySuccess("All reserved proofs unset"); }, checkActiveProofsSpendable: async function () { // iterate over this.activeProofs in batches of 50 and check if they are spendable diff --git a/src/stores/dexie.ts b/src/stores/dexie.ts index 71ccaa3..775d3ef 100644 --- a/src/stores/dexie.ts +++ b/src/stores/dexie.ts @@ -59,7 +59,8 @@ export const useDexieStore = defineStore("dexie", { cashuDb.proofs.add(proof); }); console.log( - `Migrated ${cashuDb.proofs.count()} proofs. Before: ${parsedProofs.length + `Migrated ${cashuDb.proofs.count()} proofs. Before: ${ + parsedProofs.length } proofs, After: ${(await proofsStore.getProofs()).length} proofs` ); console.log( diff --git a/src/stores/mints.ts b/src/stores/mints.ts index bd0b39d..2ce6edd 100644 --- a/src/stores/mints.ts +++ b/src/stores/mints.ts @@ -65,7 +65,7 @@ export class MintClass { } unitProofs(unit: string): WalletProof[] { - const proofsStore = useProofsStore() + const proofsStore = useProofsStore(); const unitKeysets = this.unitKeysets(unit); return proofsStore.proofs.filter( (p) => unitKeysets.map((k) => k.id).includes(p.id) && !p.reserved @@ -113,44 +113,12 @@ export const useMintsStore = defineStore("mints", { const uiStoreGlobal: any = useUiStore(); - // liveQuery(() => cashuDb.proofs.toArray()).subscribe({ - // next: (newProofs) => { - // proofs.value = newProofs; - // updateActiveProofs(); - // }, - // error: (err) => { - // console.error(err); - // }, - // }); - - // // Function to update activeProofs - // const updateActiveProofs = () => { - // const currentMint = mints.value.find( - // (m) => m.url === activeMintUrl.value - // ); - // if (!currentMint) { - // activeProofs.value = []; - // return; - // } - - // const unitKeysets = currentMint?.keysets?.filter( - // (k) => k.unit === activeUnit.value - // ); - // if (!unitKeysets || unitKeysets.length === 0) { - // activeProofs.value = []; - // return; - // } - - // const keysetIds = unitKeysets.map((k) => k.id); - // activeProofs.value = proofs.value - // .filter((p) => keysetIds.includes(p.id)) - // .filter((p) => !p.reserved); - // }; - // Watch for changes in activeMintUrl and activeUnit watch([activeMintUrl, activeUnit], async () => { const proofsStore = useProofsStore(); - console.log(`watcher: activeMintUrl: ${activeMintUrl.value}, activeUnit: ${activeUnit.value}`); + console.log( + `watcher: activeMintUrl: ${activeMintUrl.value}, activeUnit: ${activeUnit.value}` + ); await proofsStore.updateActiveProofs(); }); @@ -425,7 +393,7 @@ export const useMintsStore = defineStore("mints", { console.error(error); try { // notifyApiError(error, "Could not get mint info"); - } catch { } + } catch {} throw error; } }, @@ -465,7 +433,7 @@ export const useMintsStore = defineStore("mints", { console.error(error); try { // notifyApiError(error, "Could not get mint keys"); - } catch { } + } catch {} throw error; } }, @@ -479,7 +447,7 @@ export const useMintsStore = defineStore("mints", { console.error(error); try { // notifyApiError(error, "Could not get mint keysets"); - } catch { } + } catch {} throw error; } }, diff --git a/src/stores/proofs.ts b/src/stores/proofs.ts index ee14ffb..03baa87 100644 --- a/src/stores/proofs.ts +++ b/src/stores/proofs.ts @@ -44,9 +44,13 @@ export const useProofsStore = defineStore("proofs", { } const keysetIds = unitKeysets.map((k) => k.id); - const activeProofs = await cashuDb.proofs.where("id").anyOf(keysetIds).toArray().then((proofs) => { - return proofs.filter((p) => !p.reserved); - }); + const activeProofs = await cashuDb.proofs + .where("id") + .anyOf(keysetIds) + .toArray() + .then((proofs) => { + return proofs.filter((p) => !p.reserved); + }); mintStore.activeProofs = activeProofs; };