Skip to content

Commit

Permalink
fix scan QR code on iOS. Fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
KKA11010 committed Jul 14, 2023
1 parent cbd44db commit 362ddd8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/components/Toaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { mainColors } from '@src/styles'
import { StyleSheet, Text } from 'react-native'
import Animated, { FadeInUp, FadeOutUp } from 'react-native-reanimated'

export default function Toaster({ success, txt, top }: { success?: boolean, txt: string, top?: boolean }) {
export default function Toaster({ success, txt }: { success?: boolean, txt: string }) {
return (
<Animated.View
entering={FadeInUp}
exiting={FadeOutUp}
style={[
styles.container,
{ backgroundColor: success ? mainColors.VALID : '#FF6666', top: top ? 20 : 50 }
{ backgroundColor: success ? mainColors.VALID : mainColors.WARN }
]}
>
<Text style={styles.txt}>
Expand Down
12 changes: 0 additions & 12 deletions src/components/nav/TopNav.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import usePrompt from '@comps/hooks/Prompt'
import { QRIcon } from '@comps/Icons'
import Toaster from '@comps/Toaster'
import { isIOS } from '@consts'
import type { TBottomNavProps } from '@model/nav'
import { useNavigation } from '@react-navigation/native'
import { ThemeContext } from '@src/context/Theme'
Expand All @@ -20,7 +17,6 @@ interface TTopNavProps {
export default function TopNav({ screenName, withBackBtn, nav, backHandler }: TTopNavProps) {
const { t } = useTranslation(['common'])
const { color, highlight } = useContext(ThemeContext)
const { prompt, openPromptAutoClose } = usePrompt()
const navHook = useNavigation()
const handlePress = () => {
if (withBackBtn) {
Expand All @@ -31,13 +27,6 @@ export default function TopNav({ screenName, withBackBtn, nav, backHandler }: TT
navHook.goBack()
return
}
if (isIOS) {
openPromptAutoClose({
msg: t('iosQrErr', { ns: 'error' }),
ms: 4000
})
return
}
// open QR Scan
nav?.navigation.navigate('qr scan')
}
Expand All @@ -59,7 +48,6 @@ export default function TopNav({ screenName, withBackBtn, nav, backHandler }: TT
<QRIcon color={color.TEXT} />
}
</TouchableOpacity>
{prompt.open && <Toaster txt={prompt.msg} top />}
</View>
)
}
Expand Down
8 changes: 3 additions & 5 deletions src/components/screens/QRScan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import usePrompt from '@comps/hooks/Prompt'
import useCashuToken from '@comps/hooks/Token'
import { CloseIcon, FlashlightOffIcon, ZapIcon } from '@comps/Icons'
import Toaster from '@comps/Toaster'
import { QRType } from '@consts'
import { isIOS, QRType } from '@consts'
import { addMint, getMintsUrls } from '@db'
import { l } from '@log'
import TrustMintModal from '@modal/TrustMint'
Expand Down Expand Up @@ -118,8 +118,9 @@ export default function QRScanPage({ navigation, route }: TQRScanPageProps) {

const handleBarCodeScanned = ({ type, data }: { type: string, data: string }) => {
setScanned(true)
const bcType = isIOS ? 'org.iso.QRCode' : QRType
// early return if barcode is not a QR
if (+type !== QRType) {
if (type !== bcType) {
openPromptAutoClose({ msg: t('notQrCode') })
return
}
Expand Down Expand Up @@ -158,9 +159,6 @@ export default function QRScanPage({ navigation, route }: TQRScanPageProps) {
flashMode={flash ? FlashMode.torch : FlashMode.off}
style={StyleSheet.absoluteFill}
ratio={'16:9'}
barCodeScannerSettings={{
barCodeTypes: [`${QRType}`],
}}
onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}
/>
<QRMarker size={300} />
Expand Down
2 changes: 1 addition & 1 deletion src/consts/qr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export const qrCodeLimits = {
H: { numeric: 3057, alphanumeric: 1852, binary: 1273 }
} as const

export const QRType = 256 as const
export const QRType = '256' as const

0 comments on commit 362ddd8

Please sign in to comment.