Skip to content

Commit

Permalink
move invoice data to wallet store
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Brakke committed May 4, 2023
1 parent 7099563 commit 4696d4b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 45 deletions.
51 changes: 6 additions & 45 deletions src/pages/WalletPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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: "",
Expand Down Expand Up @@ -979,6 +954,11 @@ export default {
"proofs",
"activeMint",
]),
...mapState(useWalletStore, [
"invoiceHistory",
"invoiceData",
"payInvoiceData",
]),
...mapWritableState(useMintsStore, ["showAddMintDialog"]),
...mapWritableState(useWorkersStore, [
"invoiceCheckListener",
Expand Down Expand Up @@ -1529,7 +1509,6 @@ export default {
mint: this.activeMintUrl,
})
);
this.storeInvoiceHistory();
return data;
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -1909,7 +1888,6 @@ export default {
status: "paid",
mint: this.activeMintUrl,
});
this.storeInvoiceHistory();
this.payInvoiceData.invoice = false;
this.payInvoiceData.show = false;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
37 changes: 37 additions & 0 deletions src/stores/wallet.js
Original file line number Diff line number Diff line change
@@ -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;
},
},
});

0 comments on commit 4696d4b

Please sign in to comment.