@subwallet/extension-base 1.3.22-0 → 1.3.23-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/background/KoniTypes.d.ts +75 -2
  2. package/background/KoniTypes.js +2 -0
  3. package/cjs/background/KoniTypes.js +2 -0
  4. package/cjs/constants/environment.js +4 -2
  5. package/cjs/constants/signing.js +6 -2
  6. package/cjs/core/logic-validation/recipientAddress.js +9 -1
  7. package/cjs/core/logic-validation/transfer.js +35 -29
  8. package/cjs/core/types.js +1 -0
  9. package/cjs/core/utils.js +12 -1
  10. package/cjs/defaults.js +1 -1
  11. package/cjs/koni/api/dotsama/crowdloan.js +1 -1
  12. package/cjs/koni/api/nft/index.js +9 -16
  13. package/cjs/koni/api/staking/index.js +3 -4
  14. package/cjs/koni/background/handlers/Extension.js +234 -96
  15. package/cjs/koni/background/handlers/State.js +15 -0
  16. package/cjs/packageInfo.js +1 -1
  17. package/cjs/services/balance-service/helpers/subscribe/cardano/consts.js +11 -0
  18. package/cjs/services/balance-service/helpers/subscribe/cardano/index.js +63 -0
  19. package/cjs/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
  20. package/cjs/services/balance-service/helpers/subscribe/cardano/utils.js +74 -0
  21. package/cjs/services/balance-service/helpers/subscribe/index.js +21 -7
  22. package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +2 -2
  23. package/cjs/services/balance-service/index.js +4 -2
  24. package/cjs/services/balance-service/transfer/cardano-transfer.js +122 -0
  25. package/cjs/services/balance-service/transfer/token.js +4 -4
  26. package/cjs/services/chain-service/handler/CardanoApi.js +176 -0
  27. package/cjs/services/chain-service/handler/CardanoChainHandler.js +83 -0
  28. package/cjs/services/chain-service/handler/TonApi.js +2 -5
  29. package/cjs/services/chain-service/index.js +29 -7
  30. package/cjs/services/chain-service/utils/index.js +40 -11
  31. package/cjs/services/chain-service/utils/patch.js +1 -1
  32. package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
  33. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
  34. package/cjs/services/earning-service/service.js +6 -12
  35. package/cjs/services/fee-service/service.js +19 -8
  36. package/cjs/services/history-service/index.js +4 -6
  37. package/cjs/services/inapp-notification-service/index.js +12 -4
  38. package/cjs/services/keyring-service/context/account-context.js +17 -2
  39. package/cjs/services/keyring-service/context/handlers/Derive.js +10 -7
  40. package/cjs/services/keyring-service/context/handlers/Migration.js +268 -0
  41. package/cjs/services/keyring-service/context/handlers/Mnemonic.js +2 -2
  42. package/cjs/services/keyring-service/context/handlers/Secret.js +1 -1
  43. package/cjs/services/keyring-service/utils.js +18 -0
  44. package/cjs/services/request-service/handler/CardanoRequestHandler.js +172 -0
  45. package/cjs/services/request-service/handler/EvmRequestHandler.js +1 -1
  46. package/cjs/services/request-service/index.js +20 -2
  47. package/cjs/services/setting-service/constants.js +10 -1
  48. package/cjs/services/storage-service/DatabaseService.js +3 -0
  49. package/cjs/services/storage-service/db-stores/InappNotification.js +6 -0
  50. package/cjs/services/swap-service/handler/asset-hub/handler.js +0 -59
  51. package/cjs/services/swap-service/handler/chainflip-handler.js +33 -281
  52. package/cjs/services/swap-service/handler/hydradx-handler.js +23 -190
  53. package/cjs/services/swap-service/handler/simpleswap-handler.js +1 -222
  54. package/cjs/services/swap-service/handler/uniswap-handler.js +331 -0
  55. package/cjs/services/swap-service/index.js +31 -22
  56. package/cjs/services/swap-service/utils.js +21 -38
  57. package/cjs/services/transaction-service/helpers/index.js +6 -1
  58. package/cjs/services/transaction-service/index.js +278 -21
  59. package/cjs/services/transaction-service/utils.js +5 -1
  60. package/cjs/types/account/info/keyring.js +12 -1
  61. package/cjs/types/fee/cardano.js +1 -0
  62. package/cjs/types/swap/index.js +7 -2
  63. package/cjs/utils/account/analyze.js +2 -1
  64. package/cjs/utils/account/common.js +29 -20
  65. package/cjs/utils/account/derive/info/solo.js +9 -4
  66. package/cjs/utils/account/derive/validate.js +36 -2
  67. package/cjs/utils/account/transform.js +38 -13
  68. package/cjs/utils/fee/transfer.js +40 -7
  69. package/cjs/utils/index.js +2 -2
  70. package/cjs/utils/staticData/index.js +7 -2
  71. package/constants/environment.d.ts +1 -0
  72. package/constants/environment.js +2 -1
  73. package/constants/signing.js +6 -2
  74. package/core/logic-validation/recipientAddress.js +11 -3
  75. package/core/logic-validation/transfer.js +9 -3
  76. package/core/substrate/xcm-parser.d.ts +1 -1
  77. package/core/types.d.ts +1 -0
  78. package/core/types.js +1 -0
  79. package/core/utils.d.ts +1 -0
  80. package/core/utils.js +13 -3
  81. package/defaults.d.ts +1 -1
  82. package/defaults.js +1 -1
  83. package/koni/api/dotsama/crowdloan.js +3 -3
  84. package/koni/api/nft/index.js +10 -16
  85. package/koni/api/nft/story_odyssey_nft/index.d.ts +1 -1
  86. package/koni/api/staking/index.js +4 -5
  87. package/koni/background/handlers/Extension.d.ts +9 -0
  88. package/koni/background/handlers/Extension.js +144 -8
  89. package/koni/background/handlers/State.d.ts +5 -1
  90. package/koni/background/handlers/State.js +16 -1
  91. package/package.json +71 -9
  92. package/packageInfo.js +1 -1
  93. package/services/balance-service/helpers/subscribe/cardano/consts.d.ts +1 -0
  94. package/services/balance-service/helpers/subscribe/cardano/consts.js +4 -0
  95. package/services/balance-service/helpers/subscribe/cardano/index.d.ts +2 -0
  96. package/services/balance-service/helpers/subscribe/cardano/index.js +57 -0
  97. package/services/balance-service/helpers/subscribe/cardano/types.d.ts +34 -0
  98. package/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
  99. package/services/balance-service/helpers/subscribe/cardano/utils.d.ts +15 -0
  100. package/services/balance-service/helpers/subscribe/cardano/utils.js +62 -0
  101. package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
  102. package/services/balance-service/helpers/subscribe/index.js +23 -9
  103. package/services/balance-service/helpers/subscribe/ton/utils.d.ts +1 -1
  104. package/services/balance-service/helpers/subscribe/ton/utils.js +1 -1
  105. package/services/balance-service/index.js +4 -2
  106. package/services/balance-service/transfer/cardano-transfer.d.ts +24 -0
  107. package/services/balance-service/transfer/cardano-transfer.js +114 -0
  108. package/services/balance-service/transfer/token.d.ts +1 -1
  109. package/services/balance-service/transfer/token.js +2 -2
  110. package/services/chain-service/handler/CardanoApi.d.ts +38 -0
  111. package/services/chain-service/handler/CardanoApi.js +167 -0
  112. package/services/chain-service/handler/CardanoChainHandler.d.ts +17 -0
  113. package/services/chain-service/handler/CardanoChainHandler.js +75 -0
  114. package/services/chain-service/handler/TonApi.js +3 -6
  115. package/services/chain-service/handler/types.d.ts +1 -0
  116. package/services/chain-service/index.d.ts +3 -1
  117. package/services/chain-service/index.js +29 -7
  118. package/services/chain-service/types.d.ts +9 -1
  119. package/services/chain-service/utils/index.d.ts +4 -0
  120. package/services/chain-service/utils/index.js +32 -11
  121. package/services/chain-service/utils/patch.js +1 -1
  122. package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
  123. package/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
  124. package/services/earning-service/service.js +8 -14
  125. package/services/fee-service/service.js +19 -8
  126. package/services/history-service/index.js +6 -8
  127. package/services/inapp-notification-service/index.d.ts +3 -4
  128. package/services/inapp-notification-service/index.js +14 -6
  129. package/services/keyring-service/context/account-context.d.ts +6 -2
  130. package/services/keyring-service/context/account-context.js +17 -2
  131. package/services/keyring-service/context/handlers/Derive.d.ts +1 -1
  132. package/services/keyring-service/context/handlers/Derive.js +10 -8
  133. package/services/keyring-service/context/handlers/Migration.d.ts +17 -0
  134. package/services/keyring-service/context/handlers/Migration.js +258 -0
  135. package/services/keyring-service/context/handlers/Mnemonic.js +2 -2
  136. package/services/keyring-service/context/handlers/Secret.js +2 -2
  137. package/services/keyring-service/utils.d.ts +2 -0
  138. package/services/keyring-service/utils.js +11 -0
  139. package/services/request-service/handler/CardanoRequestHandler.d.ts +16 -0
  140. package/services/request-service/handler/CardanoRequestHandler.js +163 -0
  141. package/services/request-service/handler/EvmRequestHandler.js +1 -1
  142. package/services/request-service/index.d.ts +6 -3
  143. package/services/request-service/index.js +19 -5
  144. package/services/setting-service/constants.d.ts +3 -0
  145. package/services/setting-service/constants.js +6 -0
  146. package/services/storage-service/DatabaseService.d.ts +1 -0
  147. package/services/storage-service/DatabaseService.js +3 -0
  148. package/services/storage-service/db-stores/InappNotification.d.ts +1 -0
  149. package/services/storage-service/db-stores/InappNotification.js +6 -0
  150. package/services/swap-service/handler/asset-hub/handler.d.ts +1 -4
  151. package/services/swap-service/handler/asset-hub/handler.js +2 -61
  152. package/services/swap-service/handler/base-handler.d.ts +1 -4
  153. package/services/swap-service/handler/chainflip-handler.d.ts +2 -9
  154. package/services/swap-service/handler/chainflip-handler.js +31 -280
  155. package/services/swap-service/handler/hydradx-handler.d.ts +1 -6
  156. package/services/swap-service/handler/hydradx-handler.js +13 -180
  157. package/services/swap-service/handler/simpleswap-handler.d.ts +1 -4
  158. package/services/swap-service/handler/simpleswap-handler.js +5 -226
  159. package/services/swap-service/handler/uniswap-handler.d.ts +41 -0
  160. package/services/swap-service/handler/uniswap-handler.js +323 -0
  161. package/services/swap-service/index.js +30 -22
  162. package/services/swap-service/utils.d.ts +1 -5
  163. package/services/swap-service/utils.js +7 -21
  164. package/services/transaction-service/helpers/index.d.ts +2 -0
  165. package/services/transaction-service/helpers/index.js +4 -0
  166. package/services/transaction-service/index.d.ts +8 -2
  167. package/services/transaction-service/index.js +263 -10
  168. package/services/transaction-service/types.d.ts +7 -0
  169. package/services/transaction-service/utils.js +7 -2
  170. package/types/account/info/keyring.d.ts +4 -1
  171. package/types/account/info/keyring.js +9 -0
  172. package/types/account/info/proxy.d.ts +2 -0
  173. package/types/balance/index.d.ts +4 -1
  174. package/types/fee/base.d.ts +1 -1
  175. package/types/fee/cardano.d.ts +18 -0
  176. package/types/fee/cardano.js +1 -0
  177. package/types/fee/subscription.d.ts +4 -3
  178. package/types/swap/index.d.ts +11 -3
  179. package/types/swap/index.js +7 -2
  180. package/utils/account/analyze.js +2 -1
  181. package/utils/account/common.d.ts +11 -6
  182. package/utils/account/common.js +28 -19
  183. package/utils/account/derive/info/solo.js +10 -5
  184. package/utils/account/derive/validate.d.ts +1 -0
  185. package/utils/account/derive/validate.js +34 -1
  186. package/utils/account/transform.d.ts +2 -1
  187. package/utils/account/transform.js +37 -13
  188. package/utils/fee/transfer.d.ts +2 -1
  189. package/utils/fee/transfer.js +44 -11
  190. package/utils/index.js +4 -4
  191. package/utils/staticData/index.d.ts +4 -1
  192. package/utils/staticData/index.js +5 -1
  193. package/utils/staticData/oldChainPrefix.json +1 -0
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
5
- import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
+ import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
6
6
  import { CRON_REFRESH_CHAIN_STAKING_METADATA, CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL } from '@subwallet/extension-base/constants';
7
7
  import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
8
8
  import { _isChainEnabled, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
@@ -10,7 +10,7 @@ import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning
10
10
  import BaseLiquidStakingPoolHandler from '@subwallet/extension-base/services/earning-service/handlers/liquid-staking/base';
11
11
  import MythosNativeStakingPoolHandler from '@subwallet/extension-base/services/earning-service/handlers/native-staking/mythos';
12
12
  import { BasicTxErrorType, YieldPoolType } from '@subwallet/extension-base/types';
13
- import { addLazy, categoryAddresses, createPromiseHandler, removeLazy } from '@subwallet/extension-base/utils';
13
+ import { addLazy, createPromiseHandler, getAddressesByChainType, removeLazy } from '@subwallet/extension-base/utils';
14
14
  import { fetchStaticCache } from '@subwallet/extension-base/utils/fetchStaticCache';
15
15
  import { BehaviorSubject } from 'rxjs';
16
16
  import { AcalaLiquidStakingPoolHandler, AmplitudeNativeStakingPoolHandler, AstarNativeStakingPoolHandler, BifrostLiquidStakingPoolHandler, BifrostMantaLiquidStakingPoolHandler, InterlayLendingPoolHandler, NominationPoolHandler, ParallelLiquidStakingPoolHandler, ParaNativeStakingPoolHandler, RelayNativeStakingPoolHandler, StellaSwapLiquidStakingPoolHandler, TaoNativeStakingPoolHandler } from "./handlers/index.js";
@@ -380,10 +380,8 @@ export default class EarningService {
380
380
  async subscribePoolPositions(addresses, callback) {
381
381
  let cancel = false;
382
382
  await this.eventService.waitChainReady;
383
- const {
384
- evm: evmAddresses,
385
- substrate: substrateAddresses
386
- } = categoryAddresses(addresses);
383
+ const evmAddresses = getAddressesByChainType(addresses, [ChainType.EVM]);
384
+ const substrateAddresses = getAddressesByChainType(addresses, [ChainType.SUBSTRATE]);
387
385
  const activeChains = this.state.activeChainSlugs;
388
386
  const unsubList = [];
389
387
  for (const handler of Object.values(this.handlers)) {
@@ -526,10 +524,8 @@ export default class EarningService {
526
524
  async getPoolReward(addresses, callback) {
527
525
  let cancel = false;
528
526
  await this.eventService.waitChainReady;
529
- const {
530
- evm: evmAddresses,
531
- substrate: substrateAddresses
532
- } = categoryAddresses(addresses);
527
+ const evmAddresses = getAddressesByChainType(addresses, [ChainType.EVM]);
528
+ const substrateAddresses = getAddressesByChainType(addresses, [ChainType.SUBSTRATE]);
533
529
  const activeChains = this.state.activeChainSlugs;
534
530
  const unsubList = [];
535
531
  for (const handler of Object.values(this.handlers)) {
@@ -584,10 +580,8 @@ export default class EarningService {
584
580
  async fetchPoolRewardHistory(addresses, callback) {
585
581
  let cancel = false;
586
582
  await this.eventService.waitChainReady;
587
- const {
588
- evm: evmAddresses,
589
- substrate: substrateAddresses
590
- } = categoryAddresses(addresses);
583
+ const evmAddresses = getAddressesByChainType(addresses, [ChainType.EVM]);
584
+ const substrateAddresses = getAddressesByChainType(addresses, [ChainType.SUBSTRATE]);
591
585
  const activeChains = this.state.activeChainSlugs;
592
586
  const unsubList = [];
593
587
  for (const handler of Object.values(this.handlers)) {
@@ -9,7 +9,8 @@ export default class FeeService {
9
9
  chainFeeSubscriptionMap = {
10
10
  evm: {},
11
11
  substrate: {},
12
- ton: {}
12
+ ton: {},
13
+ cardano: {}
13
14
  };
14
15
  constructor(state) {
15
16
  this.state = state;
@@ -103,21 +104,31 @@ export default class FeeService {
103
104
  const api = this.state.getEvmApi(chain);
104
105
 
105
106
  // TODO: Handle case type === evm and not have api
106
- if (type === 'evm' && api) {
107
- calculateGasFeeParams(api, chain).then(info => {
108
- observer.next(info);
109
- }).catch(e => {
110
- console.warn(`Cannot get fee param for ${chain}`, e);
107
+ if (type === 'evm') {
108
+ if (api) {
109
+ calculateGasFeeParams(api, chain).then(info => {
110
+ observer.next(info);
111
+ }).catch(e => {
112
+ console.warn(`Cannot get fee param for ${chain}`, e);
113
+ observer.next({
114
+ type: 'evm',
115
+ gasPrice: '0',
116
+ baseGasFee: undefined,
117
+ options: undefined
118
+ });
119
+ });
120
+ } else {
121
+ console.warn(`Cannot get fee param for ${chain}`, 'Cannot get api');
111
122
  observer.next({
112
123
  type: 'evm',
113
124
  gasPrice: '0',
114
125
  baseGasFee: undefined,
115
126
  options: undefined
116
127
  });
117
- });
128
+ }
118
129
  } else {
119
130
  observer.next({
120
- type: type,
131
+ type,
121
132
  busyNetwork: false,
122
133
  options: {
123
134
  slow: {
@@ -1,14 +1,14 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { ExtrinsicStatus, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
4
+ import { ChainType, ExtrinsicStatus, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
5
  import { CRON_RECOVER_HISTORY_INTERVAL } from '@subwallet/extension-base/constants';
6
6
  import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
7
7
  import { _isChainEvmCompatible, _isChainSubstrateCompatible } from '@subwallet/extension-base/services/chain-service/utils';
8
8
  import { historyRecover, HistoryRecoverStatus } from '@subwallet/extension-base/services/history-service/helpers/recoverHistoryStatus';
9
9
  import { getExtrinsicParserKey } from '@subwallet/extension-base/services/history-service/helpers/subscan-extrinsic-parser-helper';
10
10
  import { parseSubscanExtrinsicData, parseSubscanTransferData } from '@subwallet/extension-base/services/history-service/subscan-history';
11
- import { categoryAddresses } from '@subwallet/extension-base/utils';
11
+ import { getAddressesByChainType } from '@subwallet/extension-base/utils';
12
12
  import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
13
13
  import { keyring } from '@subwallet/ui-keyring';
14
14
  import { BehaviorSubject } from 'rxjs';
@@ -144,19 +144,17 @@ export class HistoryService {
144
144
  }
145
145
  subscribeHistories(chain, proxyId, cb) {
146
146
  const addresses = this.keyringService.context.getDecodedAddresses(proxyId, false);
147
- const {
148
- evm,
149
- substrate
150
- } = categoryAddresses(addresses);
147
+ const evmAddresses = getAddressesByChainType(addresses, [ChainType.EVM]);
148
+ const substrateAddresses = getAddressesByChainType(addresses, [ChainType.SUBSTRATE]);
151
149
  const subscription = this.historySubject.subscribe(items => {
152
150
  cb(items.filter(filterHistoryItemByAddressAndChain(chain, addresses)));
153
151
  });
154
152
  const chainInfo = this.chainService.getChainInfoByKey(chain);
155
153
  if (_isChainSubstrateCompatible(chainInfo)) {
156
154
  if (_isChainEvmCompatible(chainInfo)) {
157
- this.fetchSubscanTransactionHistory(chain, evm);
155
+ this.fetchSubscanTransactionHistory(chain, evmAddresses);
158
156
  } else {
159
- this.fetchSubscanTransactionHistory(chain, substrate);
157
+ this.fetchSubscanTransactionHistory(chain, substrateAddresses);
160
158
  }
161
159
  }
162
160
  return {
@@ -28,10 +28,8 @@ export declare class InappNotificationService implements CronServiceInterface {
28
28
  validateAndWriteNotificationsToDB(notifications: _BaseNotificationInfo[], address: string): Promise<void>;
29
29
  cronCreateBridgeClaimNotification(): void;
30
30
  getCategorizedAddresses(): {
31
- substrate: string[];
32
- evm: string[];
33
- ton: string[];
34
- bitcoin: string[];
31
+ evmAddresses: string[];
32
+ substrateAddresses: string[];
35
33
  };
36
34
  createAvailBridgeClaimNotification(): void;
37
35
  processWriteAvailBridgeClaim(address: string, transactions: AvailBridgeTransaction[], token: _ChainAsset): Promise<void>;
@@ -44,4 +42,5 @@ export declare class InappNotificationService implements CronServiceInterface {
44
42
  stopCron(): Promise<void>;
45
43
  onAccountProxyRemove(): void;
46
44
  removeAccountNotifications(proxyId: string): void;
45
+ migrateNotificationProxyId(proxyIds: string[], newProxyId: string, newName: string): void;
47
46
  }
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { COMMON_ASSETS, COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
5
- import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
+ import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
6
6
  import { CRON_LISTEN_AVAIL_BRIDGE_CLAIM } from '@subwallet/extension-base/constants';
7
7
  import { fetchLastestRemindNotificationTime } from '@subwallet/extension-base/constants/remind-notification-time';
8
8
  import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
@@ -11,7 +11,7 @@ import { NotificationDescriptionMap, NotificationTitleMap, ONE_DAY_MILLISECOND }
11
11
  import { NotificationActionType, NotificationTab } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
12
12
  import { AvailBridgeSourceChain, fetchAllAvailBridgeClaimable, fetchPolygonBridgeTransactions, hrsToMillisecond } from '@subwallet/extension-base/services/inapp-notification-service/utils';
13
13
  import { ProcessType, YieldPoolType } from '@subwallet/extension-base/types';
14
- import { categoryAddresses, formatNumber, reformatAddress } from '@subwallet/extension-base/utils';
14
+ import { formatNumber, getAddressesByChainType, reformatAddress } from '@subwallet/extension-base/utils';
15
15
  import { isSubstrateAddress } from '@subwallet/keyring';
16
16
  export class InappNotificationService {
17
17
  constructor(dbService, keyringService, eventService, chainService) {
@@ -170,12 +170,17 @@ export class InappNotificationService {
170
170
  }
171
171
  getCategorizedAddresses() {
172
172
  const addresses = this.keyringService.context.getAllAddresses();
173
- return categoryAddresses(addresses);
173
+ const evmAddresses = getAddressesByChainType(addresses, [ChainType.EVM]);
174
+ const substrateAddresses = getAddressesByChainType(addresses, [ChainType.SUBSTRATE]);
175
+ return {
176
+ evmAddresses: evmAddresses,
177
+ substrateAddresses: substrateAddresses
178
+ };
174
179
  }
175
180
  createAvailBridgeClaimNotification() {
176
181
  const {
177
- evm: evmAddresses,
178
- substrate: substrateAddresses
182
+ evmAddresses,
183
+ substrateAddresses
179
184
  } = this.getCategorizedAddresses();
180
185
  const chainAssets = this.chainService.getAssetRegistry();
181
186
  let ASSET_TYPE;
@@ -262,7 +267,7 @@ export class InappNotificationService {
262
267
  // Polygon Claimable Handle
263
268
  async createPolygonClaimableTransactions() {
264
269
  const {
265
- evm: evmAddresses
270
+ evmAddresses
266
271
  } = this.getCategorizedAddresses();
267
272
  const etherChains = [COMMON_ASSETS.ETH, COMMON_ASSETS.ETH_SEPOLIA];
268
273
  const polygonAssets = Object.values(this.chainService.getAssetRegistry()).filter(asset => etherChains.includes(asset.slug));
@@ -433,4 +438,7 @@ export class InappNotificationService {
433
438
  removeAccountNotifications(proxyId) {
434
439
  this.dbService.removeAccountNotifications(proxyId).catch(console.error);
435
440
  }
441
+ migrateNotificationProxyId(proxyIds, newProxyId, newName) {
442
+ this.dbService.updateNotificationProxyId(proxyIds, newProxyId, newName);
443
+ }
436
444
  }
@@ -1,4 +1,4 @@
1
- import { AccountExternalError, RequestAccountCreateExternalV2, RequestAccountCreateHardwareMultiple, RequestAccountCreateHardwareV2, RequestAccountCreateWithSecretKey, RequestAccountExportPrivateKey, RequestChangeMasterPassword, RequestMigratePassword, ResponseAccountCreateWithSecretKey, ResponseAccountExportPrivateKey, ResponseChangeMasterPassword, ResponseMigratePassword } from '@subwallet/extension-base/background/KoniTypes';
1
+ import { AccountExternalError, RequestAccountCreateExternalV2, RequestAccountCreateHardwareMultiple, RequestAccountCreateHardwareV2, RequestAccountCreateWithSecretKey, RequestAccountExportPrivateKey, RequestChangeMasterPassword, RequestMigratePassword, RequestMigrateSoloAccount, RequestMigrateUnifiedAndFetchEligibleSoloAccounts, RequestPingSession, ResponseAccountCreateWithSecretKey, ResponseAccountExportPrivateKey, ResponseChangeMasterPassword, ResponseMigratePassword } from '@subwallet/extension-base/background/KoniTypes';
2
2
  import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
3
3
  import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
4
4
  import { AccountProxyMap, CurrentAccountInfo, RequestAccountBatchExportV2, RequestAccountCreateSuriV2, RequestAccountNameValidate, RequestAccountProxyEdit, RequestAccountProxyForget, RequestBatchJsonGetAccountInfo, RequestBatchRestoreV2, RequestChangeTonWalletContractVersion, RequestCheckPublicAndSecretKey, RequestDeriveCreateMultiple, RequestDeriveCreateV3, RequestDeriveValidateV2, RequestExportAccountProxyMnemonic, RequestGetAllTonWalletContractVersion, RequestGetDeriveAccounts, RequestGetDeriveSuggestion, RequestJsonGetAccountInfo, RequestJsonRestoreV2, RequestMnemonicCreateV2, RequestMnemonicValidateV2, RequestPrivateKeyValidateV2, ResponseAccountBatchExportV2, ResponseAccountCreateSuriV2, ResponseAccountNameValidate, ResponseBatchJsonGetAccountInfo, ResponseCheckPublicAndSecretKey, ResponseDeriveValidateV2, ResponseExportAccountProxyMnemonic, ResponseGetAllTonWalletContractVersion, ResponseGetDeriveAccounts, ResponseGetDeriveSuggestion, ResponseJsonGetAccountInfo, ResponseMnemonicCreateV2, ResponseMnemonicValidateV2, ResponsePrivateKeyValidateV2 } from '@subwallet/extension-base/types';
@@ -15,6 +15,7 @@ export declare class AccountContext {
15
15
  private readonly ledgerHandler;
16
16
  private readonly modifyHandler;
17
17
  private readonly secretHandler;
18
+ private readonly migrationHandler;
18
19
  constructor(koniState: KoniState, parentService: KeyringService);
19
20
  get pairs(): SubjectInfo;
20
21
  get observable(): {
@@ -81,9 +82,12 @@ export declare class AccountContext {
81
82
  getListDeriveAccounts(request: RequestGetDeriveAccounts): ResponseGetDeriveAccounts;
82
83
  validateDerivePath(request: RequestDeriveValidateV2): ResponseDeriveValidateV2;
83
84
  getDeriveSuggestion(request: RequestGetDeriveSuggestion): ResponseGetDeriveSuggestion;
84
- derivationAccountProxyCreate(request: RequestDeriveCreateV3): boolean;
85
+ derivationAccountProxyCreate(request: RequestDeriveCreateV3, isMigration?: boolean): boolean;
85
86
  addInjectAccounts(accounts: InjectedAccountWithMeta[]): void;
86
87
  removeInjectAccounts(_addresses: string[]): void;
88
+ migrateUnifiedAndFetchEligibleSoloAccounts(request: RequestMigrateUnifiedAndFetchEligibleSoloAccounts, setMigratingModeFn: () => void): Promise<import("@subwallet/extension-base/background/KoniTypes").ResponseMigrateUnifiedAndFetchEligibleSoloAccounts>;
89
+ migrateSoloAccount(request: RequestMigrateSoloAccount): import("@subwallet/extension-base/background/KoniTypes").ResponseMigrateSoloAccount;
90
+ pingSession(request: RequestPingSession): boolean;
87
91
  removeNoneHardwareGenesisHash(): void;
88
92
  updateMetadataForPair(): void;
89
93
  resetWallet(): void;
@@ -1,6 +1,7 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { AccountMigrationHandler } from '@subwallet/extension-base/services/keyring-service/context/handlers/Migration';
4
5
  import { AccountDeriveHandler, AccountInjectHandler, AccountJsonHandler, AccountLedgerHandler, AccountMnemonicHandler, AccountModifyHandler, AccountSecretHandler } from "./handlers/index.js";
5
6
  import { AccountState } from "./state.js";
6
7
  export class AccountContext {
@@ -15,6 +16,7 @@ export class AccountContext {
15
16
  this.ledgerHandler = new AccountLedgerHandler(this.parentService, this.state);
16
17
  this.modifyHandler = new AccountModifyHandler(this.parentService, this.state);
17
18
  this.secretHandler = new AccountSecretHandler(this.parentService, this.state);
19
+ this.migrationHandler = new AccountMigrationHandler(this.parentService, this.state);
18
20
  }
19
21
 
20
22
  // TODO: Merge to value
@@ -222,8 +224,8 @@ export class AccountContext {
222
224
  }
223
225
 
224
226
  /* Derive account proxy */
225
- derivationAccountProxyCreate(request) {
226
- return this.deriveHandler.derivationAccountProxyCreate(request);
227
+ derivationAccountProxyCreate(request, isMigration) {
228
+ return this.deriveHandler.derivationAccountProxyCreate(request, isMigration);
227
229
  }
228
230
 
229
231
  /* Derive */
@@ -239,6 +241,19 @@ export class AccountContext {
239
241
 
240
242
  /* Inject */
241
243
 
244
+ /* Migration */
245
+ async migrateUnifiedAndFetchEligibleSoloAccounts(request, setMigratingModeFn) {
246
+ return await this.migrationHandler.migrateUnifiedAndFetchEligibleSoloAccounts(request, setMigratingModeFn);
247
+ }
248
+ migrateSoloAccount(request) {
249
+ return this.migrationHandler.migrateSoloToUnifiedAccount(request);
250
+ }
251
+ pingSession(request) {
252
+ return this.migrationHandler.pingSession(request);
253
+ }
254
+
255
+ /* Migration */
256
+
242
257
  /* Others */
243
258
 
244
259
  removeNoneHardwareGenesisHash() {
@@ -25,5 +25,5 @@ export declare class AccountDeriveHandler extends AccountBaseHandler {
25
25
  /**
26
26
  * Derive account proxy
27
27
  * */
28
- derivationAccountProxyCreate(request: RequestDeriveCreateV3): boolean;
28
+ derivationAccountProxyCreate(request: RequestDeriveCreateV3, isMigration?: boolean): boolean;
29
29
  }
@@ -9,7 +9,7 @@ import { keyring } from '@subwallet/ui-keyring';
9
9
  import { t } from 'i18next';
10
10
  import { assert } from '@polkadot/util';
11
11
  import { AccountBaseHandler } from "./Base.js";
12
- const validDeriveKeypairTypes = [...SubstrateKeypairTypes, ...EthereumKeypairTypes, 'ton'];
12
+ const validDeriveKeypairTypes = [...SubstrateKeypairTypes, ...EthereumKeypairTypes, 'ton', 'cardano'];
13
13
 
14
14
  /**
15
15
  * @class AccountDeriveHandler
@@ -208,7 +208,7 @@ export class AccountDeriveHandler extends AccountBaseHandler {
208
208
  /**
209
209
  * Derive account proxy
210
210
  * */
211
- derivationAccountProxyCreate(request) {
211
+ derivationAccountProxyCreate(request, isMigration = false) {
212
212
  const {
213
213
  name,
214
214
  proxyId: deriveId,
@@ -219,7 +219,7 @@ export class AccountDeriveHandler extends AccountBaseHandler {
219
219
  const rootId = this.state.value.accounts[parentProxyId].parentId || parentProxyId;
220
220
  const rootProxyId = this.state.belongUnifiedAccount(rootId) || rootId;
221
221
  const nameExists = this.state.checkNameExists(name);
222
- if (nameExists) {
222
+ if (nameExists && !isMigration) {
223
223
  throw new SWCommonAccountError(CommonAccountErrorType.ACCOUNT_NAME_EXISTED);
224
224
  }
225
225
  const validateRs = this.validateDerivePath({
@@ -343,11 +343,13 @@ export class AccountDeriveHandler extends AccountBaseHandler {
343
343
  }
344
344
  const addresses = pairs.map(pair => pair.address);
345
345
  const exists = this.state.checkAddressExists(addresses);
346
- assert(!exists, t('Account already exists under the name "{{name}}"', {
347
- replace: {
348
- name: (exists === null || exists === void 0 ? void 0 : exists.name) || (exists === null || exists === void 0 ? void 0 : exists.address) || ''
349
- }
350
- }));
346
+ if (!isMigration) {
347
+ assert(!exists, t('Account already exists under the name "{{name}}"', {
348
+ replace: {
349
+ name: (exists === null || exists === void 0 ? void 0 : exists.name) || (exists === null || exists === void 0 ? void 0 : exists.address) || ''
350
+ }
351
+ }));
352
+ }
351
353
  childAccountProxy && this.state.upsertAccountProxyByKey(childAccountProxy);
352
354
  this.state.upsertModifyPairs(modifyPairs);
353
355
  for (const childPair of pairs) {
@@ -0,0 +1,17 @@
1
+ import { RequestMigrateSoloAccount, RequestMigrateUnifiedAndFetchEligibleSoloAccounts, RequestPingSession, ResponseMigrateSoloAccount, ResponseMigrateUnifiedAndFetchEligibleSoloAccounts, SoloAccountToBeMigrated } from '@subwallet/extension-base/background/KoniTypes';
2
+ import { AccountBaseHandler } from '@subwallet/extension-base/services/keyring-service/context/handlers/Base';
3
+ import { AccountProxy } from '@subwallet/extension-base/types';
4
+ export declare const SESSION_TIMEOUT = 10000;
5
+ export declare class AccountMigrationHandler extends AccountBaseHandler {
6
+ private sessionIdToPassword;
7
+ pingSession({ sessionId }: RequestPingSession): boolean;
8
+ migrateUnifiedAndFetchEligibleSoloAccounts(request: RequestMigrateUnifiedAndFetchEligibleSoloAccounts, setMigratingModeFn: () => void): Promise<ResponseMigrateUnifiedAndFetchEligibleSoloAccounts>;
9
+ migrateUnifiedToUnifiedAccount(password: string, accountProxies: AccountProxy[], setMigratingModeFn: () => void): Promise<string[]>;
10
+ getUACanBeMigrated(accountProxies: AccountProxy[]): AccountProxy[];
11
+ getSoloAccountsNeedToBeMigrated(accountProxies: AccountProxy[]): AccountProxy[];
12
+ groupSoloAccountByMnemonic(password: string, accountProxies: AccountProxy[]): Record<string, AccountProxy[]>;
13
+ accountProxiesToEligibleSoloAccountMap(accountProxyMap: Record<string, AccountProxy[]>): Record<string, SoloAccountToBeMigrated[]>;
14
+ sortUAByParent(accountProxies: AccountProxy[]): AccountProxy[];
15
+ migrateSoloToUnifiedAccount(request: RequestMigrateSoloAccount): ResponseMigrateSoloAccount;
16
+ migrateDerivedSoloAccountRelationship(soloAccounts: SoloAccountToBeMigrated[]): void;
17
+ }
@@ -0,0 +1,258 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AccountBaseHandler } from '@subwallet/extension-base/services/keyring-service/context/handlers/Base';
5
+ import { AccountChainType, SUPPORTED_ACCOUNT_CHAIN_TYPES } from '@subwallet/extension-base/types';
6
+ import { createAccountProxyId, getDefaultKeypairTypeFromAccountChainType, getSuri } from '@subwallet/extension-base/utils';
7
+ import { generateRandomString } from '@subwallet/extension-base/utils/getId';
8
+ import { keyring } from '@subwallet/ui-keyring';
9
+ import { keyExtractSuri } from '@polkadot/util-crypto';
10
+ export const SESSION_TIMEOUT = 10000;
11
+ export class AccountMigrationHandler extends AccountBaseHandler {
12
+ sessionIdToPassword = {};
13
+ pingSession({
14
+ sessionId
15
+ }) {
16
+ if (!this.sessionIdToPassword[sessionId]) {
17
+ // todo: if no persistent sessionId, should we jump to enter password again?
18
+ throw Error(`Session ID ${sessionId} not found.`);
19
+ }
20
+ clearTimeout(this.sessionIdToPassword[sessionId].timeoutId);
21
+ this.sessionIdToPassword[sessionId].timeoutId = setTimeout(() => {
22
+ delete this.sessionIdToPassword[sessionId];
23
+ }, SESSION_TIMEOUT);
24
+ return true;
25
+ }
26
+ async migrateUnifiedAndFetchEligibleSoloAccounts(request, setMigratingModeFn) {
27
+ // Migrate unified -> unified
28
+ const password = request.password;
29
+ const allAccountProxies = Object.values(this.state.accounts);
30
+ const UACanBeMigrated = this.getUACanBeMigrated(allAccountProxies);
31
+ const UACanBeMigratedSortedByParent = this.sortUAByParent(UACanBeMigrated); // master account must be migrated before derived account
32
+ const migratedUnifiedAccountIds = await this.migrateUnifiedToUnifiedAccount(password, UACanBeMigratedSortedByParent, setMigratingModeFn);
33
+
34
+ // Get solo accounts can be migrated
35
+ const soloAccountsNeedToBeMigrated = this.getSoloAccountsNeedToBeMigrated(allAccountProxies);
36
+ const soloAccountsNeedToBeMigratedGroup = this.groupSoloAccountByMnemonic(password, soloAccountsNeedToBeMigrated);
37
+ const eligibleSoloAccountMap = this.accountProxiesToEligibleSoloAccountMap(soloAccountsNeedToBeMigratedGroup);
38
+
39
+ // Create persistent mapping sessionId <-> password
40
+ const uniqueId = Date.now().toString();
41
+ const timeoutId = setTimeout(() => delete this.sessionIdToPassword[uniqueId], SESSION_TIMEOUT * 2);
42
+ this.sessionIdToPassword[uniqueId] = {
43
+ password,
44
+ timeoutId
45
+ };
46
+ return {
47
+ migratedUnifiedAccountIds,
48
+ soloAccounts: eligibleSoloAccountMap,
49
+ sessionId: uniqueId
50
+ };
51
+ }
52
+ async migrateUnifiedToUnifiedAccount(password, accountProxies, setMigratingModeFn) {
53
+ keyring.unlockKeyring(password);
54
+ this.parentService.updateKeyringState();
55
+ setMigratingModeFn();
56
+ const unifiedAccountIds = [];
57
+ const modifiedPairs = structuredClone(this.state.modifyPairs);
58
+ const {
59
+ derivedUnifiedAccounts,
60
+ masterUnifiedAccounts
61
+ } = accountProxies.reduce((accountInfo, account) => {
62
+ const isDerivedAccount = !!account.parentId;
63
+ isDerivedAccount ? accountInfo.derivedUnifiedAccounts.push(account) : accountInfo.masterUnifiedAccounts.push(account);
64
+ return accountInfo;
65
+ }, {
66
+ derivedUnifiedAccounts: [],
67
+ masterUnifiedAccounts: []
68
+ });
69
+ try {
70
+ for (const unifiedAccount of masterUnifiedAccounts) {
71
+ const proxyId = unifiedAccount.id;
72
+ const mnemonic = this.parentService.context.exportAccountProxyMnemonic({
73
+ password,
74
+ proxyId
75
+ }).result;
76
+ const newChainTypes = Object.values(AccountChainType).filter(type => !unifiedAccount.chainTypes.includes(type) && SUPPORTED_ACCOUNT_CHAIN_TYPES.includes(type));
77
+ const keypairTypes = newChainTypes.map(chainType => getDefaultKeypairTypeFromAccountChainType(chainType));
78
+ keypairTypes.forEach(type => {
79
+ const suri = getSuri(mnemonic, type);
80
+ const pair = keyring.createFromUri(suri, {}, type);
81
+ const address = pair.address;
82
+ modifiedPairs[address] = {
83
+ accountProxyId: proxyId,
84
+ migrated: true,
85
+ key: address
86
+ };
87
+ });
88
+ keypairTypes.forEach(type => {
89
+ const suri = getSuri(mnemonic, type);
90
+ const {
91
+ derivePath
92
+ } = keyExtractSuri(suri);
93
+ const metadata = {
94
+ name: unifiedAccount.name,
95
+ derivationPath: derivePath ? derivePath.substring(1) : undefined
96
+ };
97
+ const rs = keyring.addUri(suri, metadata, type);
98
+ const address = rs.pair.address;
99
+ this.state._addAddressToAuthList(address, true);
100
+ });
101
+ this.state.upsertModifyPairs(modifiedPairs);
102
+ unifiedAccountIds.push(proxyId);
103
+ }
104
+ await new Promise(resolve => setTimeout(resolve, 1800)); // Wait last master unified account migrated. // todo: can be optimized later by await a promise resolve if master account is migrating
105
+
106
+ for (const unifiedAccount of derivedUnifiedAccounts) {
107
+ this.parentService.context.derivationAccountProxyCreate({
108
+ name: unifiedAccount.name,
109
+ suri: unifiedAccount.suri || '',
110
+ proxyId: unifiedAccount.parentId || ''
111
+ }, true);
112
+ unifiedAccountIds.push(unifiedAccount.id);
113
+ }
114
+ } catch (error) {
115
+ console.error('Migration unified account failed with error:', error);
116
+ } finally {
117
+ keyring.lockAll(false);
118
+ this.parentService.updateKeyringState();
119
+ }
120
+ return unifiedAccountIds;
121
+ }
122
+ getUACanBeMigrated(accountProxies) {
123
+ return accountProxies.filter(account => this.state.isUnifiedAccount(account.id) && account.isNeedMigrateUnifiedAccount);
124
+ }
125
+ getSoloAccountsNeedToBeMigrated(accountProxies) {
126
+ return accountProxies.filter(account => !this.state.isUnifiedAccount(account.id) && account.isNeedMigrateUnifiedAccount);
127
+ }
128
+ groupSoloAccountByMnemonic(password, accountProxies) {
129
+ const parentService = this.parentService;
130
+ return accountProxies.reduce(function (rs, item) {
131
+ const oldProxyId = item.id;
132
+ const mnemonic = parentService.context.exportAccountProxyMnemonic({
133
+ password,
134
+ proxyId: oldProxyId
135
+ }).result;
136
+ const upcomingProxyId = createAccountProxyId(mnemonic);
137
+ if (!rs[upcomingProxyId]) {
138
+ rs[upcomingProxyId] = [];
139
+ }
140
+ rs[upcomingProxyId].push(item);
141
+ return rs;
142
+ }, {});
143
+ }
144
+ accountProxiesToEligibleSoloAccountMap(accountProxyMap) {
145
+ const eligibleSoloAccountMap = {};
146
+ Object.entries(accountProxyMap).forEach(([upcomingProxyId, accounts]) => {
147
+ eligibleSoloAccountMap[upcomingProxyId] = accounts.map(account => {
148
+ return {
149
+ upcomingProxyId,
150
+ proxyId: account.accounts[0].proxyId,
151
+ address: account.accounts[0].address,
152
+ name: account.name,
153
+ chainType: account.chainTypes[0]
154
+ };
155
+ });
156
+ });
157
+ return eligibleSoloAccountMap;
158
+ }
159
+ sortUAByParent(accountProxies) {
160
+ const undefinedToStr = str => str !== null && str !== void 0 ? str : '';
161
+ return accountProxies.sort((a, b) => undefinedToStr(a.parentId) < undefinedToStr(b.parentId) ? -1 : undefinedToStr(a.parentId) > undefinedToStr(b.parentId) ? 1 : 0);
162
+ }
163
+ migrateSoloToUnifiedAccount(request) {
164
+ const {
165
+ accountName,
166
+ sessionId,
167
+ soloAccounts
168
+ } = request;
169
+ const password = this.sessionIdToPassword[sessionId].password;
170
+ keyring.unlockKeyring(password);
171
+ this.parentService.updateKeyringState();
172
+ const modifiedPairs = structuredClone(this.state.modifyPairs);
173
+ const firstAccountInfo = soloAccounts[0];
174
+ const upcomingProxyId = firstAccountInfo.upcomingProxyId;
175
+ const firstAccountOldProxyId = firstAccountInfo.proxyId;
176
+ try {
177
+ const mnemonic = this.parentService.context.exportAccountProxyMnemonic({
178
+ password,
179
+ proxyId: firstAccountOldProxyId
180
+ }).result;
181
+ const keypairTypes = SUPPORTED_ACCOUNT_CHAIN_TYPES.map(chainType => getDefaultKeypairTypeFromAccountChainType(chainType));
182
+ keypairTypes.forEach(type => {
183
+ const suri = getSuri(mnemonic, type);
184
+ const pair = keyring.createFromUri(suri, {}, type);
185
+ const address = pair.address;
186
+ modifiedPairs[address] = {
187
+ accountProxyId: upcomingProxyId,
188
+ migrated: true,
189
+ key: address
190
+ };
191
+ });
192
+ this.state.upsertAccountProxyByKey({
193
+ id: upcomingProxyId,
194
+ name: accountName,
195
+ isMigrationDone: false
196
+ });
197
+ const soloAccountProxyIds = [];
198
+ keypairTypes.forEach(type => {
199
+ const suri = getSuri(mnemonic, type);
200
+ const {
201
+ derivePath
202
+ } = keyExtractSuri(suri);
203
+ const metadata = {
204
+ name: accountName.concat(' - ').concat(generateRandomString()),
205
+ derivationPath: derivePath ? derivePath.substring(1) : undefined
206
+ };
207
+ const rs = keyring.addUri(suri, metadata, type);
208
+ soloAccountProxyIds.push(rs.json.address);
209
+ const address = rs.pair.address;
210
+ this.state._addAddressToAuthList(address, true);
211
+ });
212
+ this.state.upsertModifyPairs(modifiedPairs);
213
+ this.migrateDerivedSoloAccountRelationship(soloAccounts);
214
+ this.state.upsertAccountProxyByKey({
215
+ id: upcomingProxyId,
216
+ name: accountName,
217
+ isMigrationDone: true
218
+ });
219
+
220
+ // Re-update account name
221
+ soloAccountProxyIds.forEach(oldProxyId => {
222
+ const pair = keyring.getPair(oldProxyId);
223
+ keyring.saveAccountMeta(pair, {
224
+ ...pair.meta,
225
+ name: accountName
226
+ });
227
+ });
228
+
229
+ // Update current account after migrating
230
+ const currentAccountProxyId = this.state.currentAccount.proxyId;
231
+ if (soloAccountProxyIds.includes(currentAccountProxyId)) {
232
+ this.state.saveCurrentAccountProxyId(upcomingProxyId);
233
+ }
234
+ } catch (error) {
235
+ console.error('Migration solo account failed with error', error);
236
+ } finally {
237
+ keyring.lockAll(false);
238
+ this.parentService.updateKeyringState();
239
+ }
240
+ return {
241
+ migratedUnifiedAccountId: upcomingProxyId
242
+ };
243
+ }
244
+ migrateDerivedSoloAccountRelationship(soloAccounts) {
245
+ const accountProxies = this.state.accountProxies;
246
+
247
+ // Use Set.has & Map.get to optimize search performance
248
+ const proxyIdsSet = new Set(soloAccounts.map(account => account.proxyId));
249
+ const proxyIdToUpcomingProxyIdMap = new Map(soloAccounts.map(account => [account.proxyId, account.upcomingProxyId]));
250
+ for (const account of Object.values(accountProxies)) {
251
+ const currentParent = account.parentId;
252
+ if (currentParent && proxyIdsSet.has(currentParent)) {
253
+ accountProxies[account.id].parentId = proxyIdToUpcomingProxyIdMap.get(currentParent);
254
+ }
255
+ }
256
+ this.state.upsertAccountProxy(accountProxies);
257
+ }
258
+ }
@@ -27,7 +27,7 @@ export class AccountMnemonicHandler extends AccountBaseHandler {
27
27
  mnemonic: _seed,
28
28
  type = 'general'
29
29
  }) {
30
- const types = type === 'general' ? ['sr25519', 'ethereum', 'ton'] : ['ton-native'];
30
+ const types = type === 'general' ? ['sr25519', 'ethereum', 'ton', 'cardano'] : ['ton-native'];
31
31
  const seed = _seed || type === 'general' ? mnemonicGenerate(length) : await tonMnemonicGenerate(length);
32
32
  const rs = {
33
33
  mnemonic: seed,
@@ -97,7 +97,7 @@ export class AccountMnemonicHandler extends AccountBaseHandler {
97
97
  const addressDict = {};
98
98
  let changedAccount = false;
99
99
  const hasMasterPassword = keyring.keyring.hasMasterPassword;
100
- const types = type ? [type] : ['sr25519', 'ethereum', 'ton'];
100
+ const types = type ? [type] : ['sr25519', 'ethereum', 'ton', 'cardano'];
101
101
  if (!hasMasterPassword) {
102
102
  if (!password) {
103
103
  throw Error(t('The password of each account is needed to set up master password'));