@subwallet/extension-base 1.0.2-1 → 1.0.2-1b

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 (120) hide show
  1. package/background/KoniTypes.d.ts +16 -34
  2. package/background/KoniTypes.js +6 -7
  3. package/background/errors/TransactionError.js +21 -1
  4. package/cjs/background/KoniTypes.js +6 -7
  5. package/cjs/background/errors/TransactionError.js +20 -0
  6. package/cjs/constants/index.js +8 -26
  7. package/cjs/koni/api/dotsama/balance.js +49 -224
  8. package/cjs/koni/api/dotsama/transfer.js +30 -29
  9. package/cjs/koni/api/nft/acala_nft/index.js +4 -1
  10. package/cjs/koni/api/nft/bit.country/index.js +4 -1
  11. package/cjs/koni/api/nft/evm_nft/index.js +7 -3
  12. package/cjs/koni/api/nft/index.js +3 -6
  13. package/cjs/koni/api/nft/karura_nft/index.js +4 -1
  14. package/cjs/koni/api/nft/rmrk_nft/index.js +8 -1
  15. package/cjs/koni/api/nft/statemine_nft/index.js +4 -1
  16. package/cjs/koni/api/nft/unique_nft/index.js +6 -1
  17. package/cjs/koni/api/nft/wasm_nft/index.js +169 -111
  18. package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
  19. package/cjs/koni/api/staking/bonding/amplitude.js +13 -9
  20. package/cjs/koni/api/staking/bonding/astar.js +15 -13
  21. package/cjs/koni/api/staking/bonding/index.js +22 -10
  22. package/cjs/koni/api/staking/bonding/paraChain.js +85 -2
  23. package/cjs/koni/api/staking/bonding/relayChain.js +119 -16
  24. package/cjs/koni/api/staking/bonding/utils.js +27 -8
  25. package/cjs/koni/api/tokens/wasm/index.js +5 -4
  26. package/cjs/koni/api/tokens/wasm/utils.js +63 -0
  27. package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
  28. package/cjs/koni/api/xcm/utils.js +18 -13
  29. package/cjs/koni/api/xcm/xTokens.js +1 -1
  30. package/cjs/koni/api/xcm/xcmPallet.js +9 -6
  31. package/cjs/koni/background/cron.js +150 -47
  32. package/cjs/koni/background/handlers/Extension.js +106 -64
  33. package/cjs/koni/background/handlers/State.js +19 -21
  34. package/cjs/koni/background/handlers/Tabs.js +8 -1
  35. package/cjs/koni/background/subscription.js +32 -29
  36. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
  37. package/cjs/services/chain-service/handler/light-client/index.js +2 -0
  38. package/cjs/services/chain-service/index.js +6 -7
  39. package/cjs/services/event-service/index.js +5 -1
  40. package/cjs/services/event-service/types.js +11 -1
  41. package/cjs/services/history-service/index.js +16 -10
  42. package/cjs/services/history-service/subsquid-multi-chain-history.js +12 -9
  43. package/cjs/services/price-service/coingecko.js +0 -1
  44. package/cjs/services/price-service/index.js +2 -3
  45. package/cjs/services/request-service/handler/AuthRequestHandler.js +6 -2
  46. package/cjs/services/storage-service/DatabaseService.js +52 -33
  47. package/cjs/services/storage-service/db-stores/Nft.js +4 -17
  48. package/cjs/services/transaction-service/event-parser/index.js +20 -48
  49. package/cjs/services/transaction-service/index.js +23 -14
  50. package/cjs/utils/index.js +7 -14
  51. package/constants/index.d.ts +7 -13
  52. package/constants/index.js +7 -13
  53. package/koni/api/dotsama/balance.d.ts +0 -1
  54. package/koni/api/dotsama/balance.js +22 -197
  55. package/koni/api/dotsama/transfer.js +5 -4
  56. package/koni/api/nft/acala_nft/index.js +3 -1
  57. package/koni/api/nft/bit.country/index.js +3 -1
  58. package/koni/api/nft/evm_nft/index.js +6 -3
  59. package/koni/api/nft/index.d.ts +1 -2
  60. package/koni/api/nft/index.js +3 -6
  61. package/koni/api/nft/karura_nft/index.js +3 -1
  62. package/koni/api/nft/nft.d.ts +1 -0
  63. package/koni/api/nft/rmrk_nft/index.js +8 -1
  64. package/koni/api/nft/statemine_nft/index.js +3 -1
  65. package/koni/api/nft/unique_nft/index.js +5 -1
  66. package/koni/api/nft/wasm_nft/index.d.ts +0 -2
  67. package/koni/api/nft/wasm_nft/index.js +167 -109
  68. package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
  69. package/koni/api/nft/wasm_nft/utils.js +7 -5
  70. package/koni/api/staking/bonding/amplitude.d.ts +0 -1
  71. package/koni/api/staking/bonding/amplitude.js +15 -10
  72. package/koni/api/staking/bonding/astar.js +8 -6
  73. package/koni/api/staking/bonding/index.d.ts +4 -1
  74. package/koni/api/staking/bonding/index.js +23 -13
  75. package/koni/api/staking/bonding/paraChain.d.ts +3 -0
  76. package/koni/api/staking/bonding/paraChain.js +86 -5
  77. package/koni/api/staking/bonding/relayChain.d.ts +5 -1
  78. package/koni/api/staking/bonding/relayChain.js +118 -18
  79. package/koni/api/staking/bonding/utils.d.ts +3 -2
  80. package/koni/api/staking/bonding/utils.js +27 -9
  81. package/koni/api/tokens/wasm/index.js +5 -4
  82. package/koni/api/tokens/wasm/utils.d.ts +6 -0
  83. package/koni/api/tokens/wasm/utils.js +54 -0
  84. package/koni/api/xcm/polkadotXcm.js +2 -2
  85. package/koni/api/xcm/utils.d.ts +5 -6
  86. package/koni/api/xcm/utils.js +15 -10
  87. package/koni/api/xcm/xTokens.js +2 -2
  88. package/koni/api/xcm/xcmPallet.js +10 -9
  89. package/koni/background/cron.d.ts +6 -1
  90. package/koni/background/cron.js +151 -48
  91. package/koni/background/handlers/Extension.d.ts +2 -2
  92. package/koni/background/handlers/Extension.js +108 -67
  93. package/koni/background/handlers/State.d.ts +5 -6
  94. package/koni/background/handlers/State.js +19 -21
  95. package/koni/background/handlers/Tabs.js +8 -1
  96. package/koni/background/subscription.js +31 -30
  97. package/package.json +9 -4
  98. package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
  99. package/services/chain-service/handler/light-client/index.d.ts +17 -1
  100. package/services/chain-service/handler/light-client/index.js +1 -1
  101. package/services/chain-service/helper/psp22_abi.json +1041 -881
  102. package/services/chain-service/helper/psp34_abi.json +2963 -1807
  103. package/services/chain-service/index.js +6 -7
  104. package/services/event-service/index.js +5 -1
  105. package/services/event-service/types.d.ts +5 -9
  106. package/services/event-service/types.js +4 -1
  107. package/services/history-service/index.d.ts +1 -1
  108. package/services/history-service/index.js +16 -10
  109. package/services/history-service/subsquid-multi-chain-history.js +15 -11
  110. package/services/price-service/coingecko.js +0 -1
  111. package/services/price-service/index.js +2 -3
  112. package/services/request-service/handler/AuthRequestHandler.js +6 -2
  113. package/services/storage-service/DatabaseService.d.ts +1 -0
  114. package/services/storage-service/DatabaseService.js +52 -33
  115. package/services/storage-service/db-stores/Nft.d.ts +1 -2
  116. package/services/storage-service/db-stores/Nft.js +4 -16
  117. package/services/transaction-service/event-parser/index.js +21 -49
  118. package/services/transaction-service/index.js +23 -14
  119. package/utils/index.d.ts +1 -1
  120. package/utils/index.js +6 -12
@@ -427,11 +427,11 @@ export default class TransactionService {
427
427
  }
428
428
  try {
429
429
  // Return one more history record if transaction send to account in the wallets
430
- const toAccount = (historyItem === null || historyItem === void 0 ? void 0 : historyItem.to) && keyring.getAccount(historyItem.to);
430
+ const toAccount = (historyItem === null || historyItem === void 0 ? void 0 : historyItem.to) && keyring.getPair(historyItem.to);
431
431
  if (toAccount) {
432
432
  return [historyItem, {
433
433
  ...historyItem,
434
- address: historyItem.to,
434
+ address: toAccount.address,
435
435
  direction: TransactionDirection.RECEIVED
436
436
  }];
437
437
  }
@@ -456,18 +456,27 @@ export default class TransactionService {
456
456
  handlePostProcessing(id) {
457
457
  // must be done after success/failure to make sure the transaction is finalized
458
458
  const transaction = this.getTransaction(id);
459
- switch (transaction.extrinsicType) {
460
- case ExtrinsicType.SEND_NFT:
461
- {
462
- const inputData = parseTransactionData(transaction.data);
463
- const sender = keyring.getAccount(inputData.senderAddress);
464
- const recipient = keyring.getAccount(inputData.recipientAddress);
465
- sender && this.databaseService.handleNftTransfer(transaction.chain, [sender.address, ALL_ACCOUNT_KEY], inputData.nftItem).catch(console.error);
466
- recipient && this.databaseService.addNft(recipient.address, {
467
- ...inputData.nftItem,
468
- owner: recipient.address
469
- }).catch(console.error);
470
- }
459
+ if (transaction.extrinsicType === ExtrinsicType.SEND_NFT) {
460
+ const inputData = parseTransactionData(transaction.data);
461
+ try {
462
+ const sender = keyring.getPair(inputData.senderAddress);
463
+ sender && this.databaseService.handleNftTransfer(transaction.chain, [sender.address, ALL_ACCOUNT_KEY], inputData.nftItem).then(() => {
464
+ this.eventService.emit('transaction.transferNft', undefined);
465
+ }).catch(console.error);
466
+ } catch (e) {
467
+ console.error(e);
468
+ }
469
+ try {
470
+ const recipient = keyring.getPair(inputData.recipientAddress);
471
+ recipient && this.databaseService.addNft(recipient.address, {
472
+ ...inputData.nftItem,
473
+ owner: recipient.address
474
+ }).catch(console.error);
475
+ } catch (e) {
476
+ console.error(e);
477
+ }
478
+ } else if ([ExtrinsicType.STAKING_BOND, ExtrinsicType.STAKING_UNBOND, ExtrinsicType.STAKING_WITHDRAW, ExtrinsicType.STAKING_CANCEL_UNSTAKE, ExtrinsicType.STAKING_CLAIM_REWARD, ExtrinsicType.STAKING_JOIN_POOL, ExtrinsicType.STAKING_POOL_WITHDRAW, ExtrinsicType.STAKING_LEAVE_POOL].includes(transaction.extrinsicType)) {
479
+ this.eventService.emit('transaction.submitStaking', transaction.chain);
471
480
  }
472
481
  }
473
482
  onSuccess({
package/utils/index.d.ts CHANGED
@@ -34,6 +34,6 @@ export declare function mergeNetworkProviders(customNetwork: NetworkJson, predef
34
34
  };
35
35
  export declare const filterAndSortingAccountByAuthType: (accounts: AccountJson[], accountAuthType: AccountAuthType, sorting?: boolean) => AccountJson[];
36
36
  export declare function parseRawNumber(value: string): number;
37
- export declare function parseNumberToDisplay(amount: BN, decimals: number | undefined): string;
38
37
  export declare function isSameAddress(address1: string, address2: string): boolean;
39
38
  export declare function getDomainFromUrl(url: string): string;
39
+ export declare function waitTimeout(ms: number): Promise<void>;
package/utils/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
 
4
4
  import { CrowdloanParaState } from '@subwallet/extension-base/background/KoniTypes';
5
5
  import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
6
- import BigNumber from 'bignumber.js';
7
6
  import { BN, hexToU8a, isHex } from '@polkadot/util';
8
7
  import { decodeAddress, encodeAddress, ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
9
8
  export { canDerive } from "./canDerive.js";
@@ -264,21 +263,16 @@ export const filterAndSortingAccountByAuthType = (accounts, accountAuthType, sor
264
263
  export function parseRawNumber(value) {
265
264
  return parseFloat(value.replaceAll(',', ''));
266
265
  }
267
- export function parseNumberToDisplay(amount, decimals) {
268
- if (!decimals) {
269
- return '0';
270
- }
271
- const parsedAmount = parseRawNumber(amount.toString());
272
- const bigN = new BigNumber(parsedAmount / 10 ** decimals);
273
- const roundedString = bigN.toFixed(9);
274
- const formattedString = parseFloat(roundedString); // remove excess zeros at the end
275
-
276
- return formattedString.toString();
277
- }
278
266
  export function isSameAddress(address1, address2) {
267
+ if (isEthereumAddress(address1)) {
268
+ return address1.toLowerCase() === address2.toLowerCase();
269
+ }
279
270
  return reformatAddress(address1, 0) === reformatAddress(address2, 0); // TODO: maybe there's a better way
280
271
  }
281
272
 
282
273
  export function getDomainFromUrl(url) {
283
274
  return url.replace(/^(https?:\/\/)?(www\.)?/, '').split('/')[0];
275
+ }
276
+ export async function waitTimeout(ms) {
277
+ return new Promise(resolve => setTimeout(resolve, ms));
284
278
  }