Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Fix QRCode scanner rerender issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mvaivre committed Nov 16, 2023
1 parent 3cec3d0 commit e40ea95
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/components/QRScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const QRScanner: React.FC<QRScannerProps> = ({ onScanSuccess }) => {

return () => {
qrCodeScanner.stop()
qrCodeScanner.destroy()
}
}, [selectedDeviceId, onScanSuccess])

Expand Down
19 changes: 11 additions & 8 deletions src/modals/SendModals/AddressInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
import { isAddressValid } from '@alephium/sdk'
import { AlbumIcon, ContactIcon, ScanLineIcon } from 'lucide-react'
import Scanner from 'qr-scanner'
import { useState } from 'react'
import { useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next'
import styled, { useTheme } from 'styled-components'

Expand Down Expand Up @@ -98,14 +98,17 @@ const AddressInputs = ({
moveFocusOnPreviousModal()
}

const handleQRCodeScan = (scanResult: Scanner.ScanResult) => {
if (!isAddressValid(scanResult.data)) return // TODO: SHOW SNACKBAR
const handleQRCodeScan = useCallback(
(scanResult: Scanner.ScanResult) => {
if (!isAddressValid(scanResult.data)) return // TODO: SHOW SNACKBAR

if (onToAddressChange) {
onToAddressChange(scanResult.data)
setIsScanningModalOpen(false)
}
}
if (onToAddressChange) {
onToAddressChange(scanResult.data)
setIsScanningModalOpen(false)
}
},
[onToAddressChange]
)

return (
<InputsContainer>
Expand Down

0 comments on commit e40ea95

Please sign in to comment.