TP-80461 | auto app updater fallback added

This commit is contained in:
Aman Chaturvedi
2024-09-21 13:57:38 +05:30
parent df76caecdd
commit 3c457e2010
3 changed files with 47 additions and 23 deletions

View File

@@ -1,8 +1,9 @@
import { BuildFlavours } from '@common/Constants';
import { ApiKeys, getApiUrl } from '@components/utlis/apiHelper';
import { logError } from '@components/utlis/errorUtils';
import axios from 'axios';
import { Linking, NativeModules } from 'react-native';
import RNFetchBlob from 'rn-fetch-blob';
import RNFetchBlob from 'react-native-blob-util';
const { ApkInstaller } = NativeModules;
@@ -40,12 +41,12 @@ export const downloadApkFromS3 = async (s3Url: string, fileName: string) => {
export const downloadLatestAppS3Url = async (buildFlavour: BuildFlavours) => {
try {
const response = await axios.get(
`https://longhorn.navi.com/api/app/download?appType=${buildFlavour}`
);
const url = getApiUrl(ApiKeys.DOWNLOAD_LATEST_APP, {}, { appType: buildFlavour });
const response = await axios.get(url);
return response.data.downloadPreSignedUrl;
} catch (err) {
logError(err as Error, 'Error while downloading the latest app');
return '';
}
};

View File

@@ -46,7 +46,10 @@ const BlockerScreen = (props: IBlockerScreen) => {
(roles?.length === 1 && roles.includes(IUserRole.ROLE_FIELD_AGENT)) ||
roles.includes(IUserRole.ROLE_OMA);
const [shouldUpdate, setShouldUpdate] = useState<string>('');
const [shouldUpdate, setShouldUpdate] = useState({
newApkCachedUrl: '',
switchToFallback: false,
});
const [showActionBtnLoader, setShowActionBtnLoader] = useState(false);
const dispatch = useAppDispatch();
@@ -57,32 +60,36 @@ const BlockerScreen = (props: IBlockerScreen) => {
const downloadLatestApp = async () => {
let apkFileUrl;
if (GLOBAL.BUILD_FLAVOUR.includes(BuildFlavours.FIELD_AGENTS)) {
// Field agent
// Download app for Field agent
apkFileUrl = await downloadLatestApkAndGetFilePath(BuildFlavours.FIELD_AGENTS);
} else {
// Calling agent
// Download app for Calling agent
apkFileUrl = await downloadLatestApkAndGetFilePath(BuildFlavours.CALLING_AGENTS);
}
if (apkFileUrl) {
setShouldUpdate(apkFileUrl);
setShouldUpdate({ newApkCachedUrl: apkFileUrl, switchToFallback: false });
} else {
setShouldUpdate({ newApkCachedUrl: '', switchToFallback: true });
}
};
const handleAppUpdate = () => {
if (shouldUpdate) {
installApk(shouldUpdate, (error) => {
if (!error) {
return;
}
let fallbackLonghornUrl;
if (GLOBAL.BUILD_FLAVOUR.includes('fieldAgents')) {
fallbackLonghornUrl = appState?.fieldAgents?.currentProdAPK;
} else {
fallbackLonghornUrl = appState?.telecallingAgents?.currentProdAPK;
}
openFallbackLonghornLink(fallbackLonghornUrl);
});
let fallbackLonghornUrl;
if (GLOBAL.BUILD_FLAVOUR.includes('fieldAgents')) {
fallbackLonghornUrl = appState?.fieldAgents?.currentProdAPK;
} else {
fallbackLonghornUrl = appState?.telecallingAgents?.currentProdAPK;
}
if (!shouldUpdate.newApkCachedUrl) {
openFallbackLonghornLink(fallbackLonghornUrl);
return;
}
installApk(shouldUpdate.newApkCachedUrl, (error) => {
if (!error) {
return;
}
openFallbackLonghornLink(fallbackLonghornUrl);
});
};
React.useEffect(() => {
@@ -106,7 +113,10 @@ const BlockerScreen = (props: IBlockerScreen) => {
) {
downloadLatestApp();
} else {
setShouldUpdate('');
setShouldUpdate({
newApkCachedUrl: '',
switchToFallback: false,
});
deleteCachedApkFiles();
}
}, [appState]);
@@ -145,10 +155,21 @@ const BlockerScreen = (props: IBlockerScreen) => {
}
};
if (shouldUpdate) {
if (shouldUpdate.newApkCachedUrl) {
return <AppUpdate onAppUpdate={handleAppUpdate} />;
}
if (shouldUpdate.switchToFallback) {
const { heading, instructions } = BLOCKER_SCREEN_DATA.UNINSTALL_APP;
return (
<BlockerInstructions
heading={heading}
instructions={instructions}
actionBtn={{ title: 'Download New App', action: handleAppUpdate }}
/>
);
}
if (!isTimeSynced) {
const { heading, instructions } = BLOCKER_SCREEN_DATA.TIME_UNSYNC;
return (

View File

@@ -94,6 +94,7 @@ export enum ApiKeys {
SEND_COMMUNICATION_NAVI_ACCOUNT = 'SEND_COMMUNICATION_NAVI_ACCOUNT',
SYNC_CALL_FEEDBACK_NUDGE_DETAILS = 'SYNC_CALL_FEEDBACK_NUDGE_DETAILS',
GENERATE_DYNAMIC_DOCUMENT = 'GENERATE_DYNAMIC_DOCUMENT',
DOWNLOAD_LATEST_APP = 'DOWNLOAD_LATEST_APP'
}
export const API_URLS: Record<ApiKeys, string> = {} as Record<ApiKeys, string>;
@@ -180,6 +181,7 @@ API_URLS[ApiKeys.FETCH_AGENT_DOCUMENTS] = '/documents/agent';
API_URLS[ApiKeys.FETCH_DOCUMENT_SPECIFIC_LANGUAGE] = '/documents/language/{loanAccountNumber}';
API_URLS[ApiKeys.SEND_COMMUNICATION_NAVI_ACCOUNT] = '/navi-communications/{loanAccountNumber}';
API_URLS[ApiKeys.GENERATE_DYNAMIC_DOCUMENT] = '/documents/generate/{loanAccountNumber}';
API_URLS[ApiKeys.DOWNLOAD_LATEST_APP] = 'https://longhorn.navi.com/api/app/download';
export const API_STATUS_CODE = {
OK: 200,