From bd3592d01ab54b270c2c4ec4bf5a34ad48843a1e Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 25 Apr 2023 20:40:07 +0200 Subject: [PATCH 1/4] fix race condition --- src/pages/WalletPage.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/WalletPage.vue b/src/pages/WalletPage.vue index 7b372d7c..6aadec58 100644 --- a/src/pages/WalletPage.vue +++ b/src/pages/WalletPage.vue @@ -2429,13 +2429,13 @@ export default { ); // startup tasks - this.checkProofsSpendable(this.activeProofs, true).catch((err) => { + await this.checkProofsSpendable(this.activeProofs, true).catch((err) => { return; }); - this.checkPendingInvoices().catch((err) => { + await this.checkPendingInvoices().catch((err) => { return; }); - this.checkPendingTokens().catch((err) => { + await this.checkPendingTokens().catch((err) => { return; }); From 6d7341442354d0b45d0ebd82674af77dccd9eb3f Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 25 Apr 2023 23:24:20 +0200 Subject: [PATCH 2/4] comments --- src/stores/mints.js | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/stores/mints.js b/src/stores/mints.js index 71da071a..3d065cda 100644 --- a/src/stores/mints.js +++ b/src/stores/mints.js @@ -1,29 +1,29 @@ -import { defineStore } from 'pinia' -import { useLocalStorage } from "@vueuse/core" +import { defineStore } from "pinia"; +import { useLocalStorage } from "@vueuse/core"; import { useWorkersStore } from "./workers"; -import {axios} from "boot/axios"; +import { axios } from "boot/axios"; import { notifyApiError, notifyError, notifySuccess } from "src/js/notify"; -export const useMintsStore = defineStore('mints', { +export const useMintsStore = defineStore("mints", { state: () => { return { - activeMintUrl: useLocalStorage('cashu.activeMintUrl', ''), - activeProofs: useLocalStorage('cashu.activeProofs', []), - keys: useLocalStorage('cashu.keys', {}), - keysets: useLocalStorage('cashu.keysets', []), - mintToAdd: 'https://8333.space:3338', - mints: useLocalStorage('cashu.mints', []), - proofs: useLocalStorage('cashu.proofs', []), + activeMintUrl: useLocalStorage("cashu.activeMintUrl", ""), + activeProofs: useLocalStorage("cashu.activeProofs", []), + keys: useLocalStorage("cashu.keys", {}), + keysets: useLocalStorage("cashu.keysets", []), + mintToAdd: "https://8333.space:3338", + mints: useLocalStorage("cashu.mints", []), + proofs: useLocalStorage("cashu.proofs", []), showAddMintDialog: false, - } + }; }, getters: {}, actions: { setShowAddMintDialog(show) { - this.showAddMintDialog = show + this.showAddMintDialog = show; }, setMintToAdd(mint) { - this.mintToAdd = mint + this.mintToAdd = mint; }, setProofs(proofs) { this.proofs = proofs; @@ -56,8 +56,11 @@ export const useMintsStore = defineStore('mints', { } }, activateMint: async function (url, verbose = false) { - const workers = useWorkersStore() + const workers = useWorkersStore(); if (url === this.activeMintUrl) { + // return here because this function is called repeatedly by the + // invoice check and token spendable check workers and would otherwise + // run until cleaAllWorkers and kill the woerkers return; } // we need to stop workers because they will reset the activeMint again @@ -178,6 +181,6 @@ export const useMintsStore = defineStore('mints', { .map((t) => t) .flat() .reduce((sum, el) => (sum += el.amount), 0); - } + }, }, -}) +}); From 5812d795bce8c0c48adba8b600105219d968626d Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 25 Apr 2023 23:34:54 +0200 Subject: [PATCH 3/4] force activation of mint for migration --- src/pages/WalletPage.vue | 2 +- src/stores/mints.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/WalletPage.vue b/src/pages/WalletPage.vue index 6aadec58..6d017edd 100644 --- a/src/pages/WalletPage.vue +++ b/src/pages/WalletPage.vue @@ -2366,7 +2366,7 @@ export default { this.walletURL = this.baseURL; } let activeMintUrl = localStorage.getItem("cashu.activeMintUrl"); - await this.activateMint(activeMintUrl); + await this.activateMint(activeMintUrl, false, true); } else { this.setTab("settings"); } diff --git a/src/stores/mints.js b/src/stores/mints.js index 3d065cda..cda8ccb1 100644 --- a/src/stores/mints.js +++ b/src/stores/mints.js @@ -55,9 +55,9 @@ export const useMintsStore = defineStore("mints", { this.showAddMintDialog = false; } }, - activateMint: async function (url, verbose = false) { + activateMint: async function (url, verbose = false, force = false) { const workers = useWorkersStore(); - if (url === this.activeMintUrl) { + if (url === this.activeMintUrl && !force) { // return here because this function is called repeatedly by the // invoice check and token spendable check workers and would otherwise // run until cleaAllWorkers and kill the woerkers From ff9fb1f87ba7491d0ad9984cdfd54cdb7cc9f216 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 25 Apr 2023 23:36:17 +0200 Subject: [PATCH 4/4] comments --- src/pages/WalletPage.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/WalletPage.vue b/src/pages/WalletPage.vue index 6d017edd..dac77653 100644 --- a/src/pages/WalletPage.vue +++ b/src/pages/WalletPage.vue @@ -2366,6 +2366,8 @@ export default { this.walletURL = this.baseURL; } let activeMintUrl = localStorage.getItem("cashu.activeMintUrl"); + // we'll force the activation of the mint for the migration + // from without a pinia store await this.activateMint(activeMintUrl, false, true); } else { this.setTab("settings");