From e253283bab3602296de12230d2c0a636c6f98908 Mon Sep 17 00:00:00 2001 From: Erik Brakke Date: Thu, 4 May 2023 06:38:12 -0600 Subject: [PATCH] move requestMint to wallet store --- src/js/utils.js | 7 ++++++- src/pages/WalletPage.vue | 35 +---------------------------------- src/stores/wallet.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/js/utils.js b/src/js/utils.js index 6d4d5a2f..bb2f34fa 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -1,4 +1,5 @@ import * as nobleSecp256k1 from "./noble-secp256k1"; +import { date } from "quasar"; function splitAmount(value) { const chunks = []; @@ -24,4 +25,8 @@ function hexToNumber(hex) { return BigInt(`0x${hex}`); } -export { splitAmount, bytesToNumber, bigIntStringify }; +function currentDateStr() { + return date.formatDate(new Date(), "YYYY-MM-DD HH:mm:ss"); +} + +export { splitAmount, bytesToNumber, bigIntStringify, currentDateStr }; diff --git a/src/pages/WalletPage.vue b/src/pages/WalletPage.vue index 4f7f1dd4..dc7cd848 100644 --- a/src/pages/WalletPage.vue +++ b/src/pages/WalletPage.vue @@ -1014,6 +1014,7 @@ export default { "addPendingToken", "setTokenPaid", ]), + ...mapActions(useWalletStore, ["requestMint"]), // TOKEN METHODS decodeToken: function (encoded_token) { return token.decode(encoded_token); @@ -1487,40 +1488,6 @@ export default { // /mint - requestMint: async function (amount = null) { - /* - gets an invoice from the mint to get new tokens - */ - if (amount != null) { - this.invoiceData.amount = amount; - } - try { - const data = await this.activeMint.requestMint(this.invoiceData.amount); - this.assertMintError(data); - console.log("### data", data); - - this.invoiceData.bolt11 = data.pr; - this.invoiceData.hash = data.hash; - this.invoiceHistory.push( - // extend dictionary - Object.assign({}, this.invoiceData, { - date: currentDateStr(), - status: "pending", - mint: this.activeMintUrl, - }) - ); - return data; - } catch (error) { - console.error(error); - try { - this.notifyApiError(error); - } catch {} - throw error; - } - }, - - // /mint - mintApi: async function (amounts, payment_hash, verbose = true) { /* asks the mint to check whether the invoice with payment_hash has been paid diff --git a/src/stores/wallet.js b/src/stores/wallet.js index 4a06e414..1ea61287 100644 --- a/src/stores/wallet.js +++ b/src/stores/wallet.js @@ -1,4 +1,6 @@ import { defineStore } from "pinia"; +import { currentDateStr } from "src/js/utils"; +import { notifyApiError } from "src/js/notify"; import { useMintsStore } from "./mints"; import { useLocalStorage } from "@vueuse/core"; @@ -34,4 +36,31 @@ export const useWalletStore = defineStore("wallet", { return wallet; }, }, + actions: { + requestMint: async function (amount = null) { + const mints = useMintsStore(); + if (amount != null) { + this.invoiceData.amount = amount; + } + try { + const data = await mints.activeMint.requestMint( + this.invoiceData.amount + ); + this.invoiceData.bolt11 = data.pr; + this.invoiceData.hash = data.hash; + this.invoiceHistory.push( + // extend dictionary + Object.assign({}, this.invoiceData, { + date: currentDateStr(), + status: "pending", + mint: this.activeMintUrl, + }) + ); + return data; + } catch (error) { + console.error(error); + notifyApiError(error); + } + }, + }, });