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] Added native phone picker #1310

Merged
merged 34 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3b99f44
Added native phone picker
martinvol Oct 11, 2019
030f7e3
clean up
martinvol Oct 11, 2019
e96a97e
lint
martinvol Oct 11, 2019
6c5eba9
Merge branch 'master' into martinvol/wallet-automatic-country
martinvol Oct 14, 2019
47c7262
lint
martinvol Oct 14, 2019
312b98e
Made an arrow function to have access to props
martinvol Oct 14, 2019
dc3f639
Added tests and fixed bad mocks
martinvol Oct 14, 2019
38fc6c5
mobile tests
martinvol Oct 15, 2019
2f50daa
deleted deprecated locales
martinvol Oct 15, 2019
91e1b04
Merge branch 'master' into martinvol/wallet-automatic-country
martinvol Oct 15, 2019
cf552fd
Merge branch 'master' into martinvol/wallet-automatic-country
martinvol Oct 15, 2019
ab3e889
Merge branch 'master' into martinvol/wallet-automatic-Country
martinvol Oct 15, 2019
7f3da2f
Don't autocomplete if not on Android
martinvol Oct 22, 2019
abdf441
Merge branch 'martinvol/wallet-automatic-country' of github.com:celo-…
martinvol Oct 22, 2019
bc97bd4
Fixed link
martinvol Oct 22, 2019
c82fa45
Merge branch 'master' into martinvol/wallet-automatic-country
martinvol Oct 23, 2019
c8e07d4
Merge branch 'master' into martinvol/wallet-automatic-country
martinvol Oct 30, 2019
b8e3c08
Merge branch 'master' into martinvol/wallet-automatic-country
martinvol Oct 31, 2019
f9beb85
updated celo/react-native-sms-retriever in react-components packages
martinvol Oct 31, 2019
0ef651a
update yarn .lock
martinvol Oct 31, 2019
dea853d
reset project.pbxproj
martinvol Oct 31, 2019
af97ab9
Merge branch 'master' into martinvol/wallet-automatic-country
martinvol Oct 31, 2019
03402b3
test
martinvol Oct 31, 2019
0c5260e
Merge branch 'master' into martinvol/wallet-automatic-country
martinvol Oct 31, 2019
b65d926
fixed verifier test
martinvol Oct 31, 2019
d6741b6
Merge branch 'master' into martinvol/wallet-automatic-country
martinvol Oct 31, 2019
df6ce7e
Added retry and avoid errors
martinvol Oct 31, 2019
c732f53
Merge branch 'martinvol/wallet-automatic-country' of github.com:celo-…
martinvol Oct 31, 2019
e8df6cf
Merge branch 'master' into martinvol/wallet-automatic-country
martinvol Oct 31, 2019
7a5fbe8
Merge branch 'master' into martinvol/wallet-automatic-country
martinvol Nov 4, 2019
d33736b
Merge branch 'martinvol/wallet-automatic-country' of github.com:celo-…
martinvol Nov 4, 2019
b2e8c6a
Merge branch 'master' into martinvol/wallet-automatic-country
martinvol Nov 4, 2019
25e6680
update snapshots
martinvol Nov 5, 2019
5f7cce8
Fixed tests, currently not skiped
martinvol Nov 5, 2019
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
103 changes: 0 additions & 103 deletions packages/mobile/locales/en.json

This file was deleted.

8 changes: 0 additions & 8 deletions packages/mobile/locales/es.json

This file was deleted.

4 changes: 0 additions & 4 deletions packages/mobile/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import locales from '@celo/mobile/locales'
import en_US from '@celo/mobile/locales/en.json'
import es_LA from '@celo/mobile/locales/es.json'
import { currencyTranslations } from '@celo/utils/src/currencies'
// @ts-ignore
import i18n from 'i18next'
Expand Down Expand Up @@ -28,11 +26,9 @@ export enum Namespaces {

const availableResources = {
'en-US': {
common: en_US,
...locales.enUS,
},
'es-419': {
common: es_LA,
...locales.es_419,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ exports[`JoinCeloScreen renders correctly 1`] = `
"width": 60,
}
}
testID="contryCodeText"
>
+1
</Text>
Expand Down Expand Up @@ -866,6 +867,7 @@ exports[`JoinCeloScreen renders with an error 1`] = `
"width": 60,
}
}
testID="contryCodeText"
>
+1
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2603,6 +2603,7 @@ exports[`renders the Input step correctly 1`] = `
"width": 60,
}
}
testID="contryCodeText"
>

</Text>
Expand Down
5 changes: 3 additions & 2 deletions packages/react-components/__mocks__/country-data.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export default (CountryData = {
callingCountries: {
all: [
{ name: 'USA', countryCallingCodes: ['1'], alpha2: 'US' },
{ name: 'UK', countryCallingCodes: ['33'], alpha2: 'GB' },
{ name: 'USA', countryCallingCodes: ['+1'], alpha2: 'US' },
{ name: 'UK', countryCallingCodes: ['+33'], alpha2: 'GB' },
{ name: 'Germany', countryCallingCodes: ['+49'], alpha2: 'GE' },
],
},
})
33 changes: 33 additions & 0 deletions packages/react-components/components/PhoneNumberInput.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import PhoneNumberInput from '@celo/react-components/components/PhoneNumberInput'
import ValidatedTextInput from '@celo/react-components/components/ValidatedTextInput'
import { shallow } from 'enzyme'
import * as React from 'react'
import { Text } from 'react-native'
import Autocomplete from 'react-native-autocomplete-input'
import * as renderer from 'react-test-renderer'

jest.mock('@celo/react-native-sms-retriever', () => {
return {
requestPhoneNumber: jest.fn(() => '+49030111111'),
}
})

describe('PhoneNumberInput', () => {
it('renders correctly with minimum props', () => {
const tree = renderer.create(
Expand Down Expand Up @@ -97,4 +104,30 @@ describe('PhoneNumberInput', () => {
)
})
})

describe('Native phone picker', () => {
it('can read phone', async () => {
const wrapper = shallow<PhoneNumberInput>(
martinvol marked this conversation as resolved.
Show resolved Hide resolved
<PhoneNumberInput
setE164Number={jest.fn()}
setCountryCode={jest.fn()}
setIsValidNumber={jest.fn()}
/>
)

await wrapper.instance().triggerPhoneNumberRequest()

wrapper.instance().setState({})

expect(wrapper.find(ValidatedTextInput).props().value).toEqual('030 111111')

expect(wrapper.instance().state.countryCallingCode).toEqual('+49')
expect(
wrapper.findWhere((node) => node.prop('testID') === 'contryCodeText').props().children
).toBe('+49')
expect(
wrapper.findWhere((node) => node.prop('testID') === 'CountryNameField').props().defaultValue
).toBe('Germany')
})
})
})
41 changes: 39 additions & 2 deletions packages/react-components/components/PhoneNumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import ValidatedTextInput, {
PhoneValidatorProps,
} from '@celo/react-components/components/ValidatedTextInput'
import colors from '@celo/react-components/styles/colors'
import SmsRetriever from '@celo/react-native-sms-retriever'
martinvol marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you confirmed that this doesn't break the verifier? Because it doesn't have this package set up so I assume the import would fail. Please run the verifier and double check the phone input screen is okay

import { Countries } from '@celo/utils/src/countries'
import { ValidatorKind } from '@celo/utils/src/inputValidation'
import { getRegionCodeFromCountryCode, parsePhoneNumber } from '@celo/utils/src/phoneNumbers'
import * as React from 'react'
import { Platform, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
import Autocomplete from 'react-native-autocomplete-input'

const TAG = 'PhoneNumberInput'

interface Props {
style?: any
defaultCountry?: string | null
Expand All @@ -35,6 +38,7 @@ interface State {
regionCode: string
phoneNumber: string
countries: Countries
country?: string
}

export default class PhoneNumberInput extends React.Component<Props, State> {
Expand Down Expand Up @@ -65,6 +69,37 @@ export default class PhoneNumberInput extends React.Component<Props, State> {
}
}

async triggerPhoneNumberRequest() {
try {
const phone = await SmsRetriever.requestPhoneNumber()
const phoneNumber = parsePhoneNumber(phone, '')

if (phoneNumber) {
martinvol marked this conversation as resolved.
Show resolved Hide resolved
this.setState({
phoneNumber: phoneNumber.displayNumber.toString(),
})
if (phoneNumber.countryCode) {
// TODO known issue, the country code is not enough to
martinvol marked this conversation as resolved.
Show resolved Hide resolved
// get a country, e.g. +1 could be USA or Canada
const displayName = this.state.countries.getCountryByPhoneCountryCode(
'+' + phoneNumber.countryCode.toString()
).displayName

this.onChangeCountryQuery(displayName)
}
}
} catch (error) {
console.debug(`${TAG}/Could not request phone`)
}
}

onCountryFocus = async () => {
if (this.props.onInputFocus) {
await this.props.onInputFocus()
}
await this.triggerPhoneNumberRequest()
martinvol marked this conversation as resolved.
Show resolved Hide resolved
}

onChangeCountryQuery = (countryQuery: string) => {
if (this.props.onInputChange) {
this.props.onInputChange()
Expand Down Expand Up @@ -156,7 +191,7 @@ export default class PhoneNumberInput extends React.Component<Props, State> {
{...props}
value={this.state.countryQuery}
underlineColorAndroid="transparent"
onFocus={this.props.onInputFocus}
onFocus={this.onCountryFocus}
placeholderTextColor={colors.inactive}
/>
)
Expand Down Expand Up @@ -197,7 +232,9 @@ export default class PhoneNumberInput extends React.Component<Props, State> {
</View>
)}
<View style={[style.phoneNumberContainer, style.borderedBox]}>
<Text style={style.phoneCountryCode}>{countryCallingCode}</Text>
<Text style={style.phoneCountryCode} testID={'contryCodeText'}>
{countryCallingCode}
</Text>
<View style={style.line} />
<ValidatedTextInput<PhoneValidatorProps>
style={[style.inputBox, style.phoneNumberInput]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ exports[`PhoneNumberInput renders correctly with minimum props 1`] = `
"width": 60,
}
}
testID="contryCodeText"
>
1
+1
</Text>
<View
style={
Expand Down Expand Up @@ -112,7 +113,7 @@ exports[`PhoneNumberInput renders correctly with minimum props 1`] = `
>
<TextInput
allowFontScaling={true}
countryCallingCode="1"
countryCallingCode="+1"
keyboardType="phone-pad"
onBlur={[Function]}
onChangeText={[Function]}
Expand Down
2 changes: 2 additions & 0 deletions packages/react-components/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ declare module '@umpirsky/country-list/data/es_AR/country.json' {
const value: { [countryCode: string]: string }
export default value
}

declare module '@celo/react-native-sms-retriever'
3 changes: 2 additions & 1 deletion packages/react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"test:watch": "export TZ=UTC && jest --watch"
},
"dependencies": {
"@celo/utils": "^0.1.0",
"@celo/react-native-sms-retriever": "git+https://github.com/celo-org/react-native-sms-retriever#d3a2fdb",
"@celo/utils": "^0.1.1",
"hoist-non-react-statics": "^3.3.0",
"lodash": "^4.17.14",
"react-native-autocomplete-input": "^4.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ exports[`PhoneNumberInput when defaultCountry renders defaults 1`] = `
"width": 60,
}
}
testID="contryCodeText"
>
+54
</Text>
Expand Down Expand Up @@ -339,6 +340,7 @@ exports[`PhoneNumberInput when no defaultCountry renders AutoComplete 1`] = `
"width": 60,
}
}
testID="contryCodeText"
>

</Text>
Expand Down
1 change: 1 addition & 0 deletions packages/verifier/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ declare module 'react-native-restart-android'
declare module 'react-native-platform-touchable'
declare module 'web3-utils'
declare module 'redux-persist/lib/stateReconciler/autoMergeLevel2'
declare module '@celo/react-native-sms-retriever'