diff --git a/src/stores/dexie.ts b/src/stores/dexie.ts index 39e51184..6eab8c94 100644 --- a/src/stores/dexie.ts +++ b/src/stores/dexie.ts @@ -1,5 +1,5 @@ import { defineStore } from "pinia"; -import Dexie, { Table } from 'dexie'; +import Dexie, { Table } from "dexie"; import { useLocalStorage } from "@vueuse/core"; import { WalletProof } from "./mints"; @@ -16,9 +16,9 @@ export class CashuDexie extends Dexie { proofs!: Table; constructor() { - super('db'); + super("db"); this.version(1).stores({ - proofs: 'secret, id, C, amount, reserved, quote', + proofs: "secret, id, C, amount, reserved, quote", }); } } @@ -29,8 +29,7 @@ export const useDexieStore = defineStore("dexie", { state: () => ({ migratedToDexie: useLocalStorage("cashu.dexie.migrated", false), }), - getters: { - }, + getters: {}, actions: { migrateToDexie: function () { if (this.migratedToDexie) { @@ -52,6 +51,6 @@ export const useDexieStore = defineStore("dexie", { }, deleteAllTables: function () { cashuDb.proofs.clear(); - } + }, }, }); diff --git a/src/stores/mints.ts b/src/stores/mints.ts index c38f70bb..b30b8e16 100644 --- a/src/stores/mints.ts +++ b/src/stores/mints.ts @@ -13,9 +13,9 @@ import { GetInfoResponse, } from "@cashu/cashu-ts"; import { useUiStore } from "./ui"; -import { cashuDb } from "src/stores/dexie" -import { liveQuery } from 'dexie'; -import { ref, computed, watch } from 'vue'; +import { cashuDb } from "src/stores/dexie"; +import { liveQuery } from "dexie"; +import { ref, computed, watch } from "vue"; export type Mint = { url: string; @@ -65,8 +65,8 @@ export class MintClass { unitProofs(unit: string) { const unitKeysets = this.unitKeysets(unit); - return this.proofs.filter((p) => - unitKeysets.map((k) => k.id).includes(p.id) && !p.reserved + return this.proofs.filter( + (p) => unitKeysets.map((k) => k.id).includes(p.id) && !p.reserved ); } @@ -96,13 +96,13 @@ export const useMintsStore = defineStore("mints", { // State variables const proofs = ref([]); const activeProofs = ref([]); - const activeUnit = useLocalStorage('cashu.activeUnit', 'sat'); - const activeMintUrl = useLocalStorage('cashu.activeMintUrl', ''); + const activeUnit = useLocalStorage("cashu.activeUnit", "sat"); + const activeMintUrl = useLocalStorage("cashu.activeMintUrl", ""); const addMintData = ref({ - url: '', - nickname: '', + url: "", + nickname: "", }); - const mints = useLocalStorage('cashu.mints', [] as Mint[]); + const mints = useLocalStorage("cashu.mints", [] as Mint[]); const showAddMintDialog = ref(false); const addMintBlocking = ref(false); const showRemoveMintDialog = ref(false); @@ -121,20 +121,26 @@ export const useMintsStore = defineStore("mints", { // Function to update activeProofs const updateActiveProofs = () => { - const currentMint = mints.value.find((m) => m.url === activeMintUrl.value); + 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); + 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); + activeProofs.value = proofs.value + .filter((p) => keysetIds.includes(p.id)) + .filter((p) => !p.reserved); }; // Watch for changes in activeMintUrl and activeUnit @@ -238,8 +244,8 @@ export const useMintsStore = defineStore("mints", { }, mintUnitProofs(mint: Mint, unit: string): WalletProof[] { const unitKeysets = mint.keysets.filter((k) => k.unit === unit); - return this.proofs.filter((p) => - unitKeysets.map((k) => k.id).includes(p.id) && !p.reserved + return this.proofs.filter( + (p) => unitKeysets.map((k) => k.id).includes(p.id) && !p.reserved ); }, toggleUnit: function () { @@ -410,7 +416,7 @@ export const useMintsStore = defineStore("mints", { console.error(error); try { // notifyApiError(error, "Could not get mint info"); - } catch { } + } catch {} throw error; } }, @@ -450,7 +456,7 @@ export const useMintsStore = defineStore("mints", { console.error(error); try { // notifyApiError(error, "Could not get mint keys"); - } catch { } + } catch {} throw error; } }, @@ -464,7 +470,7 @@ export const useMintsStore = defineStore("mints", { console.error(error); try { // notifyApiError(error, "Could not get mint keysets"); - } catch { } + } catch {} throw error; } }, @@ -487,5 +493,5 @@ export const useMintsStore = defineStore("mints", { throw new Error(`Mint error: ${response.error}`); } }, - } + }, }); diff --git a/src/stores/proofs.ts b/src/stores/proofs.ts index c7acab28..b9185972 100644 --- a/src/stores/proofs.ts +++ b/src/stores/proofs.ts @@ -20,12 +20,12 @@ export const useProofsStore = defineStore("proofs", { quote?: string ) { const setQuote: string | undefined = reserved ? quote : undefined; - await cashuDb.transaction('rw', cashuDb.proofs, async () => { + await cashuDb.transaction("rw", cashuDb.proofs, async () => { for (const p of proofs) { await cashuDb.proofs - .where('secret') + .where("secret") .equals(p.secret) - .modify(pr => { + .modify((pr) => { pr.reserved = reserved; pr.quote = setQuote; }); @@ -43,7 +43,7 @@ export const useProofsStore = defineStore("proofs", { }, async addProofs(proofs: Proof[], quote?: string) { const walletProofs = this.proofsToWalletProofs(proofs); - await cashuDb.transaction('rw', cashuDb.proofs, async () => { + await cashuDb.transaction("rw", cashuDb.proofs, async () => { walletProofs.forEach(async (p) => { await cashuDb.proofs.add(p); }); @@ -51,14 +51,14 @@ export const useProofsStore = defineStore("proofs", { }, async removeProofs(proofs: Proof[]) { const walletProofs = this.proofsToWalletProofs(proofs); - await cashuDb.transaction('rw', cashuDb.proofs, async () => { + await cashuDb.transaction("rw", cashuDb.proofs, async () => { walletProofs.forEach(async (p) => { await cashuDb.proofs.delete(p.secret); }); }); }, async getProofsForQuote(quote: string): Promise { - return await cashuDb.proofs.where('quote').equals(quote).toArray(); + return await cashuDb.proofs.where("quote").equals(quote).toArray(); }, getUnreservedProofs: function (proofs: WalletProof[]) { return proofs.filter((p) => !p.reserved); diff --git a/src/stores/restore.ts b/src/stores/restore.ts index f52f4a2d..d63ec647 100644 --- a/src/stores/restore.ts +++ b/src/stores/restore.ts @@ -106,8 +106,9 @@ export const useRestoreStore = defineStore("restore", { let restoredProofs: Proof[] = []; for (let i = 0; i < restoreProofs.length; i += BATCH_SIZE) { - this.restoreStatus = `Checking proofs ${i} to ${i + BATCH_SIZE - } for keyset ${keyset.id}`; + this.restoreStatus = `Checking proofs ${i} to ${ + i + BATCH_SIZE + } for keyset ${keyset.id}`; const checkRestoreProofs = restoreProofs.slice(i, i + BATCH_SIZE); const proofStates = await wallet.checkProofsStates( checkRestoreProofs @@ -121,7 +122,8 @@ export const useRestoreStore = defineStore("restore", { ); if (unspentProofs.length > 0) { console.log( - `Found ${unspentProofs.length + `Found ${ + unspentProofs.length } unspent proofs with sum ${unspentProofs.reduce( (s, p) => s + p.amount, 0 diff --git a/src/stores/storage.ts b/src/stores/storage.ts index 545bc526..d69e6bae 100644 --- a/src/stores/storage.ts +++ b/src/stores/storage.ts @@ -7,7 +7,6 @@ import { useTokensStore } from "./tokens"; import { currentDateStr } from "src/js/utils"; import { useProofsStore } from "./proofs"; - const proofsStore = useProofsStore(); export const useStorageStore = defineStore("storage", { diff --git a/src/stores/wallet.ts b/src/stores/wallet.ts index a815dc23..56b8c86a 100644 --- a/src/stores/wallet.ts +++ b/src/stores/wallet.ts @@ -815,8 +815,8 @@ export const useWalletStore = defineStore("wallet", { useUiStore().vibrate(); notifySuccess( "Paid " + - uIStore.formatCurrency(amount_paid, mintWallet.unit) + - " via Lightning" + uIStore.formatCurrency(amount_paid, mintWallet.unit) + + " via Lightning" ); console.log("#### pay lightning: token paid"); tokenStore.addPaidToken({ @@ -1066,10 +1066,10 @@ export const useWalletStore = defineStore("wallet", { const proofStore = useProofsStore(); notifySuccess( "Sent " + - uIStore.formatCurrency( - proofStore.sumProofs(spentProofs), - historyToken.unit - ) + uIStore.formatCurrency( + proofStore.sumProofs(spentProofs), + historyToken.unit + ) ); } else { console.log("### token not paid yet"); @@ -1151,8 +1151,8 @@ export const useWalletStore = defineStore("wallet", { useUiStore().vibrate(); notifySuccess( "Received " + - uIStore.formatCurrency(invoice.amount, invoice.unit) + - " via Lightning" + uIStore.formatCurrency(invoice.amount, invoice.unit) + + " via Lightning" ); unsub(); return proofs; @@ -1209,8 +1209,8 @@ export const useWalletStore = defineStore("wallet", { useUiStore().vibrate(); notifySuccess( "Received " + - uIStore.formatCurrency(invoice.amount, invoice.unit) + - " via Lightning" + uIStore.formatCurrency(invoice.amount, invoice.unit) + + " via Lightning" ); return proofs; } catch (error) { @@ -1259,10 +1259,10 @@ export const useWalletStore = defineStore("wallet", { useUiStore().vibrate(); notifySuccess( "Sent " + - uIStore.formatCurrency( - useProofsStore().sumProofs(proofs), - invoice.unit - ) + uIStore.formatCurrency( + useProofsStore().sumProofs(proofs), + invoice.unit + ) ); } // set invoice in history to paid @@ -1278,7 +1278,7 @@ export const useWalletStore = defineStore("wallet", { }, ////////////// UI HELPERS ////////////// addOutgoingPendingInvoiceToHistory: async function ( - quote: MeltQuoteResponse, + quote: MeltQuoteResponse ) { const mintStore = useMintsStore(); this.invoiceHistory.push({ @@ -1506,7 +1506,7 @@ export const useWalletStore = defineStore("wallet", { this.payInvoiceData.lnurlpay.maxSendable >= amount * 1000 ) { if (mintStore.activeUnit == "usd") { - const priceUsd = usePriceStore().bitcoinPrice + const priceUsd = usePriceStore().bitcoinPrice; if (priceUsd == 0) { notifyError("No price data.", "LNURL Error"); return;