Skip to content

Commit

Permalink
[Wallet] Use exit on iOS since we can't restart like Android (#1424)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanregisser committed Oct 23, 2019
1 parent 2504bc9 commit 98b068c
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/mobile/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ target 'celo' do
pod 'CeloBlockchain', :path => '../../../node_modules/@celo/client/CeloBlockchain.podspec'
pod 'RNSecureKeyStore', :path => '../../../node_modules/react-native-secure-key-store/ios'
pod 'react-native-safe-area-context', :path => '../../../node_modules/react-native-safe-area-context'
pod 'RNExitApp', :path => '../../../node_modules/react-native-exit-app'

pod 'Firebase/Core', '~> 5.20.2'
pod 'Firebase/Auth'
Expand Down
8 changes: 7 additions & 1 deletion packages/mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ PODS:
- Segment-Firebase
- RNDeviceInfo (2.1.0):
- React
- RNExitApp (1.1.0):
- React
- RNFirebase (5.5.4):
- Firebase/Core
- React
Expand Down Expand Up @@ -288,6 +290,7 @@ DEPENDENCIES:
- "RNAnalytics (from `../../../node_modules/@segment/analytics-react-native`)"
- "RNAnalyticsIntegration-Firebase (from `../../../node_modules/@segment/analytics-react-native-firebase`)"
- RNDeviceInfo (from `../../../node_modules/react-native-device-info`)
- RNExitApp (from `../../../node_modules/react-native-exit-app`)
- RNFirebase (from `../../../node_modules/react-native-firebase/ios`)
- RNFS (from `../../../node_modules/react-native-fs`)
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
Expand Down Expand Up @@ -366,6 +369,8 @@ EXTERNAL SOURCES:
:path: "../../../node_modules/@segment/analytics-react-native-firebase"
RNDeviceInfo:
:path: "../../../node_modules/react-native-device-info"
RNExitApp:
:path: "../../../node_modules/react-native-exit-app"
RNFirebase:
:path: "../../../node_modules/react-native-firebase/ios"
RNFS:
Expand Down Expand Up @@ -430,6 +435,7 @@ SPEC CHECKSUMS:
RNAnalytics: 05243c1fa17186f07be3eae30514b43aeb2e0578
RNAnalyticsIntegration-Firebase: 82b879019b012d1aa1cbcb6dfc466acd7233bb97
RNDeviceInfo: 2b4f76adc479657bf37bfc927bbfb027b17515d4
RNExitApp: c4e052df2568b43bec8a37c7cd61194d4cfee2c3
RNFirebase: 7d4733713a0f436d55388b55ca3744385c70fd2d
RNFS: 0f4d630b538e93e0e9e3519ff0b7b7b48760d8ed
RNGestureHandler: b65d391f4f570178d657b99a16ec99d09b8656b0
Expand All @@ -444,6 +450,6 @@ SPEC CHECKSUMS:
SentryReactNative: 07237139c00366ea2e75ae3e5c566e7a71c27a90
yoga: 684513b14b03201579ba3cee20218c9d1298b0cc

PODFILE CHECKSUM: 02a0ed956675dc8aa46eab297cf94e8823e80147
PODFILE CHECKSUM: 4fd5dd293e11126639ca80f4cd528455f4af5ffa

COCOAPODS: 1.7.5
2 changes: 2 additions & 0 deletions packages/mobile/ios/celo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework",
"${BUILT_PRODUCTS_DIR}/RNDeviceInfo/RNDeviceInfo.framework",
"${BUILT_PRODUCTS_DIR}/RNExitApp/RNExitApp.framework",
"${BUILT_PRODUCTS_DIR}/RNFS/RNFS.framework",
"${BUILT_PRODUCTS_DIR}/RNGestureHandler/RNGestureHandler.framework",
"${BUILT_PRODUCTS_DIR}/RNLocalize/RNLocalize.framework",
Expand Down Expand Up @@ -500,6 +501,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNDeviceInfo.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNExitApp.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNFS.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNGestureHandler.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNLocalize.framework",
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/locales/en-US/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"verifyFailed": "Failed to verify",
"canNotRequestFromUnverified": "Can not request from unverified users",
"restartApp": "Restart App",
"quitApp": "Quit",
"loading": "Loading…",
"inviteFailed": "Failure sending invite",
"importContactsFailed": "Failed to import contacts",
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/locales/es-419/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"verifyFailed": "Falla durante la verificación",
"canNotRequestFromUnverified": "No se puede solicitar a usuarios no verificados.",
"restartApp": "Reiniciar la aplicación",
"quitApp": "Dejar",
"loading": "Cargando…",
"inviteFailed": "Falló el envío de la invitación",
"importContactsFailed": "Error al importar contactos",
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"react-native-confirm-device-credentials": "^2.0.0",
"react-native-contacts": "git://github.com/celo-org/react-native-contacts#4989b0b",
"react-native-device-info": "^2.1.0",
"react-native-exit-app": "^1.1.0",
"react-native-firebase": "5.5.4",
"react-native-flag-secure-android": "git://github.com/kristiansorens/react-native-flag-secure-android#e234251",
"react-native-fs": "^2.12.1",
Expand Down
10 changes: 6 additions & 4 deletions packages/mobile/src/app/AppLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import colors from '@celo/react-components/styles/colors'
import * as React from 'react'
import { withNamespaces, WithNamespaces } from 'react-i18next'
import { StyleSheet, View } from 'react-native'
import SafeAreaView from 'react-native-safe-area-view'
import { Namespaces } from 'src/i18n'
import { restartApp } from 'src/utils/AppRestart'
import { RESTART_APP_I18N_KEY, restartApp } from 'src/utils/AppRestart'

const SHOW_RESTART_BUTTON_TIMEOUT = 10000

interface State {
Expand Down Expand Up @@ -40,19 +42,19 @@ export class AppLoading extends React.Component<Props, State> {
const { t } = this.props

return (
<View style={styles.content}>
<SafeAreaView style={styles.content}>
<View style={styles.button}>
{this.state.showRestartButton && (
<Button
onPress={restartApp}
text={t('restartApp')}
text={t(RESTART_APP_I18N_KEY)}
standard={false}
type={BtnTypes.PRIMARY}
testID="RestartButton"
/>
)}
</View>
</View>
</SafeAreaView>
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/mobile/src/app/ErrorScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react'
import { withNamespaces, WithNamespaces } from 'react-i18next'
import { Text, View } from 'react-native'
import { NavigationParams, NavigationScreenProp } from 'react-navigation'
import { restartApp } from 'src/utils/AppRestart'
import { RESTART_APP_I18N_KEY, restartApp } from 'src/utils/AppRestart'

interface OwnProps {
errorMessage?: string
Expand All @@ -29,7 +29,7 @@ class ErrorScreen extends React.Component<Props> {
const errorMessage = this.getErrorMessage()
return (
<FullscreenCTA
CTAText={t('restartApp')}
CTAText={t(RESTART_APP_I18N_KEY)}
CTAHandler={restartApp}
title={t('oops')}
subtitle={t('somethingWrong')}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AppLoading renders correctly 1`] = `
<View
<SafeAreaView
style={
Object {
"alignItems": "center",
Expand All @@ -23,5 +23,5 @@ exports[`AppLoading renders correctly 1`] = `
}
}
/>
</View>
</SafeAreaView>
`;
11 changes: 10 additions & 1 deletion packages/mobile/src/utils/AppRestart.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Platform } from 'react-native'
import RNExitApp from 'react-native-exit-app'
import { RestartAndroid } from 'react-native-restart-android'
import CeloAnalytics from 'src/analytics/CeloAnalytics'
import { CustomEventNames } from 'src/analytics/constants'
import { deleteChainData } from 'src/geth/geth'
import Logger from 'src/utils/Logger'

export const RESTART_APP_I18N_KEY = Platform.OS === 'android' ? 'restartApp' : 'quitApp'

// Call this method to restart the app.
export function restartApp() {
// Delete chain data since that's what is most likely corrupt.
Expand All @@ -12,7 +16,12 @@ export function restartApp() {
.finally(() => {
CeloAnalytics.track(CustomEventNames.user_restart)
Logger.info('utils/AppRestart/restartApp', 'Restarting app')
RestartAndroid.restart()
if (Platform.OS === 'android') {
RestartAndroid.restart()
} else {
// We can't restart on iOS, so just exit ;)
RNExitApp.exitApp()
}
})
.catch((reason) =>
Logger.error('utils/AppRestart/restartApp', `Deleting chain data failed: ${reason}`)
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26172,6 +26172,11 @@ react-native-device-info@^2.1.0:
resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-2.1.0.tgz#55eb82c1ba14c550cef6b71efc368d88b96b826a"
integrity sha512-FdHFi0DtISiytXzE2KM16Qd4GPEGnbA8DjTP1vHjcUPFJCLBtm1P0/10Xn5x/kISjEvsz17grdtJxGrd83c6Pw==

react-native-exit-app@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/react-native-exit-app/-/react-native-exit-app-1.1.0.tgz#5ec082152974240e2d6a93f1608efb49a4385f21"
integrity sha512-Spne19zfMfJvnUTX909EHUqWMk69rATtLJq9XMBGpNSHhx0M7v5yetx2Z87egBhLOqQm+CWfD/oxWzDG8rbIQA==

react-native-firebase@5.5.4:
version "5.5.4"
resolved "https://registry.yarnpkg.com/react-native-firebase/-/react-native-firebase-5.5.4.tgz#1c71d2b21a11fdb5177f7e7c05c8bf3130fb88d7"
Expand Down

0 comments on commit 98b068c

Please sign in to comment.