Merge branch 'master' into ligh

This commit is contained in:
Marcos Rodriguez Vélez 2024-09-20 13:32:19 -04:00 committed by GitHub
commit bc9ddf1220
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 27 additions and 39 deletions

View File

@ -37,7 +37,8 @@ const TotalWalletsBalance: React.FC = () => {
const formattedBalance = useMemo( const formattedBalance = useMemo(
() => formatBalanceWithoutSuffix(Number(totalBalance), totalBalancePreferredUnit, true), () => formatBalanceWithoutSuffix(Number(totalBalance), totalBalancePreferredUnit, true),
[totalBalance, totalBalancePreferredUnit], // eslint-disable-next-line react-hooks/exhaustive-deps
[totalBalance, totalBalancePreferredUnit, preferredFiatCurrency],
); );
const toolTipActions = useMemo(() => { const toolTipActions = useMemo(() => {

View File

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

4
package-lock.json generated
View File

@ -20,7 +20,7 @@
"@react-native-async-storage/async-storage": "1.24.0", "@react-native-async-storage/async-storage": "1.24.0",
"@react-native-clipboard/clipboard": "1.14.2", "@react-native-clipboard/clipboard": "1.14.2",
"@react-native-community/push-notification-ios": "1.11.0", "@react-native-community/push-notification-ios": "1.11.0",
"@react-native-menu/menu": "https://github.com/BlueWallet/menu.git#a149bbf", "@react-native-menu/menu": "https://github.com/BlueWallet/menu.git#8c6004b",
"@react-native/gradle-plugin": "^0.75.3", "@react-native/gradle-plugin": "^0.75.3",
"@react-native/metro-config": "0.75.3", "@react-native/metro-config": "0.75.3",
"@react-navigation/drawer": "6.7.2", "@react-navigation/drawer": "6.7.2",
@ -5602,7 +5602,7 @@
}, },
"node_modules/@react-native-menu/menu": { "node_modules/@react-native-menu/menu": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "git+ssh://git@github.com/BlueWallet/menu.git#a149bbfbbbc4b8841f1f6d203610a0076414ffd5", "resolved": "git+ssh://git@github.com/BlueWallet/menu.git#8c6004bae317e00ea8f163612af96dddb9cdf7e9",
"license": "MIT", "license": "MIT",
"peerDependencies": { "peerDependencies": {
"react": "*", "react": "*",

View File

@ -84,7 +84,7 @@
"@react-native-async-storage/async-storage": "1.24.0", "@react-native-async-storage/async-storage": "1.24.0",
"@react-native-clipboard/clipboard": "1.14.2", "@react-native-clipboard/clipboard": "1.14.2",
"@react-native-community/push-notification-ios": "1.11.0", "@react-native-community/push-notification-ios": "1.11.0",
"@react-native-menu/menu": "https://github.com/BlueWallet/menu.git#a149bbf", "@react-native-menu/menu": "https://github.com/BlueWallet/menu.git#8c6004b",
"@react-native/gradle-plugin": "^0.75.3", "@react-native/gradle-plugin": "^0.75.3",
"@react-native/metro-config": "0.75.3", "@react-native/metro-config": "0.75.3",
"@react-navigation/drawer": "6.7.2", "@react-navigation/drawer": "6.7.2",

View File

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