-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: QR code scanning was failing to retrieve recipient's address …
…in send flow
- Loading branch information
1 parent
e785a43
commit cc15ba0
Showing
7 changed files
with
96 additions
and
177 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"live-mobile": minor | ||
--- | ||
|
||
QR code scanning was failling to retrieve recipient's address in send flow |
70 changes: 0 additions & 70 deletions
70
apps/ledger-live-mobile/src/components/CameraScreen/QRCodeBottomLayer.tsx
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
apps/ledger-live-mobile/src/components/CameraScreen/index.tsx
This file was deleted.
Oops, something went wrong.
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,64 +1,97 @@ | ||
import React, { useContext } from "react"; | ||
import { StyleSheet, View } from "react-native"; | ||
import { BarCodeScanningResult, Camera, CameraType } from "expo-camera/legacy"; | ||
import { Flex } from "@ledgerhq/native-ui"; | ||
import StyledStatusBar from "./StyledStatusBar"; | ||
import CameraScreen from "./CameraScreen"; | ||
import getWindowDimensions from "~/logic/getWindowDimensions"; | ||
import RequiresCameraPermissions from "./RequiresCameraPermissions"; | ||
import CameraPermissionContext from "./RequiresCameraPermissions/CameraPermissionContext"; | ||
import ForceTheme from "./theme/ForceTheme"; | ||
import React from "react"; | ||
import { Box, Flex, Icons, NumberedList, Text } from "@ledgerhq/native-ui"; | ||
import { Trans, useTranslation } from "react-i18next"; | ||
import { useTheme } from "styled-components/native"; | ||
import { CameraView, BarcodeScanningResult } from "expo-camera"; | ||
import RequiresCameraPermissions from "~/components/RequiresCameraPermissions"; | ||
import CameraPermissionContext from "~/components/RequiresCameraPermissions/CameraPermissionContext"; | ||
import ScanTargetSvg from "./CameraScreen/ScanTargetSvg"; | ||
|
||
type Props = { | ||
onResult: (_: string) => void; | ||
liveQrCode?: boolean; | ||
progress?: number; | ||
instruction?: React.ReactNode | string; | ||
onResult: (data: string) => void; | ||
liveQRCode?: boolean; | ||
}; | ||
|
||
const Scanner = ({ onResult, liveQrCode, progress, instruction }: Props) => { | ||
const hasPermission = useContext(CameraPermissionContext).permissionGranted; | ||
const { width, height } = getWindowDimensions(); | ||
|
||
if (!hasPermission) return <View />; | ||
const ScanQrCode = ({ onResult, liveQRCode = false }: Props) => { | ||
const { t } = useTranslation(); | ||
const { colors } = useTheme(); | ||
const onBarCodeScanned = ({ data }: BarcodeScanningResult) => { | ||
onResult(data); | ||
}; | ||
|
||
return ( | ||
<ForceTheme selectedPalette="dark"> | ||
<Flex flex={1}> | ||
<StyledStatusBar barStyle="light-content" /> | ||
<Camera | ||
style={styles.camera} | ||
type={CameraType.back} | ||
ratio="16:9" | ||
onBarCodeScanned={({ data }: BarCodeScanningResult) => onResult(data)} | ||
barCodeScannerSettings={{ | ||
barCodeTypes: ["qr"], | ||
}} | ||
<Flex | ||
flex={1} | ||
justifyContent="flex-start" | ||
alignItems={"center"} | ||
rowGap={24} | ||
testID={"scan-camera"} | ||
> | ||
<Box height={100} /> | ||
<RequiresCameraPermissions optimisticallyMountChildren fallBackHasNoBackground> | ||
<Flex | ||
borderRadius={36} | ||
overflow={"hidden"} | ||
position={"relative"} | ||
width={288} | ||
height={288} | ||
justifyContent={"center"} | ||
alignItems={"center"} | ||
> | ||
<CameraScreen | ||
liveQrCode={liveQrCode} | ||
progress={progress} | ||
width={width} | ||
height={height} | ||
instruction={instruction} | ||
/> | ||
</Camera> | ||
</Flex> | ||
</ForceTheme> | ||
); | ||
}; | ||
|
||
const ScannerWrappedInRequiresCameraPermission: React.FC<Props> = props => { | ||
return ( | ||
<RequiresCameraPermissions optimisticallyMountChildren> | ||
<Scanner {...props} /> | ||
</RequiresCameraPermissions> | ||
<CameraPermissionContext.Consumer> | ||
{({ permissionGranted }) => | ||
permissionGranted ? ( | ||
<CameraView | ||
active={permissionGranted ?? false} | ||
style={{ | ||
backgroundColor: colors.neutral.c50, | ||
width: 280, | ||
height: 280, | ||
}} | ||
barcodeScannerSettings={{ | ||
barcodeTypes: ["qr"], | ||
}} | ||
onBarcodeScanned={onBarCodeScanned} | ||
/> | ||
) : null | ||
} | ||
</CameraPermissionContext.Consumer> | ||
<ScanTargetSvg style={{ position: "absolute" }} /> | ||
</Flex> | ||
<Flex flexDirection={"row"} alignItems={"center"} columnGap={8}> | ||
<Text variant="bodyLineHeight"> | ||
{t("walletSync.synchronize.qrCode.scan.description")} | ||
</Text> | ||
<Icons.QrCode /> | ||
</Flex> | ||
{liveQRCode && ( | ||
<> | ||
<Text variant={"h5"} fontWeight={"semiBold"} mb={6}> | ||
<Trans | ||
i18nKey={liveQRCode ? "account.import.newScan.title" : "send.scan.descBottom"} | ||
/> | ||
</Text> | ||
<Flex alignContent="center" justifyContent="center" p={4}> | ||
<NumberedList | ||
items={[ | ||
{ | ||
description: <Trans i18nKey={"account.import.newScan.instructions.line1"} />, | ||
}, | ||
{ | ||
description: <Trans i18nKey={"account.import.newScan.instructions.line2"} />, | ||
}, | ||
{ | ||
description: <Trans i18nKey={"account.import.newScan.instructions.line3"} />, | ||
}, | ||
]} | ||
itemContainerProps={{ mb: 3 }} | ||
/> | ||
</Flex> | ||
</> | ||
)} | ||
</RequiresCameraPermissions> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default ScannerWrappedInRequiresCameraPermission; | ||
const styles = StyleSheet.create({ | ||
camera: { | ||
flex: 1, | ||
}, | ||
}); | ||
export default ScanQrCode; |
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