@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
@@ -40,8 +40,8 @@ import { checkLiquidityForPool, estimateTokensForPool, getReserveForPool } from
40
40
  import { isProposalExpired, isSupportWalletConnectChain, isSupportWalletConnectNamespace } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
41
41
  import { SWStorage } from '@subwallet/extension-base/storage';
42
42
  import { AccountsStore } from '@subwallet/extension-base/stores';
43
- import { BasicTxErrorType, BasicTxWarningCode, StakingTxErrorType, YieldPoolType } from '@subwallet/extension-base/types';
44
- import { _analyzeAddress, calculateMaxTransferable, combineAllAccountProxy, createTransactionFromRLP, detectTransferTxType, isSameAddress, MODULE_SUPPORT, reformatAddress, signatureToHex, transformAccounts, transformAddresses, uniqueStringArray } from '@subwallet/extension-base/utils';
43
+ import { AccountSignMode, BasicTxErrorType, BasicTxWarningCode, CommonStepType, EarningProcessType, ProcessType, StakingTxErrorType, StepStatus, SwapFeeType, SwapStepType, YieldPoolType, YieldStepType } from '@subwallet/extension-base/types';
44
+ import { _analyzeAddress, calculateMaxTransferable, combineAllAccountProxy, createTransactionFromRLP, detectTransferTxType, getAccountSignMode, isSameAddress, MODULE_SUPPORT, reformatAddress, signatureToHex, transformAccounts, transformAddresses, uniqueStringArray } from '@subwallet/extension-base/utils';
45
45
  import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
46
46
  import { getId } from '@subwallet/extension-base/utils/getId';
47
47
  import { getKeypairTypeByAddress, isAddress, isSubstrateAddress, isTonAddress } from '@subwallet/keyring';
@@ -799,6 +799,12 @@ export default class KoniExtension {
799
799
  this.#koniState.updateSetting('isShowBalance', enable);
800
800
  return true;
801
801
  }
802
+ setAllowOneSign({
803
+ allowOneSign
804
+ }) {
805
+ this.#koniState.updateSetting('allowOneSign', allowOneSign);
806
+ return true;
807
+ }
802
808
  async subscribeAuthUrls(id, port) {
803
809
  const cb = createSubscription(id, port);
804
810
  const authorizeUrlSubscription = this.#koniState.subscribeAuthorizeUrlSubject().subscribe({
@@ -1290,6 +1296,7 @@ export default class KoniExtension {
1290
1296
  feeCustom,
1291
1297
  feeOption,
1292
1298
  from,
1299
+ isPassConfirmation,
1293
1300
  nonNativeTokenPayFeeSlug,
1294
1301
  originNetworkKey,
1295
1302
  to,
@@ -1413,6 +1420,7 @@ export default class KoniExtension {
1413
1420
  nonNativeTokenPayFeeSlug,
1414
1421
  isTransferAll: transferAll,
1415
1422
  isTransferLocalTokenAndPayThatTokenAsFee,
1423
+ isPassConfirmation,
1416
1424
  errors,
1417
1425
  additionalValidator: additionalValidator,
1418
1426
  eventsHandler: eventsHandler
@@ -2577,28 +2585,44 @@ export default class KoniExtension {
2577
2585
  } = this.#koniState.transactionService.getTransaction(id);
2578
2586
  return transactionResult;
2579
2587
  }
2580
- subscribeTransactions(id, port) {
2588
+ async subscribeTransactions(id, port) {
2581
2589
  const cb = createSubscription(id, port);
2582
- function convertRs(rs) {
2590
+ function convertRs(rs, processMap) {
2583
2591
  return Object.fromEntries(Object.entries(rs).map(([key, value]) => {
2584
2592
  const {
2585
2593
  additionalValidator,
2586
2594
  eventsHandler,
2595
+ step,
2587
2596
  transaction,
2588
- ...transactionResult
2597
+ ..._transactionResult
2589
2598
  } = value;
2599
+ const transactionResult = _transactionResult;
2600
+ if (step !== null && step !== void 0 && step.processId) {
2601
+ const process = processMap[step.processId];
2602
+ if (process) {
2603
+ transactionResult.process = process;
2604
+ }
2605
+ }
2590
2606
  return [key, transactionResult];
2591
2607
  }));
2592
2608
  }
2593
2609
  const transactionsSubject = this.#koniState.transactionService.getTransactionSubject();
2594
- const transactionsSubscription = transactionsSubject.subscribe(rs => {
2595
- cb(convertRs(rs));
2610
+ const transactionsObservable = transactionsSubject.asObservable();
2611
+ const processTransactionObservable = this.#koniState.dbService.observableProcessTransactions();
2612
+ const subscription = combineLatest({
2613
+ transactions: transactionsObservable,
2614
+ processMap: processTransactionObservable
2615
+ }).subscribe(({
2616
+ processMap,
2617
+ transactions
2618
+ }) => {
2619
+ cb(convertRs(transactions, processMap));
2596
2620
  });
2597
2621
  port.onDisconnect.addListener(() => {
2598
- transactionsSubscription.unsubscribe();
2622
+ subscription.unsubscribe();
2599
2623
  this.cancelSubscription(id);
2600
2624
  });
2601
- return convertRs(transactionsSubject.getValue());
2625
+ return convertRs(transactionsSubject.getValue(), await this.#koniState.dbService.getProcessTransactions());
2602
2626
  }
2603
2627
  subscribeNotifications(id, port) {
2604
2628
  const cb = createSubscription(id, port);
@@ -3046,12 +3070,29 @@ export default class KoniExtension {
3046
3070
  async handleYieldStep(inputData) {
3047
3071
  const {
3048
3072
  data,
3049
- path
3073
+ errorOnTimeOut,
3074
+ isPassConfirmation,
3075
+ onSend,
3076
+ path,
3077
+ processId
3050
3078
  } = inputData;
3051
3079
  const {
3052
3080
  address
3053
3081
  } = data;
3082
+ let step;
3083
+ if (processId) {
3084
+ const _step = path.steps[inputData.currentStep];
3085
+ step = {
3086
+ processId,
3087
+ stepId: _step.id
3088
+ };
3089
+ }
3054
3090
  if (!data) {
3091
+ if (step) {
3092
+ this.#koniState.transactionService.updateProcessStepStatus(step, {
3093
+ status: StepStatus.FAILED
3094
+ });
3095
+ }
3055
3096
  return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]);
3056
3097
  }
3057
3098
  const isLastStep = inputData.currentStep + 1 === path.steps.length;
@@ -3061,6 +3102,11 @@ export default class KoniExtension {
3061
3102
  }); // TODO: validate, set to fail upon submission
3062
3103
 
3063
3104
  if (yieldValidation.length > 0) {
3105
+ if (step) {
3106
+ this.#koniState.transactionService.updateProcessStepStatus(step, {
3107
+ status: StepStatus.FAILED
3108
+ });
3109
+ }
3064
3110
  return this.#koniState.transactionService.generateBeforeHandleResponseErrors(yieldValidation);
3065
3111
  }
3066
3112
 
@@ -3074,7 +3120,66 @@ export default class KoniExtension {
3074
3120
  txData
3075
3121
  } = await this.#koniState.earningService.handleYieldJoin(inputData);
3076
3122
  const isPoolSupportAlternativeFee = this.#koniState.earningService.isPoolSupportAlternativeFee(inputData.data.slug);
3123
+ const poolHandler = this.#koniState.earningService.getPoolHandler(data.slug);
3077
3124
  const isMintingStep = YIELD_EXTRINSIC_TYPES.includes(extrinsicType);
3125
+ const eventsHandler = eventEmitter => {
3126
+ if (onSend) {
3127
+ eventEmitter.on('send', onSend);
3128
+ }
3129
+ };
3130
+ if (processId && poolHandler) {
3131
+ const convertFee = fee => {
3132
+ return {
3133
+ feeComponent: [{
3134
+ amount: fee.amount || '0',
3135
+ // TODO: Add fee type
3136
+ feeType: SwapFeeType.NETWORK_FEE,
3137
+ tokenSlug: fee.slug
3138
+ }],
3139
+ defaultFeeToken: fee.slug,
3140
+ feeOptions: [fee.slug]
3141
+ };
3142
+ };
3143
+ if (!this.#koniState.transactionService.checkProcessExist(processId) && step) {
3144
+ const lastStep = path.steps[path.steps.length - 1];
3145
+ const combineInfo = {
3146
+ // In real case, only `YIELD` have multiple steps
3147
+ type: lastStep.type === YieldStepType.JOIN_NOMINATION_POOL ? EarningProcessType.NOMINATION_POOL : lastStep.type === YieldStepType.NOMINATE ? EarningProcessType.NATIVE_STAKING : EarningProcessType.YIELD,
3148
+ data,
3149
+ brief: {
3150
+ amount: data.amount,
3151
+ chain: poolHandler.chain,
3152
+ token: poolHandler.metadataInfo.inputAsset,
3153
+ method: poolHandler.type
3154
+ }
3155
+ };
3156
+ await this.#koniState.transactionService.createProcessIfNeed({
3157
+ id: processId,
3158
+ address: reformatAddress(address),
3159
+ type: ProcessType.EARNING,
3160
+ combineInfo,
3161
+ currentStepId: step.stepId,
3162
+ steps: path.steps.map((step, index) => {
3163
+ const fee = convertFee(path.totalFee[index]);
3164
+ if (![YieldStepType.XCM, YieldStepType.DEFAULT, YieldStepType.TOKEN_APPROVAL].includes(step.type)) {
3165
+ const metadata = data;
3166
+ return {
3167
+ ...step,
3168
+ status: StepStatus.QUEUED,
3169
+ fee,
3170
+ metadata: metadata
3171
+ };
3172
+ }
3173
+ return {
3174
+ ...step,
3175
+ fee,
3176
+ status: StepStatus.QUEUED
3177
+ };
3178
+ }).filter(step => step.type !== YieldStepType.DEFAULT),
3179
+ status: StepStatus.QUEUED
3180
+ });
3181
+ }
3182
+ }
3078
3183
  return await this.#koniState.transactionService.handleTransaction({
3079
3184
  address,
3080
3185
  chain: txChain,
@@ -3086,7 +3191,11 @@ export default class KoniExtension {
3086
3191
  chainType,
3087
3192
  resolveOnDone: !isLastStep,
3088
3193
  transferNativeAmount,
3089
- skipFeeValidation: isMintingStep && isPoolSupportAlternativeFee
3194
+ skipFeeValidation: isMintingStep && isPoolSupportAlternativeFee,
3195
+ errorOnTimeOut,
3196
+ ...this.createPassConfirmationParams(isPassConfirmation),
3197
+ eventsHandler,
3198
+ step
3090
3199
  });
3091
3200
  }
3092
3201
  async handleYieldLeave(params) {
@@ -3430,11 +3539,28 @@ export default class KoniExtension {
3430
3539
  async handleSwapStep(inputData) {
3431
3540
  const {
3432
3541
  address,
3542
+ errorOnTimeOut,
3543
+ isPassConfirmation,
3544
+ onSend,
3433
3545
  process,
3546
+ processId,
3434
3547
  quote,
3435
3548
  recipient
3436
3549
  } = inputData;
3550
+ let step;
3551
+ if (processId) {
3552
+ const _step = process.steps[inputData.currentStep];
3553
+ step = {
3554
+ processId,
3555
+ stepId: _step.id
3556
+ };
3557
+ }
3437
3558
  if (!quote || !address || !process) {
3559
+ if (step) {
3560
+ this.#koniState.transactionService.updateProcessStepStatus(step, {
3561
+ status: StepStatus.FAILED
3562
+ });
3563
+ }
3438
3564
  return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]);
3439
3565
  }
3440
3566
  const isLastStep = inputData.currentStep + 1 === process.steps.length;
@@ -3445,6 +3571,11 @@ export default class KoniExtension {
3445
3571
  recipient
3446
3572
  });
3447
3573
  if (swapValidations.length > 0) {
3574
+ if (step) {
3575
+ this.#koniState.transactionService.updateProcessStepStatus(step, {
3576
+ status: StepStatus.FAILED
3577
+ });
3578
+ }
3448
3579
  return this.#koniState.transactionService.generateBeforeHandleResponseErrors(swapValidations);
3449
3580
  }
3450
3581
 
@@ -3460,6 +3591,85 @@ export default class KoniExtension {
3460
3591
  // const chosenFeeToken = process.steps.findIndex((step) => step.type === SwapStepType.SET_FEE_TOKEN) > -1;
3461
3592
  // const allowSkipValidation = [ExtrinsicType.SET_FEE_TOKEN, ExtrinsicType.SWAP].includes(extrinsicType);
3462
3593
 
3594
+ const eventsHandler = eventEmitter => {
3595
+ if (onSend) {
3596
+ eventEmitter.on('send', onSend);
3597
+ }
3598
+ };
3599
+ if (processId) {
3600
+ const _step = process.steps[inputData.currentStep];
3601
+ if (!this.#koniState.transactionService.checkProcessExist(processId) && step) {
3602
+ const combineInfo = {
3603
+ provider: quote.provider,
3604
+ slippage: inputData.slippage,
3605
+ address,
3606
+ recipient,
3607
+ quote,
3608
+ process
3609
+ };
3610
+ await this.#koniState.transactionService.createProcessIfNeed({
3611
+ id: processId,
3612
+ address: reformatAddress(address),
3613
+ type: ProcessType.SWAP,
3614
+ currentStepId: step.stepId,
3615
+ combineInfo,
3616
+ steps: inputData.process.steps.map((step, index) => {
3617
+ const fee = inputData.process.totalFee[index];
3618
+ if (step.type === SwapStepType.SWAP) {
3619
+ const metadata = {
3620
+ pair: quote.pair,
3621
+ aliveUntil: quote.aliveUntil,
3622
+ fromAmount: quote.fromAmount,
3623
+ rate: quote.rate,
3624
+ provider: quote.provider,
3625
+ route: quote.route,
3626
+ toAmount: quote.toAmount
3627
+ };
3628
+ return {
3629
+ ...step,
3630
+ status: StepStatus.QUEUED,
3631
+ fee,
3632
+ metadata: metadata
3633
+ };
3634
+ }
3635
+ return {
3636
+ ...step,
3637
+ fee,
3638
+ status: StepStatus.QUEUED
3639
+ };
3640
+ }).filter(step => step.type !== CommonStepType.DEFAULT),
3641
+ status: StepStatus.QUEUED
3642
+ });
3643
+ }
3644
+ const isLastStep = inputData.currentStep === process.steps.length - 1;
3645
+ if (isLastStep) {
3646
+ const metadata = {
3647
+ pair: quote.pair,
3648
+ aliveUntil: quote.aliveUntil,
3649
+ fromAmount: quote.fromAmount,
3650
+ rate: quote.rate,
3651
+ provider: quote.provider,
3652
+ route: quote.route,
3653
+ toAmount: quote.toAmount
3654
+ };
3655
+ const step = {
3656
+ ..._step,
3657
+ // In case one sign, status already set to prepare before
3658
+ status: process.steps.length > 2 ? StepStatus.PREPARE : StepStatus.QUEUED,
3659
+ fee: process.totalFee[inputData.currentStep],
3660
+ metadata: metadata
3661
+ };
3662
+ const combineInfo = {
3663
+ provider: quote.provider,
3664
+ slippage: inputData.slippage,
3665
+ address,
3666
+ recipient,
3667
+ quote,
3668
+ process
3669
+ };
3670
+ await this.#koniState.transactionService.updateProcessInfo(processId, combineInfo, step);
3671
+ }
3672
+ }
3463
3673
  return await this.#koniState.transactionService.handleTransaction({
3464
3674
  address,
3465
3675
  chain: txChain,
@@ -3470,7 +3680,11 @@ export default class KoniExtension {
3470
3680
  // change this depends on step
3471
3681
  chainType,
3472
3682
  resolveOnDone: !isLastStep,
3473
- transferNativeAmount
3683
+ transferNativeAmount,
3684
+ ...this.createPassConfirmationParams(isPassConfirmation),
3685
+ errorOnTimeOut,
3686
+ eventsHandler,
3687
+ step
3474
3688
  // skipFeeValidation: chosenFeeToken && allowSkipValidation
3475
3689
  });
3476
3690
  }
@@ -3599,6 +3813,206 @@ export default class KoniExtension {
3599
3813
 
3600
3814
  /* Popular tokens */
3601
3815
 
3816
+ /* Multi process */
3817
+
3818
+ async handleSubmitProcessTransaction(_request) {
3819
+ const {
3820
+ address,
3821
+ id: processId,
3822
+ request: requestData,
3823
+ type
3824
+ } = _request;
3825
+ const pair = keyring.getPair(address);
3826
+ if (!pair) {
3827
+ throw new Error('Pair not found');
3828
+ }
3829
+ const signMode = getAccountSignMode(address, pair.meta);
3830
+ if (signMode !== AccountSignMode.PASSWORD) {
3831
+ throw new Error('Account can not use this feature');
3832
+ }
3833
+ const setting = await new Promise(resolve => this.#koniState.settingService.getSettings(resolve));
3834
+ if (!setting.allowOneSign) {
3835
+ throw new Error('Wallet not enable this feature');
3836
+ }
3837
+ switch (type) {
3838
+ case ProcessType.EARNING:
3839
+
3840
+ // eslint-disable-next-line no-fallthrough
3841
+ case ProcessType.SWAP:
3842
+ {
3843
+ const currentStep = requestData.currentStep;
3844
+ let stepNums;
3845
+ let submitData;
3846
+ let waitXcmData;
3847
+ if (type === ProcessType.EARNING) {
3848
+ const data = requestData;
3849
+ const poolHandler = this.#koniState.earningService.getPoolHandler(data.data.slug);
3850
+ if (poolHandler) {
3851
+ waitXcmData = {
3852
+ targetAmount: data.data.amount,
3853
+ chain: poolHandler.chain,
3854
+ token: poolHandler.metadataInfo.inputAsset,
3855
+ // TODO: Change this depends on pool
3856
+ nextTxType: ExtrinsicType.JOIN_YIELD_POOL
3857
+ };
3858
+ }
3859
+ submitData = async (step, callback) => {
3860
+ const isPassConfirmation = !callback;
3861
+ const onSend = callback
3862
+ // eslint-disable-next-line node/no-callback-literal
3863
+ ? rs => callback(rs) : undefined;
3864
+ return this.handleYieldStep({
3865
+ ...data,
3866
+ currentStep: step,
3867
+ isPassConfirmation,
3868
+ onSend,
3869
+ errorOnTimeOut: true,
3870
+ processId
3871
+ });
3872
+ };
3873
+ stepNums = data.path.steps.length;
3874
+ } else {
3875
+ const data = requestData;
3876
+ stepNums = data.process.steps.length;
3877
+ const inputAsset = this.#koniState.chainService.getAssetBySlug(data.quote.pair.from);
3878
+ waitXcmData = {
3879
+ targetAmount: data.quote.fromAmount,
3880
+ chain: inputAsset.originChain,
3881
+ token: inputAsset.slug,
3882
+ nextTxType: ExtrinsicType.SWAP
3883
+ };
3884
+ submitData = async (step, callback) => {
3885
+ const isLastStep = step === stepNums - 1;
3886
+ const isPassConfirmation = !callback;
3887
+ const onSend = callback
3888
+ // eslint-disable-next-line node/no-callback-literal
3889
+ ? rs => callback(rs) : undefined;
3890
+ if (stepNums > 2 && isLastStep) {
3891
+ const quote = data.quote;
3892
+ const latestSwapQuote = await this.getLatestSwapQuote({
3893
+ address: data.address,
3894
+ currentQuote: quote.provider,
3895
+ feeToken: quote.feeInfo.selectedFeeToken,
3896
+ recipient: data.recipient,
3897
+ pair: quote.pair,
3898
+ fromAmount: quote.fromAmount,
3899
+ slippage: data.slippage
3900
+ });
3901
+ return this.handleSwapStep({
3902
+ ...data,
3903
+ quote: latestSwapQuote.optimalQuote || data.quote,
3904
+ currentStep: step,
3905
+ isPassConfirmation,
3906
+ errorOnTimeOut: true,
3907
+ processId
3908
+ });
3909
+ }
3910
+ return this.handleSwapStep({
3911
+ ...data,
3912
+ currentStep: step,
3913
+ isPassConfirmation,
3914
+ onSend,
3915
+ errorOnTimeOut: true,
3916
+ processId
3917
+ });
3918
+ };
3919
+ }
3920
+ if (stepNums < 3) {
3921
+ throw new Error('Not need to use this feature');
3922
+ }
3923
+ const loopSubmit = async (submitFunc, step, callback) => {
3924
+ const isLastStep = step === stepNums - 1;
3925
+ const rs = await submitFunc(step, callback);
3926
+ if (isLastStep) {
3927
+ return rs;
3928
+ } else {
3929
+ if (rs.errors.length || rs.warnings.length) {
3930
+ return rs;
3931
+ }
3932
+ if (rs.extrinsicType === ExtrinsicType.TRANSFER_XCM) {
3933
+ await new Promise(resolve => {
3934
+ setTimeout(resolve, 60 * 1000);
3935
+ if (waitXcmData) {
3936
+ let unsub = noop;
3937
+ const onRs = rs => {
3938
+ var _waitXcmData;
3939
+ if (BigN(rs.value).gte(BigN(((_waitXcmData = waitXcmData) === null || _waitXcmData === void 0 ? void 0 : _waitXcmData.targetAmount) || '0'))) {
3940
+ unsub();
3941
+ resolve();
3942
+ }
3943
+ };
3944
+ this.#koniState.balanceService.subscribeTransferableBalance(address, waitXcmData.chain, waitXcmData.token, waitXcmData.nextTxType, onRs).then(([_unsub, rs]) => {
3945
+ unsub = _unsub;
3946
+ onRs(rs);
3947
+ }).catch(console.error);
3948
+ }
3949
+ });
3950
+ }
3951
+ return loopSubmit(submitFunc, step + 1);
3952
+ }
3953
+ };
3954
+ return new Promise((resolve, reject) => {
3955
+ loopSubmit(submitData, currentStep, resolve).then(resolve).catch(reject);
3956
+ });
3957
+ }
3958
+ }
3959
+ }
3960
+ createPassConfirmationParams(pass = false) {
3961
+ if (pass) {
3962
+ return {
3963
+ isPassConfirmation: true,
3964
+ signAfterCreate: id => {
3965
+ this.signingApprovePasswordV2({
3966
+ id
3967
+ }).catch(console.log);
3968
+ }
3969
+ };
3970
+ } else {
3971
+ return {
3972
+ isPassConfirmation: false
3973
+ };
3974
+ }
3975
+ }
3976
+ async subscribeProcessById(request, id, port) {
3977
+ const cb = createSubscription(id, port);
3978
+ const observable = this.#koniState.dbService.observableProcessTransactionById(request.processId);
3979
+ const subscription = observable.subscribe(rs => {
3980
+ // eslint-disable-next-line node/no-callback-literal
3981
+ cb({
3982
+ process: rs,
3983
+ id
3984
+ });
3985
+ });
3986
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
3987
+ port.onDisconnect.addListener(() => {
3988
+ this.cancelSubscription(id);
3989
+ });
3990
+ return {
3991
+ process: await this.#koniState.dbService.getProcessTransactionById(request.processId),
3992
+ id
3993
+ };
3994
+ }
3995
+ subscribeProcessAlive(id, port) {
3996
+ const cb = createSubscription(id, port);
3997
+ const observable = this.#koniState.transactionService.observables.aliveProcess;
3998
+ const convertData = rs => {
3999
+ return {
4000
+ processes: rs
4001
+ };
4002
+ };
4003
+ const subscription = observable.subscribe(rs => {
4004
+ cb(convertData(rs));
4005
+ });
4006
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
4007
+ port.onDisconnect.addListener(() => {
4008
+ this.cancelSubscription(id);
4009
+ });
4010
+ const value = this.#koniState.transactionService.values.aliveProcess;
4011
+ return convertData(value);
4012
+ }
4013
+
4014
+ /* Multi process */
4015
+
3602
4016
  // --------------------------------------------------------------
3603
4017
  // eslint-disable-next-line @typescript-eslint/require-await
3604
4018
  async handle(id, type, request, port) {
@@ -3690,6 +4104,8 @@ export default class KoniExtension {
3690
4104
  return this.setLanguage(request);
3691
4105
  case 'pri(settings.saveShowBalance)':
3692
4106
  return this.setShowBalance(request);
4107
+ case 'pri(settings.update.allowOneSign)':
4108
+ return this.setAllowOneSign(request);
3693
4109
  case 'pri(price.getPrice)':
3694
4110
  return await this.getPrice();
3695
4111
  case 'pri(price.getSubscription)':
@@ -4198,6 +4614,15 @@ export default class KoniExtension {
4198
4614
  return this.subscribePriorityTokens(id, port);
4199
4615
  /* Priority tokens */
4200
4616
 
4617
+ /* Multi process */
4618
+ case 'pri(process.transaction.submit)':
4619
+ return this.handleSubmitProcessTransaction(request);
4620
+ case 'pri(process.subscribe.id)':
4621
+ return this.subscribeProcessById(request, id, port);
4622
+ case 'pri(process.subscribe.alive)':
4623
+ return this.subscribeProcessAlive(id, port);
4624
+ /* Multi process */
4625
+
4201
4626
  // Default
4202
4627
  default:
4203
4628
  throw new Error(`Unable to handle message of type ${type}`);