Skip to content

Commit

Permalink
better restore
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Dec 19, 2024
1 parent 5322658 commit 83466ce
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 38 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Docker Build

on:
push:
pull_request:
types: [opened, synchronize, reopened]
release:
Expand Down
26 changes: 25 additions & 1 deletion src/components/RestoreView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
Restore from Seed Phrase
</q-item-label>
<q-item-label caption>
Enter your seed phrase to restore your wallet.
Enter your seed phrase to restore your wallet. Before you restore,
make sure you have added all the mints that you have used before.
</q-item-label>
<div class="row q-pt-md">
<div class="col-12">
Expand Down Expand Up @@ -39,6 +40,26 @@
</q-list>
</div>

<!-- Information about restoring mints -->
<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">
Information
</q-item-label>
<q-item-label caption>
The wizard will only <i>restore</i> ecash from another seed
phrase, you will not be able to use this seed phrase or change the
seed phrase of the wallet that you're currently using. This means
that restored ecash will not be protected by your current seed
phrase as long as you don't send the ecash to yourself once.
</q-item-label>
</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>
Expand Down Expand Up @@ -196,10 +217,13 @@ export default defineComponent({
return;
}
try {
this.restoreAllMintsText = "Restoring mint ...";
await this.restoreMint(mintUrl);
} catch (error) {
console.error("Error restoring mint:", error);
notifyError(`Error restoring mint: ${error.message || error}`);
} finally {
this.restoreAllMintsText = "Restore All Mints";
}
},
async pasteMnemonic() {
Expand Down
57 changes: 29 additions & 28 deletions src/components/SettingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,35 @@
</q-list>
</div>

<!-- restore -->
<div class="q-py-sm q-px-xs text-left" on-left>
<q-list padding>
<q-item>
<q-item-section>
<q-item-label overline class="text-weight-bold"
>Restore ecash</q-item-label
>
<q-item-label caption
>The restore wizard lets you recover lost ecash from a mnemonic
seed phrase. The seed phrase of your current wallet will remain
unaffected, the wizard will only allow you to <i>restore</i> ecash
from another seed phrase.</q-item-label
>
</q-item-section>
</q-item>
<q-item>
<q-btn
class="q-ml-sm q-px-md"
color="primary"
size="sm"
rounded
outline
to="/restore"
>Restore</q-btn
>
</q-item>
</q-list>
</div>
<!-- nostr -->
<div class="q-py-sm q-px-sm text-left" on-left>
<q-list padding>
Expand Down Expand Up @@ -672,34 +701,6 @@
</q-item>
</q-expansion-item>

<!-- restore -->
<div class="q-py-sm q-px-xs text-left" on-left>
<q-list padding>
<q-item>
<q-item-section>
<q-item-label overline class="text-weight-bold"
>Restore ecash</q-item-label
>
<q-item-label caption
>The restore wizard lets you recover lost ecash from a
mnemonic seed phrase.</q-item-label
>
</q-item-section>
</q-item>
<q-item>
<q-btn
class="q-ml-sm q-px-md"
color="primary"
size="sm"
rounded
outline
to="/restore"
>Restore</q-btn
>
</q-item>
</q-list>
</div>

<q-item>
<q-item-section>
<q-item-label overline class="text-weight-bold"
Expand Down
16 changes: 7 additions & 9 deletions src/stores/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { notify, notifyError, notifySuccess } from "src/js/notify";
import { useUiStore } from "./ui";

const BATCH_SIZE = 100;
const MAX_GAP = 2;
const MAX_GAP = 1;

export const useRestoreStore = defineStore("restore", {
state: () => ({
Expand Down Expand Up @@ -62,8 +62,8 @@ export const useRestoreStore = defineStore("restore", {
let restoredSomething = false;

// Calculate total steps for progress calculation
let totalSteps = keysets.length * MAX_GAP * 2;
let currentStep = 1;
let totalSteps = keysets.length * MAX_GAP;
let currentStep = 0;

for (const keyset of keysets) {
console.log(`Restoring keyset ${keyset.id} with unit ${keyset.unit}`);
Expand Down Expand Up @@ -93,8 +93,8 @@ export const useRestoreStore = defineStore("restore", {
);
restoreProofs = restoreProofs.concat(proofs);
emptyBatchCount = 0;
totalSteps += MAX_GAP * 2;
this.restoreCounter += proofs.length;
totalSteps += 1;
}
this.restoreStatus = `Restored ${this.restoreCounter} proofs for keyset ${keyset.id}`;
start += BATCH_SIZE;
Expand All @@ -105,9 +105,8 @@ export const useRestoreStore = defineStore("restore", {

let restoredProofs: Proof[] = [];
for (let i = 0; i < restoreProofs.length; i += BATCH_SIZE) {
this.restoreStatus = `Checking proofs ${i} to ${
i + BATCH_SIZE
} for keyset ${keyset.id}`;
this.restoreStatus = `Checking proofs ${i} to ${i + BATCH_SIZE
} for keyset ${keyset.id}`;
const checkRestoreProofs = restoreProofs.slice(i, i + BATCH_SIZE);
const proofStates = await wallet.checkProofsStates(
checkRestoreProofs
Expand All @@ -121,8 +120,7 @@ export const useRestoreStore = defineStore("restore", {
);
if (unspentProofs.length > 0) {
console.log(
`Found ${
unspentProofs.length
`Found ${unspentProofs.length
} unspent proofs with sum ${unspentProofs.reduce(
(s, p) => s + p.amount,
0
Expand Down

0 comments on commit 83466ce

Please sign in to comment.