mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-23 15:20:55 +01:00
FIX: Re-order wallet bug #3341
This commit is contained in:
parent
9e7980cd93
commit
35fc5114b1
2 changed files with 25 additions and 16 deletions
|
@ -26,7 +26,7 @@ import WalletImport from '../../class/wallet-import';
|
|||
import ActionSheet from '../ActionSheet';
|
||||
import loc from '../../loc';
|
||||
import { FContainer, FButton } from '../../components/FloatButtons';
|
||||
import { useFocusEffect, useNavigation, useRoute, useTheme } from '@react-navigation/native';
|
||||
import { useFocusEffect, useIsFocused, useNavigation, useRoute, useTheme } from '@react-navigation/native';
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
import { isDesktop, isMacCatalina, isTablet } from '../../blue_modules/environment';
|
||||
import BlueClipboard from '../../blue_modules/clipboard';
|
||||
|
@ -46,6 +46,7 @@ const WalletsList = () => {
|
|||
const { width } = useWindowDimensions();
|
||||
const { colors, scanImage } = useTheme();
|
||||
const { navigate, setOptions } = useNavigation();
|
||||
const isFocused = useIsFocused();
|
||||
const routeName = useRoute().name;
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isLargeScreen, setIsLargeScreen] = useState(
|
||||
|
@ -202,12 +203,14 @@ const WalletsList = () => {
|
|||
};
|
||||
|
||||
const onSnapToItem = e => {
|
||||
const contentOffset = e.nativeEvent.contentOffset;
|
||||
const index = Math.ceil(contentOffset.x / width);
|
||||
console.log('onSnapToItem', index);
|
||||
if (wallets[index] && (wallets[index].timeToRefreshBalance() || wallets[index].timeToRefreshTransaction())) {
|
||||
console.log(wallets[index].getLabel(), 'thinks its time to refresh either balance or transactions. refetching both');
|
||||
refreshAllWalletTransactions(index, false).finally(() => setIsLoading(false));
|
||||
if (isFocused) {
|
||||
const contentOffset = e.nativeEvent.contentOffset;
|
||||
const index = Math.ceil(contentOffset.x / width);
|
||||
console.log('onSnapToItem', index);
|
||||
if (wallets[index] && (wallets[index].timeToRefreshBalance() || wallets[index].timeToRefreshTransaction())) {
|
||||
console.log(wallets[index].getLabel(), 'thinks its time to refresh either balance or transactions. refetching both');
|
||||
refreshAllWalletTransactions(index, false).finally(() => setIsLoading(false));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -277,6 +280,7 @@ const WalletsList = () => {
|
|||
ref={walletsCarousel}
|
||||
testID="WalletsList"
|
||||
horizontal
|
||||
scrollEnabled={isFocused}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@ import { BluePrivateBalance } from '../../BlueComponents';
|
|||
import SortableList from 'react-native-sortable-list';
|
||||
import LinearGradient from 'react-native-linear-gradient';
|
||||
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
||||
import { useTheme } from '@react-navigation/native';
|
||||
import { useNavigation, useTheme } from '@react-navigation/native';
|
||||
|
||||
import navigationStyle from '../../components/navigationStyle';
|
||||
import { PlaceholderWallet, LightningCustodianWallet, MultisigHDWallet } from '../../class';
|
||||
|
@ -77,6 +77,7 @@ const ReorderWallets = () => {
|
|||
const sortableList = useRef();
|
||||
const { colors } = useTheme();
|
||||
const { wallets, setWalletsWithNewOrder } = useContext(BlueStorageContext);
|
||||
const navigation = useNavigation();
|
||||
const stylesHook = {
|
||||
root: {
|
||||
backgroundColor: colors.elevated,
|
||||
|
@ -87,15 +88,19 @@ const ReorderWallets = () => {
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (sortableList.current?.state.data.length === data.length && hasMovedARow) {
|
||||
const newWalletsOrderArray = [];
|
||||
sortableList.current.state.order.forEach(element => {
|
||||
newWalletsOrderArray.push(data[element]);
|
||||
});
|
||||
setWalletsWithNewOrder(newWalletsOrderArray);
|
||||
}
|
||||
const unsubscribe = navigation.addListener('blur', () => {
|
||||
if (sortableList.current?.state.data.length === data.length && hasMovedARow) {
|
||||
const newWalletsOrderArray = [];
|
||||
sortableList.current.state.order.forEach(element => {
|
||||
newWalletsOrderArray.push(data[element]);
|
||||
});
|
||||
setWalletsWithNewOrder(newWalletsOrderArray);
|
||||
}
|
||||
});
|
||||
|
||||
return unsubscribe;
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [hasMovedARow]);
|
||||
}, [navigation, hasMovedARow]);
|
||||
|
||||
useEffect(() => {
|
||||
const loadWallets = wallets.filter(wallet => wallet.type !== PlaceholderWallet.type);
|
||||
|
|
Loading…
Add table
Reference in a new issue