@@ -9,10 +9,16 @@ import {
99 AccountAlreadyExists ,
1010 NotImplemented ,
1111 OneKeyInternalError ,
12+ TooManyDerivedAccounts ,
13+ TooManyImportedAccounts ,
1214 TooManyWatchingAccounts ,
1315 WrongPassword ,
1416} from '../../errors' ;
15- import { WATCHING_ACCOUNT_MAX_NUM } from '../../limits' ;
17+ import {
18+ DERIVED_ACCOUNT_MAX_NUM ,
19+ IMPORTED_ACCOUNT_MAX_NUM ,
20+ WATCHING_ACCOUNT_MAX_NUM ,
21+ } from '../../limits' ;
1622import { getPath } from '../../managers/derivation' ;
1723import { walletIsImported } from '../../managers/wallet' ;
1824import { AccountType , DBAccount , DBVariantAccount } from '../../types/account' ;
@@ -765,7 +771,7 @@ class IndexedDBApi implements DBAPI {
765771 const walletId = `hd-${ context . nextHD } ` ;
766772 ret = {
767773 id : walletId ,
768- name : name || `HD Wallet ${ context . nextHD } ` ,
774+ name : name || `Wallet ${ context . nextHD } ` ,
769775 type : WALLET_TYPE_HD ,
770776 backuped,
771777 accounts : [ ] ,
@@ -827,7 +833,7 @@ class IndexedDBApi implements DBAPI {
827833 }
828834 ret = {
829835 id : walletId ,
830- name : name || `HW Wallet of ${ id } ` ,
836+ name,
831837 type : WALLET_TYPE_HW ,
832838 backuped : true ,
833839 accounts : [ ] ,
@@ -1139,6 +1145,23 @@ class IndexedDBApi implements DBAPI {
11391145 const category = `${ pathComponents [ 1 ] } /${ pathComponents [ 2 ] } ` ;
11401146 const purpose = pathComponents [ 1 ] . slice ( 0 , - 1 ) ;
11411147 const coinType = pathComponents [ 2 ] . slice ( 0 , - 1 ) ;
1148+
1149+ // Check account number limit
1150+ const accountIdPrefix = `${ walletId } --m/${ category } ` ;
1151+ if (
1152+ wallet . accounts . filter ( ( id ) => id . startsWith ( accountIdPrefix ) )
1153+ . length > DERIVED_ACCOUNT_MAX_NUM
1154+ ) {
1155+ reject (
1156+ new TooManyDerivedAccounts (
1157+ DERIVED_ACCOUNT_MAX_NUM ,
1158+ parseInt ( coinType ) ,
1159+ parseInt ( purpose ) ,
1160+ ) ,
1161+ ) ;
1162+ return ;
1163+ }
1164+
11421165 let nextId = wallet . nextAccountIds [ category ] || 0 ;
11431166 while (
11441167 wallet . accounts . includes (
@@ -1155,6 +1178,12 @@ class IndexedDBApi implements DBAPI {
11551178 . objectStore ( CONTEXT_STORE_NAME )
11561179 . get ( MAIN_CONTEXT ) ;
11571180 getMainContextRequest . onsuccess = ( _cevent ) => {
1181+ if ( wallet . accounts . length > IMPORTED_ACCOUNT_MAX_NUM ) {
1182+ reject (
1183+ new TooManyImportedAccounts ( IMPORTED_ACCOUNT_MAX_NUM ) ,
1184+ ) ;
1185+ return ;
1186+ }
11581187 const context : OneKeyContext =
11591188 getMainContextRequest . result as OneKeyContext ;
11601189 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
0 commit comments