mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-20 10:12:01 +01:00
Merge pull request #2130 from BlueWallet/ref-refresh-strategy
FIX: wallets are not refreshing when app boots; FIX: wallets are not …
This commit is contained in:
commit
04838a17b9
@ -33,14 +33,13 @@ export const BlueStorageProvider = ({ children }) => {
|
||||
const refreshAllWalletTransactions = async lastSnappedTo => {
|
||||
let noErr = true;
|
||||
try {
|
||||
// await BlueElectrum.ping();
|
||||
await BlueElectrum.waitTillConnected();
|
||||
const balanceStart = +new Date();
|
||||
await fetchWalletBalances(lastSnappedTo || 0);
|
||||
await fetchWalletBalances(lastSnappedTo);
|
||||
const balanceEnd = +new Date();
|
||||
console.log('fetch balance took', (balanceEnd - balanceStart) / 1000, 'sec');
|
||||
const start = +new Date();
|
||||
await fetchWalletTransactions(lastSnappedTo || 0);
|
||||
await fetchWalletTransactions(lastSnappedTo);
|
||||
const end = +new Date();
|
||||
console.log('fetch tx took', (end - start) / 1000, 'sec');
|
||||
} catch (err) {
|
||||
|
@ -33,7 +33,6 @@ const A = require('../../blue_modules/analytics');
|
||||
const LocalQRCode = require('@remobile/react-native-qrcode-local-image');
|
||||
|
||||
const WalletsListSections = { CAROUSEL: 'CAROUSEL', LOCALTRADER: 'LOCALTRADER', TRANSACTIONS: 'TRANSACTIONS' };
|
||||
let lastSnappedTo = 0;
|
||||
const isDesktop = getSystemName() === 'Mac OS X';
|
||||
|
||||
const WalletsList = () => {
|
||||
@ -135,14 +134,20 @@ const WalletsList = () => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Forcefully fetches TXs and balance for lastSnappedTo (i.e. current) wallet.
|
||||
* Forcefully fetches TXs and balance for ALL wallets.
|
||||
* Triggered manually by user on pull-to-refresh.
|
||||
*/
|
||||
const refreshTransactions = () => {
|
||||
setIsLoading(true);
|
||||
refreshAllWalletTransactions(lastSnappedTo).finally(() => setIsLoading(false));
|
||||
refreshAllWalletTransactions().finally(() => setIsLoading(false));
|
||||
};
|
||||
|
||||
useEffect(
|
||||
refreshTransactions,
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[],
|
||||
); // call refreshTransactions() only once, when screen mounts
|
||||
|
||||
const handleClick = index => {
|
||||
console.log('click', index);
|
||||
const wallet = carouselData[index];
|
||||
@ -186,7 +191,11 @@ const WalletsList = () => {
|
||||
|
||||
const onSnapToItem = index => {
|
||||
console.log('onSnapToItem', index);
|
||||
lastSnappedTo = 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');
|
||||
setIsLoading(true);
|
||||
refreshAllWalletTransactions(index).finally(() => setIsLoading(false));
|
||||
}
|
||||
};
|
||||
|
||||
const renderListHeaderComponent = () => {
|
||||
@ -222,6 +231,7 @@ const WalletsList = () => {
|
||||
};
|
||||
|
||||
const renderLocalTrader = () => {
|
||||
if (carouselData.every(wallet => wallet === false)) return null;
|
||||
if (carouselData.length > 0 && !carouselData.some(wallet => wallet.type === PlaceholderWallet.type)) {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
|
Loading…
Reference in New Issue
Block a user