Skip to content

Commit

Permalink
fix: unable to scan bitcoin address
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoncalves committed Nov 1, 2023
1 parent e3b5881 commit 2213c82
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/screens/send/SendScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { useCallback, useEffect } from 'react'
import { Alert, Keyboard, KeyboardAvoidingView, Platform } from 'react-native'
import { useTranslation } from 'react-i18next'
import { useIsFocused } from '@react-navigation/native'
import { convertSatoshiToBtcHuman } from '@rsksmart/rif-wallet-bitcoin'
import {
convertSatoshiToBtcHuman,
isBitcoinAddressValid,
} from '@rsksmart/rif-wallet-bitcoin'

import { sharedHeaderLeftOptions } from 'navigation/index'
import {
Expand Down Expand Up @@ -46,13 +49,21 @@ export const SendScreen = ({
const prices = useAppSelector(selectUsdPrices)
const { backScreen, contact } = route.params

const isContactBitcoin = contact && isBitcoinAddressValid(contact.address)
const isAssetBitcoin = (asset: TokenBalanceObject) => 'bips' in asset

const balances = Object.values(useAppSelector(selectBalances))
const assets = contact ? balances.filter(b => !('bips' in b)) : balances
const assets = contact
? balances.filter(b =>
isContactBitcoin ? isAssetBitcoin(b) : !isAssetBitcoin(b),
)
: balances

const contractAddress = route.params?.contractAddress || assets[0]

// We assume only one bitcoinNetwork instance exists
const { currentTransaction, executePayment, error } = usePaymentExecutor(
assets.find(asset => 'bips' in asset),
assets.find(isAssetBitcoin),
)

const onGoToHome = useCallback(
Expand Down Expand Up @@ -197,7 +208,7 @@ export const SendScreen = ({
isWalletDeployed={walletIsDeployed.isDeployed}
initialValues={{
recipient: contact,
asset: assets.find(
asset: balances.find(
asset => asset.contractAddress === contractAddress,
),
}}
Expand Down
7 changes: 6 additions & 1 deletion src/screens/walletConnect/ScanQRScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,10 @@ export const ScanQRScreen = ({
if (Platform.OS === 'android' && isFocused) {
return <AndroidQRScanner onCodeRead={onCodeRead} onClose={onClose} />
}
return <QRCodeScanner onCodeRead={onCodeRead} onClose={onClose} />
return (
<QRCodeScanner
onCodeRead={onCodeRead}
onClose={() => onCodeRead('0xa36b908c51c9ce54eb709120578576065d8ea1a1')}
/>
)
}

0 comments on commit 2213c82

Please sign in to comment.