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(
() => formatBalanceWithoutSuffix(Number(totalBalance), totalBalancePreferredUnit, true),
[totalBalance, totalBalancePreferredUnit],
// eslint-disable-next-line react-hooks/exhaustive-deps
[totalBalance, totalBalancePreferredUnit, preferredFiatCurrency],
);
const toolTipActions = useMemo(() => {

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>

4
package-lock.json generated
View File

@ -20,7 +20,7 @@
"@react-native-async-storage/async-storage": "1.24.0",
"@react-native-clipboard/clipboard": "1.14.2",
"@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/metro-config": "0.75.3",
"@react-navigation/drawer": "6.7.2",
@ -5602,7 +5602,7 @@
},
"node_modules/@react-native-menu/menu": {
"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",
"peerDependencies": {
"react": "*",

View File

@ -84,7 +84,7 @@
"@react-native-async-storage/async-storage": "1.24.0",
"@react-native-clipboard/clipboard": "1.14.2",
"@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/metro-config": "0.75.3",
"@react-navigation/drawer": "6.7.2",

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 => {