Skip to content

Commit

Permalink
Dev cashu ts fee coinselect (#242)
Browse files Browse the repository at this point in the history
* working

* fees work for melt

* restore

* fees work

* update

* restore

* add more

* adjust

* restore all

* clean up logging

* cleanup
  • Loading branch information
callebtc authored Oct 27, 2024
1 parent c43001b commit 058d55a
Show file tree
Hide file tree
Showing 14 changed files with 729 additions and 357 deletions.
1 change: 0 additions & 1 deletion src/components/ChooseMint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export default defineComponent({
},
watch: {
chosenMint: async function () {
console.log("Mint chosen ", this.chosenMint);
await this.activateMintUrl(this.chosenMint.url);
},
},
Expand Down
27 changes: 16 additions & 11 deletions src/components/InvoiceDetailDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
: 'Create Invoice'
"
:loading="globalMutexLock"
>
<template v-slot:loading>
<q-spinner-hourglass />
Creating
</template>
>
<template v-slot:loading>
<q-spinner-hourglass />
Creating
</template>
</q-btn>
<q-btn v-close-popup rounded flat color="grey" class="q-ml-auto"
>Close</q-btn
Expand Down Expand Up @@ -173,9 +173,17 @@ export default defineComponent({
},
computed: {
...mapState(useWalletStore, ["invoiceData"]),
...mapState(useMintsStore, ["activeUnit", "activeUnitLabel"]),
...mapState(useMintsStore, [
"activeUnit",
"activeUnitLabel",
"activeUnitCurrencyMultiplyer",
]),
...mapState(useWorkersStore, ["invoiceWorkerRunning"]),
...mapWritableState(useUiStore, ["showInvoiceDetails", "tickerShort", "globalMutexLock"]),
...mapWritableState(useUiStore, [
"showInvoiceDetails",
"tickerShort",
"globalMutexLock",
]),
displayUnit: function () {
let display = this.formatCurrency(
this.invoiceData.amount,
Expand All @@ -196,11 +204,8 @@ export default defineComponent({
...mapActions(useMintsStore, ["toggleUnit"]),
requestMintButton: async function () {
try {
// if unit is USD, multiply by 100
const mintStore = useMintsStore();
if (mintStore.activeUnit === "usd") {
this.invoiceData.amount = this.invoiceData.amount * 100;
}
this.invoiceData.amount *= this.activeUnitCurrencyMultiplyer;
this.createInvoiceButtonBlocked = true;
await this.requestMint();
await this.invoiceCheckWorker();
Expand Down
3 changes: 2 additions & 1 deletion src/components/MintSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
:active="mint.url == activeMintUrl"
active-class="text-weight-bold text-primary"
clickable
class="q-pb-xs"
>
<q-item-section avatar>
<q-icon
Expand Down Expand Up @@ -59,7 +60,7 @@
:label="
formatCurrency(mintClass(mint).unitBalance(unit), unit)
"
class="q-mx-xs"
class="q-mx-xs q-mb-xs"
/>
</q-item-label>
</q-item-section>
Expand Down
235 changes: 235 additions & 0 deletions src/components/RestoreView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
<template>
<div style="max-width: 800px; margin: 0 auto">
<!-- Mnemonic seed phrase input -->
<div class="q-px-xs text-left" on-left>
<q-list padding>
<q-item>
<q-item-section>
<q-item-label overline class="text-weight-bold">
Restore from Seed Phrase
</q-item-label>
<q-item-label caption>
Enter your seed phrase to restore your wallet.
</q-item-label>
<div class="row q-pt-md">
<div class="col-12">
<q-input
outlined
v-model="mnemonicToRestore"
label="Seed phrase"
autogrow
type="textarea"
:error="mnemonicError !== ''"
:error-message="mnemonicError"
>
<template v-slot:append>
<q-btn
flat
dense
icon="content_paste"
@click="pasteMnemonic"
class="cursor-pointer q-mt-md"
></q-btn>
</template>
</q-input>
</div>
</div>
</q-item-section>
</q-item>
</q-list>
</div>

<!-- Information about adding mints -->
<div class="q-px-xs text-left q-mt-md" on-left>
<q-list padding>
<q-item>
<q-item-section>
<q-item-label overline class="text-weight-bold">
Restore Mints
</q-item-label>
<q-item-label caption>
Select the mint to restore. You can add more mints in the main
screen under "Mints" and restore them here.
</q-item-label>
</q-item-section>
</q-item>
</q-list>
</div>

<!-- List of mints with restore buttons and balance badges -->
<div class="q-pb-md q-px-xs text-left" on-left>
<q-btn
class="q-ml-sm q-px-md"
color="primary"
size="md"
rounded
dense
outline
@click="restoreAllMints"
:disabled="!isMnemonicValid || restoringState"
>
<q-spinner-hourglass size="sm" v-if="restoringState" class="q-mr-sm" />
{{ restoreAllMintsText }}
</q-btn>
<q-list padding class="q-pt-md">
<!-- List mints here -->
<div v-for="mint in mints" :key="mint.url">
<q-item>
<q-item-section>
<q-item-label
class="q-mb-xs"
lines="1"
style="word-break: break-word"
>
<q-icon
name="account_balance"
size="xs"
class="q-ml-xs q-mb-xs"
/>
<q-span class="q-ma-xs" style="font-size: 15px">
{{ mint.nickname || mint.url }}
</q-span>
</q-item-label>
<q-item-label>
<q-badge
v-for="unit in mintClass(mint).units"
:key="unit"
color="primary"
:label="
formatCurrency(mintClass(mint).unitBalance(unit), unit)
"
class="q-mx-xs q-mb-xs"
/>
</q-item-label>
<q-item-label
class="q-px-xs q-pt-xs q-pb-xs"
v-if="restoringMint === mint.url"
caption
>
{{ restoreStatus }}
</q-item-label>
<q-linear-progress
v-if="restoringMint === mint.url"
:value="restoreProgress"
color="primary"
class="q-pl-md"
style="max-width: 630px"
/>
</q-item-section>
<q-item-section side>
<q-btn
class="q-ml-sm q-px-md"
color="primary"
size="md"
rounded
dense
outline
@click="restoreMintForMint(mint.url)"
:disabled="!isMnemonicValid || restoringState"
:loading="restoringMint === mint.url"
>
Restore
</q-btn>
</q-item-section>
</q-item>
<q-separator spaced />
</div>
</q-list>
</div>
</div>
</template>

<script>
import { defineComponent } from "vue";
import { mapActions, mapState, mapWritableState } from "pinia";
import { useMintsStore, MintClass } from "src/stores/mints";
import { useRestoreStore } from "src/stores/restore";
import { useWalletStore } from "src/stores/wallet";
import { notifyError, notifySuccess } from "src/js/notify";
export default defineComponent({
name: "RestoreView",
mixins: [windowMixin],
data() {
return {
mnemonicError: "",
restoreAllMintsText: "Restore All Mints",
};
},
computed: {
...mapState(useMintsStore, ["mints"]),
...mapWritableState(useWalletStore, ["mnemonic"]),
...mapWritableState(useRestoreStore, [
"mnemonicToRestore",
"restoreProgress",
]),
...mapState(useRestoreStore, [
"restoringState",
"restoringMint",
"restoreStatus",
]),
isMnemonicValid() {
if (!this.mnemonicToRestore) {
return false;
}
const words = this.mnemonicToRestore.trim().split(/\s+/);
return words.length >= 12;
},
},
methods: {
...mapActions(useRestoreStore, ["restoreMint"]),
mintClass(mint) {
return new MintClass(mint);
},
validateMnemonic() {
// Simple validation: check if mnemonicToRestore has at least 12 words
const words = this.mnemonicToRestore.trim().split(/\s+/);
if (words.length < 12) {
this.mnemonicError = "Mnemonic should be at least 12 words.";
return false;
}
this.mnemonicError = "";
return true;
},
async restoreMintForMint(mintUrl) {
if (!this.validateMnemonic()) {
return;
}
try {
await this.restoreMint(mintUrl);
} catch (error) {
console.error("Error restoring mint:", error);
notifyError(`Error restoring mint: ${error.message || error}`);
}
},
async pasteMnemonic() {
try {
const text = await navigator.clipboard.readText();
this.mnemonicToRestore = text.trim();
} catch (error) {
notifyError("Failed to read clipboard contents.");
}
},
async restoreAllMints() {
let i = 0;
if (!this.validateMnemonic()) {
return;
}
try {
for (const mint of this.mints) {
this.restoreAllMintsText = `Restoring mint ${++i} of ${
this.mints.length
} ...`;
await this.restoreMint(mint.url);
}
notifySuccess("All mints restored successfully.");
} catch (error) {
console.error("Error restoring mints:", error);
notifyError(`Error restoring mints: ${error.message || error}`);
} finally {
this.restoreAllMintsText = "Restore All Mints";
}
},
},
});
</script>
Loading

0 comments on commit 058d55a

Please sign in to comment.