Skip to content

Commit

Permalink
npm run format
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Dec 30, 2024
1 parent 0531650 commit 81681e0
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 51 deletions.
11 changes: 5 additions & 6 deletions src/stores/dexie.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -16,9 +16,9 @@ export class CashuDexie extends Dexie {
proofs!: Table<WalletProof>;

constructor() {
super('db');
super("db");
this.version(1).stores({
proofs: 'secret, id, C, amount, reserved, quote',
proofs: "secret, id, C, amount, reserved, quote",
});
}
}
Expand All @@ -29,8 +29,7 @@ export const useDexieStore = defineStore("dexie", {
state: () => ({
migratedToDexie: useLocalStorage<boolean>("cashu.dexie.migrated", false),
}),
getters: {
},
getters: {},
actions: {
migrateToDexie: function () {
if (this.migratedToDexie) {
Expand All @@ -52,6 +51,6 @@ export const useDexieStore = defineStore("dexie", {
},
deleteAllTables: function () {
cashuDb.proofs.clear();
}
},
},
});
44 changes: 25 additions & 19 deletions src/stores/mints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -96,13 +96,13 @@ export const useMintsStore = defineStore("mints", {
// State variables
const proofs = ref<WalletProof[]>([]);
const activeProofs = ref<WalletProof[]>([]);
const activeUnit = useLocalStorage<string>('cashu.activeUnit', 'sat');
const activeMintUrl = useLocalStorage<string>('cashu.activeMintUrl', '');
const activeUnit = useLocalStorage<string>("cashu.activeUnit", "sat");
const activeMintUrl = useLocalStorage<string>("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);
Expand All @@ -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
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -410,7 +416,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 @@ -450,7 +456,7 @@ export const useMintsStore = defineStore("mints", {
console.error(error);
try {
// notifyApiError(error, "Could not get mint keys");
} catch { }
} catch {}
throw error;
}
},
Expand All @@ -464,7 +470,7 @@ export const useMintsStore = defineStore("mints", {
console.error(error);
try {
// notifyApiError(error, "Could not get mint keysets");
} catch { }
} catch {}
throw error;
}
},
Expand All @@ -487,5 +493,5 @@ export const useMintsStore = defineStore("mints", {
throw new Error(`Mint error: ${response.error}`);
}
},
}
},
});
12 changes: 6 additions & 6 deletions src/stores/proofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand All @@ -43,22 +43,22 @@ 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);
});
});
},
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<WalletProof[]> {
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);
Expand Down
8 changes: 5 additions & 3 deletions src/stores/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/stores/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
32 changes: 16 additions & 16 deletions src/stores/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -1278,7 +1278,7 @@ export const useWalletStore = defineStore("wallet", {
},
////////////// UI HELPERS //////////////
addOutgoingPendingInvoiceToHistory: async function (
quote: MeltQuoteResponse,
quote: MeltQuoteResponse
) {
const mintStore = useMintsStore();
this.invoiceHistory.push({
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 81681e0

Please sign in to comment.