Merge branch 'master' into renovate/react-native-reanimated-3.x

This commit is contained in:
Marcos Rodriguez Vélez 2024-09-20 11:53:32 -04:00 committed by GitHub
commit 4170d941a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 35 deletions

View File

@ -26,7 +26,7 @@ import { CommonToolTipActions } from '../typings/CommonToolTipActions';
import { pop } from '../NavigationService';
interface TransactionListItemProps {
itemPriceUnit: BitcoinUnit;
itemPriceUnit?: BitcoinUnit;
walletID: string;
item: Transaction & LightningTransaction; // using type intersection to have less issues with ts
searchQuery?: string;

View File

@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import Clipboard from '@react-native-clipboard/clipboard';
import { I18nManager, Image, LayoutAnimation, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
@ -10,12 +10,12 @@ import { BitcoinUnit } from '../models/bitcoinUnits';
import { FiatUnit } from '../models/fiatUnit';
import { BlurredBalanceView } from './BlurredBalanceView';
import { useSettings } from '../hooks/context/useSettings';
import { ToolTipMenuProps } from './types';
import ToolTipMenu from './TooltipMenu';
interface TransactionsNavigationHeaderProps {
wallet: TWallet;
onWalletUnitChange?: (wallet: any) => void;
unit: BitcoinUnit;
onWalletUnitChange: (unit: BitcoinUnit) => void;
onManageFundsPressed?: (id?: string) => void;
onWalletBalanceVisibilityChange?: (isShouldBeVisible: boolean) => void;
}
@ -25,13 +25,12 @@ const TransactionsNavigationHeader: React.FC<TransactionsNavigationHeaderProps>
onWalletUnitChange,
onManageFundsPressed,
onWalletBalanceVisibilityChange,
unit = BitcoinUnit.BTC,
}) => {
const [wallet, setWallet] = useState(initialWallet);
const [allowOnchainAddress, setAllowOnchainAddress] = useState(false);
const { preferredFiatCurrency } = useSettings();
const menuRef = useRef<ToolTipMenuProps>(null);
const verifyIfWalletAllowsOnchainAddress = useCallback(() => {
if (wallet.type === LightningCustodianWallet.type) {
wallet
@ -55,25 +54,18 @@ const TransactionsNavigationHeader: React.FC<TransactionsNavigationHeaderProps>
}, [wallet, verifyIfWalletAllowsOnchainAddress]);
const handleCopyPress = useCallback(() => {
const value = formatBalance(wallet.getBalance(), wallet.getPreferredBalanceUnit());
const value = formatBalance(wallet.getBalance(), unit);
if (value) {
Clipboard.setString(value);
}
}, [wallet]);
}, [unit, wallet]);
const handleBalanceVisibility = useCallback(() => {
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
onWalletBalanceVisibilityChange?.(!wallet.hideBalance);
}, [onWalletBalanceVisibilityChange, wallet.hideBalance]);
const updateWalletWithNewUnit = (w: TWallet, newPreferredUnit: BitcoinUnit) => {
w.preferredBalanceUnit = newPreferredUnit;
return w;
};
const changeWalletBalanceUnit = () => {
if (menuRef.current?.dismissMenu) {
menuRef.current.dismissMenu();
}
let newWalletPreferredUnit = wallet.getPreferredBalanceUnit();
if (newWalletPreferredUnit === BitcoinUnit.BTC) {
@ -84,10 +76,8 @@ const TransactionsNavigationHeader: React.FC<TransactionsNavigationHeaderProps>
newWalletPreferredUnit = BitcoinUnit.BTC;
}
const updatedWallet = updateWalletWithNewUnit(wallet, newWalletPreferredUnit);
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
setWallet(updatedWallet);
onWalletUnitChange?.(updatedWallet);
onWalletUnitChange(newWalletPreferredUnit);
};
const handleManageFundsPressed = useCallback(
@ -126,14 +116,14 @@ const TransactionsNavigationHeader: React.FC<TransactionsNavigationHeaderProps>
}, []);
const balance = useMemo(() => {
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
const hideBalance = wallet.hideBalance;
const balanceUnit = wallet.getPreferredBalanceUnit();
const balanceFormatted =
balanceUnit === BitcoinUnit.LOCAL_CURRENCY
? formatBalance(wallet.getBalance(), balanceUnit, true)
: formatBalanceWithoutSuffix(wallet.getBalance(), balanceUnit, true);
unit === BitcoinUnit.LOCAL_CURRENCY
? formatBalance(wallet.getBalance(), unit, true)
: formatBalanceWithoutSuffix(wallet.getBalance(), unit, true);
return !hideBalance && balanceFormatted;
}, [wallet]);
}, [unit, wallet]);
const toolTipWalletBalanceActions = useMemo(() => {
return wallet.hideBalance
@ -217,9 +207,7 @@ const TransactionsNavigationHeader: React.FC<TransactionsNavigationHeaderProps>
</ToolTipMenu>
<TouchableOpacity style={styles.walletPreferredUnitView} onPress={changeWalletBalanceUnit}>
<Text style={styles.walletPreferredUnitText}>
{wallet.getPreferredBalanceUnit() === BitcoinUnit.LOCAL_CURRENCY
? (preferredFiatCurrency?.endPointKey ?? FiatUnit.USD)
: wallet.getPreferredBalanceUnit()}
{unit === BitcoinUnit.LOCAL_CURRENCY ? (preferredFiatCurrency?.endPointKey ?? FiatUnit.USD) : unit}
</Text>
</TouchableOpacity>
</View>

View File

@ -1,5 +1,5 @@
import { useFocusEffect, useRoute } from '@react-navigation/native';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import {
ActivityIndicator,
Alert,
@ -31,7 +31,7 @@ import { scanQrHelper } from '../../helpers/scan-qr';
import { unlockWithBiometrics, useBiometrics } from '../../hooks/useBiometrics';
import { useExtendedNavigation } from '../../hooks/useExtendedNavigation';
import loc from '../../loc';
import { BitcoinUnit, Chain } from '../../models/bitcoinUnits';
import { Chain } from '../../models/bitcoinUnits';
import ActionSheet from '../ActionSheet';
import { useStorage } from '../../hooks/context/useStorage';
import WatchOnlyWarning from '../../components/WatchOnlyWarning';
@ -56,8 +56,7 @@ const WalletTransactions: React.FC<WalletTransactionsProps> = ({ route }) => {
const [isLoading, setIsLoading] = useState(false);
const { walletID } = route.params;
const { name } = useRoute();
const wallet = wallets.find(w => w.getID() === walletID);
const [itemPriceUnit, setItemPriceUnit] = useState<BitcoinUnit>(wallet?.getPreferredBalanceUnit() ?? BitcoinUnit.BTC);
const wallet = useMemo(() => wallets.find(w => w.getID() === walletID), [walletID, wallets]);
const [limit, setLimit] = useState(15);
const [pageSize] = useState(20);
const navigation = useExtendedNavigation();
@ -245,7 +244,7 @@ const WalletTransactions: React.FC<WalletTransactionsProps> = ({ route }) => {
});
const renderItem = (item: { item: Transaction }) => (
<TransactionListItem item={item.item} itemPriceUnit={itemPriceUnit} walletID={walletID} />
<TransactionListItem item={item.item} itemPriceUnit={wallet?.preferredBalanceUnit} walletID={walletID} />
);
const onBarCodeRead = useCallback(
@ -375,10 +374,11 @@ const WalletTransactions: React.FC<WalletTransactionsProps> = ({ route }) => {
{wallet && (
<TransactionsNavigationHeader
wallet={wallet}
onWalletUnitChange={async passedWallet => {
setItemPriceUnit(passedWallet.getPreferredBalanceUnit());
onWalletUnitChange={async selectedUnit => {
wallet.preferredBalanceUnit = selectedUnit;
await saveToDisk();
}}
unit={wallet.preferredBalanceUnit}
onWalletBalanceVisibilityChange={async isShouldBeVisible => {
const isBiometricsEnabled = await isBiometricUseCapableAndEnabled();
if (wallet?.hideBalance && isBiometricsEnabled) {
@ -386,7 +386,6 @@ const WalletTransactions: React.FC<WalletTransactionsProps> = ({ route }) => {
if (!unlocked) throw new Error('Biometrics failed');
}
wallet!.hideBalance = isShouldBeVisible;
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
await saveToDisk();
}}
onManageFundsPressed={id => {