File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ import { updateActivityList } from '../../store/utils/activity';
7373import { refreshOrdersList } from '../../store/utils/blocktank' ;
7474import { moveMetaIncTxTags } from '../../store/utils/metadata' ;
7575import { showNewOnchainTxPrompt } from '../../store/utils/ui' ;
76+ import { appStateTracker } from '../appState' ;
7677import BitcoinActions from '../bitcoin-actions' ;
7778import { btcToSats } from '../conversion' ;
7879import { promiseTimeout } from '../helpers' ;
@@ -90,6 +91,9 @@ import { BITKIT_WALLET_SEED_HASH_PREFIX } from './constants';
9091import { getBlockHeader } from './electrum' ;
9192import { getTransferForTx } from './transfer' ;
9293
94+ // Initialize app state tracking
95+ appStateTracker . init ( ) ;
96+
9397bitcoin . initEccLib ( ecc ) ;
9498const 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 ) {
You can’t perform that action at this time.
0 commit comments