Try each federation guardian when joining

This commit is contained in:
benthecarman
2024-04-09 15:26:41 -05:00
committed by Paul Miller
parent cdc7c880fa
commit 0dbcdc568b
2 changed files with 35 additions and 8 deletions

View File

@@ -44,6 +44,7 @@ type MutinyError =
| "Failed to read or write json from the front end" | "Failed to read or write json from the front end"
| "The given node pubkey is invalid." | "The given node pubkey is invalid."
| "Failed to get nostr data." | "Failed to get nostr data."
| "Error with NIP-07 extension"
| "Failed to get the bitcoin price." | "Failed to get the bitcoin price."
| "Satoshi amount is invalid" | "Satoshi amount is invalid"
| "Failed to execute a dlc function" | "Failed to execute a dlc function"
@@ -54,6 +55,11 @@ type MutinyError =
| "Failed to create payjoin request." | "Failed to create payjoin request."
| "Payjoin response error: {0}" | "Payjoin response error: {0}"
| "Payjoin configuration failed." | "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"; | "Unknown Error";
export function matchError(e: unknown): Error { export function matchError(e: unknown): Error {

View File

@@ -110,7 +110,7 @@ function AddFederationForm(props: { refetch?: RefetchType }) {
f: FederationForm f: FederationForm
) => { ) => {
const federation_code = f.federation_code.trim(); const federation_code = f.federation_code.trim();
await onSelect(federation_code); await onSelect([federation_code]);
}; };
const [federations] = createResource(async () => { const [federations] = createResource(async () => {
@@ -124,14 +124,36 @@ function AddFederationForm(props: { refetch?: RefetchType }) {
} }
}); });
const onSelect = async (inviteCode: string) => { const onSelect = async (inviteCodes: string[]) => {
setSuccess(""); setSuccess("");
setError(undefined); setError(undefined);
setLoadingFederation(inviteCode);
try { try {
const newFederation = for (const inviteCode of inviteCodes) {
await state.mutiny_wallet?.new_federation(inviteCode); try {
console.log("New federation added:", newFederation); 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( setSuccess(
i18n.t("settings.manage_federations.federation_added_success") i18n.t("settings.manage_federations.federation_added_success")
); );
@@ -275,11 +297,10 @@ function AddFederationForm(props: { refetch?: RefetchType }) {
</div> </div>
</KeyValue> </KeyValue>
</Show> </Show>
{/* FIXME: do something smarter than just taking first code */}
<Button <Button
intent="blue" intent="blue"
onClick={() => onClick={() =>
onSelect(fed.invite_codes[0]) onSelect(fed.invite_codes)
} }
loading={fed.invite_codes.includes( loading={fed.invite_codes.includes(
loadingFederation() loadingFederation()