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

fix: pin input text and return button #520

Merged
merged 5 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 12 additions & 2 deletions e2e/e2eUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ export const testInput = async (inputId, inputText) => {
await element(by.id(inputId)).tapReturnKey();
};

export const testInputWithDone = async (inputId, inputText) => {
await element(by.id(inputId)).typeText(inputText);
if (device.getPlatform() === 'ios') {
await element(by.label('Done'))
.atIndex(0)
.tap();
} else {
await element(by.id(inputId)).tapReturnKey();
}
};

export const testScrollAndTap = async (buttonId, screenId) => {
await waitFor(element(by.id(buttonId)))
.toBeVisible()
Expand All @@ -52,6 +63,5 @@ export const testScrollAndTap = async (buttonId, screenId) => {
};

export const testUnlockPin = async pinCode => {
await testInput(IdentityPin.unlockPinInput, pinCode);
await testTap(IdentityPin.unlockPinButton);
await testInputWithDone(IdentityPin.unlockPinInput, pinCode);
};
14 changes: 6 additions & 8 deletions e2e/identityManipulation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
tapBack,
testExist,
testInput,
testInputWithDone,
testNotExist,
testNotVisible,
testScrollAndTap,
Expand Down Expand Up @@ -55,8 +56,7 @@ const mockSeedPhrase =

const testSetUpDefaultPath = async () => {
await testInput(IdentityPin.setPin, pinCode);
await testInput(IdentityPin.confirmPin, pinCode);
await testTap(IdentityPin.submitButton);
await testInputWithDone(IdentityPin.confirmPin, pinCode);
await testVisible(AccountNetworkChooser.chooserScreen);
await testScrollAndTap(
substrateNetworkButtonIndex,
Expand Down Expand Up @@ -87,17 +87,16 @@ describe('Load test', async () => {
it('recover a identity with seed phrase', async () => {
await testTap(AccountNetworkChooser.recoverButton);
await testVisible(IdentityNew.seedInput);
await element(by.id(IdentityNew.seedInput)).typeText(mockSeedPhrase);
await testInput(IdentityNew.nameInput, mockIdentityName);
await testTap(IdentityNew.recoverButton);
await element(by.id(IdentityNew.seedInput)).typeText(mockSeedPhrase);
await element(by.id(IdentityNew.seedInput)).tapReturnKey();
await testSetUpDefaultPath();
});

it('derive a new key', async () => {
await testTap(PathsList.deriveButton);
await testInput(PathDerivation.nameInput, 'first one');
await testInput(PathDerivation.pathInput, defaultPath);
await testTap(PathDerivation.deriveButton);
await testInput(PathDerivation.nameInput, 'first one');
await testUnlockPin(pinCode);
await testExist(PathsList.pathCard + `//kusama${defaultPath}`);
});
Expand Down Expand Up @@ -128,9 +127,8 @@ describe('Load test', async () => {
testIDs.AccountNetworkChooser.addCustomNetworkButton,
testIDs.AccountNetworkChooser.chooserScreen
);
await testInput(PathDerivation.nameInput, 'custom network');
await testInput(PathDerivation.pathInput, customPath);
await testTap(PathDerivation.deriveButton);
await testInput(PathDerivation.nameInput, 'custom network');
await testUnlockPin(pinCode);
await testExist(PathsList.pathCard + customPath);
});
Expand Down
4 changes: 3 additions & 1 deletion src/screens/IdentityNew.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ function IdentityNew({ accounts, navigation }) {
<>
<AccountSeed
testID={testIDs.IdentityNew.seedInput}
valid={isSeedValid.valid}
onChangeText={onSeedTextInput}
onSubmitEditing={onRecoverConfirm}
returnKeyType="done"
valid={isSeedValid.valid}
value={seedPhrase}
/>
<View style={styles.btnBox}>
Expand Down
46 changes: 36 additions & 10 deletions src/screens/IdentityPin.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ function IdentityPin({ navigation, accounts }) {

const showHintOrError = () => {
if (state.pinTooShort) {
return ' Your pin must be at least 6 digits long!';
return t.pinTooShortHint;
} else if (state.pinMismatch) {
return isUnlock ? ' Pin code is wrong!' : " Pin codes don't match!";
return isUnlock
? t.pinMisMatchHint.pinUnlock
: t.pinMisMatchHint.pinCreation;
}
return ' Choose a PIN code with 6 or more digits';
return isUnlock ? t.subtitle.pinUnlock : t.subtitle.pinCreation;
};

const onPinInputChange = (stateName, pinInput) => {
Expand All @@ -102,20 +104,21 @@ function IdentityPin({ navigation, accounts }) {
isUnlock ? (
<>
<ScreenHeading
title={'Unlock Identity'}
title={t.title.pinUnlock}
error={state.pinMismatch || state.pinTooShort}
subtitle={showHintOrError()}
/>
<PinInput
label="PIN"
label={t.pinLabel}
autoFocus
testID={testIDs.IdentityPin.unlockPinInput}
returnKeyType="done"
onChangeText={pin => onPinInputChange('pin', pin)}
onSubmitEditing={testPin}
value={state.pin}
/>
<ButtonMainAction
title={'Done'}
title={t.doneButton.pinUnlock}
bottom={false}
onPress={testPin}
testID={testIDs.IdentityPin.unlockPinButton}
Expand All @@ -124,13 +127,13 @@ function IdentityPin({ navigation, accounts }) {
) : (
<>
<ScreenHeading
title={'Set Identity PIN'}
title={t.title.pinCreation}
subtitle={showHintOrError()}
error={state.pinMismatch || state.pinTooShort}
/>

<PinInput
label="PIN"
label={t.pinLabel}
autoFocus
testID={testIDs.IdentityPin.setPin}
returnKeyType="next"
Expand All @@ -142,17 +145,18 @@ function IdentityPin({ navigation, accounts }) {
value={state.pin}
/>
<PinInput
label="Confirm PIN"
label={t.pinConfirmLabel}
returnKeyType="done"
testID={testIDs.IdentityPin.confirmPin}
focus={state.focusConfirmation}
onChangeText={confirmation =>
onPinInputChange('confirmation', confirmation)
}
value={state.confirmation}
onSubmitEditing={submit}
/>
<ButtonMainAction
title={'Done'}
title={t.doneButton.pinCreation}
bottom={false}
onPress={submit}
testID={testIDs.IdentityPin.submitButton}
Expand Down Expand Up @@ -191,6 +195,28 @@ function PinInput(props) {
);
}

const t = {
doneButton: {
pinCreation: 'DONE',
pinUnlock: 'UNLOCK'
},
pinConfirmLabel: 'Confirm PIN',
pinLabel: 'PIN',
pinMisMatchHint: {
pinCreation: "Pin codes don't match!",
pinUnlock: 'Pin code is wrong!'
},
pinTooShortHint: 'Your pin must be at least 6 digits long!',
subtitle: {
pinCreation: 'Choose a PIN code with 6 or more digits',
pinUnlock: 'Unlock the identity to use the seed'
},
title: {
pinCreation: 'Set Identity PIN',
pinUnlock: 'Unlock Identity'
}
};

const styles = StyleSheet.create({
body: {
backgroundColor: colors.bg,
Expand Down
20 changes: 13 additions & 7 deletions src/screens/PathDerivation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'use strict';

import React, { useState } from 'react';
import React, { useRef, useState } from 'react';
import { withNavigation } from 'react-navigation';
import { withAccountStore } from '../util/HOC';
import { Platform, StyleSheet, Text, View } from 'react-native';
Expand All @@ -43,6 +43,7 @@ function PathDerivation({ accounts, navigation }) {
const [derivationPath, setDerivationPath] = useState('');
const [keyPairsName, setKeyPairsName] = useState('');
const [isPathValid, setIsPathValid] = useState(true);
const pathNameInput = useRef(null);
const inheritNetworkKey = navigation.getParam('networkKey');
const isCustomPath = inheritNetworkKey === undefined;
const networkKey = inheritNetworkKey || getNetworkKeyByPath(derivationPath);
Expand Down Expand Up @@ -80,21 +81,26 @@ function PathDerivation({ accounts, navigation }) {
<KeyboardScrollView extraHeight={Platform.OS === 'ios' ? 250 : 180}>
{!isPathValid && <Text>Invalid Path</Text>}
<TextInput
autoCorrect={false}
autoCompleteType="off"
autoCorrect={false}
label="Path"
onChangeText={setDerivationPath}
onSubmitEditing={() => pathNameInput.current.focus()}
placeholder="//hard/soft"
value={derivationPath}
returnKeyType="next"
testID={testIDs.PathDerivation.pathInput}
onChangeText={setDerivationPath}
value={derivationPath}
/>
<TextInput
autoCorrect={false}
autoCompleteType="off"
autoCorrect={false}
label="Display Name"
onChangeText={keyParisName => setKeyPairsName(keyParisName)}
onSubmitEditing={onPathDerivation}
ref={pathNameInput}
returnKeyType="done"
testID={testIDs.PathDerivation.nameInput}
value={keyPairsName}
onChangeText={keyParisName => setKeyPairsName(keyParisName)}
/>
<Separator style={{ height: 0 }} />
<PathCard
Expand All @@ -108,7 +114,7 @@ function PathDerivation({ accounts, navigation }) {
style={{ marginTop: 8 }}
title="Derive Address"
testID={testIDs.PathDerivation.deriveButton}
onPress={() => onPathDerivation()}
onPress={onPathDerivation}
/>
</KeyboardScrollView>
</View>
Expand Down