Skip to content

Commit bb331df

Browse files
committed
fix(ui): only show refresh error if app was not in background
1 parent a9c1252 commit bb331df

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/utils/appState.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { AppState } from 'react-native';
2+
3+
export const appStateTracker = {
4+
lastAppState: AppState.currentState,
5+
lastBackgroundTime: 0,
6+
7+
init() {
8+
AppState.addEventListener('change', (nextAppState) => {
9+
if (['background', 'inactive'].includes(nextAppState)) {
10+
this.lastBackgroundTime = Date.now();
11+
} else if (['background', 'inactive'].includes(this.lastAppState)) {
12+
// If we're leaving background state, update the time
13+
this.lastBackgroundTime = Date.now();
14+
}
15+
this.lastAppState = nextAppState;
16+
});
17+
},
18+
19+
wasRecentlyInBackground(): boolean {
20+
const currentState = AppState.currentState;
21+
const inBackground = ['background', 'inactive'].includes(currentState);
22+
const timeSinceLastBackground = Date.now() - this.lastBackgroundTime;
23+
24+
return inBackground || timeSinceLastBackground < 3000;
25+
},
26+
};

src/utils/wallet/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import { updateActivityList } from '../../store/utils/activity';
7373
import { refreshOrdersList } from '../../store/utils/blocktank';
7474
import { moveMetaIncTxTags } from '../../store/utils/metadata';
7575
import { showNewOnchainTxPrompt } from '../../store/utils/ui';
76+
import { appStateTracker } from '../appState';
7677
import BitcoinActions from '../bitcoin-actions';
7778
import { btcToSats } from '../conversion';
7879
import { promiseTimeout } from '../helpers';
@@ -90,6 +91,9 @@ import { BITKIT_WALLET_SEED_HASH_PREFIX } from './constants';
9091
import { getBlockHeader } from './electrum';
9192
import { getTransferForTx } from './transfer';
9293

94+
// Initialize app state tracking
95+
appStateTracker.init();
96+
9397
bitcoin.initEccLib(ecc);
9498
const bip32 = BIP32Factory(ecc);
9599

@@ -197,7 +201,9 @@ const refreshBeignet = async (scanAllAddresses = false): Promise<void> => {
197201
additionalAddresses,
198202
});
199203
if (refreshWalletRes.isErr()) {
200-
handleRefreshError(refreshWalletRes.error.message);
204+
if (!appStateTracker.wasRecentlyInBackground()) {
205+
handleRefreshError(refreshWalletRes.error.message);
206+
}
201207
} else {
202208
// If refresh was successful, reset the throttled state.
203209
if (getStore().ui.isElectrumThrottled) {

0 commit comments

Comments
 (0)