128 lines
4.6 KiB
TypeScript
128 lines
4.6 KiB
TypeScript
// Metro module 13013 (f13014).
|
|
import { useState, useCallback, useEffect } from "react";
|
|
import { ActivityIndicator, ImageBackground, ScrollView, View } from "react-native";
|
|
import { createStyles } from "../../../design/components/Styles/native/createStyles";
|
|
import Module712 from "../../../_bundle/Module712";
|
|
import { useActivateDeviceStepTracking } from "../useActivateDeviceStepTracking";
|
|
import { useDeviceCodeAuthorizeCallback } from "../useDeviceCodeAuthorizeCallback";
|
|
import { openOAuth2Modal } from "../../../utils/native/ApplicationUtils";
|
|
import { ConsoleOAuthApplications } from "../../../_bundle/Module8974";
|
|
import Module13017 from "../../../_bundle/Module13017";
|
|
import { isSocialLayerUmbrellaScope } from "../../oauth2/scopes";
|
|
import Module13018 from "../../../_bundle/Module13018";
|
|
import FastImage from "../../../components_native/common/FastImage";
|
|
import { UserCodeInput } from "./UserCodeInput";
|
|
import { ActivateDeviceSuccess } from "./ActivateDeviceSuccess";
|
|
import { ActivateDeviceError } from "./ActivateDeviceError";
|
|
import { makeSource } from "../../../utils/AvatarUtils";
|
|
import Module13025 from "../../../_bundle/Module13025";
|
|
import { SafeAreaPaddingView } from "../../../components_native/common/SafeAreaView";
|
|
const useStyles = createStyles({
|
|
background: {
|
|
flex: 1
|
|
},
|
|
imageStyle: {
|
|
marginVertical: 0,
|
|
resizeMode: "cover",
|
|
backgroundColor: Module712.colors.TEXT_BRAND
|
|
},
|
|
safeArea: {
|
|
flex: 1,
|
|
justifyContent: "center",
|
|
alignItems: "center"
|
|
},
|
|
content: {
|
|
maxWidth: 480,
|
|
backgroundColor: Module712.colors.PANEL_BG,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
borderRadius: Module712.radii.lg,
|
|
padding: 24,
|
|
marginHorizontal: 24,
|
|
marginVertical: 36,
|
|
shadowColor: Module712.colors.BLACK,
|
|
shadowOpacity: 0.2,
|
|
shadowOffset: {
|
|
width: 0,
|
|
height: 4
|
|
},
|
|
shadowRadius: 4
|
|
},
|
|
scroller: {
|
|
alignSelf: "stretch",
|
|
flexGrow: 0
|
|
},
|
|
scrollerContent: {
|
|
flexDirection: "column",
|
|
gap: 16
|
|
}
|
|
});
|
|
export const ActivateDevice = ({ onClose, prefilledUserCode }) => {
|
|
let deviceCodeAuthorizeCallback;
|
|
deviceCodeAuthorizeCallback = void 0;
|
|
const styles = useStyles();
|
|
const [state, setState] = useState({
|
|
type: "user-code-input",
|
|
usePrefilledCode: true
|
|
});
|
|
const [state2, setState2] = useState(null);
|
|
useActivateDeviceStepTracking(state);
|
|
const callback = useCallback(() => {
|
|
setState({
|
|
type: "user-code-input"
|
|
});
|
|
}, [setState]);
|
|
const callback2 = useCallback((a0) => {
|
|
setState({
|
|
type: "success",
|
|
userCodeData: a0
|
|
});
|
|
}, [setState]);
|
|
deviceCodeAuthorizeCallback = useDeviceCodeAuthorizeCallback(callback, useCallback((a0) => {
|
|
setState({
|
|
type: "error",
|
|
userCodeData: a0
|
|
});
|
|
}, [setState]), callback2);
|
|
const callback3 = useCallback((a0) => {
|
|
let c27396_0 = a0;
|
|
setState({
|
|
type: "authorization",
|
|
userCodeData: a0
|
|
});
|
|
openOAuth2Modal({
|
|
clientId: a0.clientId,
|
|
scopes: a0.scopes,
|
|
responseType: "code",
|
|
isTrustedName: true,
|
|
isEmbeddedFlow: true,
|
|
withBackPressHandler: false,
|
|
callbackWithoutPost: (a0) => deviceCodeAuthorizeCallback(c27396_0, a0)
|
|
});
|
|
}, [deviceCodeAuthorizeCallback]);
|
|
useEffect(() => {
|
|
if ("userCodeData" in state) {
|
|
const userCodeData = state.userCodeData;
|
|
if ([ConsoleOAuthApplications.PLAYSTATION_APPLICATION_ID, ConsoleOAuthApplications.PLAYSTATION_STAGING_APPLICATION_ID].includes(userCodeData.clientId)) {
|
|
setState2(Module13017);
|
|
} else if (userCodeData.scopes.some((scope) => isSocialLayerUmbrellaScope(scope))) {
|
|
setState2(Module13018);
|
|
}
|
|
}
|
|
}, [state]);
|
|
useEffect(() => {
|
|
if (state2 != null) {
|
|
FastImage.preload(state2);
|
|
}
|
|
}, [state2]);
|
|
const type = state.type;
|
|
const r62 = type === "user-code-input" ? <UserCodeInput prefilledUserCode={state.usePrefilledCode ? prefilledUserCode : void 0} onUserCodeAccepted={callback3} onClose={onClose} /> : type === "authorization" ? <ActivityIndicator animating /> : type === "success" ? <ActivateDeviceSuccess onComplete={onClose} data={state.userCodeData} successImage={state2} /> : type === "error" ? <ActivateDeviceError onRetry={callback} /> : null;
|
|
return <ImageBackground source={makeSource(Module13025)} imageStyle={styles.imageStyle} style={[styles.background]}>
|
|
<SafeAreaPaddingView bottom top style={styles.safeArea}>
|
|
<View style={styles.content}>
|
|
<ScrollView bounces={false} style={styles.scroller} contentContainerStyle={styles.scrollerContent}>{r62}</ScrollView>
|
|
</View>
|
|
</SafeAreaPaddingView>
|
|
</ImageBackground>;
|
|
};
|