Skip to content

Commit

Permalink
CP-5551 Add QR scan feature to Add contact form (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
neven-s authored May 22, 2023
1 parent 15971b7 commit b96f551
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion app/screens/drawer/addressBook/components/ContactInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import React, { useEffect, useState } from 'react'
import AvaText from 'components/AvaText'
import InputText from 'components/InputText'
import { Space } from 'components/Space'
import { View } from 'react-native'
import { Modal, StyleSheet, View } from 'react-native'
import { useApplicationContext } from 'contexts/ApplicationContext'
import { isAddress } from '@ethersproject/address'
import { isBech32Address } from '@avalabs/bridge-sdk'
import AvaButton from 'components/AvaButton'
import QRScanSVG from 'components/svg/QRScanSVG'
import QrScannerAva from 'components/QrScannerAva'

const ContactInput = ({
name,
Expand All @@ -25,6 +28,8 @@ const ContactInput = ({
const { theme } = useApplicationContext()
const [addressError, setAddressError] = useState('')
const [btcAddressError, setBtcAddressError] = useState('')
const [showCChainQRScan, setShowCChainQRScan] = useState(false)
const [showBtcQRScan, setShowBtcQRScan] = useState(false)

useEffect(validateInputs, [address, addressBtc])

Expand All @@ -37,6 +42,19 @@ const ContactInput = ({
)
}

function onCChainScanQR() {
setShowCChainQRScan(true)
}

function onBtcScanQR() {
setShowBtcQRScan(true)
}

function clearQRSCan() {
setShowBtcQRScan(false)
setShowCChainQRScan(false)
}

return (
<>
<AvaText.Body2 textStyle={{ color: theme.colorText1 }}>
Expand All @@ -61,6 +79,13 @@ const ContactInput = ({
text={address}
onChangeText={onAddressChange}
/>
{!address && (
<View style={styles.qrScan}>
<AvaButton.Icon onPress={onCChainScanQR}>
<QRScanSVG />
</AvaButton.Icon>
</View>
)}
</View>
<Space y={24} />
<AvaText.Body2 textStyle={{ color: theme.colorText1 }}>
Expand All @@ -74,9 +99,43 @@ const ContactInput = ({
text={addressBtc}
onChangeText={onAddressBtcChange}
/>
{!addressBtc && (
<View style={styles.qrScan}>
<AvaButton.Icon onPress={onBtcScanQR}>
<QRScanSVG />
</AvaButton.Icon>
</View>
)}
</View>

<Modal
animationType="slide"
transparent={true}
onRequestClose={clearQRSCan}
visible={showBtcQRScan || showCChainQRScan}>
<QrScannerAva
onSuccess={data => {
if (showCChainQRScan) {
onAddressChange(data)
} else if (showBtcQRScan) {
onAddressBtcChange(data)
}
clearQRSCan()
}}
onCancel={clearQRSCan}
/>
</Modal>
</>
)
}

const styles = StyleSheet.create({
qrScan: {
position: 'absolute',
right: 16,
justifyContent: 'center',
height: '100%'
}
})

export default ContactInput

0 comments on commit b96f551

Please sign in to comment.