@@ -28,7 +28,11 @@ import {
2828 transformPortfolioPopulateStatus ,
2929 encryptSpecificFields ,
3030} from './transforms/transforms' ;
31- import { decryptPersistValue , encryptPersistValue } from './transforms/encrypt' ;
31+ import {
32+ deserializePersistValue ,
33+ encryptPersistValue ,
34+ } from './transforms/encrypt' ;
35+ import { createRehydrationFailureMiddleware } from './persistence-guard' ;
3236import { appReducer , appReduxPersistBlackList } from './app/app.reducer' ;
3337import {
3438 bitPayIdReducer ,
@@ -421,8 +425,15 @@ const logger = createLogger({
421425} ) ;
422426
423427const getStore = async ( ) => {
428+ let rehydrationFailure : Error | null = null ;
424429 const middlewares : Middleware [ ] = [ thunkMiddleware as unknown as Middleware ] ;
425430
431+ middlewares . push (
432+ createRehydrationFailureMiddleware ( error => {
433+ rehydrationFailure ??= error ;
434+ } ) ,
435+ ) ;
436+
426437 const cleanupPortfolioOnDeleteKeyMiddleware : Middleware = store => next => {
427438 return ( action : AnyAction ) => {
428439 if ( action ?. type !== WalletActionTypes . DELETE_KEY ) {
@@ -515,25 +526,12 @@ const getStore = async () => {
515526 ) ;
516527 } ,
517528 ( outboundState , key ) => {
518- if ( typeof key === 'string' && unencryptedPersistStores . has ( key ) ) {
519- if ( typeof outboundState === 'string' ) {
520- try {
521- return JSON . parse ( outboundState ) ;
522- } catch { }
523- } else {
524- return outboundState ;
525- }
526- }
527-
528- if ( typeof outboundState !== 'string' ) {
529- return outboundState ;
530- }
531-
532529 try {
533- return decryptPersistValue (
530+ return deserializePersistValue (
534531 outboundState ,
535532 secretKey ,
536533 `persist:${ String ( key ) } ` ,
534+ typeof key === 'string' && unencryptedPersistStores . has ( key ) ,
537535 ) ;
538536 } catch ( err ) {
539537 const errStr =
@@ -620,7 +618,18 @@ const getStore = async () => {
620618 storeDispatch ( LogActions . clear ( ) ) ;
621619 initLogs . drainAndDispatch ( storeDispatch ) ;
622620
623- const persistor = persistStore ( store ) ;
621+ let resolveBootstrap : ( ) => void = ( ) => { } ;
622+ const bootstrapped = new Promise < void > ( resolve => {
623+ resolveBootstrap = resolve ;
624+ } ) ;
625+ const persistor = persistStore ( store , undefined , resolveBootstrap ) ;
626+
627+ await bootstrapped ;
628+ if ( rehydrationFailure ) {
629+ persistor . pause ( ) ;
630+ Sentry . captureException ( rehydrationFailure , { level : 'error' } ) ;
631+ throw rehydrationFailure ;
632+ }
624633
625634 if ( __DEV__ ) {
626635 // persistor.purge().then(() => console.log('purged persistence'));
0 commit comments