@subwallet/extension-base 1.0.2-2 → 1.0.3-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 (151) hide show
  1. package/background/KoniTypes.d.ts +56 -40
  2. package/background/KoniTypes.js +11 -9
  3. package/background/errors/TransactionError.js +25 -1
  4. package/background/types.d.ts +10 -5
  5. package/cjs/background/KoniTypes.js +11 -9
  6. package/cjs/background/errors/TransactionError.js +24 -0
  7. package/cjs/constants/index.js +8 -26
  8. package/cjs/koni/api/dotsama/balance.js +49 -224
  9. package/cjs/koni/api/dotsama/transfer.js +34 -39
  10. package/cjs/koni/api/nft/acala_nft/index.js +7 -7
  11. package/cjs/koni/api/nft/bit.country/index.js +7 -6
  12. package/cjs/koni/api/nft/evm_nft/index.js +8 -3
  13. package/cjs/koni/api/nft/index.js +3 -6
  14. package/cjs/koni/api/nft/karura_nft/index.js +7 -6
  15. package/cjs/koni/api/nft/rmrk_nft/index.js +11 -1
  16. package/cjs/koni/api/nft/statemine_nft/index.js +7 -6
  17. package/cjs/koni/api/nft/unique_nft/index.js +5 -1
  18. package/cjs/koni/api/nft/wasm_nft/index.js +170 -111
  19. package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
  20. package/cjs/koni/api/staking/bonding/amplitude.js +13 -9
  21. package/cjs/koni/api/staking/bonding/astar.js +15 -13
  22. package/cjs/koni/api/staking/bonding/index.js +22 -10
  23. package/cjs/koni/api/staking/bonding/paraChain.js +85 -2
  24. package/cjs/koni/api/staking/bonding/relayChain.js +122 -16
  25. package/cjs/koni/api/staking/bonding/utils.js +27 -8
  26. package/cjs/koni/api/tokens/wasm/index.js +5 -4
  27. package/cjs/koni/api/tokens/wasm/utils.js +63 -0
  28. package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
  29. package/cjs/koni/api/xcm/utils.js +18 -13
  30. package/cjs/koni/api/xcm/xTokens.js +1 -1
  31. package/cjs/koni/api/xcm/xcmPallet.js +9 -6
  32. package/cjs/koni/background/cron.js +171 -61
  33. package/cjs/koni/background/handlers/Extension.js +391 -207
  34. package/cjs/koni/background/handlers/State.js +49 -34
  35. package/cjs/koni/background/handlers/Tabs.js +50 -17
  36. package/cjs/koni/background/subscription.js +53 -28
  37. package/cjs/packageInfo.js +1 -1
  38. package/cjs/services/base/types.js +20 -0
  39. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
  40. package/cjs/services/chain-service/index.js +73 -49
  41. package/cjs/services/event-service/index.js +5 -1
  42. package/cjs/services/event-service/types.js +11 -1
  43. package/cjs/services/history-service/index.js +101 -50
  44. package/cjs/services/history-service/subsquid-multi-chain-history.js +13 -10
  45. package/cjs/services/keyring-service/index.js +11 -13
  46. package/cjs/services/migration-service/scripts/MigrateImportedToken.js +2 -1
  47. package/cjs/services/price-service/coingecko.js +0 -1
  48. package/cjs/services/price-service/index.js +71 -24
  49. package/cjs/services/request-service/handler/AuthRequestHandler.js +13 -7
  50. package/cjs/services/request-service/handler/EvmRequestHandler.js +8 -12
  51. package/cjs/services/request-service/index.js +14 -5
  52. package/cjs/services/storage-service/DatabaseService.js +66 -34
  53. package/cjs/services/storage-service/db-stores/Nft.js +7 -15
  54. package/cjs/services/storage-service/db-stores/Transaction.js +6 -10
  55. package/cjs/services/transaction-service/event-parser/index.js +20 -48
  56. package/cjs/services/transaction-service/index.js +104 -48
  57. package/cjs/services/transaction-service/utils.js +10 -8
  58. package/cjs/utils/address.js +10 -1
  59. package/cjs/utils/index.js +9 -15
  60. package/cjs/utils/promise.js +26 -0
  61. package/constants/index.d.ts +7 -13
  62. package/constants/index.js +7 -13
  63. package/koni/api/dotsama/balance.d.ts +0 -1
  64. package/koni/api/dotsama/balance.js +22 -197
  65. package/koni/api/dotsama/transfer.js +11 -16
  66. package/koni/api/nft/acala_nft/index.js +7 -7
  67. package/koni/api/nft/bit.country/index.js +7 -6
  68. package/koni/api/nft/evm_nft/index.js +7 -3
  69. package/koni/api/nft/index.d.ts +1 -2
  70. package/koni/api/nft/index.js +3 -6
  71. package/koni/api/nft/karura_nft/index.js +7 -6
  72. package/koni/api/nft/nft.d.ts +1 -0
  73. package/koni/api/nft/rmrk_nft/index.js +11 -1
  74. package/koni/api/nft/statemine_nft/index.js +7 -6
  75. package/koni/api/nft/unique_nft/index.js +5 -1
  76. package/koni/api/nft/wasm_nft/index.d.ts +0 -2
  77. package/koni/api/nft/wasm_nft/index.js +168 -109
  78. package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
  79. package/koni/api/nft/wasm_nft/utils.js +7 -5
  80. package/koni/api/staking/bonding/amplitude.d.ts +0 -1
  81. package/koni/api/staking/bonding/amplitude.js +15 -10
  82. package/koni/api/staking/bonding/astar.js +8 -6
  83. package/koni/api/staking/bonding/index.d.ts +4 -1
  84. package/koni/api/staking/bonding/index.js +23 -13
  85. package/koni/api/staking/bonding/paraChain.d.ts +3 -0
  86. package/koni/api/staking/bonding/paraChain.js +86 -5
  87. package/koni/api/staking/bonding/relayChain.d.ts +5 -1
  88. package/koni/api/staking/bonding/relayChain.js +121 -18
  89. package/koni/api/staking/bonding/utils.d.ts +3 -2
  90. package/koni/api/staking/bonding/utils.js +27 -9
  91. package/koni/api/tokens/wasm/index.js +5 -4
  92. package/koni/api/tokens/wasm/utils.d.ts +6 -0
  93. package/koni/api/tokens/wasm/utils.js +54 -0
  94. package/koni/api/xcm/polkadotXcm.js +2 -2
  95. package/koni/api/xcm/utils.d.ts +5 -6
  96. package/koni/api/xcm/utils.js +15 -10
  97. package/koni/api/xcm/xTokens.js +2 -2
  98. package/koni/api/xcm/xcmPallet.js +10 -9
  99. package/koni/background/cron.d.ts +6 -1
  100. package/koni/background/cron.js +172 -62
  101. package/koni/background/handlers/Extension.d.ts +9 -3
  102. package/koni/background/handlers/Extension.js +306 -126
  103. package/koni/background/handlers/State.d.ts +5 -6
  104. package/koni/background/handlers/State.js +51 -34
  105. package/koni/background/handlers/Tabs.js +50 -17
  106. package/koni/background/subscription.d.ts +2 -0
  107. package/koni/background/subscription.js +51 -29
  108. package/package.json +29 -14
  109. package/packageInfo.js +1 -1
  110. package/services/base/types.d.ts +34 -0
  111. package/services/base/types.js +15 -0
  112. package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
  113. package/services/chain-service/helper/psp22_abi.json +1041 -881
  114. package/services/chain-service/helper/psp34_abi.json +2963 -1807
  115. package/services/chain-service/index.d.ts +5 -2
  116. package/services/chain-service/index.js +68 -45
  117. package/services/chain-service/types.d.ts +1 -0
  118. package/services/event-service/index.js +5 -1
  119. package/services/event-service/types.d.ts +5 -9
  120. package/services/event-service/types.js +4 -1
  121. package/services/history-service/index.d.ts +28 -7
  122. package/services/history-service/index.js +101 -50
  123. package/services/history-service/subsquid-multi-chain-history.js +16 -12
  124. package/services/keyring-service/index.d.ts +4 -2
  125. package/services/keyring-service/index.js +11 -13
  126. package/services/migration-service/scripts/MigrateImportedToken.js +2 -1
  127. package/services/price-service/coingecko.js +0 -1
  128. package/services/price-service/index.d.ts +22 -1
  129. package/services/price-service/index.js +71 -24
  130. package/services/request-service/handler/AuthRequestHandler.d.ts +3 -1
  131. package/services/request-service/handler/AuthRequestHandler.js +13 -7
  132. package/services/request-service/handler/EvmRequestHandler.js +8 -12
  133. package/services/request-service/index.d.ts +3 -1
  134. package/services/request-service/index.js +14 -5
  135. package/services/storage-service/DatabaseService.d.ts +2 -0
  136. package/services/storage-service/DatabaseService.js +66 -34
  137. package/services/storage-service/db-stores/Nft.d.ts +2 -2
  138. package/services/storage-service/db-stores/Nft.js +7 -14
  139. package/services/storage-service/db-stores/Transaction.d.ts +2 -0
  140. package/services/storage-service/db-stores/Transaction.js +6 -10
  141. package/services/transaction-service/event-parser/index.js +21 -49
  142. package/services/transaction-service/index.d.ts +2 -0
  143. package/services/transaction-service/index.js +86 -32
  144. package/services/transaction-service/types.d.ts +2 -0
  145. package/services/transaction-service/utils.js +10 -8
  146. package/utils/address.d.ts +3 -0
  147. package/utils/address.js +8 -1
  148. package/utils/index.d.ts +2 -2
  149. package/utils/index.js +7 -13
  150. package/utils/promise.d.ts +6 -0
  151. package/utils/promise.js +20 -0
@@ -44,7 +44,7 @@ class TransactionService {
44
44
  return Object.values(this.transactions);
45
45
  }
46
46
  get processingTransactions() {
47
- return this.allTransactions.filter(t => t.status === _KoniTypes.ExtrinsicStatus.PENDING || t.status === _KoniTypes.ExtrinsicStatus.PROCESSING);
47
+ return this.allTransactions.filter(t => t.status === _KoniTypes.ExtrinsicStatus.QUEUED || t.status === _KoniTypes.ExtrinsicStatus.PROCESSING);
48
48
  }
49
49
  getTransaction(id) {
50
50
  return this.transactions[id];
@@ -164,6 +164,7 @@ class TransactionService {
164
164
  }
165
165
  fillTransactionDefaultInfo(transaction) {
166
166
  const isInternal = !transaction.url;
167
+ const transactionId = (0, _helpers.getTransactionId)(transaction.chainType, transaction.chain, isInternal);
167
168
  return {
168
169
  ...transaction,
169
170
  createdAt: new Date(),
@@ -171,10 +172,10 @@ class TransactionService {
171
172
  errors: transaction.errors || [],
172
173
  warnings: transaction.warnings || [],
173
174
  url: transaction.url || _constants2.EXTENSION_REQUEST_URL,
174
- status: _KoniTypes.ExtrinsicStatus.PENDING,
175
+ status: _KoniTypes.ExtrinsicStatus.QUEUED,
175
176
  isInternal,
176
- id: (0, _helpers.getTransactionId)(transaction.chainType, transaction.chain, isInternal),
177
- extrinsicHash: ''
177
+ id: transactionId,
178
+ extrinsicHash: transactionId
178
179
  };
179
180
  }
180
181
  async addTransaction(inputTransaction) {
@@ -187,9 +188,6 @@ class TransactionService {
187
188
  this.transactionSubject.next({
188
189
  ...transactions
189
190
  });
190
- console.log(transaction);
191
-
192
- // Send transaction
193
191
  return await this.sendTransaction(transaction);
194
192
  }
195
193
  generateBeforeHandleResponseErrors(errors) {
@@ -216,7 +214,8 @@ class TransactionService {
216
214
  validatedTransaction.warnings = [];
217
215
  const emitter = await this.addTransaction(validatedTransaction);
218
216
  await new Promise(resolve => {
219
- emitter.on('extrinsicHash', data => {
217
+ emitter.on('signed', data => {
218
+ validatedTransaction.id = data.id;
220
219
  validatedTransaction.extrinsicHash = data.extrinsicHash;
221
220
  resolve();
222
221
  });
@@ -232,6 +231,12 @@ class TransactionService {
232
231
  async sendTransaction(transaction) {
233
232
  // Send Transaction
234
233
  const emitter = transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : await this.signAndSendEvmTransaction(transaction);
234
+ emitter.on('signed', data => {
235
+ this.onSigned(data);
236
+ });
237
+ emitter.on('send', data => {
238
+ this.onSend(data);
239
+ });
235
240
  emitter.on('extrinsicHash', data => {
236
241
  this.onHasTransactionHash(data);
237
242
  });
@@ -284,7 +289,8 @@ class TransactionService {
284
289
  to: '',
285
290
  chainType: transaction.chainType,
286
291
  address: transaction.address,
287
- status: _KoniTypes.ExtrinsicStatus.PROCESSING,
292
+ status: transaction.status,
293
+ transactionId: transaction.id,
288
294
  extrinsicHash: transaction.extrinsicHash,
289
295
  time: transaction.createdAt.getTime(),
290
296
  fee: transaction.estimateFee,
@@ -427,18 +433,24 @@ class TransactionService {
427
433
  break;
428
434
  }
429
435
  case _KoniTypes.ExtrinsicType.EVM_EXECUTE:
430
- // Todo: Update historyItem.to
431
- break;
436
+ {
437
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
438
+ const data = (0, _utils2.parseTransactionData)(transaction.data);
439
+
440
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
441
+ historyItem.to = (data === null || data === void 0 ? void 0 : data.to) || '';
442
+ break;
443
+ }
432
444
  case _KoniTypes.ExtrinsicType.UNKNOWN:
433
445
  break;
434
446
  }
435
447
  try {
436
448
  // Return one more history record if transaction send to account in the wallets
437
- const toAccount = (historyItem === null || historyItem === void 0 ? void 0 : historyItem.to) && _uiKeyring.default.getAccount(historyItem.to);
449
+ const toAccount = (historyItem === null || historyItem === void 0 ? void 0 : historyItem.to) && _uiKeyring.default.getPair(historyItem.to);
438
450
  if (toAccount) {
439
451
  return [historyItem, {
440
452
  ...historyItem,
441
- address: historyItem.to,
453
+ address: toAccount.address,
442
454
  direction: _KoniTypes.TransactionDirection.RECEIVED
443
455
  }];
444
456
  }
@@ -447,43 +459,73 @@ class TransactionService {
447
459
  }
448
460
  return [historyItem];
449
461
  }
450
- onHasTransactionHash(_ref) {
462
+ onSigned(_ref) {
451
463
  let {
452
- eventLogs,
453
- extrinsicHash,
454
464
  id
455
465
  } = _ref;
456
- // Write processing transaction history
466
+ console.log(`Transaction "${id}" is signed`);
467
+ }
468
+ onSend(_ref2) {
469
+ let {
470
+ id
471
+ } = _ref2;
472
+ // Update transaction status
457
473
  this.updateTransaction(id, {
474
+ status: _KoniTypes.ExtrinsicStatus.SUBMITTING
475
+ });
476
+
477
+ // Create Input History Transaction History
478
+ this.historyService.insertHistories(this.transactionToHistories(id)).catch(console.error);
479
+ console.log(`Transaction "${id}" is sent`);
480
+ }
481
+ onHasTransactionHash(_ref3) {
482
+ let {
483
+ extrinsicHash,
484
+ id
485
+ } = _ref3;
486
+ // Write processing transaction history
487
+ const updateData = {
458
488
  extrinsicHash,
459
489
  status: _KoniTypes.ExtrinsicStatus.PROCESSING
460
- });
461
- this.historyService.insertHistories(this.transactionToHistories(id, eventLogs)).catch(console.error);
490
+ };
491
+ this.updateTransaction(id, updateData);
492
+
493
+ // In this case transaction id is the same as extrinsic hash and will change after below update
494
+ this.historyService.updateHistoryByExtrinsicHash(id, updateData).catch(console.error);
462
495
  console.log(`Transaction "${id}" is submitted with hash ${extrinsicHash || ''}`);
463
496
  }
464
497
  handlePostProcessing(id) {
465
498
  // must be done after success/failure to make sure the transaction is finalized
466
499
  const transaction = this.getTransaction(id);
467
- switch (transaction.extrinsicType) {
468
- case _KoniTypes.ExtrinsicType.SEND_NFT:
469
- {
470
- const inputData = (0, _utils2.parseTransactionData)(transaction.data);
471
- const sender = _uiKeyring.default.getAccount(inputData.senderAddress);
472
- const recipient = _uiKeyring.default.getAccount(inputData.recipientAddress);
473
- sender && this.databaseService.handleNftTransfer(transaction.chain, [sender.address, _constants.ALL_ACCOUNT_KEY], inputData.nftItem).catch(console.error);
474
- recipient && this.databaseService.addNft(recipient.address, {
475
- ...inputData.nftItem,
476
- owner: recipient.address
477
- }).catch(console.error);
478
- }
500
+ if (transaction.extrinsicType === _KoniTypes.ExtrinsicType.SEND_NFT) {
501
+ const inputData = (0, _utils2.parseTransactionData)(transaction.data);
502
+ try {
503
+ const sender = _uiKeyring.default.getPair(inputData.senderAddress);
504
+ sender && this.databaseService.handleNftTransfer(transaction.chain, [sender.address, _constants.ALL_ACCOUNT_KEY], inputData.nftItem).then(() => {
505
+ this.eventService.emit('transaction.transferNft', undefined);
506
+ }).catch(console.error);
507
+ } catch (e) {
508
+ console.error(e);
509
+ }
510
+ try {
511
+ const recipient = _uiKeyring.default.getPair(inputData.recipientAddress);
512
+ recipient && this.databaseService.addNft(recipient.address, {
513
+ ...inputData.nftItem,
514
+ owner: recipient.address
515
+ }).catch(console.error);
516
+ } catch (e) {
517
+ console.error(e);
518
+ }
519
+ } else if ([_KoniTypes.ExtrinsicType.STAKING_BOND, _KoniTypes.ExtrinsicType.STAKING_UNBOND, _KoniTypes.ExtrinsicType.STAKING_WITHDRAW, _KoniTypes.ExtrinsicType.STAKING_CANCEL_UNSTAKE, _KoniTypes.ExtrinsicType.STAKING_CLAIM_REWARD, _KoniTypes.ExtrinsicType.STAKING_JOIN_POOL, _KoniTypes.ExtrinsicType.STAKING_POOL_WITHDRAW, _KoniTypes.ExtrinsicType.STAKING_LEAVE_POOL].includes(transaction.extrinsicType)) {
520
+ this.eventService.emit('transaction.submitStaking', transaction.chain);
479
521
  }
480
522
  }
481
- onSuccess(_ref2) {
523
+ onSuccess(_ref4) {
482
524
  let {
483
525
  blockHash,
484
526
  blockNumber,
485
527
  id
486
- } = _ref2;
528
+ } = _ref4;
487
529
  const transaction = this.getTransaction(id);
488
530
  this.updateTransaction(id, {
489
531
  status: _KoniTypes.ExtrinsicStatus.SUCCESS
@@ -507,24 +549,25 @@ class TransactionService {
507
549
  });
508
550
  this.eventService.emit('transaction.done', transaction);
509
551
  }
510
- onFailed(_ref3) {
552
+ onFailed(_ref5) {
511
553
  let {
512
554
  blockHash,
513
555
  blockNumber,
514
556
  errors,
515
557
  id
516
- } = _ref3;
558
+ } = _ref5;
517
559
  const transaction = this.getTransaction(id);
560
+ const nextStatus = _KoniTypes.ExtrinsicStatus.FAIL;
518
561
  if (transaction) {
519
562
  this.updateTransaction(id, {
520
- status: _KoniTypes.ExtrinsicStatus.FAIL,
563
+ status: nextStatus,
521
564
  errors
522
565
  });
523
566
  console.log('Transaction failed', id, transaction.extrinsicHash);
524
567
 
525
568
  // Write failed transaction history
526
569
  this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
527
- status: _KoniTypes.ExtrinsicStatus.FAIL,
570
+ status: nextStatus,
528
571
  blockNumber: blockNumber || 0,
529
572
  blockHash: blockHash || ''
530
573
  }).catch(console.error);
@@ -558,14 +601,14 @@ class TransactionService {
558
601
  const encoded = _rlp.default.encode(data);
559
602
  return (0, _util.u8aToHex)(encoded);
560
603
  }
561
- async signAndSendEvmTransaction(_ref4) {
604
+ async signAndSendEvmTransaction(_ref6) {
562
605
  let {
563
606
  address,
564
607
  chain,
565
608
  id,
566
609
  transaction,
567
610
  url
568
- } = _ref4;
611
+ } = _ref6;
569
612
  const payload = transaction;
570
613
  const evmApi = this.chainService.getEvmApi(chain);
571
614
  const chainInfo = this.chainService.getChainInfoByKey(chain);
@@ -587,6 +630,9 @@ class TransactionService {
587
630
  payload.isToContract = isToContract;
588
631
  payload.parseData = isToContract ? payload.data ? (await (0, _parseTransaction.parseContractInput)(payload.data || '', payload.to || '', chainInfo)).result : '' : payload.data || '';
589
632
  }
633
+ if ('data' in payload && payload.data === undefined) {
634
+ delete payload.data;
635
+ }
590
636
 
591
637
  // Set unique nonce to avoid transaction errors
592
638
  if (!payload.nonce) {
@@ -622,11 +668,11 @@ class TransactionService {
622
668
  errors: [],
623
669
  warnings: []
624
670
  };
625
- this.requestService.addConfirmation(id, url || _constants2.EXTENSION_REQUEST_URL, 'evmSendTransactionRequest', payload, {}).then(_ref5 => {
671
+ this.requestService.addConfirmation(id, url || _constants2.EXTENSION_REQUEST_URL, 'evmSendTransactionRequest', payload, {}).then(_ref7 => {
626
672
  let {
627
673
  isApproved,
628
674
  payload
629
- } = _ref5;
675
+ } = _ref7;
630
676
  if (isApproved) {
631
677
  let signedTransaction;
632
678
  if (!payload) {
@@ -643,6 +689,12 @@ class TransactionService {
643
689
  }
644
690
  signedTransaction = signed;
645
691
  }
692
+
693
+ // Emit signed event
694
+ emitter.emit('signed', eventData);
695
+
696
+ // Send transaction
697
+ emitter.emit('send', eventData); // This event is needed after sending transaction with queue
646
698
  signedTransaction && web3Api.eth.sendSignedTransaction(signedTransaction).once('transactionHash', hash => {
647
699
  eventData.extrinsicHash = hash;
648
700
  emitter.emit('extrinsicHash', eventData);
@@ -669,20 +721,19 @@ class TransactionService {
669
721
  });
670
722
  return emitter;
671
723
  }
672
- signAndSendSubstrateTransaction(_ref6) {
724
+ signAndSendSubstrateTransaction(_ref8) {
673
725
  let {
674
726
  address,
675
727
  id,
676
728
  transaction,
677
729
  url
678
- } = _ref6;
730
+ } = _ref8;
679
731
  const emitter = new _eventemitter.default();
680
732
  const eventData = {
681
733
  id,
682
734
  errors: [],
683
735
  warnings: []
684
736
  };
685
- console.debug(address, transaction);
686
737
  transaction.signAsync(address, {
687
738
  signer: {
688
739
  signPayload: async payload => {
@@ -694,6 +745,11 @@ class TransactionService {
694
745
  }
695
746
  }
696
747
  }).then(rs => {
748
+ // Emit signed event
749
+ emitter.emit('signed', eventData);
750
+
751
+ // Send transaction
752
+ emitter.emit('send', eventData); // This event is needed after sending transaction with queue
697
753
  rs.send(txState => {
698
754
  // handle events, logs, history
699
755
  if (!txState || !txState.status) {
@@ -709,20 +765,20 @@ class TransactionService {
709
765
  if (txState.status.isFinalized) {
710
766
  eventData.eventLogs = txState.events;
711
767
  // TODO: push block hash and block number into eventData
712
- txState.events.filter(_ref7 => {
768
+ txState.events.filter(_ref9 => {
713
769
  let {
714
770
  event: {
715
771
  section
716
772
  }
717
- } = _ref7;
773
+ } = _ref9;
718
774
  return section === 'system';
719
- }).forEach(_ref8 => {
775
+ }).forEach(_ref10 => {
720
776
  let {
721
777
  event: {
722
778
  method,
723
779
  data: [error]
724
780
  }
725
- } = _ref8;
781
+ } = _ref10;
726
782
  if (method === 'ExtrinsicFailed') {
727
783
  eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.SEND_TRANSACTION_FAILED, error.toString()));
728
784
  emitter.emit('error', eventData);
@@ -15,15 +15,17 @@ function parseTransactionData(data) {
15
15
  return data;
16
16
  }
17
17
  function getTransactionLink(chainInfo, extrinsicHash) {
18
- const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
19
- if ((0, _utils._isPureEvmChain)(chainInfo)) {
20
- if (explorerLink) {
21
- return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}tx/${extrinsicHash}`;
22
- }
23
- } else {
18
+ if (extrinsicHash.startsWith('0x')) {
24
19
  const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
25
- if (explorerLink) {
26
- return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${extrinsicHash}`;
20
+ if ((0, _utils._isPureEvmChain)(chainInfo)) {
21
+ if (explorerLink) {
22
+ return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}tx/${extrinsicHash}`;
23
+ }
24
+ } else {
25
+ const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
26
+ if (explorerLink) {
27
+ return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${extrinsicHash}`;
28
+ }
27
29
  }
28
30
  }
29
31
  return undefined;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.convertSubjectInfoToAddresses = void 0;
6
7
  exports.quickFormatAddressToCompare = quickFormatAddressToCompare;
7
8
  exports.simpleAddress = void 0;
8
9
  var _index = require("@subwallet/extension-base/utils/index");
@@ -22,4 +23,12 @@ function quickFormatAddressToCompare(address) {
22
23
  return address;
23
24
  }
24
25
  return (0, _index.reformatAddress)(address, 42).toLowerCase();
25
- }
26
+ }
27
+ const convertSubjectInfoToAddresses = subjectInfo => {
28
+ return Object.values(subjectInfo).map(info => ({
29
+ address: info.json.address,
30
+ type: info.type,
31
+ ...info.json.meta
32
+ }));
33
+ };
34
+ exports.convertSubjectInfoToAddresses = convertSubjectInfoToAddresses;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
@@ -28,15 +27,14 @@ exports.isUrl = isUrl;
28
27
  exports.isValidSubstrateAddress = exports.isValidProvider = void 0;
29
28
  exports.mergeNetworkProviders = mergeNetworkProviders;
30
29
  exports.parseIpfsLink = exports.notDef = exports.nonEmptyArr = void 0;
31
- exports.parseNumberToDisplay = parseNumberToDisplay;
32
30
  exports.parseRawNumber = parseRawNumber;
33
31
  exports.reformatAddress = reformatAddress;
34
32
  exports.sumBN = sumBN;
35
33
  exports.toUnit = void 0;
36
34
  exports.utf16ToString = utf16ToString;
35
+ exports.waitTimeout = waitTimeout;
37
36
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
38
37
  var _constants = require("@subwallet/extension-base/constants");
39
- var _bignumber = _interopRequireDefault(require("bignumber.js"));
40
38
  var _util = require("@polkadot/util");
41
39
  var _utilCrypto = require("@polkadot/util-crypto");
42
40
  var _canDerive = require("./canDerive");
@@ -54,7 +52,8 @@ exports.isEmptyArray = isEmptyArray;
54
52
  function isAccountAll(address) {
55
53
  return address === _constants.ALL_ACCOUNT_KEY;
56
54
  }
57
- function reformatAddress(address, networkPrefix) {
55
+ function reformatAddress(address) {
56
+ let networkPrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 42;
58
57
  let isEthereum = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
59
58
  try {
60
59
  if ((0, _utilCrypto.isEthereumAddress)(address)) {
@@ -315,21 +314,16 @@ exports.filterAndSortingAccountByAuthType = filterAndSortingAccountByAuthType;
315
314
  function parseRawNumber(value) {
316
315
  return parseFloat(value.replaceAll(',', ''));
317
316
  }
318
- function parseNumberToDisplay(amount, decimals) {
319
- if (!decimals) {
320
- return '0';
321
- }
322
- const parsedAmount = parseRawNumber(amount.toString());
323
- const bigN = new _bignumber.default(parsedAmount / 10 ** decimals);
324
- const roundedString = bigN.toFixed(9);
325
- const formattedString = parseFloat(roundedString); // remove excess zeros at the end
326
-
327
- return formattedString.toString();
328
- }
329
317
  function isSameAddress(address1, address2) {
318
+ if ((0, _utilCrypto.isEthereumAddress)(address1)) {
319
+ return address1.toLowerCase() === address2.toLowerCase();
320
+ }
330
321
  return reformatAddress(address1, 0) === reformatAddress(address2, 0); // TODO: maybe there's a better way
331
322
  }
332
323
 
333
324
  function getDomainFromUrl(url) {
334
325
  return url.replace(/^(https?:\/\/)?(www\.)?/, '').split('/')[0];
326
+ }
327
+ async function waitTimeout(ms) {
328
+ return new Promise(resolve => setTimeout(resolve, ms));
335
329
  }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createPromiseHandler = createPromiseHandler;
7
+ // Copyright 2019-2022 @subwallet/extension-base
8
+ // SPDX-License-Identifier: Apache-2.0
9
+
10
+ function createPromiseHandler() {
11
+ let _resolve = () => {
12
+ console.warn('This promise handler is not implemented');
13
+ };
14
+ let _reject = () => {
15
+ console.warn('This promise handler is not implemented');
16
+ };
17
+ const promise = new Promise((resolve, reject) => {
18
+ _resolve = resolve;
19
+ _reject = reject;
20
+ });
21
+ return {
22
+ resolve: _resolve,
23
+ reject: _reject,
24
+ promise
25
+ };
26
+ }
@@ -1,22 +1,16 @@
1
1
  export declare const CRON_REFRESH_PRICE_INTERVAL = 30000;
2
- export declare const DOTSAMA_API_TIMEOUT = 30000;
3
- export declare const DOTSAMA_AUTO_CONNECT_MS = 3000;
4
- export declare const DOTSAMA_MAX_CONTINUE_RETRY = 2;
5
2
  export declare const CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = 60000;
6
3
  export declare const CRON_AUTO_RECOVER_WEB3_INTERVAL = 90000;
7
4
  export declare const ACALA_REFRESH_CROWDLOAN_INTERVAL = 300000;
8
- export declare const ACALA_REFRESH_BALANCE_INTERVAL = 30000;
9
- export declare const ASTAR_REFRESH_BALANCE_INTERVAL = 30000;
10
- export declare const SUB_TOKEN_REFRESH_BALANCE_INTERVAL = 30000;
11
- export declare const SUBSCRIBE_BALANCE_FAST_INTERVAL = 9000;
12
- export declare const CRON_REFRESH_NFT_INTERVAL = 900000;
5
+ export declare const ASTAR_REFRESH_BALANCE_INTERVAL = 60000;
6
+ export declare const SUB_TOKEN_REFRESH_BALANCE_INTERVAL = 60000;
7
+ export declare const CRON_REFRESH_NFT_INTERVAL = 7200000;
13
8
  export declare const CRON_REFRESH_STAKING_REWARD_INTERVAL = 900000;
14
- export declare const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 10000;
15
- export declare const CRON_REFRESH_HISTORY_INTERVAL = 90000;
16
- export declare const CRON_GET_API_MAP_STATUS = 5000;
17
- export declare const CRON_REFRESH_STAKING_DATA = 30000;
9
+ export declare const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 300000;
10
+ export declare const CRON_REFRESH_HISTORY_INTERVAL = 900000;
11
+ export declare const CRON_GET_API_MAP_STATUS = 10000;
18
12
  export declare const CRON_REFRESH_CHAIN_STAKING_METADATA = 900000;
19
- export declare const CRON_REFRESH_CHAIN_NOMINATOR_METADATA = 900000;
13
+ export declare const CRON_REFRESH_CHAIN_NOMINATOR_METADATA = 1800000;
20
14
  export declare const ALL_ACCOUNT_KEY = "ALL";
21
15
  export declare const ALL_NETWORK_KEY = "all";
22
16
  export declare const ALL_GENESIS_HASH: null;
@@ -2,24 +2,18 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  export const CRON_REFRESH_PRICE_INTERVAL = 30000;
5
- export const DOTSAMA_API_TIMEOUT = 30000;
6
- export const DOTSAMA_AUTO_CONNECT_MS = 3000;
7
- export const DOTSAMA_MAX_CONTINUE_RETRY = 2;
8
5
  export const CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = 60000;
9
6
  export const CRON_AUTO_RECOVER_WEB3_INTERVAL = 90000;
10
7
  export const ACALA_REFRESH_CROWDLOAN_INTERVAL = 300000;
11
- export const ACALA_REFRESH_BALANCE_INTERVAL = 30000;
12
- export const ASTAR_REFRESH_BALANCE_INTERVAL = 30000;
13
- export const SUB_TOKEN_REFRESH_BALANCE_INTERVAL = 30000;
14
- export const SUBSCRIBE_BALANCE_FAST_INTERVAL = 9000;
15
- export const CRON_REFRESH_NFT_INTERVAL = 900000;
8
+ export const ASTAR_REFRESH_BALANCE_INTERVAL = 60000;
9
+ export const SUB_TOKEN_REFRESH_BALANCE_INTERVAL = 60000;
10
+ export const CRON_REFRESH_NFT_INTERVAL = 7200000;
16
11
  export const CRON_REFRESH_STAKING_REWARD_INTERVAL = 900000;
17
- export const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 10000;
18
- export const CRON_REFRESH_HISTORY_INTERVAL = 90000;
19
- export const CRON_GET_API_MAP_STATUS = 5000;
20
- export const CRON_REFRESH_STAKING_DATA = 30000;
12
+ export const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 300000;
13
+ export const CRON_REFRESH_HISTORY_INTERVAL = 900000;
14
+ export const CRON_GET_API_MAP_STATUS = 10000;
21
15
  export const CRON_REFRESH_CHAIN_STAKING_METADATA = 900000;
22
- export const CRON_REFRESH_CHAIN_NOMINATOR_METADATA = 900000;
16
+ export const CRON_REFRESH_CHAIN_NOMINATOR_METADATA = 1800000;
23
17
  export const ALL_ACCOUNT_KEY = 'ALL';
24
18
  export const ALL_NETWORK_KEY = 'all';
25
19
  export const ALL_GENESIS_HASH = null;
@@ -4,4 +4,3 @@ import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain
4
4
  export declare function subscribeBalance(addresses: string[], chainInfoMap: Record<string, _ChainInfo>, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, callback: (rs: BalanceItem) => void): () => void;
5
5
  export declare function subscribeSubstrateBalance(addresses: string[], chainInfo: _ChainInfo, chain: string, networkAPI: _SubstrateApi, evmApiMap: Record<string, _EvmApi>, callBack: (rs: BalanceItem) => void): Promise<() => void>;
6
6
  export declare function subscribeEVMBalance(chain: string, addresses: string[], evmApiMap: Record<string, _EvmApi>, callback: (rs: BalanceItem) => void, tokenInfo: _ChainAsset): () => void;
7
- export declare function getFreeBalance(chain: string, address: string, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, tokenSlug?: string): Promise<string>;