Skip to content

Commit

Permalink
replace axios calls to mint with cashu-ts mint
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Brakke committed May 4, 2023
1 parent 859e546 commit 044692b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
39 changes: 11 additions & 28 deletions src/pages/WalletPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,7 @@ export default {
"keys",
"mints",
"proofs",
"activeMint",
]),
...mapWritableState(useMintsStore, ["showAddMintDialog"]),
...mapWritableState(useWorkersStore, [
Expand Down Expand Up @@ -1514,9 +1515,7 @@ export default {
this.invoiceData.amount = amount;
}
try {
const { data } = await axios.get(
`${this.activeMintUrl}/mint?amount=${this.invoiceData.amount}`
);
const data = await this.activeMint.requestMint(this.invoiceData.amount);
this.assertMintError(data);
console.log("### data", data);
Expand Down Expand Up @@ -1553,18 +1552,13 @@ export default {
let secrets = await this.generateSecrets(amounts);
let { outputs, rs } = await this.constructOutputs(amounts, secrets);
const keys = this.keys; // fix keys for constructProofs
const promises = await axios.post(
`${this.activeMintUrl}/mint?payment_hash=${payment_hash}`,
{
outputs,
}
);
this.assertMintError(promises.data, false);
if (promises.data.promises == null) {
const data = await this.activeMint.mint({ outputs }, payment_hash);
this.assertMintError(data, false);
if (data.promises == null) {
return {};
}
let proofs = await this.constructProofs(
promises.data.promises,
data.promises,
secrets,
rs,
keys
Expand Down Expand Up @@ -1663,10 +1657,8 @@ export default {
outputs,
};
const keys = this.keys; // fix keys for constructProofs
const { data } = await axios.post(
`${this.activeMintUrl}/split`,
payload
);
const data = await this.activeMint.split(payload);
this.assertMintError(data);
const frst_rs = rs.slice(0, frst_amounts.length);
const frst_secrets = secrets.slice(0, frst_amounts.length);
Expand Down Expand Up @@ -1874,10 +1866,7 @@ export default {
outputs,
};
const keys = this.keys; // fix keys for constructProofs
const { data } = await axios.post(
`${this.activeMintUrl}/melt`,
payload
);
const data = await this.activeMint.melt(payload);
this.assertMintError(data);
if (data.paid != true) {
throw new Error("Invoice not paid.");
Expand Down Expand Up @@ -1948,10 +1937,7 @@ export default {
}),
};
try {
const { data } = await axios.post(
`${this.activeMintUrl}/check`,
payload
);
const data = await this.activeMint.check(payload);
this.assertMintError(data);
// delete proofs from database if it is spent
let spentProofs = proofs.filter((p, pidx) => !data.spendable[pidx]);
Expand Down Expand Up @@ -1983,10 +1969,7 @@ export default {
pr: payment_request,
};
try {
const { data } = await axios.post(
`${this.activeMintUrl}/checkfees`,
payload
);
const data = await this.activeMint.checkFees(payload);
this.assertMintError(data);
console.log("#### checkFees", payment_request, data.fee);
return data.fee;
Expand Down
7 changes: 6 additions & 1 deletion src/stores/mints.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useLocalStorage } from "@vueuse/core";
import { useWorkersStore } from "./workers";
import { axios } from "boot/axios";
import { notifyApiError, notifyError, notifySuccess } from "src/js/notify";
import { CashuMint } from "@cashu/cashu-ts";

export const useMintsStore = defineStore("mints", {
state: () => {
Expand All @@ -17,7 +18,11 @@ export const useMintsStore = defineStore("mints", {
showAddMintDialog: false,
};
},
getters: {},
getters: {
activeMint({ activeMintUrl }) {
return new CashuMint(activeMintUrl);
},
},
actions: {
setShowAddMintDialog(show) {
this.showAddMintDialog = show;
Expand Down

0 comments on commit 044692b

Please sign in to comment.