@@ -35,7 +35,6 @@ import {
35
35
import type { Draft } from 'immer' ;
36
36
37
37
import {
38
- deepCloneDraft ,
39
38
getUUIDFromAddressOfNormalAccount ,
40
39
isNormalKeyringType ,
41
40
keyringTypeToName ,
@@ -412,12 +411,8 @@ export class AccountsController extends BaseController<
412
411
...account ,
413
412
metadata : { ...account . metadata , name : accountName } ,
414
413
} ;
415
- // FIXME: deep clone of old state to get around Type instantiation is excessively deep and possibly infinite.
416
- const newState = deepCloneDraft ( currentState ) ;
417
-
418
- newState . internalAccounts . accounts [ accountId ] = internalAccount ;
419
-
420
- return newState ;
414
+ // @ts -expect-error Type instantiation is excessively deep and possibly infinite. See: https://github.com/MetaMask/utils/issues/168
415
+ currentState . internalAccounts . accounts [ accountId ] = internalAccount ;
421
416
} ) ;
422
417
}
423
418
@@ -474,12 +469,7 @@ export class AccountsController extends BaseController<
474
469
} , { } as Record < string , InternalAccount > ) ;
475
470
476
471
this . update ( ( currentState : Draft < AccountsControllerState > ) => {
477
- // FIXME: deep clone of old state to get around Type instantiation is excessively deep and possibly infinite.
478
- const newState = deepCloneDraft ( currentState ) ;
479
-
480
- newState . internalAccounts . accounts = accounts ;
481
-
482
- return newState ;
472
+ currentState . internalAccounts . accounts = accounts ;
483
473
} ) ;
484
474
}
485
475
@@ -491,12 +481,7 @@ export class AccountsController extends BaseController<
491
481
loadBackup ( backup : AccountsControllerState ) : void {
492
482
if ( backup . internalAccounts ) {
493
483
this . update ( ( currentState : Draft < AccountsControllerState > ) => {
494
- // FIXME: deep clone of old state to get around Type instantiation is excessively deep and possibly infinite.
495
- const newState = deepCloneDraft ( currentState ) ;
496
-
497
- newState . internalAccounts = backup . internalAccounts ;
498
-
499
- return newState ;
484
+ currentState . internalAccounts = backup . internalAccounts ;
500
485
} ) ;
501
486
}
502
487
}
@@ -718,42 +703,41 @@ export class AccountsController extends BaseController<
718
703
}
719
704
720
705
this . update ( ( currentState : Draft < AccountsControllerState > ) => {
721
- const newState = deepCloneDraft ( currentState ) ;
722
-
723
706
if ( deletedAccounts . length > 0 ) {
724
707
for ( const account of deletedAccounts ) {
725
- newState . internalAccounts . accounts = this . #handleAccountRemoved(
726
- newState . internalAccounts . accounts ,
708
+ currentState . internalAccounts . accounts = this . #handleAccountRemoved(
709
+ currentState . internalAccounts . accounts ,
727
710
account . id ,
728
711
) ;
729
712
}
730
713
}
731
714
732
715
if ( addedAccounts . length > 0 ) {
733
716
for ( const account of addedAccounts ) {
734
- newState . internalAccounts . accounts = this . #handleNewAccountAdded(
735
- newState . internalAccounts . accounts ,
736
- account ,
737
- ) ;
717
+ currentState . internalAccounts . accounts =
718
+ this . #handleNewAccountAdded(
719
+ currentState . internalAccounts . accounts ,
720
+ account ,
721
+ ) ;
738
722
}
739
723
}
740
724
741
725
// We don't use list accounts because it is not the updated state yet.
742
726
const existingAccounts = Object . values (
743
- newState . internalAccounts . accounts ,
727
+ currentState . internalAccounts . accounts ,
744
728
) ;
745
729
746
730
// handle if the selected account was deleted
747
731
if (
748
- ! newState . internalAccounts . accounts [
732
+ ! currentState . internalAccounts . accounts [
749
733
this . state . internalAccounts . selectedAccount
750
734
]
751
735
) {
752
736
// if the accountToSelect is undefined, then there are no accounts
753
737
// it mean the keyring was reinitialized.
754
738
if ( existingAccounts . length === 0 ) {
755
- newState . internalAccounts . selectedAccount = '' ;
756
- return newState ;
739
+ currentState . internalAccounts . selectedAccount = '' ;
740
+ return ;
757
741
}
758
742
759
743
const [ accountToSelect ] = existingAccounts . sort (
@@ -766,10 +750,8 @@ export class AccountsController extends BaseController<
766
750
} ,
767
751
) ;
768
752
769
- newState . internalAccounts . selectedAccount = accountToSelect . id ;
753
+ currentState . internalAccounts . selectedAccount = accountToSelect . id ;
770
754
}
771
-
772
- return newState ;
773
755
} ) ;
774
756
}
775
757
}
0 commit comments