2024-04-22 16:13:14 +05:30
|
|
|
import { init } from "@sentry/react-native";
|
2024-03-27 20:36:03 +05:30
|
|
|
import { Component } from "react";
|
|
|
|
|
import codePush from "react-native-code-push";
|
2024-07-19 01:01:24 +05:30
|
|
|
import {
|
|
|
|
|
GenericErrorScreen
|
|
|
|
|
} from "./App/Container/Navi-Insurance";
|
2024-06-16 16:20:34 +05:30
|
|
|
import {
|
|
|
|
|
BundleState,
|
|
|
|
|
CODEPUSH_METHOD,
|
2024-07-19 01:01:24 +05:30
|
|
|
EVENT_NAMES,
|
|
|
|
|
EVENT_PROPERTY_KEYS,
|
|
|
|
|
EVENT_PROPERTY_VALUES,
|
2024-06-16 16:20:34 +05:30
|
|
|
SentryConstants,
|
|
|
|
|
} from "./App/common/constants";
|
2024-07-19 01:01:24 +05:30
|
|
|
import { sendAsAnalyticsEvent } from "./App/common/hooks/useAnalyticsEvent";
|
2024-03-29 15:33:27 +05:30
|
|
|
import { logToSentry } from "./App/common/hooks/useSentryLogging";
|
2024-03-27 20:36:03 +05:30
|
|
|
import { CtaData } from "./App/common/interface";
|
|
|
|
|
import RnApp from "./App/common/navigator/RnAppCreator";
|
2024-03-29 15:33:27 +05:30
|
|
|
import {
|
|
|
|
|
getBuildConfigDetails,
|
|
|
|
|
setBuildConfigDetails,
|
|
|
|
|
} from "./App/common/utilities/CacheUtils";
|
2024-05-21 12:07:06 +05:30
|
|
|
import {
|
|
|
|
|
getStringPreference,
|
|
|
|
|
setStringPreference,
|
|
|
|
|
} from "./App/common/utilities/SharedPreferenceUtils";
|
2024-03-29 15:33:27 +05:30
|
|
|
|
2024-04-22 16:13:14 +05:30
|
|
|
init({
|
2024-04-01 19:43:10 +05:30
|
|
|
dsn: SentryConstants.SENTRY_DSN,
|
|
|
|
|
environment: SentryConstants.SENTRY_ENVIRONMENT_PRODUCTION,
|
2024-03-29 15:33:27 +05:30
|
|
|
});
|
2024-03-27 20:36:03 +05:30
|
|
|
|
2024-05-21 12:07:06 +05:30
|
|
|
interface AppState {
|
|
|
|
|
bundleState: BundleState;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-09 15:17:20 +05:30
|
|
|
const preloadBundle: string = "PreloadBundle";
|
2024-06-18 14:47:12 +05:30
|
|
|
|
2024-05-21 12:07:06 +05:30
|
|
|
export default class App extends Component<{}, AppState> {
|
|
|
|
|
constructor(props: {}) {
|
|
|
|
|
super(props);
|
|
|
|
|
let bundleState = BundleState.LOADING;
|
|
|
|
|
getBundleStatus().then(value => (bundleState = value));
|
|
|
|
|
this.state = {
|
|
|
|
|
bundleState: bundleState,
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-05-14 23:40:14 +05:30
|
|
|
checkForUpdates = async () => {
|
2024-03-29 15:33:27 +05:30
|
|
|
let flavor: string | undefined;
|
2024-05-14 23:40:14 +05:30
|
|
|
getBuildConfigDetails().then(res => {
|
2024-03-29 15:33:27 +05:30
|
|
|
flavor = res?.baseUrl;
|
|
|
|
|
});
|
2024-07-19 01:01:24 +05:30
|
|
|
const cta = this.getInitialCta();
|
2024-04-26 20:34:37 +05:30
|
|
|
await codePush.sync(
|
2024-04-12 17:41:45 +05:30
|
|
|
{
|
2024-07-19 01:01:24 +05:30
|
|
|
installMode: (cta?.title === preloadBundle) ? codePush.InstallMode.IMMEDIATE : codePush.InstallMode.ON_NEXT_RESTART,
|
2024-04-12 17:41:45 +05:30
|
|
|
mandatoryInstallMode: codePush.InstallMode.IMMEDIATE,
|
|
|
|
|
},
|
2024-05-14 23:40:14 +05:30
|
|
|
status => {
|
2024-04-12 17:41:45 +05:30
|
|
|
this.onCodepushStatusChange(status);
|
2024-05-14 23:40:14 +05:30
|
|
|
},
|
2024-04-12 17:41:45 +05:30
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onCodepushStatusChange = (status: codePush.SyncStatus) => {
|
|
|
|
|
switch (status) {
|
2024-05-21 12:07:06 +05:30
|
|
|
case codePush.SyncStatus.CHECKING_FOR_UPDATE:
|
|
|
|
|
case codePush.SyncStatus.DOWNLOADING_PACKAGE:
|
|
|
|
|
case codePush.SyncStatus.INSTALLING_UPDATE:
|
|
|
|
|
this.setState({ bundleState: BundleState.LOADING });
|
|
|
|
|
storeBundleStatus(BundleState.LOADING);
|
|
|
|
|
break;
|
|
|
|
|
case codePush.SyncStatus.UP_TO_DATE:
|
|
|
|
|
this.setState({ bundleState: BundleState.LOADED });
|
|
|
|
|
storeBundleStatus(BundleState.LOADED);
|
|
|
|
|
break;
|
2024-04-12 17:41:45 +05:30
|
|
|
case codePush.SyncStatus.UPDATE_IGNORED:
|
2024-05-21 12:07:06 +05:30
|
|
|
this.setState({ bundleState: BundleState.LOADED });
|
|
|
|
|
storeBundleStatus(BundleState.LOADED);
|
2024-04-12 17:41:45 +05:30
|
|
|
logToSentry(
|
2024-06-16 16:20:34 +05:30
|
|
|
`Codepush Ignored | Status: ${status} | MethodName: ${CODEPUSH_METHOD}`,
|
2024-04-12 17:41:45 +05:30
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case codePush.SyncStatus.UNKNOWN_ERROR:
|
2024-05-21 12:07:06 +05:30
|
|
|
this.setState({ bundleState: BundleState.ERROR });
|
2024-06-16 16:20:34 +05:30
|
|
|
sendAsAnalyticsEvent({
|
|
|
|
|
name: EVENT_NAMES.CODEPUSH_FETCH_ERROR,
|
2024-07-02 14:02:30 +05:30
|
|
|
properties: {
|
2024-07-09 15:17:20 +05:30
|
|
|
[EVENT_PROPERTY_KEYS.STATUS]: EVENT_PROPERTY_VALUES.UNKNOWN_ERROR,
|
|
|
|
|
},
|
2024-06-16 16:20:34 +05:30
|
|
|
});
|
2024-04-12 17:41:45 +05:30
|
|
|
logToSentry(
|
2024-06-16 16:20:34 +05:30
|
|
|
`Codepush Failed | Status: ${status} | MethodName: ${CODEPUSH_METHOD}`,
|
2024-04-12 17:41:45 +05:30
|
|
|
);
|
2024-05-21 12:07:06 +05:30
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
this.setState({ bundleState: BundleState.LOADED });
|
|
|
|
|
storeBundleStatus(BundleState.LOADED);
|
2024-04-12 17:41:45 +05:30
|
|
|
}
|
2024-03-27 20:36:03 +05:30
|
|
|
};
|
2024-05-14 23:40:14 +05:30
|
|
|
|
2024-05-21 12:07:06 +05:30
|
|
|
override shouldComponentUpdate(
|
|
|
|
|
nextProps: Readonly<{}>,
|
|
|
|
|
nextState: Readonly<AppState>,
|
|
|
|
|
_: any,
|
|
|
|
|
): boolean {
|
|
|
|
|
return this.state.bundleState !== nextState.bundleState;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-27 20:36:03 +05:30
|
|
|
getInitialCta = (): CtaData | undefined => {
|
|
|
|
|
const { CtaData } = this.props as any;
|
|
|
|
|
|
|
|
|
|
if (!CtaData) {
|
|
|
|
|
logToSentry(
|
2024-05-14 23:40:14 +05:30
|
|
|
`CtaData is missing or invalid: ${CtaData} | MethodName: getInitialCta`,
|
2024-03-27 20:36:03 +05:30
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-14 23:40:14 +05:30
|
|
|
|
2024-03-27 20:36:03 +05:30
|
|
|
try {
|
|
|
|
|
const cta = JSON.parse(CtaData) as CtaData;
|
|
|
|
|
return cta;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logToSentry(
|
2024-05-14 23:40:14 +05:30
|
|
|
`Error parsing CtaData: ${CtaData} | Error: ${error} | MethodName: getInitialCta`,
|
2024-03-27 20:36:03 +05:30
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
override componentDidMount(): void {
|
|
|
|
|
this.checkForUpdates();
|
2024-05-21 12:07:06 +05:30
|
|
|
setBuildConfigDetails();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override componentWillUnmount(): void {
|
|
|
|
|
invalidateStatus(BundleState.LOADING);
|
2024-03-27 20:36:03 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override render() {
|
|
|
|
|
const cta = this.getInitialCta();
|
2024-06-18 14:47:12 +05:30
|
|
|
|
|
|
|
|
if (cta?.title === preloadBundle) {
|
|
|
|
|
return <></>;
|
|
|
|
|
}
|
2024-07-19 01:01:24 +05:30
|
|
|
else if (!!cta){
|
|
|
|
|
return RnApp.create(cta)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sendAsAnalyticsEvent({
|
|
|
|
|
name: EVENT_NAMES.INVALID_SCREEN_CTA
|
|
|
|
|
});
|
|
|
|
|
return <GenericErrorScreen />;
|
|
|
|
|
}
|
2024-03-27 20:36:03 +05:30
|
|
|
}
|
2024-04-12 17:41:45 +05:30
|
|
|
}
|
2024-05-21 12:07:06 +05:30
|
|
|
|
|
|
|
|
const storeBundleStatus = (bundleState: string) => {
|
|
|
|
|
return setStringPreference("reactBundleState", bundleState);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const invalidateStatus = (bundleState: string) => {
|
|
|
|
|
return setStringPreference("reactBundleState", bundleState);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getBundleStatus = async () => {
|
|
|
|
|
return await getStringPreference("reactBundleState", "string");
|
|
|
|
|
};
|