Skip to content

Commit

Permalink
Fedimint resync
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Jul 12, 2024
1 parent 0b224f4 commit 3036759
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/components/SetupErrorDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ export function SetupErrorDisplay(props: {
)}
</ExternalLink>
</NiceP>
<NiceP>
{i18n.t("error.on_boot.loading_failed.in_the_meantime")}{" "}
<a href="/?safe_mode=true">
{" "}
{i18n.t("error.on_boot.loading_failed.safe_mode")}
</a>
.
</NiceP>
<ImportExport emergency />
<ToggleReportDiagnostics />
<Logs />
Expand Down
6 changes: 3 additions & 3 deletions src/components/layout/Misc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ export function ModalCloseButton() {
);
}

const SIMPLE_OVERLAY = "fixed inset-0 z-50 bg-black/50 backdrop-blur-lg";
const SIMPLE_DIALOG_POSITIONER =
export const SIMPLE_OVERLAY = "fixed inset-0 z-50 bg-black/50 backdrop-blur-lg";
export const SIMPLE_DIALOG_POSITIONER =
"fixed inset-0 z-50 flex items-center justify-center";
const SIMPLE_DIALOG_CONTENT =
export const SIMPLE_DIALOG_CONTENT =
"max-w-[500px] w-[90vw] max-h-device overflow-y-scroll disable-scrollbars mx-4 p-4 bg-neutral-800/90 rounded-xl border border-white/10";

export const SimpleDialog: ParentComponent<{
Expand Down
93 changes: 91 additions & 2 deletions src/routes/settings/ManageFederations.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Progress } from "@kobalte/core";
import {
createForm,
required,
Expand All @@ -7,7 +8,14 @@ import {
} from "@modular-forms/solid";
import { FederationBalance, TagItem } from "@mutinywallet/mutiny-wasm";
import { A, useNavigate, useSearchParams } from "@solidjs/router";
import { ArrowLeftRight, BadgeCheck, LogOut, Scan, Trash } from "lucide-solid";
import {
ArrowLeftRight,
BadgeCheck,
LogOut,
RefreshCw,
Scan,
Trash
} from "lucide-solid";
import {
createResource,
createSignal,
Expand Down Expand Up @@ -45,7 +53,7 @@ import {
} from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import { eify, timeAgo } from "~/utils";
import { eify, timeAgo, timeout } from "~/utils";

type FederationForm = {
federation_code: string;
Expand All @@ -68,6 +76,12 @@ export type Metadata = {
about?: string;
};

export type ResyncProgress = {
total: number;
complete: number;
done: boolean;
};

export type DiscoveredFederation = {
id: string;
invite_codes: string[];
Expand Down Expand Up @@ -298,6 +312,22 @@ function RecommendButton(props: { fed: MutinyFederationIdentity }) {
);
}

function ResyncLoadingBar(props: { value: number; max: number }) {
return (
<Progress.Root
value={props.value}
minValue={0}
maxValue={props.max}
class="flex w-full flex-col gap-2"
>
<Progress.ValueLabel class="text-sm text-m-grey-400" />
<Progress.Track class="h-6 rounded bg-white/10">
<Progress.Fill class="h-full w-[var(--kb-progress-fill-width)] rounded bg-m-blue transition-[width]" />
</Progress.Track>
</Progress.Root>
);
}

function FederationListItem(props: {
fed: MutinyFederationIdentity;
balance?: bigint;
Expand All @@ -317,10 +347,37 @@ function FederationListItem(props: {
setConfirmLoading(false);
}

async function resyncFederation() {
setResyncLoading(true);
try {
await sw.resync_federation(props.fed.federation_id);

for (let i = 0; i < 60; i++) {
await timeout(1000);
const progress = await sw.get_federation_resync_progress(
props.fed.federation_id
);
console.log("progress", progress);
if (progress?.total !== 0) {
setResyncProgress(progress);
setResyncOpen(false);
break;
}
}
} catch (e) {
console.error(e);
setResyncLoading(false);
}
}

async function confirmRemove() {
setConfirmOpen(true);
}

async function confirmResync() {
setResyncOpen(true);
}

const [transferDialogOpen, setTransferDialogOpen] = createSignal(false);

async function transferFunds() {
Expand All @@ -335,6 +392,13 @@ function FederationListItem(props: {
const [confirmOpen, setConfirmOpen] = createSignal(false);
const [confirmLoading, setConfirmLoading] = createSignal(false);

const [resyncOpen, setResyncOpen] = createSignal(false);
const [resyncLoading, setResyncLoading] = createSignal(false);

const [resyncProgress, setResyncProgress] = createSignal<
ResyncProgress | undefined
>(undefined);

return (
<>
<FancyCard>
Expand Down Expand Up @@ -404,6 +468,12 @@ function FederationListItem(props: {
<LogOut class="h-4 w-4" />
{i18n.t("settings.manage_federations.remove")}
</SubtleButton>
<Show when={state.safe_mode}>
<SubtleButton intent="red" onClick={confirmResync}>
<RefreshCw class="h-4 w-4" />
Resync
</SubtleButton>
</Show>
</VStack>
</FancyCard>
<ConfirmDialog
Expand All @@ -416,6 +486,25 @@ function FederationListItem(props: {
"settings.manage_federations.federation_remove_confirm"
)}
</ConfirmDialog>
<ConfirmDialog
loading={resyncLoading()}
open={resyncOpen()}
onConfirm={resyncFederation}
onCancel={() => setResyncOpen(false)}
>
Are you sure you want to resync this federation? This will
rescan the federation for your ecash, this can take multiple
hours in some cases. If you stop the rescan it can cause your
wallet to be bricked. Please be sure you can run the rescan
before you start it.
</ConfirmDialog>
{/* todo put this in a dialog */}
<Show when={resyncProgress()}>
<ResyncLoadingBar
value={resyncProgress()!.complete}
max={resyncProgress()!.total}
/>
</Show>
</>
);
}
Expand Down
23 changes: 22 additions & 1 deletion src/workers/walletWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import { MutinyWalletSettingStrings } from "~/logic/mutinyWalletSetup";
import { FakeDirectMessage, OnChainTx } from "~/routes";
import {
DiscoveredFederation,
MutinyFederationIdentity
MutinyFederationIdentity,
ResyncProgress
} from "~/routes/settings";

const RELEASE_VERSION = import.meta.env.__RELEASE_VERSION__;
Expand Down Expand Up @@ -1201,6 +1202,26 @@ export async function remove_federation(federation_id: string): Promise<void> {
await wallet!.remove_federation(federation_id);
}

/**
* Resyncs a federation
* @param {string} federation_id
* @returns {Promise<void>}
*/
export async function resync_federation(federation_id: string): Promise<void> {
await wallet!.resync_federation(federation_id);

Check failure on line 1211 in src/workers/walletWorker.ts

View workflow job for this annotation

GitHub Actions / code_quality

Property 'resync_federation' does not exist on type 'MutinyWallet'.

Check failure on line 1211 in src/workers/walletWorker.ts

View workflow job for this annotation

GitHub Actions / Build APK

Property 'resync_federation' does not exist on type 'MutinyWallet'.

Check failure on line 1211 in src/workers/walletWorker.ts

View workflow job for this annotation

GitHub Actions / Build iOS

Property 'resync_federation' does not exist on type 'MutinyWallet'.
}

/**
* Gets the resync progress for a federation
* @param {string} federation_id
* @returns {Promise<ResyncProgress>}
*/
export async function get_federation_resync_progress(
federation_id: string
): Promise<ResyncProgress | undefined> {
return wallet!.get_federation_resync_progress(federation_id);

Check failure on line 1222 in src/workers/walletWorker.ts

View workflow job for this annotation

GitHub Actions / code_quality

Property 'get_federation_resync_progress' does not exist on type 'MutinyWallet'.

Check failure on line 1222 in src/workers/walletWorker.ts

View workflow job for this annotation

GitHub Actions / Build APK

Property 'get_federation_resync_progress' does not exist on type 'MutinyWallet'.

Check failure on line 1222 in src/workers/walletWorker.ts

View workflow job for this annotation

GitHub Actions / Build iOS

Property 'get_federation_resync_progress' does not exist on type 'MutinyWallet'.
}

/**
* Opens a channel from our selected node to the given pubkey.
* The amount is in satoshis.
Expand Down

0 comments on commit 3036759

Please sign in to comment.