diff --git a/src/logic/errorDispatch.ts b/src/logic/errorDispatch.ts index f9002cdc..e8eae7ae 100644 --- a/src/logic/errorDispatch.ts +++ b/src/logic/errorDispatch.ts @@ -44,6 +44,7 @@ type MutinyError = | "Failed to read or write json from the front end" | "The given node pubkey is invalid." | "Failed to get nostr data." + | "Error with NIP-07 extension" | "Failed to get the bitcoin price." | "Satoshi amount is invalid" | "Failed to execute a dlc function" @@ -54,6 +55,11 @@ type MutinyError = | "Failed to create payjoin request." | "Payjoin response error: {0}" | "Payjoin configuration failed." + | "Error calling Cashu Mint" + | "Mint URL in token is empty" + | "Token has been already spent." + | "A federation is required" + | "Failed to connect to a federation." | "Unknown Error"; export function matchError(e: unknown): Error { diff --git a/src/routes/settings/ManageFederations.tsx b/src/routes/settings/ManageFederations.tsx index ec2b1d66..23d0a964 100644 --- a/src/routes/settings/ManageFederations.tsx +++ b/src/routes/settings/ManageFederations.tsx @@ -110,7 +110,7 @@ function AddFederationForm(props: { refetch?: RefetchType }) { f: FederationForm ) => { const federation_code = f.federation_code.trim(); - await onSelect(federation_code); + await onSelect([federation_code]); }; const [federations] = createResource(async () => { @@ -124,14 +124,36 @@ function AddFederationForm(props: { refetch?: RefetchType }) { } }); - const onSelect = async (inviteCode: string) => { + const onSelect = async (inviteCodes: string[]) => { setSuccess(""); setError(undefined); - setLoadingFederation(inviteCode); try { - const newFederation = - await state.mutiny_wallet?.new_federation(inviteCode); - console.log("New federation added:", newFederation); + for (const inviteCode of inviteCodes) { + try { + console.log("Adding federation:", inviteCode); + setLoadingFederation(inviteCode); + const newFederation = + await state.mutiny_wallet?.new_federation(inviteCode); + console.log("New federation added:", newFederation); + break; + } catch (e) { + const error = eify(e); + console.log("Error adding federation:", error.message); + // if we can't connect to the guardian, try to others, + // otherwise throw the error + if ( + error.message === + "Failed to connect to a federation." || + error.message === "Invalid Arguments were given" + ) { + console.error( + "Failed to connect to guardian, trying another one" + ); + } else { + throw e; + } + } + } setSuccess( i18n.t("settings.manage_federations.federation_added_success") ); @@ -275,11 +297,10 @@ function AddFederationForm(props: { refetch?: RefetchType }) { - {/* FIXME: do something smarter than just taking first code */}