Files
inji-wallet/App.tsx
Harsh Vardhan 2adef1a78b feat(INJI-343): Text changes & other UI enhancements (#854)
* feat(INJI-343): update error msg texts

* fix(INJI-343): fix display message on receiveVCScreen

* fix(INJI-343): add custom button option in MessageOverlay

* feat(INJI-343): add customHeight prop in MessageOverlay for long text

Co-authored-by: Kiruthika Jeyashankar <81218987+KiruthikaJeyashankar@users.noreply.github.com>

* feat(INJI-343): update error msg texts

Conflicts:
      locales/ara.json
      locales/fil.json
      locales/hin.json
      locales/kan.json
      locales/spa.json
      locales/tam.json

* feat(INJI-343): remove duplicate button and make custm btn txt configurable

* refactor(INJI-343): rename MessageOverlay customButton prop

Co-authored-by: Kiruthika Jeyashankar <81218987+KiruthikaJeyashankar@users.noreply.github.com>

---------

Co-authored-by: Kiruthika Jeyashankar <81218987+KiruthikaJeyashankar@users.noreply.github.com>
2023-09-25 12:42:40 +05:30

125 lines
3.6 KiB
TypeScript

import React, {useContext, useEffect} from 'react';
import AppLoading from 'expo-app-loading';
import {AppLayout} from './screens/AppLayout';
import {useFont} from './shared/hooks/useFont';
import {GlobalContextProvider} from './components/GlobalContextProvider';
import {GlobalContext} from './shared/GlobalContext';
import {useSelector} from '@xstate/react';
import {useTranslation} from 'react-i18next';
import {
selectIsDecryptError,
selectIsKeyInvalidateError,
selectIsReadError,
selectIsReady,
} from './machines/app';
import {DualMessageOverlay} from './components/DualMessageOverlay';
import {useApp} from './screens/AppController';
import {Alert} from 'react-native';
import {
getAppInfoData,
getTelemetryConfigData,
initializeTelemetry,
sendAppInfoEvent,
} from './shared/telemetry/TelemetryUtils';
import {MessageOverlay} from './components/MessageOverlay';
import SecureKeystore from 'react-native-secure-keystore';
import {isCustomSecureKeystore} from './shared/cryptoutil/cryptoUtil';
import i18n from './i18n';
// kludge: this is a bad practice but has been done temporarily to surface
// an occurance of a bug with minimal residual code changes, this should
// be removed once the bug cause is determined & fixed, ref: INJI-222
const DecryptErrorAlert = (controller, t) => {
const heading = t('errors.decryptionFailed');
const desc = t('errors.decryptionFailed');
const ignoreBtnTxt = t('ignore');
Alert.alert(heading, desc, [
{
text: ignoreBtnTxt,
onPress: () => controller.ignoreDecrypt(),
style: 'cancel',
},
]);
};
function configureTelemetry() {
const config = getTelemetryConfigData();
initializeTelemetry(config);
sendAppInfoEvent(getAppInfoData());
}
const AppLayoutWrapper: React.FC = () => {
const {appService} = useContext(GlobalContext);
const isDecryptError = useSelector(appService, selectIsDecryptError);
const controller = useApp();
const {t} = useTranslation('WelcomeScreen');
if (isDecryptError) {
DecryptErrorAlert(controller, t);
}
configureTelemetry();
return <AppLayout />;
};
const AppLoadingWrapper: React.FC = () => {
const {appService} = useContext(GlobalContext);
const isReadError = useSelector(appService, selectIsReadError);
const isKeyInvalidateError = useSelector(
appService,
selectIsKeyInvalidateError,
);
const controller = useApp();
const {t} = useTranslation('WelcomeScreen');
return (
<>
<AppLoading />
<MessageOverlay
isVisible={isKeyInvalidateError}
title={t('errors.invalidateKeyError.title')}
message={t('errors.invalidateKeyError.message')}
onButtonPress={controller.RESET}
buttonText={t('common:ok')}
customHeight={'auto'}
/>
{isReadError ? (
<DualMessageOverlay
isVisible={isReadError}
title={t('failedToReadKeys')}
message={t('retryRead')}
onTryAgain={controller.TRY_AGAIN}
onIgnore={controller.IGNORE}
/>
) : null}
</>
);
};
const AppInitialization: React.FC = () => {
const {appService} = useContext(GlobalContext);
const isReady = useSelector(appService, selectIsReady);
const hasFontsLoaded = useFont();
const {t} = useTranslation('common');
useEffect(() => {
if (isCustomSecureKeystore()) {
SecureKeystore.updatePopup(
t('biometricPopup.title'),
t('biometricPopup.description'),
);
}
}, [i18n.language]);
return isReady && hasFontsLoaded ? (
<AppLayoutWrapper />
) : (
<AppLoadingWrapper />
);
};
export default function App() {
return (
<GlobalContextProvider>
<AppInitialization />
</GlobalContextProvider>
);
}