Skip to content

Commit

Permalink
Check if valid code in clipboard before displaying Open Messages (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
sallyjyl authored and jmrossy committed Jul 24, 2019
1 parent 7a46a3c commit 0b95817
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/mobile/src/invite/EnterInviteCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ interface StateProps {
interface State {
inviteCode: string
isSubmitting: boolean
messageAppOpened: boolean
appState: AppStateStatus
validCodeInClipboard: boolean
}
Expand Down Expand Up @@ -105,32 +104,33 @@ export class EnterInviteCode extends React.Component<Props, State> {
state: State = {
inviteCode: '',
isSubmitting: false,
messageAppOpened: false,
appState: AppState.currentState,
validCodeInClipboard: false,
}

componentDidMount() {
async componentDidMount() {
AppState.addEventListener('change', this.handleValidCodeInClipboard)
this.checkIfValidCodeInClipboard()
}

componentWillUnmount() {
AppState.addEventListener('change', this.handleValidCodeInClipboard)
}

openMessage = () => {
this.setState({
messageAppOpened: true,
})
SendIntentAndroid.openSMSApp()
}

checkIfValidCodeInClipboard = async () => {
const message = await Clipboard.getString()
const validCode = extractValidInviteCode(message)

this.setState({ validCodeInClipboard: validCode !== null })
}

handleValidCodeInClipboard = async (nextAppState: AppStateStatus) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
const message = await Clipboard.getString()
const validCode = extractValidInviteCode(message)

this.setState({ validCodeInClipboard: validCode !== null })
this.checkIfValidCodeInClipboard()
}
this.setState({ appState: nextAppState })
}
Expand Down Expand Up @@ -186,7 +186,7 @@ export class EnterInviteCode extends React.Component<Props, State> {
<Text style={fontStyles.bodySmallBold}>{t('inviteCodeText.inviteAccepted')}</Text>
) : (
!this.state.isSubmitting &&
(!(this.state.messageAppOpened && this.state.validCodeInClipboard) ? (
(!this.state.validCodeInClipboard ? (
<View>
<Text style={[styles.body, styles.hint]}>
<Text style={fontStyles.bodySmallSemiBold}>
Expand Down

0 comments on commit 0b95817

Please sign in to comment.