diff --git a/src/components/MintSettings.vue b/src/components/MintSettings.vue index 1a5edd37..0f47fd3b 100644 --- a/src/components/MintSettings.vue +++ b/src/components/MintSettings.vue @@ -47,7 +47,7 @@ lines="1" v-if="mint.nickname" @click=" - activateMintUrl(mint.url, (verbose = false), (force = true)) + activateMintUrl(mint.url, (verbose = false), (force = false)) " class="cursor-pointer" style="word-break: break-word" @@ -56,7 +56,7 @@ - + diff --git a/src/stores/mints.ts b/src/stores/mints.ts index 62d86bae..ce747b3d 100644 --- a/src/stores/mints.ts +++ b/src/stores/mints.ts @@ -122,8 +122,6 @@ export const useMintsStore = defineStore("mints", { } else { if (this.mints.length) { console.error("No active mint. This should not happen. switching to first one.") - // fallback - // this.activeMintUrl = this.mints[0].url this.activateMintUrl(this.mints[0].url, false, true) return new MintClass(this.mints[0]); } @@ -238,14 +236,28 @@ export const useMintsStore = defineStore("mints", { this.addMintBlocking = false; } }, - activateMintUrl: async function (url: string, verbose = false, force = false) { + activateMintUrl: async function (url: string, verbose = false, force = false, unit: string | undefined = undefined) { const mint = this.mints.filter((m) => m.url === url)[0]; if (mint) { await this.activateMint(mint, verbose, force); + if (unit) { + await this.activateUnit(unit, verbose); + } } else { notifyError("Mint not found", "Mint activation failed"); } }, + activateUnit: async function (unit: string, verbose = false) { + const mint = this.mints.find((m) => m.url === this.activeMintUrl); + if (!mint) { + notifyError("No active mint", "Unit activation failed"); + return; + } + const mintClass = new MintClass(mint); + if (mintClass.units.includes(unit)) { + this.activeUnit = unit; + } + }, activateMint: async function (mint: Mint, verbose = false, force = false) { const workers = useWorkersStore(); if (mint.url === this.activeMintUrl && !force) { diff --git a/src/stores/wallet.ts b/src/stores/wallet.ts index 0e0fe3bb..6d4069a7 100644 --- a/src/stores/wallet.ts +++ b/src/stores/wallet.ts @@ -38,7 +38,7 @@ type Invoice = { type InvoiceHistory = Invoice & { date: string; status: "pending" | "paid"; - mint?: string; + mint: string; unit?: string; token?: string; }; @@ -371,15 +371,10 @@ export const useWalletStore = defineStore("wallet", { } let proofs = token.getProofs(tokenJson); - if (token.getMint(tokenJson) != mintStore.activeMintUrl) { - await mintStore.activateMintUrl(token.getMint(tokenJson)); - } - const amount = proofs.reduce((s, t) => (s += t.amount), 0); + // activate the mint and the unit + await mintStore.activateMintUrl(token.getMint(tokenJson), false, false, tokenJson.unit); - // set unit to unit in token - if (tokenJson.unit != undefined) { - mintStore.activeUnit = tokenJson.unit - } + const amount = proofs.reduce((s, t) => (s += t.amount), 0); try { // redeem const keysetId = this.getKeyset() @@ -725,9 +720,8 @@ export const useWalletStore = defineStore("wallet", { const proofs = token.getProofs(tokenJson); // activate the mint - if (token.getMint(tokenJson).length > 0) { - await mintStore.activateMintUrl(token.getMint(tokenJson)); - } + const mintInToken = token.getMint(tokenJson); + await mintStore.activateMintUrl(mintInToken); const spentProofs = await this.checkProofsSpendable(proofs); if (spentProofs != undefined && spentProofs.length == proofs.length) { @@ -777,9 +771,9 @@ export const useWalletStore = defineStore("wallet", { throw new Error("invoice not found"); } try { - if (invoice.mint != mintStore.activeMintUrl && invoice.mint != undefined) { - await mintStore.activateMintUrl(invoice.mint, false); - } + // activate the mint + await mintStore.activateMintUrl(invoice.mint, false, false, invoice.unit); + const proofs = await this.mint(invoice.amount, invoice.quote, verbose); if (!!window.navigator.vibrate) navigator.vibrate(200); notifySuccess("Received " + uIStore.formatCurrency(invoice.amount, mintStore.activeUnit) + " via Lightning"); @@ -799,9 +793,7 @@ export const useWalletStore = defineStore("wallet", { throw new Error("invoice not found"); } try { - if (invoice.mint != mintStore.activeMintUrl && invoice.mint != undefined) { - await mintStore.activateMintUrl(invoice.mint, false); - } + await mintStore.activateMintUrl(invoice.mint, false, false, invoice.unit); // this is an outgoing invoice, we first do a getMintQuote to check if the invoice is paid const mintQuote = await mintStore.activeMint().api.getMeltQuote(quote); console.log("### mintQuote", mintQuote);