-
Notifications
You must be signed in to change notification settings - Fork 375
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] Add spinner, timer, and tip text to Verification input screen #1656
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bb92bc8
[Wallet] Hide get invite code link for pilot build
jmrossy 1269d8c
Update comment in keyplacer
jmrossy 8154618
[Wallet] Fix scrolling and some related style issues with tx review f…
jmrossy ca4c907
Merge branch 'master' into rossy/wa-review-frame-fixes
jmrossy f8c8a9c
Update snapshots
jmrossy 90040ba
Fix spanish string
jmrossy 8ed5961
Address feedback
jmrossy a637526
Fix signing issue breaking verification for Alfajores/Pilot
jmrossy 4e76b88
Merge branch 'master' into rossy/wa-ver-sign-fix
jmrossy 90e3cbf
Fix import ordering
jmrossy c736e39
Add spinner and tip text to verification input screen
jmrossy f49fc19
Merge branch 'master' into rossy/wa-ver-spinner-fix
jmrossy 1d32132
Undo loading screen change
jmrossy 17a51c7
Merge branch 'master' into rossy/wa-ver-spinner-fix
jmrossy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import * as React from 'react' | ||
import 'react-native' | ||
import { render } from 'react-native-testing-library' | ||
import VerificationCodeRow from 'src/verify/VerificationCodeRow' | ||
import { mockAttestationMessage } from 'test/values' | ||
|
||
describe('VerificationCodeRow', () => { | ||
it('renders correctly when input enabled', () => { | ||
const { toJSON } = render( | ||
<VerificationCodeRow | ||
index={0} | ||
attestationCodes={[]} | ||
isInputEnabled={true} | ||
inputValue={'test'} | ||
onInputChange={jest.fn()} | ||
isCodeSubmitting={false} | ||
isCodeAccepted={false} | ||
/> | ||
) | ||
expect(toJSON()).toMatchSnapshot() | ||
}) | ||
it('renders correctly when input disabled', () => { | ||
const { toJSON } = render( | ||
<VerificationCodeRow | ||
index={0} | ||
attestationCodes={[]} | ||
isInputEnabled={false} | ||
inputValue={'test'} | ||
onInputChange={jest.fn()} | ||
isCodeSubmitting={false} | ||
isCodeAccepted={false} | ||
/> | ||
) | ||
expect(toJSON()).toMatchSnapshot() | ||
}) | ||
it('renders correctly when submitting', () => { | ||
const { toJSON } = render( | ||
<VerificationCodeRow | ||
index={0} | ||
attestationCodes={[]} | ||
isInputEnabled={true} | ||
inputValue={'test'} | ||
onInputChange={jest.fn()} | ||
isCodeSubmitting={true} | ||
isCodeAccepted={false} | ||
/> | ||
) | ||
expect(toJSON()).toMatchSnapshot() | ||
}) | ||
it('renders correctly when code received', () => { | ||
const { toJSON } = render( | ||
<VerificationCodeRow | ||
index={0} | ||
attestationCodes={[mockAttestationMessage]} | ||
isInputEnabled={true} | ||
inputValue={'test'} | ||
onInputChange={jest.fn()} | ||
isCodeSubmitting={false} | ||
isCodeAccepted={false} | ||
/> | ||
) | ||
expect(toJSON()).toMatchSnapshot() | ||
}) | ||
it('renders correctly when code accepted', () => { | ||
const { toJSON } = render( | ||
<VerificationCodeRow | ||
index={0} | ||
attestationCodes={[mockAttestationMessage]} | ||
isInputEnabled={true} | ||
inputValue={'test'} | ||
onInputChange={jest.fn()} | ||
isCodeSubmitting={false} | ||
isCodeAccepted={true} | ||
/> | ||
) | ||
expect(toJSON()).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import TextInput from '@celo/react-components/components/TextInput' | ||
import withTextInputPasteAware from '@celo/react-components/components/WithTextInputPasteAware' | ||
import Checkmark from '@celo/react-components/icons/Checkmark' | ||
import colors from '@celo/react-components/styles/colors' | ||
import fontStyles from '@celo/react-components/styles/fonts' | ||
import { stripHexLeader } from '@celo/utils/src/signatureUtils' | ||
import { extractAttestationCodeFromMessage } from '@celo/walletkit' | ||
import * as React from 'react' | ||
import { withNamespaces, WithNamespaces } from 'react-i18next' | ||
import { ActivityIndicator, StyleSheet, Text, View } from 'react-native' | ||
import i18n, { Namespaces } from 'src/i18n' | ||
import { ATTESTATION_CODE_PLACEHOLDER } from 'src/identity/reducer' | ||
import { AttestationCode } from 'src/identity/verification' | ||
import Logger from 'src/utils/Logger' | ||
|
||
const TAG = 'VerificationCodeRow' | ||
|
||
export const CODE_INPUT_PLACEHOLDER = '<#> m9oASm/3g7aZ...' | ||
|
||
const CodeInput = withTextInputPasteAware(TextInput) | ||
|
||
interface OwnProps { | ||
index: number // index of code in attestationCodes array | ||
attestationCodes: AttestationCode[] // The codes in the redux store | ||
isInputEnabled: boolean // input disabled until previous code is in | ||
inputValue: string // the raw code inputed by the user | ||
isCodeSubmitting: boolean // is the inputted code being processed | ||
isCodeAccepted: boolean // has the code been accepted and completed | ||
onInputChange: (value: string) => void | ||
} | ||
|
||
type Props = OwnProps & WithNamespaces | ||
|
||
function VerificationCodeRow({ | ||
index, | ||
attestationCodes, | ||
isInputEnabled, | ||
inputValue, | ||
onInputChange, | ||
isCodeSubmitting, | ||
isCodeAccepted, | ||
t, | ||
}: Props) { | ||
if (attestationCodes[index]) { | ||
return ( | ||
<View style={styles.codeContainer}> | ||
<Text style={styles.codeValue} numberOfLines={1} ellipsizeMode={'tail'}> | ||
{getRecodedAttestationValue(attestationCodes[index], t)} | ||
</Text> | ||
{isCodeAccepted && ( | ||
<View style={styles.checkmarkContainer}> | ||
<Checkmark height={20} width={20} /> | ||
</View> | ||
)} | ||
</View> | ||
) | ||
} | ||
|
||
if (!isInputEnabled) { | ||
return ( | ||
<View style={styles.codeInputDisabledContainer}> | ||
<Text style={styles.codeValue}>{CODE_INPUT_PLACEHOLDER}</Text> | ||
</View> | ||
) | ||
} | ||
|
||
return ( | ||
<View style={styles.codeInputContainer}> | ||
<CodeInput | ||
value={inputValue} | ||
placeholder={CODE_INPUT_PLACEHOLDER} | ||
shouldShowClipboard={shouldShowClipboard(attestationCodes)} | ||
onChangeText={onInputChange} | ||
style={styles.codeInput} | ||
/> | ||
{isCodeSubmitting && ( | ||
<ActivityIndicator size="small" color={colors.celoGreen} style={styles.codeInputSpinner} /> | ||
)} | ||
</View> | ||
) | ||
} | ||
|
||
function shouldShowClipboard(attestationCodes: AttestationCode[]) { | ||
return (value: string) => { | ||
const extractedCode = extractAttestationCodeFromMessage(value) | ||
return !!extractedCode && !attestationCodes.find((c) => c.code === extractedCode) | ||
} | ||
} | ||
|
||
function getRecodedAttestationValue(attestationCode: AttestationCode, t: i18n.TranslationFunction) { | ||
try { | ||
if (!attestationCode.code || attestationCode.code === ATTESTATION_CODE_PLACEHOLDER) { | ||
return t('input.codeAccepted') | ||
} | ||
return Buffer.from(stripHexLeader(attestationCode.code), 'hex').toString('base64') | ||
} catch (error) { | ||
Logger.warn(TAG, 'Could not recode verification code to base64') | ||
return t('input.codeAccepted') | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
codeContainer: { | ||
justifyContent: 'center', | ||
marginVertical: 5, | ||
paddingHorizontal: 10, | ||
backgroundColor: colors.darkLightest, | ||
borderRadius: 3, | ||
height: 50, | ||
}, | ||
checkmarkContainer: { | ||
backgroundColor: colors.darkLightest, | ||
position: 'absolute', | ||
top: 3, | ||
right: 3, | ||
padding: 10, | ||
}, | ||
codeInputContainer: { | ||
position: 'relative', | ||
}, | ||
codeInput: { | ||
flex: 0, | ||
backgroundColor: '#FFF', | ||
borderColor: colors.inputBorder, | ||
borderRadius: 3, | ||
borderWidth: 1, | ||
height: 50, | ||
marginVertical: 5, | ||
}, | ||
codeInputSpinner: { | ||
backgroundColor: '#FFF', | ||
position: 'absolute', | ||
top: 9, | ||
right: 3, | ||
padding: 10, | ||
}, | ||
codeInputDisabledContainer: { | ||
justifyContent: 'center', | ||
paddingHorizontal: 10, | ||
marginVertical: 5, | ||
borderColor: colors.inputBorder, | ||
borderRadius: 3, | ||
borderWidth: 1, | ||
height: 50, | ||
backgroundColor: '#F0F0F0', | ||
}, | ||
codeValue: { | ||
...fontStyles.body, | ||
fontSize: 15, | ||
color: colors.darkSecondary, | ||
}, | ||
}) | ||
|
||
export default withNamespaces(Namespaces.nuxVerification2)(VerificationCodeRow) |
14 changes: 7 additions & 7 deletions
14
packages/mobile/src/verify/VerificationInputScreen.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import * as React from 'react' | ||
import 'react-native' | ||
import { render } from 'react-native-testing-library' | ||
import { Provider } from 'react-redux' | ||
import * as renderer from 'react-test-renderer' | ||
import VerificationInputScreen from 'src/verify/VerificationInputScreen' | ||
import { createMockStore } from 'test/utils' | ||
|
||
describe('VerificationInputScreen', () => { | ||
const store = createMockStore({}) | ||
|
||
it('renders correctly', () => { | ||
const tree = renderer.create( | ||
const { toJSON, queryByTestId } = render( | ||
<Provider store={store}> | ||
<VerificationInputScreen /> | ||
</Provider> | ||
) | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
expect(toJSON()).toMatchSnapshot() | ||
expect(queryByTestId('noTypeTip')).toBeFalsy() | ||
|
||
it('enables button after timer', () => { | ||
// TODO | ||
// TODO find way to simulate keyboard showing | ||
// expect(queryByTestId('noTypeTip')).toBeTruthy() | ||
}) | ||
|
||
it('shows tip when typing', () => { | ||
it('enables button after timer', () => { | ||
// TODO | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want our custom activity indicator everywhere now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet but soon!