Skip to content

Commit

Permalink
Merge pull request cashubtc#26 from cashubtc/fix/migration_to_storage
Browse files Browse the repository at this point in the history
Fix/migration to storage
  • Loading branch information
callebtc authored Apr 25, 2023
2 parents 7c1669d + ff9fb1f commit df10e27
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/pages/WalletPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2366,7 +2366,9 @@ export default {
this.walletURL = this.baseURL;
}
let activeMintUrl = localStorage.getItem("cashu.activeMintUrl");
await this.activateMint(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");
}
Expand Down
41 changes: 22 additions & 19 deletions src/stores/mints.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -55,9 +55,12 @@ export const useMintsStore = defineStore('mints', {
this.showAddMintDialog = false;
}
},
activateMint: async function (url, verbose = false) {
const workers = useWorkersStore()
if (url === this.activeMintUrl) {
activateMint: async function (url, verbose = false, force = false) {
const workers = useWorkersStore();
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
return;
}
// we need to stop workers because they will reset the activeMint again
Expand Down Expand Up @@ -178,6 +181,6 @@ export const useMintsStore = defineStore('mints', {
.map((t) => t)
.flat()
.reduce((sum, el) => (sum += el.amount), 0);
}
},
},
})
});

0 comments on commit df10e27

Please sign in to comment.