Merge pull request #2586 from BlueWallet/2555

This commit is contained in:
Marcos Rodriguez Vélez 2021-02-08 21:51:11 -05:00 committed by GitHub
commit f6c6be0577
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 95 deletions

View File

@ -1265,7 +1265,7 @@ export const BlueReceiveButtonIcon = props => {
); );
}; };
export const BlueTransactionListItem = React.memo(({ item, itemPriceUnit = BitcoinUnit.BTC, timeElapsed }) => { export const BlueTransactionListItem = React.memo(({ item, itemPriceUnit = BitcoinUnit.BTC, walletID }) => {
const [subtitleNumberOfLines, setSubtitleNumberOfLines] = useState(1); const [subtitleNumberOfLines, setSubtitleNumberOfLines] = useState(1);
const { colors } = useTheme(); const { colors } = useTheme();
const { navigate } = useNavigation(); const { navigate } = useNavigation();
@ -1422,46 +1422,38 @@ export const BlueTransactionListItem = React.memo(({ item, itemPriceUnit = Bitco
const onPress = useCallback(async () => { const onPress = useCallback(async () => {
if (item.hash) { if (item.hash) {
navigate('TransactionStatus', { hash: item.hash }); navigate('TransactionStatus', { hash: item.hash, walletID });
} else if (item.type === 'user_invoice' || item.type === 'payment_request' || item.type === 'paid_invoice') { } else if (item.type === 'user_invoice' || item.type === 'payment_request' || item.type === 'paid_invoice') {
const lightningWallet = wallets.filter(wallet => { try {
if (typeof wallet === 'object') { // is it a successful lnurl-pay?
if ('secret' in wallet) { const LN = new Lnurl(false, AsyncStorage);
return wallet.getSecret() === item.fromWallet; let paymentHash = item.payment_hash;
} if (typeof paymentHash === 'object') {
paymentHash = Buffer.from(paymentHash.data).toString('hex');
} }
}); const loaded = await LN.loadSuccessfulPayment(paymentHash);
if (lightningWallet.length === 1) { if (loaded) {
try { NavigationService.navigate('ScanLndInvoiceRoot', {
// is it a successful lnurl-pay? screen: 'LnurlPaySuccess',
const LN = new Lnurl(false, AsyncStorage); params: {
let paymentHash = item.payment_hash; paymentHash,
if (typeof paymentHash === 'object') { justPaid: false,
paymentHash = Buffer.from(paymentHash.data).toString('hex'); fromWalletID: walletID,
} },
const loaded = await LN.loadSuccessfulPayment(paymentHash); });
if (loaded) { return;
NavigationService.navigate('ScanLndInvoiceRoot', {
screen: 'LnurlPaySuccess',
params: {
paymentHash,
justPaid: false,
fromWalletID: lightningWallet[0].getID(),
},
});
return;
}
} catch (e) {
console.log(e);
} }
} catch (e) {
navigate('LNDViewInvoice', { console.log(e);
invoice: item,
walletID: lightningWallet[0].getID(),
isModal: false,
});
} }
navigate('LNDViewInvoice', {
invoice: item,
walletID,
isModal: false,
});
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [item, wallets]); }, [item, wallets]);
@ -1484,7 +1476,7 @@ export const BlueTransactionListItem = React.memo(({ item, itemPriceUnit = Bitco
onPress={onPress} onPress={onPress}
onLongPress={onLongPress} onLongPress={onLongPress}
chevron={false} chevron={false}
Component={TouchableOpacity} Component={item.type === 'bitcoind_tx' ? View : TouchableOpacity}
rightTitle={rowTitle} rightTitle={rowTitle}
rightTitleStyle={rowTitleStyle} rightTitleStyle={rowTitleStyle}
containerStyle={containerStyle} containerStyle={containerStyle}

View File

@ -567,6 +567,7 @@ export class AppStorage {
const walletTransactions = wallet.getTransactions(); const walletTransactions = wallet.getTransactions();
for (const t of walletTransactions) { for (const t of walletTransactions) {
t.walletPreferredBalanceUnit = wallet.getPreferredBalanceUnit(); t.walletPreferredBalanceUnit = wallet.getPreferredBalanceUnit();
t.walletID = wallet.getID();
} }
txs = txs.concat(walletTransactions); txs = txs.concat(walletTransactions);
} }

View File

@ -251,13 +251,13 @@ PODS:
- React - React
- react-native-blur (0.8.0): - react-native-blur (0.8.0):
- React - React
- react-native-camera (3.40.0): - react-native-camera (3.42.0):
- React-Core - React-Core
- react-native-camera/RCT (= 3.40.0) - react-native-camera/RCT (= 3.42.0)
- react-native-camera/RN (= 3.40.0) - react-native-camera/RN (= 3.42.0)
- react-native-camera/RCT (3.40.0): - react-native-camera/RCT (3.42.0):
- React-Core - React-Core
- react-native-camera/RN (3.40.0): - react-native-camera/RN (3.42.0):
- React-Core - React-Core
- react-native-document-picker (3.5.4): - react-native-document-picker (3.5.4):
- React - React
@ -367,7 +367,7 @@ PODS:
- React - React
- RNInAppBrowser (3.5.1): - RNInAppBrowser (3.5.1):
- React-Core - React-Core
- RNLocalize (1.4.2): - RNLocalize (2.0.1):
- React-Core - React-Core
- RNPrivacySnapshot (1.0.0): - RNPrivacySnapshot (1.0.0):
- React - React
@ -379,14 +379,14 @@ PODS:
- React-Core - React-Core
- RNReanimated (1.13.1): - RNReanimated (1.13.1):
- React - React
- RNScreens (2.11.0): - RNScreens (2.16.1):
- React - React-Core
- RNSecureKeyStore (1.0.0): - RNSecureKeyStore (1.0.0):
- React - React
- RNSentry (1.9.0): - RNSentry (1.9.0):
- React-Core - React-Core
- Sentry (~> 5.2.0) - Sentry (~> 5.2.0)
- RNShare (4.0.2): - RNShare (5.1.0):
- React-Core - React-Core
- RNSVG (12.1.0): - RNSVG (12.1.0):
- React - React
@ -699,7 +699,7 @@ SPEC CHECKSUMS:
React-jsinspector: 8e68ffbfe23880d3ee9bafa8be2777f60b25cbe2 React-jsinspector: 8e68ffbfe23880d3ee9bafa8be2777f60b25cbe2
react-native-blue-crypto: 23f1558ad3d38d7a2edb7e2f6ed1bc520ed93e56 react-native-blue-crypto: 23f1558ad3d38d7a2edb7e2f6ed1bc520ed93e56
react-native-blur: cad4d93b364f91e7b7931b3fa935455487e5c33c react-native-blur: cad4d93b364f91e7b7931b3fa935455487e5c33c
react-native-camera: 5c1fbfecf63b802b8ca4a71c60d30a71550fb348 react-native-camera: d145df27a9178041b48b839b80ad79c9ef373fbd
react-native-document-picker: c5752781fbc0c126c627c1549b037c139444a4cf react-native-document-picker: c5752781fbc0c126c627c1549b037c139444a4cf
react-native-fingerprint-scanner: c68136ca57e3704d7bdf5faa554ea535ce15b1d0 react-native-fingerprint-scanner: c68136ca57e3704d7bdf5faa554ea535ce15b1d0
react-native-idle-timer: 97b8283237d45146a7a5c25bdebe9e1e85f3687b react-native-idle-timer: 97b8283237d45146a7a5c25bdebe9e1e85f3687b
@ -733,16 +733,16 @@ SPEC CHECKSUMS:
RNGestureHandler: 7a5833d0f788dbd107fbb913e09aa0c1ff333c39 RNGestureHandler: 7a5833d0f788dbd107fbb913e09aa0c1ff333c39
RNHandoff: d3b0754cca3a6bcd9b25f544f733f7f033ccf5fa RNHandoff: d3b0754cca3a6bcd9b25f544f733f7f033ccf5fa
RNInAppBrowser: 3733c1aa6699983a1c9b4963e85d5e5a48ad297e RNInAppBrowser: 3733c1aa6699983a1c9b4963e85d5e5a48ad297e
RNLocalize: 4071198b59b461f3b74eebc5fee8c50f13e39e79 RNLocalize: dcf0fdb332b37b0d24178e876a7ce4dbbc9c838d
RNPrivacySnapshot: 71919dde3c6a29dd332115409c2aec564afee8f4 RNPrivacySnapshot: 71919dde3c6a29dd332115409c2aec564afee8f4
RNQuickAction: 6d404a869dc872cde841ad3147416a670d13fa93 RNQuickAction: 6d404a869dc872cde841ad3147416a670d13fa93
RNRate: 2b31dad120cd1b78e33c6034808561c386a3dddf RNRate: 2b31dad120cd1b78e33c6034808561c386a3dddf
RNReactNativeHapticFeedback: 653a8c126a0f5e88ce15ffe280b3ff37e1fbb285 RNReactNativeHapticFeedback: 653a8c126a0f5e88ce15ffe280b3ff37e1fbb285
RNReanimated: dd8c286ab5dd4ba36d3a7fef8bff7e08711b5476 RNReanimated: dd8c286ab5dd4ba36d3a7fef8bff7e08711b5476
RNScreens: 0e91da98ab26d5d04c7b59a9b6bd694124caf88c RNScreens: 45c457af3d2ee9e08fc01e70da87e653d46b1198
RNSecureKeyStore: f1ad870e53806453039f650720d2845c678d89c8 RNSecureKeyStore: f1ad870e53806453039f650720d2845c678d89c8
RNSentry: 1adaa43b01c6a3ab5091d4d1add66b7c58558898 RNSentry: 1adaa43b01c6a3ab5091d4d1add66b7c58558898
RNShare: 7a7277f3c313652422d9de072ac50714dff5e8a4 RNShare: fed99fd743f80ca255903c1da46fc9a6430efab6
RNSVG: ce9d996113475209013317e48b05c21ee988d42e RNSVG: ce9d996113475209013317e48b05c21ee988d42e
RNVectorIcons: bc69e6a278b14842063605de32bec61f0b251a59 RNVectorIcons: bc69e6a278b14842063605de32bec61f0b251a59
RNWatch: e4c5d19506c94506860032fb68aedd5991beb985 RNWatch: e4c5d19506c94506860032fb68aedd5991beb985

4
package-lock.json generated
View File

@ -20149,6 +20149,10 @@
"object-assign": "^4.1.1" "object-assign": "^4.1.1"
} }
}, },
"scryptsy": {
"version": "file:blue_modules/scryptsy",
"integrity": "sha512-1CdSqHQowJBnMAFyPEBRfqag/YP9OF394FV+4YREIJX4ljD7OxvQRDayyoyyCk+senRjSkP6VnUNQmVQqB6g7w=="
},
"secp256k1": { "secp256k1": {
"version": "3.8.0", "version": "3.8.0",
"resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.8.0.tgz", "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.8.0.tgz",

View File

@ -1,4 +1,4 @@
import React, { useContext, useEffect, useRef, useState } from 'react'; import React, { useContext, useEffect, useState } from 'react';
import { View, ActivityIndicator, Text, TouchableOpacity, StyleSheet, StatusBar } from 'react-native'; import { View, ActivityIndicator, Text, TouchableOpacity, StyleSheet, StatusBar } from 'react-native';
import { Icon } from 'react-native-elements'; import { Icon } from 'react-native-elements';
import { useNavigation, useRoute, useTheme } from '@react-navigation/native'; import { useNavigation, useRoute, useTheme } from '@react-navigation/native';
@ -28,16 +28,16 @@ const buttonStatus = Object.freeze({
notPossible: 3, notPossible: 3,
}); });
const TransactionsStatus = () => { const TransactionStatus = () => {
const { setSelectedWallet, wallets, txMetadata, getTransactions } = useContext(BlueStorageContext); const { setSelectedWallet, wallets, txMetadata, getTransactions } = useContext(BlueStorageContext);
const { hash } = useRoute().params; const { hash, walletID } = useRoute().params;
const { navigate, setOptions } = useNavigation(); const { navigate, setOptions } = useNavigation();
const { colors } = useTheme(); const { colors } = useTheme();
const wallet = useRef(); const wallet = wallets.find(w => w.getID() === walletID);
const [isCPFPPossible, setIsCPFPPossible] = useState(); const [isCPFPPossible, setIsCPFPPossible] = useState();
const [isRBFBumpFeePossible, setIsRBFBumpFeePossible] = useState(); const [isRBFBumpFeePossible, setIsRBFBumpFeePossible] = useState();
const [isRBFCancelPossible, setIsRBFCancelPossible] = useState(); const [isRBFCancelPossible, setIsRBFCancelPossible] = useState();
const [tx, setTX] = useState(); const tx = getTransactions(null, Infinity, true).find(transactionHash => transactionHash.hash === hash);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const stylesHook = StyleSheet.create({ const stylesHook = StyleSheet.create({
root: { root: {
@ -76,27 +76,6 @@ const TransactionsStatus = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [colors]); }, [colors]);
useEffect(() => {
for (const w of wallets) {
for (const t of w.getTransactions()) {
if (t.hash === hash) {
console.log('tx', hash, 'belongs to', w.getLabel());
wallet.current = w;
break;
}
}
}
for (const tx of getTransactions(null, Infinity, true)) {
if (tx.hash === hash) {
setTX(tx);
break;
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hash]);
const initialState = async () => { const initialState = async () => {
try { try {
await checkPossibilityOfCPFP(); await checkPossibilityOfCPFP();
@ -118,7 +97,7 @@ const TransactionsStatus = () => {
useEffect(() => { useEffect(() => {
if (wallet) { if (wallet) {
setSelectedWallet(wallet.current.getID()); setSelectedWallet(wallet.getID());
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [wallet]); }, [wallet]);
@ -128,11 +107,11 @@ const TransactionsStatus = () => {
}, []); }, []);
const checkPossibilityOfCPFP = async () => { const checkPossibilityOfCPFP = async () => {
if (!wallet.current.allowRBF()) { if (!wallet.allowRBF()) {
return setIsCPFPPossible(buttonStatus.notPossible); return setIsCPFPPossible(buttonStatus.notPossible);
} }
const cpfbTx = new HDSegwitBech32Transaction(null, tx.hash, wallet.current); const cpfbTx = new HDSegwitBech32Transaction(null, tx.hash, wallet);
if ((await cpfbTx.isToUsTransaction()) && (await cpfbTx.getRemoteConfirmationsNum()) === 0) { if ((await cpfbTx.isToUsTransaction()) && (await cpfbTx.getRemoteConfirmationsNum()) === 0) {
return setIsCPFPPossible(buttonStatus.possible); return setIsCPFPPossible(buttonStatus.possible);
} else { } else {
@ -141,11 +120,11 @@ const TransactionsStatus = () => {
}; };
const checkPossibilityOfRBFBumpFee = async () => { const checkPossibilityOfRBFBumpFee = async () => {
if (!wallet.current.allowRBF()) { if (!wallet.allowRBF()) {
return setIsRBFBumpFeePossible(buttonStatus.notPossible); return setIsRBFBumpFeePossible(buttonStatus.notPossible);
} }
const rbfTx = new HDSegwitBech32Transaction(null, tx.hash, wallet.current); const rbfTx = new HDSegwitBech32Transaction(null, tx.hash, wallet);
if ( if (
(await rbfTx.isOurTransaction()) && (await rbfTx.isOurTransaction()) &&
(await rbfTx.getRemoteConfirmationsNum()) === 0 && (await rbfTx.getRemoteConfirmationsNum()) === 0 &&
@ -159,11 +138,11 @@ const TransactionsStatus = () => {
}; };
const checkPossibilityOfRBFCancel = async () => { const checkPossibilityOfRBFCancel = async () => {
if (!wallet.current.allowRBF()) { if (!wallet.allowRBF()) {
return setIsRBFCancelPossible(buttonStatus.notPossible); return setIsRBFCancelPossible(buttonStatus.notPossible);
} }
const rbfTx = new HDSegwitBech32Transaction(null, tx.hash, wallet.current); const rbfTx = new HDSegwitBech32Transaction(null, tx.hash, wallet);
if ( if (
(await rbfTx.isOurTransaction()) && (await rbfTx.isOurTransaction()) &&
(await rbfTx.getRemoteConfirmationsNum()) === 0 && (await rbfTx.getRemoteConfirmationsNum()) === 0 &&
@ -179,21 +158,21 @@ const TransactionsStatus = () => {
const navigateToRBFBumpFee = () => { const navigateToRBFBumpFee = () => {
navigate('RBFBumpFee', { navigate('RBFBumpFee', {
txid: tx.hash, txid: tx.hash,
wallet: wallet.current, wallet: wallet,
}); });
}; };
const navigateToRBFCancel = () => { const navigateToRBFCancel = () => {
navigate('RBFCancel', { navigate('RBFCancel', {
txid: tx.hash, txid: tx.hash,
wallet: wallet.current, wallet: wallet,
}); });
}; };
const navigateToCPFP = () => { const navigateToCPFP = () => {
navigate('CPFP', { navigate('CPFP', {
txid: tx.hash, txid: tx.hash,
wallet: wallet.current, wallet: wallet,
}); });
}; };
const navigateToTransactionDetials = () => { const navigateToTransactionDetials = () => {
@ -290,9 +269,9 @@ const TransactionsStatus = () => {
<BlueCard> <BlueCard>
<View style={styles.center}> <View style={styles.center}>
<Text style={[styles.value, stylesHook.value]}> <Text style={[styles.value, stylesHook.value]}>
{formatBalanceWithoutSuffix(tx.value, wallet.current.preferredBalanceUnit, true)}{' '} {formatBalanceWithoutSuffix(tx.value, wallet.preferredBalanceUnit, true)}{' '}
{wallet.current.preferredBalanceUnit !== BitcoinUnit.LOCAL_CURRENCY && ( {wallet.preferredBalanceUnit !== BitcoinUnit.LOCAL_CURRENCY && (
<Text style={[styles.valueUnit, stylesHook.valueUnit]}>{loc.units[wallet.current.preferredBalanceUnit]}</Text> <Text style={[styles.valueUnit, stylesHook.valueUnit]}>{loc.units[wallet.preferredBalanceUnit]}</Text>
)} )}
</Text> </Text>
</View> </View>
@ -331,8 +310,8 @@ const TransactionsStatus = () => {
{tx.fee && ( {tx.fee && (
<View style={styles.fee}> <View style={styles.fee}>
<BlueText style={styles.feeText}> <BlueText style={styles.feeText}>
{loc.send.create_fee.toLowerCase()} {formatBalanceWithoutSuffix(tx.fee, wallet.current.preferredBalanceUnit, true)}{' '} {loc.send.create_fee.toLowerCase()} {formatBalanceWithoutSuffix(tx.fee, wallet.preferredBalanceUnit, true)}{' '}
{wallet.current.preferredBalanceUnit !== BitcoinUnit.LOCAL_CURRENCY && wallet.current.preferredBalanceUnit} {wallet.preferredBalanceUnit !== BitcoinUnit.LOCAL_CURRENCY && wallet.preferredBalanceUnit}
</BlueText> </BlueText>
</View> </View>
)} )}
@ -360,7 +339,7 @@ const TransactionsStatus = () => {
); );
}; };
export default TransactionsStatus; export default TransactionStatus;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
root: { root: {
flex: 1, flex: 1,
@ -460,6 +439,6 @@ const styles = StyleSheet.create({
}, },
}); });
TransactionsStatus.navigationOptions = navigationStyle({ TransactionStatus.navigationOptions = navigationStyle({
title: '', title: '',
}); });

View File

@ -225,7 +225,7 @@ const WalletsList = () => {
const renderTransactionListsRow = data => { const renderTransactionListsRow = data => {
return ( return (
<View style={styles.transaction}> <View style={styles.transaction}>
<BlueTransactionListItem item={data.item} itemPriceUnit={data.item.walletPreferredBalanceUnit} /> <BlueTransactionListItem item={data.item} itemPriceUnit={data.item.walletPreferredBalanceUnit} walletID={data.item.walletID} />
</View> </View>
); );
}; };

View File

@ -437,7 +437,9 @@ const WalletTransactions = () => {
}); });
}; };
const renderItem = item => <BlueTransactionListItem item={item.item} itemPriceUnit={itemPriceUnit} timeElapsed={timeElapsed} />; const renderItem = item => (
<BlueTransactionListItem item={item.item} itemPriceUnit={itemPriceUnit} timeElapsed={timeElapsed} walletID={walletID} />
);
const onBarCodeRead = ret => { const onBarCodeRead = ret => {
if (!isLoading) { if (!isLoading) {