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] Limit QR code scanner to 1 code per second #1676

Merged
merged 5 commits into from
Nov 13, 2019
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
11 changes: 4 additions & 7 deletions packages/mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -491,22 +491,19 @@ DEPENDENCIES:
- Yoga (from `../../../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
https://cdn.cocoapods.org/:
https://github.com/cocoapods/specs.git:
- Analytics
- boost-for-react-native
- Fabric
- Firebase
- FirebaseCore
- FirebaseInstanceID
- GoogleUtilities
https://github.com/cocoapods/specs.git:
- Crashlytics
- Fabric
- Firebase
- FirebaseAnalytics
- FirebaseAnalyticsInterop
- FirebaseAuth
- FirebaseAuthInterop
- FirebaseCore
- FirebaseDatabase
- FirebaseInstanceID
- FirebaseMessaging
- FirebaseStorage
- GoogleAppMeasurement
Expand Down
2 changes: 2 additions & 0 deletions packages/mobile/ios/celo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
Expand Down
31 changes: 28 additions & 3 deletions packages/mobile/src/qrcode/QRScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,50 @@ interface DispatchProps {
handleBarcodeDetected: typeof handleBarcodeDetected
}

interface State {
isScanningEnabled: boolean
}

type Props = DispatchProps & WithNamespaces & NavigationFocusInjectedProps

class QRScanner extends React.Component<Props> {
class QRScanner extends React.Component<Props, State> {
static navigationOptions = () => ({
...headerWithBackButton,
headerTitle: i18n.t('sendFlow7:scanCode'),
})

timeout: undefined | number = undefined

state = {
isScanningEnabled: true,
}

camera: RNCamera | null = null

// This method would be called multiple times with the same
// QR code, so we need to catch only the first one
onBardCodeDetected = (rawData: any) => {
Logger.debug('QRScanner', 'Bar code detected')
this.props.handleBarcodeDetected(rawData)
if (this.state.isScanningEnabled) {
this.setState({ isScanningEnabled: false }, () => {
Logger.debug('QRScanner', 'Bar code detected')
this.props.handleBarcodeDetected(rawData)
})
this.timeout = setTimeout(() => {
this.setState({ isScanningEnabled: true })
}, 1000)
}
}

onPressShowYourCode = () => {
navigate(Screens.QRCode)
}

componentWillUnmount() {
if (this.timeout) {
clearTimeout(this.timeout)
}
}

render() {
const { t } = this.props
return (
Expand Down