Enable lint rules for Promise handling to discourage misuse of them.

Squashed all of Hugh's commits into one.
This commit is contained in:
Hugh Nimmo-Smith
2024-07-10 16:20:59 +01:00
committed by Timo
parent c2cc0937c1
commit 480a995be1
31 changed files with 332 additions and 198 deletions

View File

@@ -49,7 +49,7 @@ export function useInteractiveLogin(
const interactiveAuth = new InteractiveAuth({
matrixClient: authClient,
doRequest: (): Promise<LoginResponse> =>
doRequest: async (): Promise<LoginResponse> =>
authClient.login("m.login.password", {
identifier: {
type: "m.id.user",
@@ -58,7 +58,7 @@ export function useInteractiveLogin(
password,
}),
stateUpdated: (): void => {},
requestEmailToken: (): Promise<{ sid: string }> => {
requestEmailToken: async (): Promise<{ sid: string }> => {
return Promise.resolve({ sid: "" });
},
});

View File

@@ -21,6 +21,7 @@ import {
MatrixClient,
RegisterResponse,
} from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger";
import { initClient } from "../utils/matrix";
import { Session } from "../ClientContext";
@@ -75,7 +76,7 @@ export const useInteractiveRegistration = (
): Promise<[MatrixClient, Session]> => {
const interactiveAuth = new InteractiveAuth({
matrixClient: authClient.current!,
doRequest: (auth): Promise<RegisterResponse> =>
doRequest: async (auth): Promise<RegisterResponse> =>
authClient.current!.registerRequest({
username,
password,
@@ -87,17 +88,25 @@ export const useInteractiveRegistration = (
}
if (nextStage === "m.login.terms") {
interactiveAuth.submitAuthDict({
type: "m.login.terms",
});
interactiveAuth
.submitAuthDict({
type: "m.login.terms",
})
.catch((e) => {
logger.error(e);
});
} else if (nextStage === "m.login.recaptcha") {
interactiveAuth.submitAuthDict({
type: "m.login.recaptcha",
response: recaptchaResponse,
});
interactiveAuth
.submitAuthDict({
type: "m.login.recaptcha",
response: recaptchaResponse,
})
.catch((e) => {
logger.error(e);
});
}
},
requestEmailToken: (): Promise<{ sid: string }> => {
requestEmailToken: async (): Promise<{ sid: string }> => {
return Promise.resolve({ sid: "dummy" });
},
});

View File

@@ -72,7 +72,7 @@ export function useRecaptcha(sitekey?: string): {
}
}, [recaptchaId, sitekey]);
const execute = useCallback((): Promise<string> => {
const execute = useCallback(async (): Promise<string> => {
if (!sitekey) {
return Promise.resolve("");
}
@@ -104,7 +104,12 @@ export function useRecaptcha(sitekey?: string): {
},
};
window.grecaptcha.execute();
window.grecaptcha.execute().then(
() => {}, // noop
(e) => {
logger.error("Recaptcha execution failed", e);
},
);
const iframe = document.querySelector<HTMLIFrameElement>(
'iframe[src*="recaptcha/api2/bframe"]',