From 4696d4b596a8d306b164ee1e16862f5bd697b7e6 Mon Sep 17 00:00:00 2001 From: Erik Brakke Date: Thu, 4 May 2023 06:05:54 -0600 Subject: [PATCH] move invoice data to wallet store --- src/pages/WalletPage.vue | 51 +++++----------------------------------- src/stores/wallet.js | 37 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 45 deletions(-) create mode 100644 src/stores/wallet.js diff --git a/src/pages/WalletPage.vue b/src/pages/WalletPage.vue index f7018dc7..4f7f1dd4 100644 --- a/src/pages/WalletPage.vue +++ b/src/pages/WalletPage.vue @@ -815,6 +815,7 @@ import { mapActions, mapState, mapWritableState } from "pinia"; import { useMintsStore } from "src/stores/mints"; import { useWorkersStore } from "src/stores/workers"; import { useTokensStore } from "src/stores/tokens"; +import { useWalletStore } from "src/stores/wallet"; var currentDateStr = function () { return date.formatDate(new Date(), "YYYY-MM-DD HH:mm:ss"); @@ -840,37 +841,11 @@ export default { mintId: "", mintName: "", deferredPWAInstallPrompt: null, - invoiceHistory: [], - invoiceData: { - amount: 0, - memo: "", - bolt11: "", - hash: "", - }, camera: { data: null, show: false, camera: "auto", }, - //invoiceCheckListener: () => {}, - payInvoiceData: { - blocking: false, - bolt11: "", - show: false, - invoice: null, - lnurlpay: null, - lnurlauth: null, - data: { - request: "", - amount: 0, - comment: "", - }, - paymentChecker: null, - camera: { - show: false, - camera: "auto", - }, - }, sendData: { amount: 0, memo: "", @@ -979,6 +954,11 @@ export default { "proofs", "activeMint", ]), + ...mapState(useWalletStore, [ + "invoiceHistory", + "invoiceData", + "payInvoiceData", + ]), ...mapWritableState(useMintsStore, ["showAddMintDialog"]), ...mapWritableState(useWorkersStore, [ "invoiceCheckListener", @@ -1529,7 +1509,6 @@ export default { mint: this.activeMintUrl, }) ); - this.storeInvoiceHistory(); return data; } catch (error) { console.error(error); @@ -1909,7 +1888,6 @@ export default { status: "paid", mint: this.activeMintUrl, }); - this.storeInvoiceHistory(); this.payInvoiceData.invoice = false; this.payInvoiceData.show = false; @@ -1986,7 +1964,6 @@ export default { setInvoicePaid: async function (payment_hash) { const invoice = this.invoiceHistory.find((i) => i.hash === payment_hash); invoice.status = "paid"; - this.storeInvoiceHistory(); }, checkInvoice: async function (payment_hash, verbose = true) { console.log("### checkInvoice.hash", payment_hash); @@ -2240,18 +2217,6 @@ export default { downloadLink.click(); }, - storeInvoiceHistory: function () { - localStorage.setItem( - "cashu.invoiceHistory", - JSON.stringify(this.invoiceHistory) - ); - }, - /*storeProofs: function () { - localStorage.setItem( - "cashu.proofs", - JSON.stringify(this.proofs, bigIntStringify) - ); - },*/ migrationLocalstorage: async function () { // migration from old db to multimint for (var key in localStorage) { @@ -2353,10 +2318,6 @@ export default { this.mintName = params.get("mint_name"); } - this.invoiceHistory = JSON.parse( - localStorage.getItem("cashu.invoiceHistory") || "[]" - ); - // run migrations await this.migrationLocalstorage(); diff --git a/src/stores/wallet.js b/src/stores/wallet.js new file mode 100644 index 00000000..4a06e414 --- /dev/null +++ b/src/stores/wallet.js @@ -0,0 +1,37 @@ +import { defineStore } from "pinia"; +import { useMintsStore } from "./mints"; +import { useLocalStorage } from "@vueuse/core"; + +export const useWalletStore = defineStore("wallet", { + state: () => { + return { + invoiceHistory: useLocalStorage("cashu.invoiceHistory", []), + invoiceData: { + amount: 0, + memo: "", + bolt11: "", + hash: "", + }, + payInvoiceData: { + blocking: false, + bolt11: "", + show: false, + invoice: null, + lnurlpay: null, + lnurlauth: null, + data: { + request: "", + amount: 0, + comment: "", + }, + }, + }; + }, + getters: { + wallet() { + const mints = useMintsStore(); + const wallet = new CashuWallet(mints.keys, mints.activeMint); + return wallet; + }, + }, +});