mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-04 04:13:49 +01:00
FIX: TX details screen would hang when loading large data
This commit is contained in:
parent
538a1327b6
commit
b395e1b782
2 changed files with 80 additions and 74 deletions
|
@ -8,6 +8,7 @@ import loc from '../loc';
|
|||
import * as BlueElectrum from './BlueElectrum';
|
||||
import triggerHapticFeedback, { HapticFeedbackTypes } from './hapticFeedback';
|
||||
import A from '../blue_modules/analytics';
|
||||
import { InteractionManager } from 'react-native';
|
||||
|
||||
const BlueApp = BlueAppClass.getInstance();
|
||||
|
||||
|
@ -71,16 +72,16 @@ export const BlueStorageProvider = ({ children }: { children: React.ReactNode })
|
|||
const [reloadTransactionsMenuActionFunction, setReloadTransactionsMenuActionFunction] = useState<() => void>(() => {});
|
||||
|
||||
useEffect(() => {
|
||||
BlueElectrum.isDisabled().then(setIsElectrumDisabled);
|
||||
}, []);
|
||||
setWallets(BlueApp.getWallets());
|
||||
|
||||
useEffect(() => {
|
||||
BlueElectrum.isDisabled().then(setIsElectrumDisabled);
|
||||
if (walletsInitialized) {
|
||||
BlueElectrum.connectMain();
|
||||
}
|
||||
}, [walletsInitialized]);
|
||||
|
||||
const saveToDisk = async (force: boolean = false) => {
|
||||
InteractionManager.runAfterInteractions(async () => {
|
||||
if (BlueApp.getWallets().length === 0 && !force) {
|
||||
console.log('not saving empty wallets array');
|
||||
return;
|
||||
|
@ -89,12 +90,9 @@ export const BlueStorageProvider = ({ children }: { children: React.ReactNode })
|
|||
await BlueApp.saveToDisk();
|
||||
setWallets([...BlueApp.getWallets()]);
|
||||
txMetadata = BlueApp.tx_metadata;
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setWallets(BlueApp.getWallets());
|
||||
}, []);
|
||||
|
||||
const resetWallets = () => {
|
||||
setWallets(BlueApp.getWallets());
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React, { useContext, useEffect, useLayoutEffect, useState } from 'react';
|
||||
import { View, ScrollView, TouchableOpacity, Text, TextInput, Linking, StyleSheet, Keyboard } from 'react-native';
|
||||
import { useNavigation, useRoute } from '@react-navigation/native';
|
||||
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { View, ScrollView, TouchableOpacity, Text, TextInput, Linking, StyleSheet, Keyboard, InteractionManager } from 'react-native';
|
||||
import { useFocusEffect, useNavigation, useRoute } from '@react-navigation/native';
|
||||
import Clipboard from '@react-native-clipboard/clipboard';
|
||||
import dayjs from 'dayjs';
|
||||
import { BlueCard, BlueLoading, BlueSpacing20, BlueText } from '../../BlueComponents';
|
||||
|
@ -59,10 +59,17 @@ const TransactionsDetails = () => {
|
|||
},
|
||||
});
|
||||
|
||||
useLayoutEffect(() => {
|
||||
setOptions({
|
||||
// eslint-disable-next-line react/no-unstable-nested-components
|
||||
headerRight: () => (
|
||||
const handleOnSaveButtonTapped = useCallback(() => {
|
||||
Keyboard.dismiss();
|
||||
txMetadata[tx.hash] = { memo };
|
||||
saveToDisk().then(_success => {
|
||||
triggerHapticFeedback(HapticFeedbackTypes.Success);
|
||||
presentAlert({ message: loc.transactions.transaction_note_saved });
|
||||
});
|
||||
}, [tx, memo, saveToDisk, txMetadata]);
|
||||
|
||||
const HeaderRightButton = useMemo(() => {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
accessibilityRole="button"
|
||||
disabled={isLoading}
|
||||
|
@ -71,12 +78,17 @@ const TransactionsDetails = () => {
|
|||
>
|
||||
<Text style={[styles.saveText, stylesHooks.saveText]}>{loc.wallets.details_save}</Text>
|
||||
</TouchableOpacity>
|
||||
),
|
||||
});
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [colors, isLoading, memo]);
|
||||
);
|
||||
}, [isLoading, stylesHooks.save, stylesHooks.saveText, handleOnSaveButtonTapped]);
|
||||
|
||||
useEffect(() => {
|
||||
// This effect only handles changes in `colors`
|
||||
setOptions({ headerRight: () => HeaderRightButton });
|
||||
}, [colors, HeaderRightButton, setOptions]);
|
||||
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
const task = InteractionManager.runAfterInteractions(() => {
|
||||
let foundTx = {};
|
||||
let newFrom = [];
|
||||
let newTo = [];
|
||||
|
@ -110,17 +122,13 @@ const TransactionsDetails = () => {
|
|||
setFrom(newFrom);
|
||||
setTo(newTo);
|
||||
setIsLoading(false);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [hash, wallets]);
|
||||
|
||||
const handleOnSaveButtonTapped = () => {
|
||||
Keyboard.dismiss();
|
||||
txMetadata[tx.hash] = { memo };
|
||||
saveToDisk().then(_success => {
|
||||
triggerHapticFeedback(HapticFeedbackTypes.Success);
|
||||
presentAlert({ message: loc.transactions.transaction_note_saved });
|
||||
});
|
||||
return () => {
|
||||
task.cancel();
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [hash, wallets]),
|
||||
);
|
||||
|
||||
const handleOnOpenTransactionOnBlockExplorerTapped = () => {
|
||||
const url = `https://mempool.space/tx/${tx.hash}`;
|
||||
|
|
Loading…
Add table
Reference in a new issue