@subwallet/extension-base 1.3.20-0 → 1.3.22-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 (123) hide show
  1. package/background/KoniTypes.d.ts +8 -1
  2. package/cjs/defaults.js +1 -1
  3. package/cjs/koni/background/handlers/Extension.js +519 -90
  4. package/cjs/packageInfo.js +1 -1
  5. package/cjs/services/chain-service/constants.js +8 -3
  6. package/cjs/services/chain-service/handler/EvmApi.js +1 -3
  7. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -2
  8. package/cjs/services/chain-service/index.js +9 -0
  9. package/cjs/services/chain-service/utils/patch.js +1 -1
  10. package/cjs/services/earning-service/constants/chains.js +2 -1
  11. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +19 -8
  12. package/cjs/services/earning-service/handlers/native-staking/mythos.js +337 -0
  13. package/cjs/services/earning-service/handlers/special.js +16 -10
  14. package/cjs/services/earning-service/service.js +4 -0
  15. package/cjs/services/earning-service/utils/index.js +2 -0
  16. package/cjs/services/history-service/helpers/recoverHistoryStatus.js +14 -5
  17. package/cjs/services/history-service/index.js +15 -3
  18. package/cjs/services/inapp-notification-service/index.js +78 -0
  19. package/cjs/services/inapp-notification-service/interfaces.js +2 -0
  20. package/cjs/services/keyring-service/context/state.js +2 -1
  21. package/cjs/services/migration-service/scripts/databases/ClearMetadataDatabase.js +3 -23
  22. package/cjs/services/migration-service/scripts/databases/ClearMetadataForChains.js +40 -0
  23. package/cjs/services/migration-service/scripts/databases/ClearMetadataForMythos.js +15 -0
  24. package/cjs/services/migration-service/scripts/index.js +6 -2
  25. package/cjs/services/request-service/handler/EvmRequestHandler.js +10 -0
  26. package/cjs/services/request-service/handler/SubstrateRequestHandler.js +4 -3
  27. package/cjs/services/request-service/index.js +2 -2
  28. package/cjs/services/setting-service/constants.js +5 -2
  29. package/cjs/services/storage-service/DatabaseService.js +101 -2
  30. package/cjs/services/storage-service/databases/index.js +3 -0
  31. package/cjs/services/storage-service/db-stores/Metadata.js +3 -0
  32. package/cjs/services/storage-service/db-stores/Migration.js +6 -1
  33. package/cjs/services/storage-service/db-stores/ProcessTransaction.js +47 -0
  34. package/cjs/services/storage-service/db-stores/Transaction.js +2 -0
  35. package/cjs/services/storage-service/db-stores/index.js +8 -1
  36. package/cjs/services/swap-service/handler/asset-hub/handler.js +30 -11
  37. package/cjs/services/swap-service/handler/hydradx-handler.js +18 -10
  38. package/cjs/services/swap-service/index.js +3 -0
  39. package/cjs/services/swap-service/utils.js +1 -0
  40. package/cjs/services/transaction-service/index.js +218 -9
  41. package/cjs/types/index.js +11 -0
  42. package/cjs/types/setting.js +1 -0
  43. package/cjs/types/swap/index.js +4 -1
  44. package/cjs/types/transaction/index.js +11 -0
  45. package/cjs/types/transaction/process.js +28 -0
  46. package/cjs/types/yield/actions/join/submit.js +16 -1
  47. package/defaults.d.ts +1 -1
  48. package/defaults.js +1 -1
  49. package/koni/background/handlers/Extension.d.ts +5 -0
  50. package/koni/background/handlers/Extension.js +437 -12
  51. package/package.json +52 -22
  52. package/packageInfo.js +1 -1
  53. package/services/chain-service/constants.js +8 -3
  54. package/services/chain-service/handler/EvmApi.js +1 -3
  55. package/services/chain-service/handler/SubstrateChainHandler.js +3 -2
  56. package/services/chain-service/index.d.ts +1 -0
  57. package/services/chain-service/index.js +9 -0
  58. package/services/chain-service/utils/patch.js +1 -1
  59. package/services/earning-service/constants/chains.d.ts +1 -0
  60. package/services/earning-service/constants/chains.js +2 -1
  61. package/services/earning-service/handlers/liquid-staking/stella-swap.js +19 -8
  62. package/services/earning-service/handlers/native-staking/mythos.d.ts +35 -0
  63. package/services/earning-service/handlers/native-staking/mythos.js +329 -0
  64. package/services/earning-service/handlers/special.js +18 -12
  65. package/services/earning-service/service.js +4 -0
  66. package/services/earning-service/utils/index.js +2 -0
  67. package/services/history-service/helpers/recoverHistoryStatus.js +14 -5
  68. package/services/history-service/index.d.ts +6 -5
  69. package/services/history-service/index.js +16 -5
  70. package/services/inapp-notification-service/index.d.ts +2 -0
  71. package/services/inapp-notification-service/index.js +79 -1
  72. package/services/inapp-notification-service/interfaces.d.ts +8 -1
  73. package/services/inapp-notification-service/interfaces.js +2 -0
  74. package/services/keyring-service/context/state.d.ts +1 -1
  75. package/services/keyring-service/context/state.js +3 -2
  76. package/services/migration-service/scripts/databases/ClearMetadataDatabase.d.ts +3 -3
  77. package/services/migration-service/scripts/databases/ClearMetadataDatabase.js +3 -23
  78. package/services/migration-service/scripts/databases/ClearMetadataForChains.d.ts +5 -0
  79. package/services/migration-service/scripts/databases/ClearMetadataForChains.js +32 -0
  80. package/services/migration-service/scripts/databases/ClearMetadataForMythos.d.ts +4 -0
  81. package/services/migration-service/scripts/databases/ClearMetadataForMythos.js +7 -0
  82. package/services/migration-service/scripts/index.d.ts +1 -0
  83. package/services/migration-service/scripts/index.js +4 -1
  84. package/services/request-service/handler/EvmRequestHandler.js +10 -0
  85. package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -1
  86. package/services/request-service/handler/SubstrateRequestHandler.js +4 -3
  87. package/services/request-service/index.d.ts +1 -1
  88. package/services/request-service/index.js +2 -2
  89. package/services/setting-service/constants.d.ts +1 -0
  90. package/services/setting-service/constants.js +3 -1
  91. package/services/storage-service/DatabaseService.d.ts +13 -3
  92. package/services/storage-service/DatabaseService.js +103 -4
  93. package/services/storage-service/databases/index.d.ts +2 -1
  94. package/services/storage-service/databases/index.js +3 -0
  95. package/services/storage-service/db-stores/Metadata.d.ts +1 -0
  96. package/services/storage-service/db-stores/Metadata.js +3 -0
  97. package/services/storage-service/db-stores/Migration.d.ts +1 -0
  98. package/services/storage-service/db-stores/Migration.js +6 -1
  99. package/services/storage-service/db-stores/ProcessTransaction.d.ts +14 -0
  100. package/services/storage-service/db-stores/ProcessTransaction.js +39 -0
  101. package/services/storage-service/db-stores/Transaction.js +2 -0
  102. package/services/storage-service/db-stores/index.d.ts +1 -0
  103. package/services/storage-service/db-stores/index.js +2 -1
  104. package/services/swap-service/handler/asset-hub/handler.js +30 -11
  105. package/services/swap-service/handler/hydradx-handler.js +18 -10
  106. package/services/swap-service/index.js +3 -0
  107. package/services/swap-service/utils.js +1 -0
  108. package/services/transaction-service/index.d.ts +19 -1
  109. package/services/transaction-service/index.js +220 -11
  110. package/services/transaction-service/types.d.ts +13 -4
  111. package/types/index.d.ts +1 -0
  112. package/types/index.js +1 -0
  113. package/types/setting.d.ts +3 -0
  114. package/types/setting.js +1 -0
  115. package/types/swap/index.d.ts +3 -2
  116. package/types/swap/index.js +4 -1
  117. package/types/transaction/index.d.ts +1 -0
  118. package/types/transaction/index.js +1 -0
  119. package/types/transaction/process.d.ts +84 -0
  120. package/types/transaction/process.js +20 -0
  121. package/types/transaction/request.d.ts +3 -1
  122. package/types/yield/actions/join/submit.d.ts +18 -3
  123. package/types/yield/actions/join/submit.js +11 -1
@@ -6,10 +6,12 @@ import { 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';
9
+ import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning-service/constants';
9
10
  import { NotificationDescriptionMap, NotificationTitleMap, ONE_DAY_MILLISECOND } from '@subwallet/extension-base/services/inapp-notification-service/consts';
10
11
  import { NotificationActionType, NotificationTab } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
11
12
  import { AvailBridgeSourceChain, fetchAllAvailBridgeClaimable, fetchPolygonBridgeTransactions, hrsToMillisecond } from '@subwallet/extension-base/services/inapp-notification-service/utils';
12
- import { categoryAddresses, formatNumber } from '@subwallet/extension-base/utils';
13
+ import { ProcessType, YieldPoolType } from '@subwallet/extension-base/types';
14
+ import { categoryAddresses, formatNumber, reformatAddress } from '@subwallet/extension-base/utils';
13
15
  import { isSubstrateAddress } from '@subwallet/keyring';
14
16
  export class InappNotificationService {
15
17
  constructor(dbService, keyringService, eventService, chainService) {
@@ -126,6 +128,17 @@ export class InappNotificationService {
126
128
  }
127
129
  }
128
130
  }
131
+ if ([NotificationActionType.SWAP, NotificationActionType.EARNING].includes(candidateNotification.actionType)) {
132
+ const candidateMetadata = candidateNotification.metadata;
133
+ const processId = candidateMetadata.processId;
134
+ for (const notification of comparedNotifications) {
135
+ const comparedMetadata = notification.metadata;
136
+ const _processId = comparedMetadata.processId;
137
+ if (processId === _processId) {
138
+ return false;
139
+ }
140
+ }
141
+ }
129
142
  return true;
130
143
  }
131
144
  async validateAndWriteNotificationsToDB(notifications, address) {
@@ -319,6 +332,71 @@ export class InappNotificationService {
319
332
  });
320
333
  await this.validateAndWriteNotificationsToDB(notifications, address);
321
334
  }
335
+ async createProcessNotification(process) {
336
+ const timestamp = Date.now();
337
+ const _id = process.id;
338
+ const address = process.address;
339
+ let actionType;
340
+ let extrinsicType;
341
+ let title = '';
342
+ let description = '';
343
+ if (process.type === ProcessType.SWAP) {
344
+ actionType = NotificationActionType.SWAP;
345
+ extrinsicType = ExtrinsicType.SWAP;
346
+ const combineInfo = process.combineInfo;
347
+ const fromAsset = this.chainService.getAssetBySlug(combineInfo.quote.pair.from);
348
+ const toAsset = this.chainService.getAssetBySlug(combineInfo.quote.pair.to);
349
+ const fromChain = this.chainService.getChainInfoByKey(fromAsset.originChain);
350
+ const toChain = this.chainService.getChainInfoByKey(toAsset.originChain);
351
+ title = '[{{accountName}}] SWAPPED {{fromAsset}}'.replace('{{fromAsset}}', fromAsset.symbol);
352
+ description = '{{fromAmount}} {{fromAsset}} on {{fromChain}} swapped for {{toAmount}} {{toAsset}} on {{toChain}}. Click to view details'.replace('{{fromAmount}}', formatNumber(combineInfo.quote.fromAmount, fromAsset.decimals || 0)).replace('{{fromAsset}}', fromAsset.symbol).replace('{{fromChain}}', fromChain.name).replace('{{toAmount}}', formatNumber(combineInfo.quote.toAmount, toAsset.decimals || 0)).replace('{{toAsset}}', toAsset.symbol).replace('{{toChain}}', toChain.name);
353
+ } else {
354
+ actionType = NotificationActionType.EARNING;
355
+ extrinsicType = ExtrinsicType.JOIN_YIELD_POOL; // Not used
356
+
357
+ const combineInfo = process.combineInfo;
358
+ const asset = this.chainService.getAssetBySlug(combineInfo.brief.token);
359
+ const chain = this.chainService.getChainInfoByKey(combineInfo.brief.chain);
360
+ const amount = combineInfo.brief.amount;
361
+ let method;
362
+ switch (combineInfo.brief.method) {
363
+ case YieldPoolType.LIQUID_STAKING:
364
+ method = 'Liquid staking';
365
+ break;
366
+ case YieldPoolType.LENDING:
367
+ method = 'Lending';
368
+ break;
369
+ case YieldPoolType.SINGLE_FARMING:
370
+ method = 'Single farming';
371
+ break;
372
+ case YieldPoolType.NOMINATION_POOL:
373
+ method = 'Nomination pool';
374
+ break;
375
+ case YieldPoolType.PARACHAIN_STAKING:
376
+ method = 'Parachain staking';
377
+ break;
378
+ case YieldPoolType.NATIVE_STAKING:
379
+ method = _STAKING_CHAIN_GROUP.astar.includes(chain.slug) ? 'dApp staking' : 'Direct nomination';
380
+ break;
381
+ }
382
+ title = '[{{accountName}}] STAKED {{asset}}'.replace('{{asset}}', asset.symbol);
383
+ description = '{{amount}} {{asset}} on {{chain}} staked via {{method}}. Click to view details'.replace('{{amount}}', formatNumber(amount, asset.decimals || 0)).replace('{{asset}}', asset.symbol).replace('{{chain}}', chain.name).replace('{{method}}', method);
384
+ }
385
+ const notification = {
386
+ id: `${actionType}___${_id}___${timestamp}`,
387
+ address: reformatAddress(address),
388
+ title,
389
+ actionType,
390
+ metadata: {
391
+ processId: process.id
392
+ },
393
+ time: timestamp,
394
+ description,
395
+ isRead: false,
396
+ extrinsicType
397
+ };
398
+ await this.validateAndWriteNotificationsToDB([notification], process.address);
399
+ }
322
400
 
323
401
  // Polygon Claimable Handle
324
402
 
@@ -28,6 +28,8 @@ export interface ActionTypeToMetadataMap {
28
28
  [NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_AVAIL]: ClaimAvailBridgeNotificationMetadata;
29
29
  [NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM]: ClaimAvailBridgeNotificationMetadata;
30
30
  [NotificationActionType.CLAIM_POLYGON_BRIDGE]: ClaimPolygonBridgeNotificationMetadata;
31
+ [NotificationActionType.SWAP]: ProcessNotificationMetadata;
32
+ [NotificationActionType.EARNING]: ProcessNotificationMetadata;
31
33
  }
32
34
  export interface SendReceiveNotificationMetadata {
33
35
  chain: string;
@@ -71,6 +73,9 @@ export interface ClaimPolygonBridgeNotificationMetadata {
71
73
  transactionInitiator?: string;
72
74
  userAddress: string;
73
75
  }
76
+ export interface ProcessNotificationMetadata {
77
+ processId: string;
78
+ }
74
79
  export declare enum NotificationTimePeriod {
75
80
  TODAY = "TODAY",
76
81
  THIS_WEEK = "THIS_WEEK",
@@ -83,7 +88,9 @@ export declare enum NotificationActionType {
83
88
  CLAIM = "CLAIM",
84
89
  CLAIM_AVAIL_BRIDGE_ON_AVAIL = "CLAIM_AVAIL_BRIDGE_ON_AVAIL",
85
90
  CLAIM_AVAIL_BRIDGE_ON_ETHEREUM = "CLAIM_AVAIL_BRIDGE_ON_ETHEREUM",
86
- CLAIM_POLYGON_BRIDGE = "CLAIM_POLYGON_BRIDGE"
91
+ CLAIM_POLYGON_BRIDGE = "CLAIM_POLYGON_BRIDGE",
92
+ SWAP = "SWAP",
93
+ EARNING = "EARNING"
87
94
  }
88
95
  export declare enum NotificationTab {
89
96
  ALL = "ALL",
@@ -22,6 +22,8 @@ export let NotificationActionType;
22
22
  NotificationActionType["CLAIM_AVAIL_BRIDGE_ON_AVAIL"] = "CLAIM_AVAIL_BRIDGE_ON_AVAIL";
23
23
  NotificationActionType["CLAIM_AVAIL_BRIDGE_ON_ETHEREUM"] = "CLAIM_AVAIL_BRIDGE_ON_ETHEREUM";
24
24
  NotificationActionType["CLAIM_POLYGON_BRIDGE"] = "CLAIM_POLYGON_BRIDGE";
25
+ NotificationActionType["SWAP"] = "SWAP";
26
+ NotificationActionType["EARNING"] = "EARNING";
25
27
  })(NotificationActionType || (NotificationActionType = {}));
26
28
  export let NotificationTab;
27
29
  (function (NotificationTab) {
@@ -64,7 +64,7 @@ export declare class AccountState {
64
64
  upsertAccountProxyByKey(data: AccountProxyData, callback?: () => void): void;
65
65
  deleteAccountProxy(key: string, callback?: () => void): void;
66
66
  isUnifiedAccount(proxyId: string): boolean;
67
- belongUnifiedAccount(address: string): string | undefined;
67
+ belongUnifiedAccount(_address: string): string | undefined;
68
68
  addressesByProxyId(proxyId: string): string[];
69
69
  upsertModifyPairs(data: ModifyPairStoreData): void;
70
70
  getAllAddresses(): string[];
@@ -6,7 +6,7 @@ import { AccountProxyStoreSubject, CurrentAccountStoreSubject, ModifyPairStoreSu
6
6
  import { SWStorage } from '@subwallet/extension-base/storage';
7
7
  import { AccountRefStore } from '@subwallet/extension-base/stores';
8
8
  import { AccountProxyType } from '@subwallet/extension-base/types';
9
- import { addLazy, combineAccountsWithSubjectInfo, isAddressValidWithAuthType, isSameAddress, parseUnifiedSuriToDerivationPath } from '@subwallet/extension-base/utils';
9
+ import { addLazy, combineAccountsWithSubjectInfo, isAddressValidWithAuthType, isSameAddress, parseUnifiedSuriToDerivationPath, reformatAddress } from '@subwallet/extension-base/utils';
10
10
  import { generateRandomString } from '@subwallet/extension-base/utils/getId';
11
11
  import { EthereumKeypairTypes } from '@subwallet/keyring/types';
12
12
  import { keyring } from '@subwallet/ui-keyring';
@@ -381,10 +381,11 @@ export class AccountState {
381
381
  const accountProxies = this.accounts;
382
382
  return Object.values(accountProxies).some(value => value.accountType === AccountProxyType.UNIFIED && value.id === proxyId);
383
383
  }
384
- belongUnifiedAccount(address) {
384
+ belongUnifiedAccount(_address) {
385
385
  var _modifyPairs$address;
386
386
  const modifyPairs = this.modifyPairs;
387
387
  const accountProxies = this.accountProxies;
388
+ const address = reformatAddress(_address);
388
389
  const proxyId = (_modifyPairs$address = modifyPairs[address]) === null || _modifyPairs$address === void 0 ? void 0 : _modifyPairs$address.accountProxyId;
389
390
  if (proxyId) {
390
391
  var _accountProxies$proxy;
@@ -1,4 +1,4 @@
1
- import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
- export default class ClearMetadataDatabase extends BaseMigrationJob {
3
- run(): Promise<void>;
1
+ import ClearMetadataForChains from './ClearMetadataForChains';
2
+ export default class ClearMetadataDatabase extends ClearMetadataForChains {
3
+ chains: string[];
4
4
  }
@@ -1,27 +1,7 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
5
- import { cacheMetadata, waitTimeout } from '@subwallet/extension-base/utils';
6
- export default class ClearMetadataDatabase extends BaseMigrationJob {
7
- async run() {
8
- // Clear all old metadata data
9
- await this.state.dbService.stores.metadata.clear();
10
- const activeChains = this.state.chainService.getActiveChains();
11
- const chainInfoMap = this.state.chainService.getChainInfoMap();
12
- const reloadChains = activeChains.filter(chain => {
13
- var _chainInfoMap$chain$s;
14
- return !!((_chainInfoMap$chain$s = chainInfoMap[chain].substrateInfo) !== null && _chainInfoMap$chain$s !== void 0 && _chainInfoMap$chain$s.genesisHash);
15
- });
16
- for (const chain of reloadChains) {
17
- const substrateApi = this.state.chainService.getSubstrateApi(chain);
18
- const callback = substrateApi => {
19
- cacheMetadata(chain, substrateApi, this.state.chainService);
20
- };
21
- Promise.race([substrateApi.isReady, waitTimeout(2000)]).finally(() => {
22
- substrateApi === null || substrateApi === void 0 ? void 0 : substrateApi.connect(callback);
23
- });
24
- }
25
- return Promise.resolve();
26
- }
4
+ import ClearMetadataForChains from "./ClearMetadataForChains.js";
5
+ export default class ClearMetadataDatabase extends ClearMetadataForChains {
6
+ chains = [];
27
7
  }
@@ -0,0 +1,5 @@
1
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
+ export default abstract class ClearMetadataForChains extends BaseMigrationJob {
3
+ protected abstract chains: string[];
4
+ run(): Promise<void>;
5
+ }
@@ -0,0 +1,32 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
5
+ import { cacheMetadata, waitTimeout } from '@subwallet/extension-base/utils';
6
+ export default class ClearMetadataForChains extends BaseMigrationJob {
7
+ async run() {
8
+ const isClearAll = this.chains.length === 0;
9
+ if (isClearAll) {
10
+ // Clear all old metadata data
11
+ await this.state.dbService.stores.metadata.clear();
12
+ } else {
13
+ await this.state.dbService.stores.metadata.clearByChains(this.chains);
14
+ }
15
+ const activeChains = this.state.chainService.getActiveChains();
16
+ const chainInfoMap = this.state.chainService.getChainInfoMap();
17
+ const reloadChains = activeChains.filter(chain => {
18
+ var _chainInfoMap$chain$s;
19
+ return !!((_chainInfoMap$chain$s = chainInfoMap[chain].substrateInfo) !== null && _chainInfoMap$chain$s !== void 0 && _chainInfoMap$chain$s.genesisHash) && (isClearAll || this.chains.includes(chain));
20
+ });
21
+ for (const chain of reloadChains) {
22
+ const substrateApi = this.state.chainService.getSubstrateApi(chain);
23
+ const callback = substrateApi => {
24
+ cacheMetadata(chain, substrateApi, this.state.chainService);
25
+ };
26
+ Promise.race([substrateApi.isReady, waitTimeout(2000)]).finally(() => {
27
+ substrateApi === null || substrateApi === void 0 ? void 0 : substrateApi.connect(callback);
28
+ });
29
+ }
30
+ return Promise.resolve();
31
+ }
32
+ }
@@ -0,0 +1,4 @@
1
+ import ClearMetadataForChains from './ClearMetadataForChains';
2
+ export default class ClearMetadataForMythos extends ClearMetadataForChains {
3
+ chains: string[];
4
+ }
@@ -0,0 +1,7 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import ClearMetadataForChains from "./ClearMetadataForChains.js";
5
+ export default class ClearMetadataForMythos extends ClearMetadataForChains {
6
+ chains = ['mythos', 'muse_testnet'];
7
+ }
@@ -1,4 +1,5 @@
1
1
  import BaseMigrationJob from '../Base';
2
2
  export declare const EVERYTIME = "__everytime__";
3
+ export declare const MYTHOS_MIGRATION_KEY = "1.3.21-01";
3
4
  declare const _default: Record<string, typeof BaseMigrationJob>;
4
5
  export default _default;
@@ -3,6 +3,7 @@
3
3
 
4
4
  import AutoEnableSomeTokens from "./databases/AutoEnableSomeTokens.js";
5
5
  import ClearMetadataDatabase from "./databases/ClearMetadataDatabase.js";
6
+ import ClearMetadataForMythos from "./databases/ClearMetadataForMythos.js";
6
7
  import MigrateAssetSetting from "./databases/MigrateAssetSetting.js";
7
8
  import MigrateEarningVersion from "./databases/MigrateEarningVersion.js";
8
9
  import ReloadMetadata from "./databases/ReloadMetadata.js";
@@ -31,6 +32,7 @@ import MigrateTransactionHistoryBridge from "./MigrateTransactionHistoryBridge.j
31
32
  import MigrateTransactionHistoryBySymbol from "./MigrateTransactionHistoryBySymbol.js";
32
33
  import MigrateWalletReference from "./MigrateWalletReference.js";
33
34
  export const EVERYTIME = '__everytime__';
35
+ export const MYTHOS_MIGRATION_KEY = '1.3.21-01';
34
36
  export default {
35
37
  '1.0.1-11': MigrateNetworkSettings,
36
38
  '1.0.1-20': MigrateImportedToken,
@@ -61,7 +63,8 @@ export default {
61
63
  '1.2.13-01': ReloadMetadata,
62
64
  '1.2.32-01': MigratePairData,
63
65
  '1.3.6-01': MigrateTransactionHistoryBridge,
64
- '1.3.10-01': ClearMetadataDatabase
66
+ '1.3.10-01': ClearMetadataDatabase,
67
+ [MYTHOS_MIGRATION_KEY]: ClearMetadataForMythos
65
68
  // [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
66
69
  // [`${EVERYTIME}-1`]: AutoEnableChainsTokens
67
70
  };
@@ -77,6 +77,16 @@ export default class EvmRequestHandler {
77
77
  if (!isInternal) {
78
78
  this.#requestService.popupOpen();
79
79
  }
80
+ if (options.isPassConfirmation) {
81
+ await this.completeConfirmation({
82
+ evmSendTransactionRequest: {
83
+ id,
84
+ url,
85
+ isApproved: true,
86
+ payload: ''
87
+ }
88
+ });
89
+ }
80
90
  this.#requestService.updateIconV2();
81
91
  return promise;
82
92
  }
@@ -13,6 +13,6 @@ export default class SubstrateRequestHandler {
13
13
  private signComplete;
14
14
  get numSubstrateRequests(): number;
15
15
  sign(url: string, request: RequestSign, _id?: string): Promise<ResponseSigning>;
16
- signTransaction(id: string, address: string, url: string, payload: SignerPayloadJSON): Promise<ResponseSigning>;
16
+ signTransaction(id: string, address: string, url: string, payload: SignerPayloadJSON, onSign?: (id: string) => void): Promise<ResponseSigning>;
17
17
  resetWallet(): void;
18
18
  }
@@ -74,9 +74,9 @@ export default class SubstrateRequestHandler {
74
74
  this.#requestService.popupOpen();
75
75
  });
76
76
  }
77
- async signTransaction(id, address, url, payload) {
77
+ async signTransaction(id, address, url, payload, onSign) {
78
78
  const isAlwaysRequired = await this.#requestService.settingService.isAlwaysRequired;
79
- if (isAlwaysRequired) {
79
+ if (isAlwaysRequired && !onSign) {
80
80
  this.#requestService.keyringService.lock();
81
81
  }
82
82
  return new Promise((resolve, reject) => {
@@ -88,9 +88,10 @@ export default class SubstrateRequestHandler {
88
88
  url: url
89
89
  };
90
90
  this.updateIconSign();
91
- if (!isInternalRequest(url)) {
91
+ if (!isInternalRequest(url) && !onSign) {
92
92
  this.#requestService.popupOpen();
93
93
  }
94
+ onSign === null || onSign === void 0 ? void 0 : onSign(id);
94
95
  });
95
96
  }
96
97
  resetWallet() {
@@ -50,7 +50,7 @@ export default class RequestService {
50
50
  get confirmationsQueueSubject(): BehaviorSubject<ConfirmationsQueue>;
51
51
  get confirmationsQueueSubjectTon(): BehaviorSubject<ConfirmationsQueueTon>;
52
52
  getSignRequest(id: string): import("./types").SignRequest | undefined;
53
- signInternalTransaction(id: string, address: string, url: string, payload: SignerPayloadJSON): Promise<ResponseSigning>;
53
+ signInternalTransaction(id: string, address: string, url: string, payload: SignerPayloadJSON, onSign?: (id: string) => void): Promise<ResponseSigning>;
54
54
  addConfirmation<CT extends ConfirmationType>(id: string, url: string, type: CT, payload: ConfirmationDefinitions[CT][0]['payload'], options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitions[CT][1]) => Error | undefined): Promise<ConfirmationDefinitions[CT][1]>;
55
55
  addConfirmationTon<CT extends ConfirmationTypeTon>(id: string, url: string, type: CT, payload: ConfirmationDefinitionsTon[CT][0]['payload'], // todo: messages <-> payload
56
56
  options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitionsTon[CT][1]) => Error | undefined): Promise<ConfirmationDefinitionsTon[CT][1]>;
@@ -151,8 +151,8 @@ export default class RequestService {
151
151
  getSignRequest(id) {
152
152
  return this.#substrateRequestHandler.getSignRequest(id);
153
153
  }
154
- async signInternalTransaction(id, address, url, payload) {
155
- return this.#substrateRequestHandler.signTransaction(id, address, url, payload);
154
+ async signInternalTransaction(id, address, url, payload, onSign) {
155
+ return this.#substrateRequestHandler.signTransaction(id, address, url, payload, onSign);
156
156
  }
157
157
  addConfirmation(id, url, type, payload, options = {}, validator) {
158
158
  return this.#evmRequestHandler.addConfirmation(id, url, type, payload, options, validator);
@@ -11,5 +11,6 @@ export declare const DEFAULT_SHOW_ZERO_BALANCE = true;
11
11
  export declare const DEFAULT_SHOW_BALANCE = false;
12
12
  export declare const DEFAULT_ALL_LOGO = "";
13
13
  export declare const DEFAULT_CAMERA_ENABLE = false;
14
+ export declare const DEFAULT_ALLOW_ONE_SIGN = true;
14
15
  export declare const DEFAULT_NOTIFICATION_SETUP: NotificationSetup;
15
16
  export declare const DEFAULT_SETTING: UiSettings;
@@ -14,6 +14,7 @@ export const DEFAULT_SHOW_ZERO_BALANCE = true;
14
14
  export const DEFAULT_SHOW_BALANCE = false;
15
15
  export const DEFAULT_ALL_LOGO = '';
16
16
  export const DEFAULT_CAMERA_ENABLE = false;
17
+ export const DEFAULT_ALLOW_ONE_SIGN = true;
17
18
  export const DEFAULT_NOTIFICATION_SETUP = {
18
19
  isEnabled: true,
19
20
  showNotice: {
@@ -42,5 +43,6 @@ export const DEFAULT_SETTING = {
42
43
  timeAutoLock: DEFAULT_AUTO_LOCK_TIME,
43
44
  enableChainPatrol: DEFAULT_CHAIN_PATROL_ENABLE,
44
45
  notificationSetup: DEFAULT_NOTIFICATION_SETUP,
45
- walletReference: ''
46
+ walletReference: '',
47
+ allowOneSign: DEFAULT_ALLOW_ONE_SIGN
46
48
  };
@@ -3,7 +3,7 @@ import { ChainStakingMetadata, CrowdloanItem, MantaPayConfig, NftCollection, Nft
3
3
  import { EventService } from '@subwallet/extension-base/services/event-service';
4
4
  import { _NotificationInfo } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
5
5
  import { IBalance, ICampaign, IChain, INft } from '@subwallet/extension-base/services/storage-service/databases';
6
- import { AssetStore, BalanceStore, ChainStore, CrowdloanStore, MetadataStore, MetadataV15Store, MigrationStore, NftCollectionStore, NftStore, PriceStore, StakingStore, TransactionStore } from '@subwallet/extension-base/services/storage-service/db-stores';
6
+ import { AssetStore, BalanceStore, ChainStore, CrowdloanStore, MetadataStore, MetadataV15Store, MigrationStore, NftCollectionStore, NftStore, PriceStore, ProcessTransactionStore, StakingStore, TransactionStore } from '@subwallet/extension-base/services/storage-service/db-stores';
7
7
  import CampaignStore from '@subwallet/extension-base/services/storage-service/db-stores/Campaign';
8
8
  import ChainStakingMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/ChainStakingMetadata';
9
9
  import InappNotificationStore from '@subwallet/extension-base/services/storage-service/db-stores/InappNotification';
@@ -12,7 +12,7 @@ import NominatorMetadataStore from '@subwallet/extension-base/services/storage-s
12
12
  import { HistoryQuery } from '@subwallet/extension-base/services/storage-service/db-stores/Transaction';
13
13
  import YieldPoolStore from '@subwallet/extension-base/services/storage-service/db-stores/YieldPoolStore';
14
14
  import YieldPositionStore from '@subwallet/extension-base/services/storage-service/db-stores/YieldPositionStore';
15
- import { BalanceItem, YieldPoolInfo, YieldPoolType, YieldPositionInfo } from '@subwallet/extension-base/types';
15
+ import { BalanceItem, ProcessTransactionData, YieldPoolInfo, YieldPoolType, YieldPositionInfo } from '@subwallet/extension-base/types';
16
16
  import { GetNotificationParams, RequestSwitchStatusParams } from '@subwallet/extension-base/types/notification';
17
17
  import { Subscription } from 'dexie';
18
18
  import { DexieExportJsonStructure } from 'dexie-export-import';
@@ -40,6 +40,7 @@ export default class DatabaseService {
40
40
  mantaPay: MantaPayStore;
41
41
  campaign: CampaignStore;
42
42
  inappNotification: InappNotificationStore;
43
+ processTransactions: ProcessTransactionStore;
43
44
  };
44
45
  private logger;
45
46
  private nftSubscription;
@@ -67,7 +68,9 @@ export default class DatabaseService {
67
68
  subscribeNominatorMetadata(addresses: string[], callback: (data: NominatorMetadata[]) => void): Subscription;
68
69
  getHistories(query?: HistoryQuery): Promise<import("@subwallet/extension-base/services/storage-service/databases").ITransactionHistoryItem[]>;
69
70
  upsertHistory(histories: TransactionHistoryItem[]): Promise<unknown>;
70
- updateHistoryByExtrinsicHash(extrinsicHash: string, updateData: Partial<TransactionHistoryItem>): Promise<unknown>;
71
+ updateHistoryByExtrinsicHash(extrinsicHash: string, updateData: Partial<TransactionHistoryItem>, isRecover: boolean): Promise<unknown>;
72
+ restoreProcessTransaction(): Promise<void>;
73
+ recoverProcessTransaction(extrinsicHash: string, updateData: Partial<TransactionHistoryItem>): Promise<void>;
71
74
  addNftCollection(collection: NftCollection): Promise<unknown>;
72
75
  deleteNftCollection(chain: string, collectionId: string): Promise<void>;
73
76
  getAllNftCollection(chainHashes?: string[]): import("dexie").PromiseExtended<NftCollection[]>;
@@ -134,4 +137,11 @@ export default class DatabaseService {
134
137
  exportDB(): Promise<string>;
135
138
  importDB(data: string): Promise<boolean>;
136
139
  getExportJson(): Promise<DexieExportJsonStructure>;
140
+ upsertProcessTransaction(processTransaction: ProcessTransactionData): Promise<unknown>;
141
+ observableProcessTransactions(): import("dexie").Observable<Record<string, ProcessTransactionData>>;
142
+ getProcessTransactions(): Promise<Record<string, ProcessTransactionData>>;
143
+ getProcessTransactionById(processId: string): Promise<ProcessTransactionData | undefined>;
144
+ observableProcessTransactionById(processId: string): import("dexie").Observable<ProcessTransactionData | undefined>;
145
+ deleteProcessTransactionById(processId: string): Promise<void>;
146
+ hasRunScript(key: string): Promise<boolean>;
137
147
  }
@@ -1,9 +1,9 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { APIItemState, StakingType } from '@subwallet/extension-base/background/KoniTypes';
4
+ import { APIItemState, ExtrinsicStatus, StakingType } from '@subwallet/extension-base/background/KoniTypes';
5
5
  import KoniDatabase from '@subwallet/extension-base/services/storage-service/databases';
6
- import { AssetStore, BalanceStore, ChainStore, CrowdloanStore, MetadataStore, MetadataV15Store, MigrationStore, NftCollectionStore, NftStore, PriceStore, StakingStore, TransactionStore } from '@subwallet/extension-base/services/storage-service/db-stores';
6
+ import { AssetStore, BalanceStore, ChainStore, CrowdloanStore, MetadataStore, MetadataV15Store, MigrationStore, NftCollectionStore, NftStore, PriceStore, ProcessTransactionStore, StakingStore, TransactionStore } from '@subwallet/extension-base/services/storage-service/db-stores';
7
7
  import CampaignStore from '@subwallet/extension-base/services/storage-service/db-stores/Campaign';
8
8
  import ChainStakingMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/ChainStakingMetadata';
9
9
  import InappNotificationStore from '@subwallet/extension-base/services/storage-service/db-stores/InappNotification';
@@ -11,6 +11,7 @@ import MantaPayStore from '@subwallet/extension-base/services/storage-service/db
11
11
  import NominatorMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/NominatorMetadata';
12
12
  import YieldPoolStore from '@subwallet/extension-base/services/storage-service/db-stores/YieldPoolStore';
13
13
  import YieldPositionStore from '@subwallet/extension-base/services/storage-service/db-stores/YieldPositionStore';
14
+ import { StepStatus } from '@subwallet/extension-base/types';
14
15
  import { BN_ZERO, reformatAddress } from '@subwallet/extension-base/utils';
15
16
  import keyring from '@subwallet/ui-keyring';
16
17
  import BigN from 'bignumber.js';
@@ -51,7 +52,9 @@ export default class DatabaseService {
51
52
  // assetRef: new AssetRefStore(this._db.assetRef)
52
53
 
53
54
  // inapp notification
54
- inappNotification: new InappNotificationStore(this._db.inappNotification)
55
+ inappNotification: new InappNotificationStore(this._db.inappNotification),
56
+ // process transaction
57
+ processTransactions: new ProcessTransactionStore(this._db.processTransactions)
55
58
  };
56
59
  }
57
60
  async updatePriceStore(priceData) {
@@ -260,15 +263,90 @@ export default class DatabaseService {
260
263
  const cleanedHistory = histories.filter(x => x && x.address && x.chain && x.extrinsicHash);
261
264
  return this.stores.transaction.bulkUpsert(cleanedHistory);
262
265
  }
263
- async updateHistoryByExtrinsicHash(extrinsicHash, updateData) {
266
+ async updateHistoryByExtrinsicHash(extrinsicHash, updateData, isRecover) {
264
267
  const canUpdate = updateData && extrinsicHash;
265
268
  if (!canUpdate) {
266
269
  return;
267
270
  }
271
+ if (isRecover) {
272
+ await this.recoverProcessTransaction(extrinsicHash, updateData);
273
+ }
268
274
  return this.stores.transaction.updateWithQuery({
269
275
  extrinsicHash
270
276
  }, updateData);
271
277
  }
278
+ async restoreProcessTransaction() {
279
+ const processes = await this.stores.processTransactions.getSubmittingProcess();
280
+ const queuedProcesses = processes.filter(process => process.status === StepStatus.QUEUED);
281
+ const processingProcesses = processes.filter(process => process.status === StepStatus.PROCESSING);
282
+ await this.stores.processTransactions.bulkDelete(queuedProcesses.map(process => process.id));
283
+ for (const process of processingProcesses) {
284
+ const currentStepId = process.currentStepId;
285
+ const currentStep = process.steps.find(step => step.id === currentStepId);
286
+ if (currentStep) {
287
+ const currentStepStatus = currentStep.status;
288
+ if ([StepStatus.QUEUED, StepStatus.PREPARE].includes(currentStepStatus)) {
289
+ currentStep.status = StepStatus.CANCELLED;
290
+ process.status = StepStatus.CANCELLED;
291
+ } else if (currentStepStatus === StepStatus.TIMEOUT) {
292
+ currentStep.status = StepStatus.CANCELLED;
293
+ }
294
+ const nextSteps = process.steps.filter(step => step.id > currentStepId);
295
+ for (const step of nextSteps) {
296
+ step.status = StepStatus.CANCELLED;
297
+ }
298
+ }
299
+ }
300
+ await this.stores.processTransactions.bulkUpsert(processingProcesses);
301
+ }
302
+ async recoverProcessTransaction(extrinsicHash, updateData) {
303
+ const txs = await this.stores.transaction.queryHistory({
304
+ extrinsicHash
305
+ });
306
+ const map = new Map(txs.filter(x => !!x.processId && x.extrinsicHash === extrinsicHash).map(tx => [tx.processId || '', tx.transactionId || '']));
307
+ if (map.size && updateData.status) {
308
+ const processes = await this.stores.processTransactions.getByIds(Array.from(map.keys()));
309
+ for (const [processId, process] of Object.entries(processes)) {
310
+ const txId = map.get(processId);
311
+ if (txId) {
312
+ const currentStep = process.steps.find(tx => tx.transactionId === txId);
313
+ if (currentStep) {
314
+ const differentHash = txId !== extrinsicHash && currentStep.extrinsicHash !== extrinsicHash;
315
+ if (currentStep.status === StepStatus.PROCESSING || currentStep.status === StepStatus.SUBMITTING) {
316
+ switch (updateData.status) {
317
+ case ExtrinsicStatus.SUCCESS:
318
+ currentStep.status = StepStatus.COMPLETE;
319
+ if (differentHash) {
320
+ currentStep.extrinsicHash = extrinsicHash;
321
+ }
322
+ break;
323
+ case ExtrinsicStatus.FAIL:
324
+ currentStep.status = StepStatus.FAILED;
325
+ if (differentHash) {
326
+ currentStep.extrinsicHash = extrinsicHash;
327
+ }
328
+ break;
329
+ case ExtrinsicStatus.UNKNOWN:
330
+ currentStep.status = StepStatus.TIMEOUT;
331
+ break;
332
+ }
333
+ }
334
+ const isLastStep = process.steps[process.steps.length - 1].id === currentStep.id;
335
+ if (isLastStep) {
336
+ process.status = currentStep.status;
337
+ } else {
338
+ if (currentStep.status === StepStatus.TIMEOUT) {
339
+ process.status = StepStatus.TIMEOUT;
340
+ } else {
341
+ process.status = StepStatus.CANCELLED;
342
+ }
343
+ }
344
+ await this.stores.processTransactions.upsert(process);
345
+ }
346
+ }
347
+ }
348
+ }
349
+ }
272
350
 
273
351
  // NFT Collection
274
352
  async addNftCollection(collection) {
@@ -543,6 +621,27 @@ export default class DatabaseService {
543
621
  async getExportJson() {
544
622
  return JSON.parse(await this.exportDB());
545
623
  }
624
+ upsertProcessTransaction(processTransaction) {
625
+ return this.stores.processTransactions.upsert(processTransaction);
626
+ }
627
+ observableProcessTransactions() {
628
+ return this.stores.processTransactions.observableAll();
629
+ }
630
+ getProcessTransactions() {
631
+ return this.stores.processTransactions.getAll();
632
+ }
633
+ getProcessTransactionById(processId) {
634
+ return this.stores.processTransactions.getOne(processId);
635
+ }
636
+ observableProcessTransactionById(processId) {
637
+ return this.stores.processTransactions.observableOne(processId);
638
+ }
639
+ deleteProcessTransactionById(processId) {
640
+ return this.stores.processTransactions.delete(processId);
641
+ }
642
+ hasRunScript(key) {
643
+ return this.stores.migration.hasRunScript(key);
644
+ }
546
645
 
547
646
  // public setAssetRef (assetRef: Record<string, _AssetRef>) {
548
647
  // const assetRefList = Object.entries(assetRef).map(([slug, item]) => {
@@ -1,7 +1,7 @@
1
1
  import { _AssetRef, _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
2
  import { CampaignData, ChainStakingMetadata, CrowdloanItem, MetadataItem, MetadataV15Item, NftCollection, NftItem, NominatorMetadata, PriceJson, StakingItem, TransactionHistoryItem } from '@subwallet/extension-base/background/KoniTypes';
3
3
  import { _NotificationInfo } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
4
- import { BalanceItem, YieldPoolInfo, YieldPositionInfo } from '@subwallet/extension-base/types';
4
+ import { BalanceItem, ProcessTransactionData, YieldPoolInfo, YieldPositionInfo } from '@subwallet/extension-base/types';
5
5
  import Dexie, { Table } from 'dexie';
6
6
  export declare const DEFAULT_DATABASE = "SubWalletDB_v2";
7
7
  export interface DefaultChainDoc {
@@ -64,6 +64,7 @@ export default class KoniDatabase extends Dexie {
64
64
  campaign: Table<ICampaign, object>;
65
65
  keyValue: Table<IKeyValue, object>;
66
66
  inappNotification: Table<_NotificationInfo, object>;
67
+ processTransactions: Table<ProcessTransactionData, object>;
67
68
  private schemaVersion;
68
69
  constructor(name?: string, schemaVersion?: number);
69
70
  private conditionalVersion;
@@ -46,6 +46,9 @@ export default class KoniDatabase extends Dexie {
46
46
  this.conditionalVersion(8, {
47
47
  metadataV15: 'genesisHash, chain'
48
48
  });
49
+ this.conditionalVersion(9, {
50
+ processTransactions: 'id, address'
51
+ });
49
52
  }
50
53
  conditionalVersion(version, schema, upgrade) {
51
54
  if (this.schemaVersion != null && this.schemaVersion < version) {
@@ -5,4 +5,5 @@ export default class MetadataStore extends BaseStoreWithChain<IMetadataItem> {
5
5
  upsertMetadata(chain: string, metadata: IMetadataItem): import("dexie").PromiseExtended<unknown>;
6
6
  getMetadataByGenesisHash(genesisHash: string): import("dexie").PromiseExtended<IMetadataItem | undefined>;
7
7
  updateMetadataByGenesisHash(genesisHash: string, metadata: IMetadataItem): import("dexie").PromiseExtended<unknown>;
8
+ clearByChains(chains: string[]): import("dexie").PromiseExtended<number>;
8
9
  }