mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-23 15:20:55 +01:00
Revert "REF: TransactionDetails screen: pass walletID so it won’t always have to find its wallet"
This reverts commit 92f999f44f
.
This commit is contained in:
parent
0dc883016d
commit
bbd791afd5
5 changed files with 83 additions and 57 deletions
|
@ -1265,7 +1265,7 @@ export const BlueReceiveButtonIcon = props => {
|
|||
);
|
||||
};
|
||||
|
||||
export const BlueTransactionListItem = React.memo(({ item, itemPriceUnit = BitcoinUnit.BTC, walletID }) => {
|
||||
export const BlueTransactionListItem = React.memo(({ item, itemPriceUnit = BitcoinUnit.BTC, timeElapsed }) => {
|
||||
const [subtitleNumberOfLines, setSubtitleNumberOfLines] = useState(1);
|
||||
const { colors } = useTheme();
|
||||
const { navigate } = useNavigation();
|
||||
|
@ -1422,38 +1422,46 @@ export const BlueTransactionListItem = React.memo(({ item, itemPriceUnit = Bitco
|
|||
|
||||
const onPress = useCallback(async () => {
|
||||
if (item.hash) {
|
||||
navigate('TransactionStatus', { hash: item.hash, walletID });
|
||||
navigate('TransactionStatus', { hash: item.hash });
|
||||
} else if (item.type === 'user_invoice' || item.type === 'payment_request' || item.type === 'paid_invoice') {
|
||||
try {
|
||||
// is it a successful lnurl-pay?
|
||||
const LN = new Lnurl(false, AsyncStorage);
|
||||
let paymentHash = item.payment_hash;
|
||||
if (typeof paymentHash === 'object') {
|
||||
paymentHash = Buffer.from(paymentHash.data).toString('hex');
|
||||
const lightningWallet = wallets.filter(wallet => {
|
||||
if (typeof wallet === 'object') {
|
||||
if ('secret' in wallet) {
|
||||
return wallet.getSecret() === item.fromWallet;
|
||||
}
|
||||
}
|
||||
const loaded = await LN.loadSuccessfulPayment(paymentHash);
|
||||
if (loaded) {
|
||||
NavigationService.navigate('ScanLndInvoiceRoot', {
|
||||
screen: 'LnurlPaySuccess',
|
||||
params: {
|
||||
paymentHash,
|
||||
justPaid: false,
|
||||
fromWalletID: walletID,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
navigate('LNDViewInvoice', {
|
||||
invoice: item,
|
||||
walletID,
|
||||
isModal: false,
|
||||
});
|
||||
}
|
||||
if (lightningWallet.length === 1) {
|
||||
try {
|
||||
// is it a successful lnurl-pay?
|
||||
const LN = new Lnurl(false, AsyncStorage);
|
||||
let paymentHash = item.payment_hash;
|
||||
if (typeof paymentHash === 'object') {
|
||||
paymentHash = Buffer.from(paymentHash.data).toString('hex');
|
||||
}
|
||||
const loaded = await LN.loadSuccessfulPayment(paymentHash);
|
||||
if (loaded) {
|
||||
NavigationService.navigate('ScanLndInvoiceRoot', {
|
||||
screen: 'LnurlPaySuccess',
|
||||
params: {
|
||||
paymentHash,
|
||||
justPaid: false,
|
||||
fromWalletID: lightningWallet[0].getID(),
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
navigate('LNDViewInvoice', {
|
||||
invoice: item,
|
||||
walletID: lightningWallet[0].getID(),
|
||||
isModal: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [item, wallets]);
|
||||
|
||||
|
@ -1476,7 +1484,7 @@ export const BlueTransactionListItem = React.memo(({ item, itemPriceUnit = Bitco
|
|||
onPress={onPress}
|
||||
onLongPress={onLongPress}
|
||||
chevron={false}
|
||||
Component={item.type === 'bitcoind_tx' ? View : TouchableOpacity}
|
||||
Component={TouchableOpacity}
|
||||
rightTitle={rowTitle}
|
||||
rightTitleStyle={rowTitleStyle}
|
||||
containerStyle={containerStyle}
|
||||
|
|
|
@ -567,7 +567,6 @@ export class AppStorage {
|
|||
const walletTransactions = wallet.getTransactions();
|
||||
for (const t of walletTransactions) {
|
||||
t.walletPreferredBalanceUnit = wallet.getPreferredBalanceUnit();
|
||||
t.walletID = wallet.getID();
|
||||
}
|
||||
txs = txs.concat(walletTransactions);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import React, { useContext, useEffect, useRef, useState } from 'react';
|
||||
import { View, ActivityIndicator, Text, TouchableOpacity, StyleSheet, StatusBar } from 'react-native';
|
||||
import { Icon } from 'react-native-elements';
|
||||
import { useNavigation, useRoute, useTheme } from '@react-navigation/native';
|
||||
|
@ -28,16 +28,16 @@ const buttonStatus = Object.freeze({
|
|||
notPossible: 3,
|
||||
});
|
||||
|
||||
const TransactionStatus = () => {
|
||||
const TransactionsStatus = () => {
|
||||
const { setSelectedWallet, wallets, txMetadata, getTransactions } = useContext(BlueStorageContext);
|
||||
const { hash, walletID } = useRoute().params;
|
||||
const { hash } = useRoute().params;
|
||||
const { navigate, setOptions } = useNavigation();
|
||||
const { colors } = useTheme();
|
||||
const wallet = wallets.find(w => w.getID() === walletID);
|
||||
const wallet = useRef();
|
||||
const [isCPFPPossible, setIsCPFPPossible] = useState();
|
||||
const [isRBFBumpFeePossible, setIsRBFBumpFeePossible] = useState();
|
||||
const [isRBFCancelPossible, setIsRBFCancelPossible] = useState();
|
||||
const tx = getTransactions(null, Infinity, true).find(transactionHash => transactionHash.hash === hash);
|
||||
const [tx, setTX] = useState();
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const stylesHook = StyleSheet.create({
|
||||
root: {
|
||||
|
@ -76,6 +76,27 @@ const TransactionStatus = () => {
|
|||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [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 () => {
|
||||
try {
|
||||
await checkPossibilityOfCPFP();
|
||||
|
@ -97,7 +118,7 @@ const TransactionStatus = () => {
|
|||
|
||||
useEffect(() => {
|
||||
if (wallet) {
|
||||
setSelectedWallet(wallet.getID());
|
||||
setSelectedWallet(wallet.current.getID());
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [wallet]);
|
||||
|
@ -107,11 +128,11 @@ const TransactionStatus = () => {
|
|||
}, []);
|
||||
|
||||
const checkPossibilityOfCPFP = async () => {
|
||||
if (!wallet.allowRBF()) {
|
||||
if (!wallet.current.allowRBF()) {
|
||||
return setIsCPFPPossible(buttonStatus.notPossible);
|
||||
}
|
||||
|
||||
const cpfbTx = new HDSegwitBech32Transaction(null, tx.hash, wallet);
|
||||
const cpfbTx = new HDSegwitBech32Transaction(null, tx.hash, wallet.current);
|
||||
if ((await cpfbTx.isToUsTransaction()) && (await cpfbTx.getRemoteConfirmationsNum()) === 0) {
|
||||
return setIsCPFPPossible(buttonStatus.possible);
|
||||
} else {
|
||||
|
@ -120,11 +141,11 @@ const TransactionStatus = () => {
|
|||
};
|
||||
|
||||
const checkPossibilityOfRBFBumpFee = async () => {
|
||||
if (!wallet.allowRBF()) {
|
||||
if (!wallet.current.allowRBF()) {
|
||||
return setIsRBFBumpFeePossible(buttonStatus.notPossible);
|
||||
}
|
||||
|
||||
const rbfTx = new HDSegwitBech32Transaction(null, tx.hash, wallet);
|
||||
const rbfTx = new HDSegwitBech32Transaction(null, tx.hash, wallet.current);
|
||||
if (
|
||||
(await rbfTx.isOurTransaction()) &&
|
||||
(await rbfTx.getRemoteConfirmationsNum()) === 0 &&
|
||||
|
@ -138,11 +159,11 @@ const TransactionStatus = () => {
|
|||
};
|
||||
|
||||
const checkPossibilityOfRBFCancel = async () => {
|
||||
if (!wallet.allowRBF()) {
|
||||
if (!wallet.current.allowRBF()) {
|
||||
return setIsRBFCancelPossible(buttonStatus.notPossible);
|
||||
}
|
||||
|
||||
const rbfTx = new HDSegwitBech32Transaction(null, tx.hash, wallet);
|
||||
const rbfTx = new HDSegwitBech32Transaction(null, tx.hash, wallet.current);
|
||||
if (
|
||||
(await rbfTx.isOurTransaction()) &&
|
||||
(await rbfTx.getRemoteConfirmationsNum()) === 0 &&
|
||||
|
@ -158,21 +179,21 @@ const TransactionStatus = () => {
|
|||
const navigateToRBFBumpFee = () => {
|
||||
navigate('RBFBumpFee', {
|
||||
txid: tx.hash,
|
||||
wallet: wallet,
|
||||
wallet: wallet.current,
|
||||
});
|
||||
};
|
||||
|
||||
const navigateToRBFCancel = () => {
|
||||
navigate('RBFCancel', {
|
||||
txid: tx.hash,
|
||||
wallet: wallet,
|
||||
wallet: wallet.current,
|
||||
});
|
||||
};
|
||||
|
||||
const navigateToCPFP = () => {
|
||||
navigate('CPFP', {
|
||||
txid: tx.hash,
|
||||
wallet: wallet,
|
||||
wallet: wallet.current,
|
||||
});
|
||||
};
|
||||
const navigateToTransactionDetials = () => {
|
||||
|
@ -269,9 +290,9 @@ const TransactionStatus = () => {
|
|||
<BlueCard>
|
||||
<View style={styles.center}>
|
||||
<Text style={[styles.value, stylesHook.value]}>
|
||||
{formatBalanceWithoutSuffix(tx.value, wallet.preferredBalanceUnit, true)}{' '}
|
||||
{wallet.preferredBalanceUnit !== BitcoinUnit.LOCAL_CURRENCY && (
|
||||
<Text style={[styles.valueUnit, stylesHook.valueUnit]}>{loc.units[wallet.preferredBalanceUnit]}</Text>
|
||||
{formatBalanceWithoutSuffix(tx.value, wallet.current.preferredBalanceUnit, true)}{' '}
|
||||
{wallet.current.preferredBalanceUnit !== BitcoinUnit.LOCAL_CURRENCY && (
|
||||
<Text style={[styles.valueUnit, stylesHook.valueUnit]}>{loc.units[wallet.current.preferredBalanceUnit]}</Text>
|
||||
)}
|
||||
</Text>
|
||||
</View>
|
||||
|
@ -310,8 +331,8 @@ const TransactionStatus = () => {
|
|||
{tx.fee && (
|
||||
<View style={styles.fee}>
|
||||
<BlueText style={styles.feeText}>
|
||||
{loc.send.create_fee.toLowerCase()} {formatBalanceWithoutSuffix(tx.fee, wallet.preferredBalanceUnit, true)}{' '}
|
||||
{wallet.preferredBalanceUnit !== BitcoinUnit.LOCAL_CURRENCY && wallet.preferredBalanceUnit}
|
||||
{loc.send.create_fee.toLowerCase()} {formatBalanceWithoutSuffix(tx.fee, wallet.current.preferredBalanceUnit, true)}{' '}
|
||||
{wallet.current.preferredBalanceUnit !== BitcoinUnit.LOCAL_CURRENCY && wallet.current.preferredBalanceUnit}
|
||||
</BlueText>
|
||||
</View>
|
||||
)}
|
||||
|
@ -339,7 +360,7 @@ const TransactionStatus = () => {
|
|||
);
|
||||
};
|
||||
|
||||
export default TransactionStatus;
|
||||
export default TransactionsStatus;
|
||||
const styles = StyleSheet.create({
|
||||
root: {
|
||||
flex: 1,
|
||||
|
@ -439,6 +460,6 @@ const styles = StyleSheet.create({
|
|||
},
|
||||
});
|
||||
|
||||
TransactionStatus.navigationOptions = navigationStyle({
|
||||
TransactionsStatus.navigationOptions = navigationStyle({
|
||||
title: '',
|
||||
});
|
||||
|
|
|
@ -225,7 +225,7 @@ const WalletsList = () => {
|
|||
const renderTransactionListsRow = data => {
|
||||
return (
|
||||
<View style={styles.transaction}>
|
||||
<BlueTransactionListItem item={data.item} itemPriceUnit={data.item.walletPreferredBalanceUnit} walletID={data.item.walletID} />
|
||||
<BlueTransactionListItem item={data.item} itemPriceUnit={data.item.walletPreferredBalanceUnit} />
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -437,9 +437,7 @@ const WalletTransactions = () => {
|
|||
});
|
||||
};
|
||||
|
||||
const renderItem = item => (
|
||||
<BlueTransactionListItem item={item.item} itemPriceUnit={itemPriceUnit} timeElapsed={timeElapsed} walletID={walletID} />
|
||||
);
|
||||
const renderItem = item => <BlueTransactionListItem item={item.item} itemPriceUnit={itemPriceUnit} timeElapsed={timeElapsed} />;
|
||||
|
||||
const onBarCodeRead = ret => {
|
||||
if (!isLoading) {
|
||||
|
|
Loading…
Add table
Reference in a new issue