Skip to content

Commit

Permalink
Fedimint resync
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Jul 11, 2024
1 parent b4c3407 commit 0d9d57b
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 7 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
88 changes: 85 additions & 3 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,7 @@ import {
} from "@modular-forms/solid";
import { FederationBalance, TagItem } from "@mutinywallet/mutiny-wasm";
import { A, useNavigate, useSearchParams } from "@solidjs/router";
import { BadgeCheck, LogOut, Scan, Trash } from "lucide-solid";
import { BadgeCheck, LogOut, RefreshCw, Scan, Trash } from "lucide-solid";
import {
createResource,
createSignal,
Expand Down Expand Up @@ -45,7 +46,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 +69,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 @@ -300,12 +307,28 @@ 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;
}) {
const i18n = useI18n();
const [_state, actions, sw] = useMegaStore();
const [state, actions, sw] = useMegaStore();

async function removeFederation() {
setConfirmLoading(true);
Expand All @@ -318,15 +341,49 @@ 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) {
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);

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 @@ -392,6 +449,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 @@ -404,6 +467,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);
}

/**
* 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);
}

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

0 comments on commit 0d9d57b

Please sign in to comment.