Skip to content

Commit

Permalink
Warn if different wallet (#1677)
Browse files Browse the repository at this point in the history
* Warn me if I want to sync a different wallet

* remove existing user check from importwallet

* locales
  • Loading branch information
estebanmino authored Jul 7, 2020
1 parent 4de93db commit c6996bc
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 105 deletions.
45 changes: 29 additions & 16 deletions app/components/UI/ActionModal/ActionContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { strings } from '../../../../../locales/i18n';

const styles = StyleSheet.create({
viewWrapper: {
flexDirection: 'column',
flex: 1,
justifyContent: 'center',
alignItems: 'center',
marginHorizontal: 24
Expand All @@ -19,24 +19,26 @@ const styles = StyleSheet.create({
},
actionContainer: {
borderTopColor: colors.grey200,
borderTopWidth: 1,
borderTopWidth: 1
},
actionHorizontalContainer: {
flexDirection: 'row',
padding: 16
},
actionVerticalContainer: {
flexDirection: 'column',
paddingHorizontal: 16,
paddingVertical: 8
},
childrenContainer: {
minHeight: 250,
width: '100%',
flexDirection: 'row',
alignItems: 'center'
},
button: {
flex: 1
},
cancel: {
marginRight: 8
margin: 8
},
confirm: {
marginLeft: 8
buttonHorizontal: {
flex: 1
}
});

Expand All @@ -61,19 +63,26 @@ export default function ActionContent({
viewWrapperStyle,
viewContainerStyle,
actionContainerStyle,
childrenContainerStyle
childrenContainerStyle,
verticalButtons
}) {
return (
<View style={[styles.viewWrapper, viewWrapperStyle]}>
<View style={[styles.viewContainer, viewContainerStyle]}>
<View style={[styles.childrenContainer, childrenContainerStyle]}>{children}</View>
<View style={[styles.actionContainer, actionContainerStyle]}>
<View
style={[
styles.actionContainer,
verticalButtons ? styles.actionVerticalContainer : styles.actionHorizontalContainer,
actionContainerStyle
]}
>
{displayCancelButton && (
<StyledButton
testID={cancelTestID}
type={cancelButtonMode}
onPress={onCancelPress}
containerStyle={[styles.button, displayConfirmButton ? styles.cancel : {}]}
containerStyle={[styles.button, verticalButtons ? {} : styles.buttonHorizontal]}
>
{cancelText}
</StyledButton>
Expand All @@ -83,7 +92,7 @@ export default function ActionContent({
testID={confirmTestID}
type={confirmButtonMode}
onPress={onConfirmPress}
containerStyle={[styles.button, displayCancelButton ? styles.confirm : {}]}
containerStyle={[styles.button, verticalButtons ? {} : styles.buttonHorizontal]}
disabled={confirmDisabled}
>
{confirmText}
Expand Down Expand Up @@ -130,11 +139,11 @@ ActionContent.propTypes = {
/**
* Type of button to show as the cancel button
*/
cancelButtonMode: PropTypes.oneOf(['cancel', 'neutral', 'confirm', 'normal']),
cancelButtonMode: PropTypes.oneOf(['cancel', 'neutral', 'confirm', 'normal', 'warning']),
/**
* Type of button to show as the confirm button
*/
confirmButtonMode: PropTypes.oneOf(['normal', 'confirm', 'warning']),
confirmButtonMode: PropTypes.oneOf(['normal', 'neutral', 'confirm', 'warning']),
/**
* Whether confirm button is disabled
*/
Expand Down Expand Up @@ -171,6 +180,10 @@ ActionContent.propTypes = {
* Action container style
*/
actionContainerStyle: PropTypes.object,
/**
* Whether buttons are rendered vertically
*/
verticalButtons: PropTypes.bool,
/**
* Children container style
*/
Expand Down
12 changes: 9 additions & 3 deletions app/components/UI/ActionModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export default function ActionModal({
viewWrapperStyle,
viewContainerStyle,
actionContainerStyle,
childrenContainerStyle
childrenContainerStyle,
verticalButtons
}) {
return (
<Modal
Expand All @@ -61,6 +62,7 @@ export default function ActionModal({
viewContainerStyle={viewContainerStyle}
actionContainerStyle={actionContainerStyle}
childrenContainerStyle={childrenContainerStyle}
verticalButtons={verticalButtons}
>
{children}
</ActionContent>
Expand Down Expand Up @@ -100,11 +102,11 @@ ActionModal.propTypes = {
/**
* Type of button to show as the cancel button
*/
cancelButtonMode: PropTypes.oneOf(['cancel', 'neutral', 'confirm', 'normal']),
cancelButtonMode: PropTypes.oneOf(['cancel', 'neutral', 'confirm', 'normal', 'warning']),
/**
* Type of button to show as the confirm button
*/
confirmButtonMode: PropTypes.oneOf(['normal', 'confirm', 'warning']),
confirmButtonMode: PropTypes.oneOf(['normal', 'neutral', 'confirm', 'warning']),
/**
* Whether confirm button is disabled
*/
Expand Down Expand Up @@ -153,6 +155,10 @@ ActionModal.propTypes = {
* Action container style
*/
actionContainerStyle: PropTypes.object,
/**
* Whether buttons are rendered vertically
*/
verticalButtons: PropTypes.bool,
/**
* Children container style
*/
Expand Down
65 changes: 13 additions & 52 deletions app/components/Views/ImportWallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,11 @@ class ImportWallet extends PureComponent {
mounted = false;

state = {
loading: false,
existingUser: false
loading: false
};

async checkIfExistingUser() {
const existingUser = await AsyncStorage.getItem('@MetaMask:existingUser');
if (existingUser !== null) {
this.setState({ existingUser: true });
}
}

componentDidMount() {
this.mounted = true;
this.checkIfExistingUser();
InteractionManager.runAfterInteractions(() => {
PreventScreenshot.forbid();
});
Expand Down Expand Up @@ -357,48 +348,18 @@ class ImportWallet extends PureComponent {
}
};

alertExistingUser = callback => {
Alert.alert(
strings('sync_with_extension.warning_title'),
strings('sync_with_extension.warning_message'),
[
{ text: strings('sync_with_extension.warning_cancel_button'), onPress: () => false, style: 'cancel' },
{ text: strings('sync_with_extension.warning_ok_button'), onPress: () => callback() }
],
{ cancelable: false }
);
};

onPressImport = () => {
const { existingUser } = this.state;
const action = () => {
this.props.navigation.push('ImportFromSeed');
InteractionManager.runAfterInteractions(async () => {
if (Analytics.getEnabled()) {
Analytics.trackEvent(ANALYTICS_EVENT_OPTS.ONBOARDING_SELECTED_IMPORT_WITH_SEEDPHRASE);
return;
}
const metricsOptIn = await AsyncStorage.getItem('@MetaMask:metricsOptIn');
if (!metricsOptIn) {
this.props.saveOnboardingEvent(ANALYTICS_EVENT_OPTS.ONBOARDING_SELECTED_IMPORT_WITH_SEEDPHRASE);
}
});
};
if (existingUser) {
this.alertExistingUser(action);
} else {
action();
}
};

safeSync = () => {
const { existingUser } = this.state;
const action = () => this.onPressSync();
if (existingUser) {
this.alertExistingUser(action);
} else {
action();
}
this.props.navigation.push('ImportFromSeed');
InteractionManager.runAfterInteractions(async () => {
if (Analytics.getEnabled()) {
Analytics.trackEvent(ANALYTICS_EVENT_OPTS.ONBOARDING_SELECTED_IMPORT_WITH_SEEDPHRASE);
return;
}
const metricsOptIn = await AsyncStorage.getItem('@MetaMask:metricsOptIn');
if (!metricsOptIn) {
this.props.saveOnboardingEvent(ANALYTICS_EVENT_OPTS.ONBOARDING_SELECTED_IMPORT_WITH_SEEDPHRASE);
}
});
};

onPressSync = () => {
Expand Down Expand Up @@ -448,7 +409,7 @@ class ImportWallet extends PureComponent {
</View>
<View style={styles.ctaWrapper}>
<View style={styles.flexGrow}>
<StyledButton type={'blue'} onPress={this.safeSync} testID={'onboarding-import-button'}>
<StyledButton type={'blue'} onPress={this.onPressSync} testID={'onboarding-import-button'}>
{strings('import_wallet.sync_from_browser_extension_button')}
</StyledButton>
</View>
Expand Down
Loading

0 comments on commit c6996bc

Please sign in to comment.