Skip to content

Commit

Permalink
fix: unset reserved proofs in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jan 13, 2025
1 parent 61a81cc commit 14d6a69
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 59 deletions.
26 changes: 10 additions & 16 deletions src/components/SettingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1164,11 +1164,12 @@
</q-btn></row
><row>
<q-item-label class="q-px-sm" caption
>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.
</q-item-label>
</row>
</q-item-section>
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/stores/dexie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
46 changes: 7 additions & 39 deletions src/stores/mints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
});

Expand Down Expand Up @@ -425,7 +393,7 @@ export const useMintsStore = defineStore("mints", {
console.error(error);
try {
// notifyApiError(error, "Could not get mint info");
} catch { }
} catch {}
throw error;
}
},
Expand Down Expand Up @@ -465,7 +433,7 @@ export const useMintsStore = defineStore("mints", {
console.error(error);
try {
// notifyApiError(error, "Could not get mint keys");
} catch { }
} catch {}
throw error;
}
},
Expand All @@ -479,7 +447,7 @@ export const useMintsStore = defineStore("mints", {
console.error(error);
try {
// notifyApiError(error, "Could not get mint keysets");
} catch { }
} catch {}
throw error;
}
},
Expand Down
10 changes: 7 additions & 3 deletions src/stores/proofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit 14d6a69

Please sign in to comment.