@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
@@ -9,15 +9,17 @@ export function parseTransactionData(data) {
9
9
  return data;
10
10
  }
11
11
  export function getTransactionLink(chainInfo, extrinsicHash) {
12
- const explorerLink = _getBlockExplorerFromChain(chainInfo);
13
- if (_isPureEvmChain(chainInfo)) {
14
- if (explorerLink) {
15
- return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}tx/${extrinsicHash}`;
16
- }
17
- } else {
12
+ if (extrinsicHash.startsWith('0x')) {
18
13
  const explorerLink = _getBlockExplorerFromChain(chainInfo);
19
- if (explorerLink) {
20
- return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${extrinsicHash}`;
14
+ if (_isPureEvmChain(chainInfo)) {
15
+ if (explorerLink) {
16
+ return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}tx/${extrinsicHash}`;
17
+ }
18
+ } else {
19
+ const explorerLink = _getBlockExplorerFromChain(chainInfo);
20
+ if (explorerLink) {
21
+ return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${extrinsicHash}`;
22
+ }
21
23
  }
22
24
  }
23
25
  return undefined;
@@ -1,2 +1,5 @@
1
+ import { AddressJson } from '@subwallet/extension-base/background/types';
2
+ import { SubjectInfo } from '@subwallet/ui-keyring/observable/types';
1
3
  export declare const simpleAddress: (address: string) => string;
2
4
  export declare function quickFormatAddressToCompare(address?: string): string | undefined;
5
+ export declare const convertSubjectInfoToAddresses: (subjectInfo: SubjectInfo) => AddressJson[];
package/utils/address.js CHANGED
@@ -14,4 +14,11 @@ export function quickFormatAddressToCompare(address) {
14
14
  return address;
15
15
  }
16
16
  return reformatAddress(address, 42).toLowerCase();
17
- }
17
+ }
18
+ export const convertSubjectInfoToAddresses = subjectInfo => {
19
+ return Object.values(subjectInfo).map(info => ({
20
+ address: info.json.address,
21
+ type: info.type,
22
+ ...info.json.meta
23
+ }));
24
+ };
package/utils/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export declare const isDef: (x: any) => boolean;
8
8
  export declare const nonEmptyArr: (x: any) => boolean;
9
9
  export declare const isEmptyArray: (x: any) => boolean;
10
10
  export declare function isAccountAll(address?: string): boolean;
11
- export declare function reformatAddress(address: string, networkPrefix: number, isEthereum?: boolean): string;
11
+ export declare function reformatAddress(address: string, networkPrefix?: number, isEthereum?: boolean): string;
12
12
  export declare function filterAddressByNetworkKey(addresses: string[], networkKey: string, isEthereum?: boolean): string[];
13
13
  export declare function categoryAddresses(addresses: string[]): string[][];
14
14
  export declare function categoryNetworks(networks: NetworkJson[]): string[][];
@@ -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";
@@ -14,7 +13,7 @@ export const isEmptyArray = x => !Array.isArray(x) || Array.isArray(x) && x.leng
14
13
  export function isAccountAll(address) {
15
14
  return address === ALL_ACCOUNT_KEY;
16
15
  }
17
- export function reformatAddress(address, networkPrefix, isEthereum = false) {
16
+ export function reformatAddress(address, networkPrefix = 42, isEthereum = false) {
18
17
  try {
19
18
  if (isEthereumAddress(address)) {
20
19
  return address;
@@ -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
  }
@@ -0,0 +1,6 @@
1
+ export declare function createPromiseHandler<T>(): {
2
+ resolve: (value: T) => void;
3
+ reject: (reason?: unknown) => void;
4
+ promise: Promise<T>;
5
+ };
6
+ export declare type PromiseHandler<T> = ReturnType<typeof createPromiseHandler<T>>;
@@ -0,0 +1,20 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export function createPromiseHandler() {
5
+ let _resolve = () => {
6
+ console.warn('This promise handler is not implemented');
7
+ };
8
+ let _reject = () => {
9
+ console.warn('This promise handler is not implemented');
10
+ };
11
+ const promise = new Promise((resolve, reject) => {
12
+ _resolve = resolve;
13
+ _reject = reject;
14
+ });
15
+ return {
16
+ resolve: _resolve,
17
+ reject: _reject,
18
+ promise
19
+ };
20
+ }