1- import { toBuffer } from '@ethereumjs/util' ;
21import type {
32 ControllerGetStateAction ,
43 ControllerStateChangeEvent ,
@@ -657,23 +656,21 @@ export class AccountsController extends BaseController<
657656 * @returns The list of accounts associcated with this keyring type.
658657 */
659658 #getAccountsByKeyringType( keyringType : string ) {
660- return this . listAccounts ( ) . filter (
661- ( internalAccount ) => {
662- // We do consider `hd` and `simple` keyrings to be of same type. So we check those 2 types
663- // to group those accounts together!
664- if (
665- keyringType === KeyringTypes . hd ||
666- keyringType === KeyringTypes . simple
667- ) {
668- return (
669- internalAccount . metadata . keyring . type === KeyringTypes . hd ||
670- internalAccount . metadata . keyring . type === KeyringTypes . simple
671- ) ;
672- }
659+ return this . listAccounts ( ) . filter ( ( internalAccount ) => {
660+ // We do consider `hd` and `simple` keyrings to be of same type. So we check those 2 types
661+ // to group those accounts together!
662+ if (
663+ keyringType === KeyringTypes . hd ||
664+ keyringType === KeyringTypes . simple
665+ ) {
666+ return (
667+ internalAccount . metadata . keyring . type === KeyringTypes . hd ||
668+ internalAccount . metadata . keyring . type === KeyringTypes . simple
669+ ) ;
670+ }
673671
674- return internalAccount . metadata . keyring . type === keyringType ;
675- } ,
676- ) ;
672+ return internalAccount . metadata . keyring . type === keyringType ;
673+ } ) ;
677674 }
678675
679676 /**
@@ -687,27 +684,27 @@ export class AccountsController extends BaseController<
687684 } {
688685 const keyringName = keyringTypeToName ( keyringType ) ;
689686 const keyringAccounts = this . #getAccountsByKeyringType( keyringType ) ;
690- const lastDefaultIndexUsedForKeyringType =
691- keyringAccounts
692- . reduce ( ( maxInternalAccountIndex , internalAccount ) => {
693- // We **DO NOT USE** `\d+` here to only consider valid "human"
694- // number (rounded decimal number)
695- const match = ( new RegExp ( `${ keyringName } ([0-9]+)$` , 'u' ) ) . exec (
696- internalAccount . metadata . name ,
697- ) ;
698-
699- if ( match ) {
700- // Quoting `RegExp.exec` documentation:
701- // > The returned array has the matched text as the first item, and then one item for
702- // > each capturing group of the matched text.
703- // So use `match[1]` to get the captured value
704- const internalAccountIndex = parseInt ( match [ 1 ] , 10 ) ;
705- return Math . max ( maxInternalAccountIndex , internalAccountIndex ) ;
706- }
687+ const lastDefaultIndexUsedForKeyringType = keyringAccounts . reduce (
688+ ( maxInternalAccountIndex , internalAccount ) => {
689+ // We **DO NOT USE** `\d+` here to only consider valid "human"
690+ // number (rounded decimal number)
691+ const match = new RegExp ( `${ keyringName } ([0-9]+)$` , 'u' ) . exec (
692+ internalAccount . metadata . name ,
693+ ) ;
707694
708- return maxInternalAccountIndex ;
695+ if ( match ) {
696+ // Quoting `RegExp.exec` documentation:
697+ // > The returned array has the matched text as the first item, and then one item for
698+ // > each capturing group of the matched text.
699+ // So use `match[1]` to get the captured value
700+ const internalAccountIndex = parseInt ( match [ 1 ] , 10 ) ;
701+ return Math . max ( maxInternalAccountIndex , internalAccountIndex ) ;
702+ }
709703
710- } , 0 ) ;
704+ return maxInternalAccountIndex ;
705+ } ,
706+ 0 ,
707+ ) ;
711708
712709 const indexToUse = Math . max (
713710 keyringAccounts . length + 1 ,
0 commit comments