Skip to content

Commit

Permalink
move requestMint 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 4696d4b commit e253283
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
7 changes: 6 additions & 1 deletion src/js/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as nobleSecp256k1 from "./noble-secp256k1";
import { date } from "quasar";

function splitAmount(value) {
const chunks = [];
Expand All @@ -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 };
35 changes: 1 addition & 34 deletions src/pages/WalletPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ export default {
"addPendingToken",
"setTokenPaid",
]),
...mapActions(useWalletStore, ["requestMint"]),
// TOKEN METHODS
decodeToken: function (encoded_token) {
return token.decode(encoded_token);
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions src/stores/wallet.js
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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);
}
},
},
});

0 comments on commit e253283

Please sign in to comment.