mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-01-06 15:54:23 +01:00
Try each federation guardian when joining
This commit is contained in:
committed by
Paul Miller
parent
cdc7c880fa
commit
0dbcdc568b
@@ -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 {
|
||||
|
||||
@@ -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 }) {
|
||||
</div>
|
||||
</KeyValue>
|
||||
</Show>
|
||||
{/* FIXME: do something smarter than just taking first code */}
|
||||
<Button
|
||||
intent="blue"
|
||||
onClick={() =>
|
||||
onSelect(fed.invite_codes[0])
|
||||
onSelect(fed.invite_codes)
|
||||
}
|
||||
loading={fed.invite_codes.includes(
|
||||
loadingFederation()
|
||||
|
||||
Reference in New Issue
Block a user