Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wallet] Rollback zeroSync toggle in case it was not successful #2434

Merged
merged 6 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/mobile/locales/en-US/accountScreen10.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@
"enableDataSaver": "Enable Data Saver",
"dataSaverDetail":
"Data Saver mode allows you to communicate with the Celo Network through a trusted node. You can always change this mode in app settings.",
"restartModal": {
"restartModalSwitchOff": {
"header": "Restart To Switch Off Data Saver",
"body": "To switch Data Saver on and off repeatedly, you will need to restart the app.",
"restart": "Restart to Switch"
},
"restartModalSwitchOn": {
"header": "Beware Of Restart",
"body": "In case of incorrect PIN, you will need to restart the app.",
"understand": "I understand"
},
"testFaqLink": "Celo Wallet FAQ",
"termsOfServiceLink": "Terms of service",
"editProfile": "Edit Profile",
Expand Down
14 changes: 9 additions & 5 deletions packages/mobile/locales/es-419/accountScreen10.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
"sendIssueReport": "Reportar un incidente",
"analytics": "Estadisticas de uso",
"shareAnalytics": "Compartir estadisticas de uso",
"shareAnalytics_detail":
"Recopilamos datos anónimos sobre cómo utiliza Celo para ayudar a mejorar la aplicación para todos.",
"shareAnalytics_detail": "Recopilamos datos anónimos sobre cómo utiliza Celo para ayudar a mejorar la aplicación para todos.",
"dataSaver": "Data Saver",
"enableDataSaver": "Habilitar Data Saver",
"dataSaverDetail":
"El modo Data Saver te permite comunicarte con la Red Celo a través de un nodo confiable. Puedes cambiar este modo en la configuración de la aplicación.",
"restartModal": {
"dataSaverDetail": "El modo Data Saver te permite comunicarte con la Red Celo a través de un nodo confiable. Puedes cambiar este modo en la configuración de la aplicación.",
"restartModalSwitchOff": {
"header": "Reiniciar para apagar Data Saver",
"body": "Para encender y apagar Data Saver repetidamente, deberá reiniciar la aplicación.",
"restart": "Reiniciar para alternar"
},
"restartModalSwitchOn": {
"header": "~~Beware Of Restart",
"body": "~~In case of incorrect PIN, you will need to restart the app.",
"understand": "~~I understand"
},

"testFaqLink": "Las Preguntas Frecuentes del Monedero Celo",
"termsOfServiceLink": "Las Condiciones de Servicio",
"editProfile": "Editar perfil",
Expand Down
69 changes: 53 additions & 16 deletions packages/mobile/src/account/DataSaver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const mapStateToProps = (state: RootState): StateProps => {
}

interface State {
modalVisible: boolean
switchOffModalVisible: boolean
switchOnModalVisible: boolean
}

export class DataSaver extends React.Component<Props, State> {
Expand All @@ -45,29 +46,45 @@ export class DataSaver extends React.Component<Props, State> {
})

state = {
modalVisible: false,
switchOffModalVisible: false,
switchOnModalVisible: false,
}

showModal = () => {
this.setState({ modalVisible: true })
showSwitchOffModal = () => {
this.setState({ switchOffModalVisible: true })
}

hideModal = () => {
this.setState({ modalVisible: false })
hideSwitchOffModal = () => {
this.setState({ switchOffModalVisible: false })
}

onPressToggleWithRestartModal = () => {
onPressToggleWithSwitchOffModal = () => {
this.props.toggleZeroSyncMode(false)
this.hideModal()
this.hideSwitchOffModal()
}

showSwitchOnModal = () => {
this.setState({ switchOnModalVisible: true })
}

hideSwitchOnModal = () => {
this.setState({ switchOnModalVisible: false })
}

onPressToggleWithSwitchOnModal = () => {
this.props.toggleZeroSyncMode(true)
this.hideSwitchOnModal()
}

handleZeroSyncToggle = (zeroSyncMode: boolean) => {
if (!zeroSyncMode && this.props.gethStartedThisSession) {
// Starting geth a second time this app session which will
// require an app restart, so show restart modal
this.showModal()
this.showSwitchOffModal()
} else {
this.props.toggleZeroSyncMode(zeroSyncMode)
// If move to zeroSync was not successful we will need
// to rollback starting geth a second time
this.showSwitchOnModal()
}
}

Expand All @@ -82,16 +99,36 @@ export class DataSaver extends React.Component<Props, State> {
>
<Text style={fontStyles.body}>{t('enableDataSaver')}</Text>
</SettingsSwitchItem>
<Modal isVisible={this.state.modalVisible}>
<Modal isVisible={this.state.switchOffModalVisible}>
<View style={styles.modalContainer}>
<Text style={styles.modalHeader}>{t('restartModalSwitchOff.header')}</Text>
<Text style={fontStyles.body}>{t('restartModalSwitchOff.body')}</Text>
<View style={styles.modalButtonsContainer}>
<TextButton onPress={this.hideSwitchOffModal} style={styles.modalCancelText}>
{t('global:cancel')}
</TextButton>
<TextButton
onPress={this.onPressToggleWithSwitchOffModal}
style={styles.modalSkipText}
>
{t('restartModalSwitchOff.restart')}
</TextButton>
</View>
</View>
</Modal>
<Modal isVisible={this.state.switchOnModalVisible}>
<View style={styles.modalContainer}>
<Text style={styles.modalHeader}>{t('restartModal.header')}</Text>
<Text style={fontStyles.body}>{t('restartModal.body')}</Text>
<Text style={styles.modalHeader}>{t('restartModalSwitchOn.header')}</Text>
<Text style={fontStyles.body}>{t('restartModalSwitchOn.body')}</Text>
<View style={styles.modalButtonsContainer}>
<TextButton onPress={this.hideModal} style={styles.modalCancelText}>
<TextButton onPress={this.hideSwitchOnModal} style={styles.modalCancelText}>
{t('global:cancel')}
</TextButton>
<TextButton onPress={this.onPressToggleWithRestartModal} style={styles.modalSkipText}>
{t('restartModal.restart')}
<TextButton
onPress={this.onPressToggleWithSwitchOnModal}
style={styles.modalSkipText}
>
{t('restartModalSwitchOn.understand')}
</TextButton>
</View>
</View>
Expand Down
211 changes: 208 additions & 3 deletions packages/mobile/src/account/__snapshots__/DataSaver.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ exports[`DataSaver renders correctly 1`] = `
}
}
>
restartModal.header
restartModalSwitchOff.header
</Text>
<Text
style={
Expand All @@ -197,7 +197,7 @@ exports[`DataSaver renders correctly 1`] = `
}
}
>
restartModal.body
restartModalSwitchOff.body
</Text>
<View
style={
Expand Down Expand Up @@ -286,7 +286,212 @@ exports[`DataSaver renders correctly 1`] = `
]
}
>
restartModal.restart
restartModalSwitchOff.restart
</Text>
</View>
</View>
</View>
</View>
</Modal>
<Modal
animationType="none"
hardwareAccelerated={false}
hideModalContentWhileAnimating={false}
onModalHide={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onRequestClose={[Function]}
scrollHorizontal={false}
scrollOffset={0}
scrollOffsetMax={0}
scrollTo={null}
supportedOrientations={
Array [
"portrait",
"landscape",
]
}
swipeThreshold={100}
transparent={true}
visible={false}
>
<View
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"backgroundColor": "black",
"bottom": 0,
"height": 1334,
"left": 0,
"opacity": 0,
"position": "absolute",
"right": 0,
"top": 0,
"width": 750,
}
}
/>
<View
hideModalContentWhileAnimating={false}
onModalHide={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
pointerEvents="box-none"
scrollHorizontal={false}
scrollOffset={0}
scrollOffsetMax={0}
scrollTo={null}
style={
Object {
"flex": 1,
"justifyContent": "center",
"margin": 37.5,
"transform": Array [
Object {
"translateY": 0,
},
],
}
}
supportedOrientations={
Array [
"portrait",
"landscape",
]
}
swipeThreshold={100}
>
<View
style={
Object {
"backgroundColor": "#FFFFFF",
"borderRadius": 4,
"marginHorizontal": 10,
"padding": 20,
}
}
>
<Text
style={
Object {
"color": "#2E3338",
"fontFamily": "Hind-Bold",
"fontSize": 18,
"marginVertical": 15,
"textAlign": "center",
}
}
>
restartModalSwitchOn.header
</Text>
<Text
style={
Object {
"color": "#2E3338",
"fontFamily": "Hind-Regular",
"fontSize": 16,
"lineHeight": 24,
}
}
>
restartModalSwitchOn.body
</Text>
<View
style={
Object {
"alignItems": "center",
"flexDirection": "row",
"justifyContent": "space-evenly",
"marginTop": 25,
}
}
>
<View
accessible={true}
focusable={true}
isTVSelectable={true}
nativeBackgroundAndroid={
Object {
"attribute": "selectableItemBackgroundBorderless",
"type": "ThemeAttrAndroid",
}
}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
>
<Text
style={
Array [
Object {
"color": "#42D689",
"fontFamily": "Hind-SemiBold",
"fontSize": 14,
"lineHeight": 18,
},
Object {
"color": "#2E3338",
"fontFamily": "Hind-SemiBold",
"fontSize": 16,
"lineHeight": 24,
"paddingRight": 20,
},
]
}
>
global:cancel
</Text>
</View>
<View
accessible={true}
focusable={true}
isTVSelectable={true}
nativeBackgroundAndroid={
Object {
"attribute": "selectableItemBackgroundBorderless",
"type": "ThemeAttrAndroid",
}
}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
>
<Text
style={
Array [
Object {
"color": "#42D689",
"fontFamily": "Hind-SemiBold",
"fontSize": 14,
"lineHeight": 18,
},
Object {
"color": "#42D689",
"fontFamily": "Hind-SemiBold",
"fontSize": 16,
"lineHeight": 24,
"paddingLeft": 20,
},
]
}
>
restartModalSwitchOn.understand
</Text>
</View>
</View>
Expand Down
Loading