Files
discord-decomp/modules/mfa/native/screens/WebAuthnScreen.tsx
T
2026-11-01 12:12:55 +02:00

98 lines
3.6 KiB
TypeScript

// Metro module 14770 (f14771).
import { useState, useMemo, useCallback } from "react";
import { NativeModules } from "react-native";
import { createStyles } from "../../../../design/components/Styles/native/createStyles";
import Module712 from "../../../../_bundle/Module712";
import { intl, t } from "../../../../intl/index.native";
import { RadioGroup } from "../../../../design/void/native";
import { isAndroid } from "../../../../utils/PlatformUtils";
import { HTTPResponseError } from "../../../../_bundle/sendRequest";
import { captureWebAuthnException } from "../../../../utils/MFAUtils";
import MfaOptionScreen from "./MfaOptionScreen";
import { KeyImage } from "../components/KeyImage";
import NativeCeremonies from "../../../webauthn/native/NativeCeremonies";
import MFAButton from "../components/button";
let useStyles, c10416_7, c10416_8;
const AndroidAuthRadioGroup = function AndroidAuthRadioGroup(props) {
const { authenticatorSelection, setAuthenticator, inProgress } = props;
return <RadioGroup style={useStyles().radioItem} options={[{
value: c10416_7.ANDROID_PASSKEY,
name: intl.string(t.PVVXRI)
}, {
value: c10416_7.AUTHENTICATE,
name: intl.string(t.TKop3X)
}]} onChange={(event) => setAuthenticator(event.value)} value={authenticatorSelection} disabled={inProgress} withSpacing />;
};
useStyles = createStyles({
radioItem: {
backgroundColor: Module712.colors.BACKGROUND_SURFACE_HIGH,
borderRadius: Module712.radii.md
}
});
c10416_7 = {
AUTHENTICATE: 0,
0: "AUTHENTICATE",
ANDROID_PASSKEY: 1,
1: "ANDROID_PASSKEY"
};
const r43 = {};
r43[c10416_7.AUTHENTICATE] = NativeModules.DCDSecurityKeyManager.authenticate;
r43[c10416_7.ANDROID_PASSKEY] = NativeModules.DCDSecurityKeyManager.authenticatePasskey;
c10416_8 = r43;
export default function WebAuthnScreen(props) {
let memo;
const { mfaChallenge, finish } = props;
memo = void 0;
let [disabled, setState] = useState(false);
const [error, setState2] = useState(void 0);
const [state, setAuthenticator2] = useState(isAndroid() ? c10416_7.ANDROID_PASSKEY : c10416_7.AUTHENTICATE);
const [state2, setState3] = useState(false);
const challenge = mfaChallenge.methods.find((method) => method.type === "webauthn").challenge;
memo = useMemo(() => c10416_8[state], [state]);
const callback = useCallback(() => {
setState2(void 0);
setState(true);
memo(challenge).then((result) => finish({
mfaType: "webauthn",
data: result
})).then(() => setState3(true)).catch((error) => {
if (error instanceof HTTPResponseError) {
setState2(intl.string(t.xSCvBf));
} else {
captureWebAuthnException(error, {});
setState2(error.message);
}
}).finally(() => setState(false));
}, [memo, challenge, finish]);
const props2 = {
headerText: intl.string(t.saHocI),
subtitle: intl.string(t.YpMrqM),
headerImage: <KeyImage />,
content: NativeCeremonies.shouldDisplayAndroidFidoSelector && <AndroidAuthRadioGroup authenticatorSelection={state} setAuthenticator={setAuthenticator2} inProgress={disabled ? disabled : state2} />,
submit: null,
screenProps: null,
mfaMethod: "webauthn",
error: null
};
const props3 = {
variant: "primary",
text: intl.string(t.Xr3Eks),
loading: disabled ? disabled : state2,
disabled: null,
onPress: null
};
if (!disabled) {
disabled = state2;
}
props3.disabled = disabled;
props3.onPress = callback;
props2.submit = <MFAButton {...props3} />;
props2.screenProps = {
mfaChallenge,
finish
};
props2.error = error;
return <MfaOptionScreen {...props2} />;
};
export { c10416_7 as AuthenticatorOption };