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

159 lines
5.5 KiB
TypeScript

// Metro module 14767 (f14768).
import { useMemo, useCallback } from "react";
import { LogBox, Keyboard } from "react-native";
import { hasWebAuthn } from "../../../utils/MFAUtils";
import ModalActionCreators from "../../../actions/ModalActionCreators";
import { intl, t } from "../../../intl/index.native";
import { MfaScreens } from "./MfaStepsTypes";
import { HeaderActionButton } from "../../../design/components/Navigator/native/HeaderActionButton.native";
import Module7699 from "../../../_bundle/Module7699";
import { getHeaderBackButton, getHeaderCloseButton } from "../../../design/components/Navigator/native/NavigatorHeader.native";
import SelectScreen from "./screens/SelectScreen";
import WebAuthnScreen from "./screens/WebAuthnScreen";
import TotpScreen from "./screens/TotpScreen";
import BackupScreen from "./screens/BackupScreen";
import SmsScreen from "./screens/SmsScreen";
import PasswordScreen from "./screens/PasswordScreen";
import { Navigator } from "../../../design/components/Navigator/native/Navigator.native";
import AlertActionCreators from "../../../actions/native/AlertActionCreators";
let c10414_7;
let env10414 = {};
export function MFAModal(props) {
let env21326 = {
$parent: env10414
};
const { mfaChallenge, finish, cancel, handleOnClose, ignoreKeyboard: _ignoreKeyboard, ...props2 } = props;
env21326[0] = mfaChallenge;
env21326[1] = finish;
env21326[2] = cancel;
env21326[3] = handleOnClose;
let ignoreKeyboard = props.ignoreKeyboard;
if (ignoreKeyboard === void 0) {
ignoreKeyboard = false;
}
let c21327_0;
env21326[4] = ignoreKeyboard;
env21326[5] = void 0;
env21326[6] = void 0;
env21326[7] = void 0;
const memo = useMemo(() => {
const r13 = env21326[0];
return hasWebAuthn ? r13 : {
...r13,
methods: r13.methods.filter((method) => method.type !== "webauthn")
};
}, [mfaChallenge]);
env21326[5] = memo;
c21327_0 = void 0;
c21327_0 = async (c30766_0) => {
let c30766_2;
c30766_2 = void 0;
let c31730_0 = c30766_0.mfaType;
let c31730_1 = c30766_0.data;
await void 0;
const r42 = c30766_2.$parent;
await (0, r42[1])({
mfaType: c31730_0,
data: c31730_1,
ticket: r42[5].ticket
});
ModalActionCreators.popWithKey(c10414_7);
};
const callback = useCallback(function() {
return c21327_0.apply(this, arguments);
}, [finish, memo.ticket]);
env21326[6] = callback;
const callback2 = useCallback(() => {
const r2 = env21326[3];
if (r2 == null) {
ModalActionCreators.popWithKey(c10414_7);
const r16 = env21326[2];
if (r16 != null) {
r16(new Error(intl.string(t.N2yb9a)));
}
} else {
r2();
}
}, [cancel, handleOnClose]);
env21326[7] = callback2;
const memo2 = useMemo(() => {
const mfaChallenge = env21326[5];
const finish = env21326[6];
const r4 = {
name: MfaScreens.SELECT,
params: {
mfaChallenge,
finish
}
};
const type = mfaChallenge.methods[0]?.type;
return type === void 0 ? [r4] : [{
name: type,
params: {
mfaChallenge,
finish
}
}];
}, [memo, callback]);
return <Navigator screens={useMemo(() => {
const headerRight = function headerRight() {
return <HeaderActionButton accessibilityLabel={intl.string(t.cpT0Cq)} onPress={env21326[7]} source={Module7699} />;
};
const r9 = {
fullscreen: true,
ignoreKeyboard: env21326[4],
headerTitle: ""
};
const r20 = {};
r20[MfaScreens.SELECT] = {
...r9,
headerLeft: getHeaderBackButton(),
headerRight,
render: (a0) => <SelectScreen {...a0} />
};
const WEBAUTHN = MfaScreens.WEBAUTHN;
const r36 = env21326[5];
r20[WEBAUTHN] = {
...r9,
headerLeft: r36.methods[0]?.type === "webauthn" ? getHeaderCloseButton(env21326[7]) : getHeaderBackButton(),
headerRight: r36.methods[0]?.type !== "webauthn" ? headerRight : void 0,
render: (a0) => <WebAuthnScreen {...a0} />
};
r20[MfaScreens.TOTP] = {
...r9,
headerLeft: r36.methods[0]?.type === "totp" ? getHeaderCloseButton(env21326[7]) : getHeaderBackButton(),
headerRight: r36.methods[0]?.type !== "totp" ? headerRight : void 0,
render: (a0) => <TotpScreen {...a0} />
};
r20[MfaScreens.BACKUP] = {
...r9,
headerLeft: r36.methods[0]?.type === "backup" ? getHeaderCloseButton(env21326[7]) : getHeaderBackButton(),
headerRight: r36.methods[0]?.type !== "backup" ? headerRight : void 0,
render: (a0) => <BackupScreen {...a0} />
};
r20[MfaScreens.SMS] = {
...r9,
headerLeft: r36.methods[0]?.type === "sms" ? getHeaderCloseButton(env21326[7]) : getHeaderBackButton(),
headerRight: r36.methods[0]?.type !== "sms" ? headerRight : void 0,
render: (a0) => <SmsScreen {...a0} />
};
r20[MfaScreens.PASSWORD] = {
...r9,
headerLeft: r36.methods[0]?.type === "password" ? getHeaderCloseButton(env21326[7]) : getHeaderBackButton(),
headerRight: r36.methods[0]?.type !== "password" ? headerRight : void 0,
render: (a0) => <PasswordScreen {...a0} />
};
return r20;
}, [callback2, memo.methods, ignoreKeyboard])} initialRouteStack={memo2} onWillFocus={Keyboard.dismiss} {...props2} />;
}
LogBox.ignoreLogs(["Non-serializable values were found in the navigation state"]);
c10414_7 = "MFA_MODAL_KEY";
export function openMFAModal(a0, a1, a2) {
ModalActionCreators.push(MFAModal, {
mfaChallenge: a0,
finish: a1,
cancel: a2
}, c10414_7);
AlertActionCreators.close();
}