@subwallet/extension-base 1.2.23-0 → 1.2.24-1

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 (97) hide show
  1. package/background/KoniTypes.d.ts +14 -0
  2. package/cjs/constants/index.js +4 -1
  3. package/cjs/core/substrate/assets-pallet.js +35 -0
  4. package/cjs/core/substrate/foreign-asset-pallet.js +13 -3
  5. package/cjs/core/substrate/nominationpools-pallet.js +4 -6
  6. package/cjs/core/substrate/ormlTokens-pallet.js +24 -0
  7. package/cjs/core/substrate/system-pallet.js +16 -18
  8. package/cjs/core/substrate/tokens-pallet.js +24 -0
  9. package/cjs/core/substrate/types.js +19 -0
  10. package/cjs/core/substrate/xcm-parser.js +16 -2
  11. package/cjs/core/utils.js +31 -0
  12. package/cjs/koni/background/cron.js +10 -0
  13. package/cjs/koni/background/handlers/Extension.js +61 -5
  14. package/cjs/koni/background/handlers/State.js +3 -0
  15. package/cjs/packageInfo.js +1 -1
  16. package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +2 -2
  17. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +120 -133
  18. package/cjs/services/balance-service/transfer/xcm/index.js +2 -1
  19. package/cjs/services/balance-service/transfer/xcm/polkadotXcm.js +1 -1
  20. package/cjs/services/balance-service/transfer/xcm/utils.js +3 -2
  21. package/cjs/services/chain-service/constants.js +1 -1
  22. package/cjs/services/chain-service/handler/SubstrateApi.js +128 -34
  23. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +26 -9
  24. package/cjs/services/chain-service/utils/index.js +5 -0
  25. package/cjs/services/migration-service/scripts/MigrateLedgerAccountV2.js +3 -3
  26. package/cjs/services/mkt-campaign-service/index.js +284 -0
  27. package/cjs/services/mkt-campaign-service/types.js +17 -0
  28. package/cjs/services/storage-service/DatabaseService.js +115 -0
  29. package/cjs/services/storage-service/db-stores/Balance.js +6 -0
  30. package/cjs/services/storage-service/db-stores/Crowdloan.js +8 -0
  31. package/cjs/services/storage-service/db-stores/Nft.js +12 -0
  32. package/cjs/services/storage-service/db-stores/NftCollection.js +11 -0
  33. package/cjs/services/storage-service/db-stores/YieldPositionStore.js +6 -0
  34. package/constants/index.d.ts +1 -0
  35. package/constants/index.js +1 -0
  36. package/core/substrate/assets-pallet.d.ts +4 -0
  37. package/core/substrate/assets-pallet.js +28 -0
  38. package/core/substrate/foreign-asset-pallet.d.ts +4 -8
  39. package/core/substrate/foreign-asset-pallet.js +13 -3
  40. package/core/substrate/nominationpools-pallet.d.ts +4 -10
  41. package/core/substrate/nominationpools-pallet.js +4 -5
  42. package/core/substrate/ormlTokens-pallet.d.ts +4 -0
  43. package/core/substrate/ormlTokens-pallet.js +17 -0
  44. package/core/substrate/system-pallet.d.ts +4 -24
  45. package/core/substrate/system-pallet.js +16 -21
  46. package/core/substrate/tokens-pallet.d.ts +5 -0
  47. package/core/substrate/tokens-pallet.js +16 -0
  48. package/core/substrate/types.d.ts +43 -0
  49. package/core/substrate/types.js +12 -0
  50. package/core/substrate/xcm-parser.d.ts +1 -0
  51. package/core/substrate/xcm-parser.js +15 -2
  52. package/core/utils.d.ts +4 -0
  53. package/core/utils.js +23 -0
  54. package/koni/api/staking/bonding/relayChain.d.ts +1 -1
  55. package/koni/background/cron.d.ts +1 -0
  56. package/koni/background/cron.js +11 -1
  57. package/koni/background/handlers/Extension.d.ts +3 -0
  58. package/koni/background/handlers/Extension.js +61 -5
  59. package/koni/background/handlers/State.d.ts +4 -2
  60. package/koni/background/handlers/State.js +3 -0
  61. package/package.json +41 -6
  62. package/packageInfo.js +1 -1
  63. package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +2 -2
  64. package/services/balance-service/helpers/subscribe/substrate/index.js +109 -121
  65. package/services/balance-service/transfer/xcm/index.d.ts +1 -1
  66. package/services/balance-service/transfer/xcm/index.js +2 -1
  67. package/services/balance-service/transfer/xcm/polkadotXcm.js +1 -1
  68. package/services/balance-service/transfer/xcm/utils.d.ts +1 -1
  69. package/services/balance-service/transfer/xcm/utils.js +3 -2
  70. package/services/chain-service/constants.js +1 -1
  71. package/services/chain-service/handler/SubstrateApi.d.ts +5 -7
  72. package/services/chain-service/handler/SubstrateApi.js +128 -35
  73. package/services/chain-service/handler/SubstrateChainHandler.d.ts +5 -6
  74. package/services/chain-service/handler/SubstrateChainHandler.js +26 -9
  75. package/services/chain-service/index.d.ts +3 -3
  76. package/services/chain-service/types.d.ts +22 -5
  77. package/services/chain-service/utils/index.d.ts +1 -0
  78. package/services/chain-service/utils/index.js +3 -0
  79. package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -1
  80. package/services/migration-service/scripts/MigrateLedgerAccountV2.js +3 -3
  81. package/services/mkt-campaign-service/index.d.ts +30 -0
  82. package/services/mkt-campaign-service/index.js +275 -0
  83. package/services/mkt-campaign-service/types.d.ts +107 -0
  84. package/services/mkt-campaign-service/types.js +11 -0
  85. package/services/storage-service/DatabaseService.d.ts +5 -0
  86. package/services/storage-service/DatabaseService.js +116 -1
  87. package/services/storage-service/db-stores/Balance.d.ts +2 -0
  88. package/services/storage-service/db-stores/Balance.js +6 -0
  89. package/services/storage-service/db-stores/Crowdloan.d.ts +2 -0
  90. package/services/storage-service/db-stores/Crowdloan.js +8 -0
  91. package/services/storage-service/db-stores/Nft.d.ts +2 -0
  92. package/services/storage-service/db-stores/Nft.js +12 -0
  93. package/services/storage-service/db-stores/NftCollection.d.ts +1 -0
  94. package/services/storage-service/db-stores/NftCollection.js +11 -0
  95. package/services/storage-service/db-stores/YieldPositionStore.d.ts +2 -0
  96. package/services/storage-service/db-stores/YieldPositionStore.js +6 -0
  97. package/types/balance/index.d.ts +2 -3
@@ -5,6 +5,7 @@ import { AccountAuthType, AccountJson, AddressJson, AuthorizeRequest, Confirmati
5
5
  import { RequestOptimalTransferProcess } from '@subwallet/extension-base/services/balance-service/helpers';
6
6
  import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
7
7
  import { _ChainState, _EvmApi, _NetworkUpsertParams, _SubstrateApi, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse, EnableChainParams, EnableMultiChainParams } from '@subwallet/extension-base/services/chain-service/types';
8
+ import { AppBannerData, AppConfirmationData, AppPopupData } from '@subwallet/extension-base/services/mkt-campaign-service/types';
8
9
  import { CrowdloanContributionsResponse } from '@subwallet/extension-base/services/subscan-service/types';
9
10
  import { SWTransactionResponse, SWTransactionResult } from '@subwallet/extension-base/services/transaction-service/types';
10
11
  import { WalletConnectNotSupportRequest, WalletConnectSessionRequest } from '@subwallet/extension-base/services/wallet-connect-service/types';
@@ -737,6 +738,7 @@ export interface RequestAccountCreateHardwareV2 {
737
738
  address: string;
738
739
  addressOffset: number;
739
740
  genesisHash: string;
741
+ originGenesisHash: string;
740
742
  hardwareType: string;
741
743
  name: string;
742
744
  isAllowed?: boolean;
@@ -746,6 +748,7 @@ export interface CreateHardwareAccountItem {
746
748
  address: string;
747
749
  addressOffset: number;
748
750
  genesisHash: string;
751
+ originGenesisHash: string;
749
752
  hardwareType: string;
750
753
  name: string;
751
754
  isEthereum: boolean;
@@ -1079,9 +1082,14 @@ export interface LedgerNetwork {
1079
1082
  isGeneric: boolean;
1080
1083
  /** Use for evm account */
1081
1084
  isEthereum: boolean;
1085
+ /** Hide networks that are supported by the dot migration app */
1086
+ isHide?: boolean;
1082
1087
  /** Slip44 in the derivation path */
1083
1088
  slip44: number;
1084
1089
  }
1090
+ export interface MigrationLedgerNetwork extends Omit<LedgerNetwork, 'isGeneric' | 'isEthereum' | 'isDevMode' | 'icon'> {
1091
+ ss58_addr_type: number;
1092
+ }
1085
1093
  export interface FormattedMethod {
1086
1094
  args?: ArgInfo[];
1087
1095
  methodName: string;
@@ -1766,6 +1774,12 @@ export interface KoniRequestSignatures {
1766
1774
  'pri(campaign.banner.subscribe)': [null, CampaignBanner[], CampaignBanner[]];
1767
1775
  'pri(campaign.popup.subscribeVisibility)': [null, ShowCampaignPopupRequest, ShowCampaignPopupRequest];
1768
1776
  'pri(campaign.popup.toggle)': [ShowCampaignPopupRequest, null];
1777
+ 'pri(campaign.popup.getData)': [null, AppPopupData[]];
1778
+ 'pri(campaign.banner.getData)': [null, AppBannerData[]];
1779
+ 'pri(campaign.confirmation.getData)': [null, AppConfirmationData[]];
1780
+ 'pri(campaign.popups.subscribe)': [null, AppPopupData[], AppPopupData[]];
1781
+ 'pri(campaign.banners.subscribe)': [null, AppBannerData[], AppBannerData[]];
1782
+ 'pri(campaign.confirmations.subscribe)': [null, AppConfirmationData[], AppConfirmationData[]];
1769
1783
  'pri(campaign.banner.complete)': [RequestCampaignBannerComplete, boolean];
1770
1784
  'pri(buyService.tokens.subscribe)': [null, Record<string, BuyTokenInfo>, Record<string, BuyTokenInfo>];
1771
1785
  'pri(buyService.services.subscribe)': [null, Record<string, BuyServiceInfo>, Record<string, BuyServiceInfo>];
@@ -13,6 +13,7 @@ var _exportNames = {
13
13
  ASTAR_REFRESH_BALANCE_INTERVAL: true,
14
14
  SUB_TOKEN_REFRESH_BALANCE_INTERVAL: true,
15
15
  CRON_REFRESH_NFT_INTERVAL: true,
16
+ CRON_REFRESH_MKT_CAMPAIGN_INTERVAL: true,
16
17
  CRON_REFRESH_STAKING_REWARD_INTERVAL: true,
17
18
  CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL: true,
18
19
  CRON_REFRESH_HISTORY_INTERVAL: true,
@@ -35,7 +36,7 @@ var _exportNames = {
35
36
  ORDINAL_COLLECTION: true,
36
37
  ORDINAL_METHODS: true
37
38
  };
38
- exports.XCM_MIN_AMOUNT_RATIO = exports.XCM_FEE_RATIO = exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.ORDINAL_METHODS = exports.ORDINAL_COLLECTION = exports.NETWORK_MULTI_GAS_FEE = exports.MANTA_PAY_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.GAS_PRICE_RATIO = exports.CRON_SYNC_MANTA_PAY = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.BASE_SECOND_INTERVAL = exports.BASE_MINUTE_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
39
+ exports.XCM_MIN_AMOUNT_RATIO = exports.XCM_FEE_RATIO = exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.ORDINAL_METHODS = exports.ORDINAL_COLLECTION = exports.NETWORK_MULTI_GAS_FEE = exports.MANTA_PAY_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.GAS_PRICE_RATIO = exports.CRON_SYNC_MANTA_PAY = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_MKT_CAMPAIGN_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.BASE_SECOND_INTERVAL = exports.BASE_MINUTE_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
39
40
  var _staking = require("./staking");
40
41
  Object.keys(_staking).forEach(function (key) {
41
42
  if (key === "default" || key === "__esModule") return;
@@ -81,6 +82,8 @@ const SUB_TOKEN_REFRESH_BALANCE_INTERVAL = 60000;
81
82
  exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = SUB_TOKEN_REFRESH_BALANCE_INTERVAL;
82
83
  const CRON_REFRESH_NFT_INTERVAL = 7200000;
83
84
  exports.CRON_REFRESH_NFT_INTERVAL = CRON_REFRESH_NFT_INTERVAL;
85
+ const CRON_REFRESH_MKT_CAMPAIGN_INTERVAL = 15 * BASE_MINUTE_INTERVAL;
86
+ exports.CRON_REFRESH_MKT_CAMPAIGN_INTERVAL = CRON_REFRESH_MKT_CAMPAIGN_INTERVAL;
84
87
  const CRON_REFRESH_STAKING_REWARD_INTERVAL = 900000;
85
88
  exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = CRON_REFRESH_STAKING_REWARD_INTERVAL;
86
89
  const CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = 90000;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports._getAssetsPalletLockedBalance = _getAssetsPalletLockedBalance;
7
+ exports._getAssetsPalletTransferable = _getAssetsPalletTransferable;
8
+ var _types = require("@subwallet/extension-base/core/substrate/types");
9
+ var _utils = require("@subwallet/extension-base/core/utils");
10
+ // Copyright 2019-2022 @subwallet/extension-base
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ function _getAssetsPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
14
+ const strictMode = (0, _utils.getStrictMode)(_types.BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
15
+ const bnAppliedExistentialDeposit = (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode);
16
+ let bnTransferable = BigInt(0);
17
+ if (!accountInfo) {
18
+ return BigInt(0);
19
+ }
20
+ if (['Liquid'].includes(accountInfo.status)) {
21
+ bnTransferable = BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
22
+ }
23
+ return bnTransferable;
24
+ }
25
+ function _getAssetsPalletLockedBalance(accountInfo) {
26
+ let bnLocked = BigInt(0);
27
+ if (!accountInfo) {
28
+ return bnLocked;
29
+ }
30
+ if (!['Liquid'].includes(accountInfo.status)) {
31
+ // todo: check case accountInfo has isFrozen?
32
+ bnLocked = BigInt(accountInfo.balance);
33
+ }
34
+ return bnLocked;
35
+ }
@@ -5,12 +5,22 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports._getForeignAssetPalletLockedBalance = _getForeignAssetPalletLockedBalance;
7
7
  exports._getForeignAssetPalletTransferable = _getForeignAssetPalletTransferable;
8
+ var _types = require("@subwallet/extension-base/core/substrate/types");
9
+ var _utils = require("@subwallet/extension-base/core/utils");
8
10
  // Copyright 2019-2022 @subwallet/extension-base
9
11
  // SPDX-License-Identifier: Apache-2.0
10
12
 
11
- function _getForeignAssetPalletTransferable(accountInfo) {
12
- return accountInfo.status !== 'Liquid' ? BigInt(0) : BigInt(accountInfo.balance);
13
+ function _getForeignAssetPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
14
+ const strictMode = (0, _utils.getStrictMode)(_types.BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
15
+ if (!accountInfo || accountInfo.status !== 'Liquid') {
16
+ return BigInt(0);
17
+ }
18
+ const bnAppliedExistentialDeposit = (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode);
19
+ return BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
13
20
  }
14
21
  function _getForeignAssetPalletLockedBalance(accountInfo) {
15
- return accountInfo.status === 'Liquid' ? BigInt(0) : BigInt(accountInfo.balance);
22
+ if (!accountInfo || accountInfo.status === 'Liquid') {
23
+ return BigInt(0);
24
+ }
25
+ return BigInt(accountInfo.balance);
16
26
  }
@@ -1,23 +1,21 @@
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
  });
7
6
  exports._getActiveStakeInNominationPool = _getActiveStakeInNominationPool;
8
7
  exports._getTotalStakeInNominationPool = _getTotalStakeInNominationPool;
9
8
  exports._getUnbondingStakeInNominationPool = _getUnbondingStakeInNominationPool;
10
- var _bignumber = _interopRequireDefault(require("bignumber.js"));
11
9
  // Copyright 2019-2022 @subwallet/extension-base
12
10
  // SPDX-License-Identifier: Apache-2.0
13
11
 
14
12
  function _getActiveStakeInNominationPool(memberInfo) {
15
- return new _bignumber.default(memberInfo.points.toString());
13
+ return BigInt(memberInfo.points);
16
14
  }
17
15
  function _getUnbondingStakeInNominationPool(memberInfo) {
18
- const unbondingValues = Object.values(memberInfo.unbondingEras).map(unbonding => new _bignumber.default(unbonding));
19
- return new _bignumber.default(Object.values(unbondingValues).reduce((a, b) => a.plus(b), new _bignumber.default(0)));
16
+ const unbondingValues = Object.values(memberInfo.unbondingEras).map(unbonding => BigInt(unbonding));
17
+ return unbondingValues.reduce((a, b) => a + b, BigInt(0));
20
18
  }
21
19
  function _getTotalStakeInNominationPool(memberInfo) {
22
- return _getActiveStakeInNominationPool(memberInfo).plus(_getUnbondingStakeInNominationPool(memberInfo));
20
+ return _getActiveStakeInNominationPool(memberInfo) + _getUnbondingStakeInNominationPool(memberInfo);
23
21
  }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports._getOrmlTokensPalletLockedBalance = _getOrmlTokensPalletLockedBalance;
7
+ exports._getOrmlTokensPalletTransferable = _getOrmlTokensPalletTransferable;
8
+ var _types = require("@subwallet/extension-base/core/substrate/types");
9
+ var _utils = require("@subwallet/extension-base/core/utils");
10
+ // Copyright 2019-2022 @subwallet/extension-base
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ function _getOrmlTokensPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
14
+ const strictMode = (0, _utils.getStrictMode)(_types.BalanceAccountType.OrmlTokensAccountData, extrinsicType);
15
+ const bnAppliedExistentialDeposit = (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode);
16
+ const bnFrozen = BigInt(accountInfo.frozen);
17
+ const bnFree = BigInt(accountInfo.free);
18
+ return bnFree - (0, _utils.getMaxBigint)(bnFrozen, bnAppliedExistentialDeposit);
19
+ }
20
+ function _getOrmlTokensPalletLockedBalance(accountInfo) {
21
+ const bnFrozen = BigInt(accountInfo.frozen);
22
+ const bnReserved = BigInt(accountInfo.reserved);
23
+ return bnReserved + bnFrozen;
24
+ }
@@ -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
  });
@@ -9,8 +8,8 @@ exports._getAppliedExistentialDepositWithExtrinsicType = _getAppliedExistentialD
9
8
  exports._getSystemPalletTotalBalance = _getSystemPalletTotalBalance;
10
9
  exports._getSystemPalletTransferable = _getSystemPalletTransferable;
11
10
  exports._isAccountActive = _isAccountActive;
12
- var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
13
- var _bignumber = _interopRequireDefault(require("bignumber.js"));
11
+ var _types = require("@subwallet/extension-base/core/substrate/types");
12
+ var _utils = require("@subwallet/extension-base/core/utils");
14
13
  // Copyright 2019-2022 @subwallet/extension-base
15
14
  // SPDX-License-Identifier: Apache-2.0
16
15
 
@@ -18,7 +17,7 @@ function isV1(accountInfo) {
18
17
  return accountInfo.data.miscFrozen !== undefined && accountInfo.data.feeFrozen !== undefined;
19
18
  }
20
19
  function _getSystemPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
21
- const strictMode = !extrinsicType || ![_KoniTypes.ExtrinsicType.TRANSFER_BALANCE].includes(extrinsicType); // always apply strict mode to keep account alive unless explicitly specified otherwise
20
+ const strictMode = (0, _utils.getStrictMode)(_types.BalanceAccountType.FrameSystemAccountInfo, extrinsicType); // always apply strict mode to keep account alive unless explicitly specified otherwise
22
21
 
23
22
  if (isV1(accountInfo)) {
24
23
  return _getSystemPalletTransferableV1(accountInfo, existentialDeposit, strictMode);
@@ -41,7 +40,7 @@ function _getSystemPalletTotalBalance(accountInfo) {
41
40
  }
42
41
  }
43
42
  function _getAppliedExistentialDepositWithExtrinsicType(accountInfo, existentialDeposit, extrinsicType) {
44
- const strictMode = !extrinsicType || ![_KoniTypes.ExtrinsicType.TRANSFER_BALANCE].includes(extrinsicType); // always apply strict mode to keep account alive unless explicitly specified otherwise
43
+ const strictMode = (0, _utils.getStrictMode)(_types.BalanceAccountType.FrameSystemAccountInfo, extrinsicType); // always apply strict mode to keep account alive unless explicitly specified otherwise
45
44
 
46
45
  return _getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode);
47
46
  }
@@ -49,29 +48,28 @@ function _getAppliedExistentialDepositWithExtrinsicType(accountInfo, existential
49
48
  // ----------------------------------------------------------------------
50
49
 
51
50
  function _getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode) {
51
+ const bnExistentialDeposit = BigInt(existentialDeposit);
52
+
52
53
  // strict mode will always apply existential deposit to keep account alive
53
54
  if (strictMode) {
54
- return existentialDeposit;
55
+ return bnExistentialDeposit;
55
56
  }
56
- return _canAccountBeReaped(accountInfo) ? '0' : existentialDeposit; // account for ED here will go better with max transfer logic
57
+ return _canAccountBeReaped(accountInfo) ? BigInt(0) : bnExistentialDeposit; // account for ED here will go better with max transfer logic
57
58
  }
58
59
 
59
60
  function _getSystemPalletTransferableV2(accountInfo, existentialDeposit, strictMode) {
60
- const bnFree = new _bignumber.default(accountInfo.data.free);
61
- const bnLocked = new _bignumber.default(accountInfo.data.frozen).minus(accountInfo.data.reserved); // locked can go below 0 but this shouldn't matter
62
- const bnAppliedExistentialDeposit = new _bignumber.default(_getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode));
63
- const bnTransferableBalance = bnFree.minus(_bignumber.default.max(bnLocked, bnAppliedExistentialDeposit));
64
- return _bignumber.default.max(bnTransferableBalance, 0).toFixed();
61
+ const bnLocked = BigInt(accountInfo.data.frozen) - BigInt(accountInfo.data.reserved); // locked can go below 0 but this shouldn't matter
62
+ const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode);
63
+ return BigInt(accountInfo.data.free) - (0, _utils.getMaxBigint)(bnLocked, bnAppliedExistentialDeposit);
65
64
  }
66
65
  function _getSystemPalletTotalBalanceV2(accountInfo) {
67
- return new _bignumber.default(accountInfo.data.free).plus(accountInfo.data.reserved).toFixed();
66
+ return BigInt(accountInfo.data.free) + BigInt(accountInfo.data.reserved);
68
67
  }
69
68
  function _getSystemPalletTransferableV1(accountInfo, existentialDeposit, strictMode) {
70
- const bnAppliedExistentialDeposit = new _bignumber.default(_getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode));
71
- const bnAppliedFrozen = _bignumber.default.max(accountInfo.data.feeFrozen, accountInfo.data.miscFrozen);
72
- const bnTransferableBalance = new _bignumber.default(accountInfo.data.free).minus(_bignumber.default.max(bnAppliedFrozen, bnAppliedExistentialDeposit));
73
- return _bignumber.default.max(bnTransferableBalance, 0).toFixed();
69
+ const bnAppliedExistentialDeposit = BigInt(_getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode));
70
+ const bnAppliedFrozen = (0, _utils.getMaxBigint)(BigInt(accountInfo.data.feeFrozen), BigInt(accountInfo.data.miscFrozen));
71
+ return BigInt(accountInfo.data.free) - (0, _utils.getMaxBigint)(bnAppliedFrozen, bnAppliedExistentialDeposit);
74
72
  }
75
73
  function _getSystemPalletTotalBalanceV1(accountInfo) {
76
- return new _bignumber.default(accountInfo.data.free).plus(accountInfo.data.reserved).toFixed();
74
+ return BigInt(accountInfo.data.free) + BigInt(accountInfo.data.reserved);
77
75
  }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports._getTokensPalletLocked = _getTokensPalletLocked;
7
+ exports._getTokensPalletTotalBalance = _getTokensPalletTotalBalance;
8
+ exports._getTokensPalletTransferable = _getTokensPalletTransferable;
9
+ var _types = require("@subwallet/extension-base/core/substrate/types");
10
+ var _utils = require("@subwallet/extension-base/core/utils");
11
+ // Copyright 2019-2022 @subwallet/extension-base
12
+ // SPDX-License-Identifier: Apache-2.0
13
+
14
+ function _getTokensPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
15
+ const strictMode = (0, _utils.getStrictMode)(_types.BalanceAccountType.OrmlTokensAccountData, extrinsicType);
16
+ const bnAppliedExistentialDeposit = (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode);
17
+ return BigInt(accountInfo.free) - (0, _utils.getMaxBigint)(BigInt(accountInfo.frozen), bnAppliedExistentialDeposit);
18
+ }
19
+ function _getTokensPalletLocked(accountInfo) {
20
+ return BigInt(accountInfo.reserved) + BigInt(accountInfo.frozen);
21
+ }
22
+ function _getTokensPalletTotalBalance(accountInfo) {
23
+ return BigInt(accountInfo.free) + BigInt(accountInfo.reserved);
24
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BalanceAccountType = void 0;
7
+ // Copyright 2019-2022 @subwallet/extension-base
8
+ // SPDX-License-Identifier: Apache-2.0
9
+
10
+ // https://crates.parity.io/frame_system/struct.AccountInfo.html
11
+ // https://wiki.polkadot.network/docs/learn-account-balances
12
+
13
+ // export type BalanceAccountType = 'FrameSystemAccountInfo' | 'OrmlTokensAccountData' | 'PalletAssetsAssetAccount' | 'PalletNominationPoolsPoolMember';
14
+ const BalanceAccountType = {
15
+ FrameSystemAccountInfo: 'FrameSystemAccountInfo',
16
+ OrmlTokensAccountData: 'OrmlTokensAccountData',
17
+ PalletAssetsAssetAccount: 'PalletAssetsAssetAccount'
18
+ };
19
+ exports.BalanceAccountType = BalanceAccountType;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports._adaptX1Interior = _adaptX1Interior;
6
7
  exports._getXcmBeneficiary = _getXcmBeneficiary;
7
8
  exports._getXcmDestWeight = _getXcmDestWeight;
8
9
  exports._getXcmMultiAssets = _getXcmMultiAssets;
@@ -204,15 +205,28 @@ function _getRecipientLocation(destChainInfo, recipient, version) {
204
205
  };
205
206
  }
206
207
  function _getAssetIdentifier(tokenInfo, version) {
207
- const assetIdentifier = (0, _utils._getXcmAssetMultilocation)(tokenInfo);
208
- if (!assetIdentifier) {
208
+ const _assetIdentifier = (0, _utils._getXcmAssetMultilocation)(tokenInfo);
209
+ if (!_assetIdentifier) {
209
210
  throw new Error('Asset must have multilocation');
210
211
  }
212
+ const assetIdentifier = _adaptX1Interior(structuredClone(_assetIdentifier), version);
211
213
  return version >= 4 // from V4, Concrete is removed
212
214
  ? assetIdentifier : {
213
215
  Concrete: assetIdentifier
214
216
  };
215
217
  }
218
+ function _adaptX1Interior(assetIdentifier, version) {
219
+ const interior = assetIdentifier.interior;
220
+ const isInteriorObj = typeof interior === 'object' && interior !== null;
221
+ const isX1 = isInteriorObj && 'X1' in interior;
222
+ const needModifyX1 = version <= 4 && Array.isArray(interior.X1);
223
+ if (isInteriorObj && isX1 && needModifyX1) {
224
+ // X1 is an object for version < 4. From V4, it's an array
225
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
226
+ interior.X1 = interior.X1[0];
227
+ }
228
+ return assetIdentifier;
229
+ }
216
230
  function _getNetworkByVersion(version) {
217
231
  switch (version) {
218
232
  case 1:
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports._getAppliedExistentialDeposit = _getAppliedExistentialDeposit;
7
+ exports.getMaxBigint = getMaxBigint;
8
+ exports.getStrictMode = getStrictMode;
9
+ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
10
+ var _types = require("@subwallet/extension-base/core/substrate/types");
11
+ // Copyright 2019-2022 @subwallet/extension-base
12
+ // SPDX-License-Identifier: Apache-2.0
13
+
14
+ function getStrictMode(type, extrinsicType) {
15
+ if (!extrinsicType) {
16
+ return true;
17
+ }
18
+ if (type === _types.BalanceAccountType.FrameSystemAccountInfo) {
19
+ return ![_KoniTypes.ExtrinsicType.TRANSFER_BALANCE].includes(extrinsicType);
20
+ }
21
+ if (type === _types.BalanceAccountType.OrmlTokensAccountData || type === _types.BalanceAccountType.PalletAssetsAssetAccount) {
22
+ return ![_KoniTypes.ExtrinsicType.TRANSFER_TOKEN, _KoniTypes.ExtrinsicType.TRANSFER_BALANCE].includes(extrinsicType);
23
+ }
24
+ return true;
25
+ }
26
+ function _getAppliedExistentialDeposit(existentialDeposit, strictMode) {
27
+ return strictMode ? BigInt(existentialDeposit) : BigInt(0);
28
+ }
29
+ function getMaxBigint(a, b) {
30
+ return a > b ? a : b;
31
+ }
@@ -65,10 +65,12 @@ class KoniCron {
65
65
  await Promise.all([this.state.eventService.waitKeyringReady, this.state.eventService.waitAssetReady]);
66
66
  const currentAccountInfo = this.state.keyringService.currentAccount;
67
67
  const commonReloadEvents = ['account.add', 'account.remove', 'account.updateCurrent', 'chain.add', 'asset.updateState'];
68
+ const mktCampaignReloadEvents = ['account.add', 'account.remove'];
68
69
  this.eventHandler = (events, eventTypes) => {
69
70
  var _serviceInfo$currentA;
70
71
  const serviceInfo = this.state.getServiceInfo();
71
72
  const commonReload = eventTypes.some(eventType => commonReloadEvents.includes(eventType));
73
+ const mktCampaignNeedReload = eventTypes.some(eventType => mktCampaignReloadEvents.includes(eventType));
72
74
  const chainUpdated = eventTypes.includes('chain.updateState');
73
75
  const reloadMantaPay = eventTypes.includes('mantaPay.submitTransaction') || eventTypes.includes('mantaPay.enable');
74
76
  const updatedChains = [];
@@ -98,6 +100,10 @@ class KoniCron {
98
100
  (commonReload || needUpdateNft) && this.resetNft(address);
99
101
  (commonReload || needUpdateNft) && this.removeCron('refreshNft');
100
102
  commonReload && this.removeCron('refreshPoolingStakingReward');
103
+ if (mktCampaignNeedReload) {
104
+ this.removeCron('fetchMktCampaignData');
105
+ this.addCron('fetchMktCampaignData', this.fetchMktCampaignData, _constants.CRON_REFRESH_MKT_CAMPAIGN_INTERVAL);
106
+ }
101
107
  if (chainUpdated) {
102
108
  this.stopPoolInfo();
103
109
  this.removeCron('fetchPoolInfo');
@@ -113,6 +119,7 @@ class KoniCron {
113
119
  };
114
120
  this.state.eventService.onLazy(this.eventHandler);
115
121
  this.addCron('fetchPoolInfo', this.fetchPoolInfo, _constants.CRON_REFRESH_CHAIN_STAKING_METADATA);
122
+ this.addCron('fetchMktCampaignData', this.fetchMktCampaignData, _constants.CRON_REFRESH_MKT_CAMPAIGN_INTERVAL);
116
123
  if (!(currentAccountInfo !== null && currentAccountInfo !== void 0 && currentAccountInfo.address)) {
117
124
  return;
118
125
  }
@@ -151,6 +158,9 @@ class KoniCron {
151
158
  fetchPoolInfo = () => {
152
159
  this.state.earningService.runSubscribePoolsInfo().catch(console.error);
153
160
  };
161
+ fetchMktCampaignData = () => {
162
+ this.state.mktCampaignService.fetchMktCampaignData();
163
+ };
154
164
  stopPoolInfo = () => {
155
165
  this.state.earningService.runUnsubscribePoolsInfo();
156
166
  };
@@ -2001,7 +2001,7 @@ class KoniExtension {
2001
2001
  if (destinationTokenInfo) {
2002
2002
  const [bnMockFee, {
2003
2003
  value
2004
- }] = await Promise.all([(0, _xcm.getXcmMockTxFee)(substrateApi, chainInfoMap, address, originTokenInfo, destinationTokenInfo), this.getAddressTransferableBalance({
2004
+ }] = await Promise.all([(0, _xcm.getXcmMockTxFee)(substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo), this.getAddressTransferableBalance({
2005
2005
  extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_XCM,
2006
2006
  address,
2007
2007
  networkKey: originTokenInfo.originChain,
@@ -2192,14 +2192,15 @@ class KoniExtension {
2192
2192
  genesisHash,
2193
2193
  hardwareType,
2194
2194
  isAllowed,
2195
- name
2195
+ name,
2196
+ originGenesisHash
2196
2197
  } = _ref56;
2197
2198
  const key = _uiKeyring.keyring.addHardware(address, hardwareType, {
2198
2199
  accountIndex,
2199
2200
  addressOffset,
2200
2201
  genesisHash,
2201
2202
  name,
2202
- originGenesisHash: genesisHash
2203
+ originGenesisHash
2203
2204
  });
2204
2205
  const result = key.pair;
2205
2206
  const _address = result.address;
@@ -2234,7 +2235,8 @@ class KoniExtension {
2234
2235
  hardwareType,
2235
2236
  isEthereum,
2236
2237
  isGeneric,
2237
- name
2238
+ name,
2239
+ originGenesisHash
2238
2240
  } = account;
2239
2241
  let result;
2240
2242
  const baseMeta = {
@@ -2243,7 +2245,7 @@ class KoniExtension {
2243
2245
  accountIndex,
2244
2246
  addressOffset,
2245
2247
  genesisHash,
2246
- originGenesisHash: genesisHash,
2248
+ originGenesisHash,
2247
2249
  isGeneric
2248
2250
  };
2249
2251
  if (isEthereum) {
@@ -4083,6 +4085,54 @@ class KoniExtension {
4083
4085
  this.#koniState.campaignService.toggleCampaignPopup(value);
4084
4086
  return null;
4085
4087
  }
4088
+ subscribeAppPopupData(id, port) {
4089
+ const cb = (0, _subscriptions.createSubscription)(id, port);
4090
+ let ready = false;
4091
+ const callback = rs => {
4092
+ if (ready) {
4093
+ cb(rs);
4094
+ }
4095
+ };
4096
+ const subscription = this.#koniState.mktCampaignService.subscribePopupsData(callback);
4097
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
4098
+ port.onDisconnect.addListener(() => {
4099
+ this.cancelSubscription(id);
4100
+ });
4101
+ ready = true;
4102
+ return this.#koniState.mktCampaignService.getAppPopupsData();
4103
+ }
4104
+ subscribeAppBannerData(id, port) {
4105
+ const cb = (0, _subscriptions.createSubscription)(id, port);
4106
+ let ready = false;
4107
+ const callback = rs => {
4108
+ if (ready) {
4109
+ cb(rs);
4110
+ }
4111
+ };
4112
+ const subscription = this.#koniState.mktCampaignService.subscribeBannersData(callback);
4113
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
4114
+ port.onDisconnect.addListener(() => {
4115
+ this.cancelSubscription(id);
4116
+ });
4117
+ ready = true;
4118
+ return this.#koniState.mktCampaignService.getAppBannersData();
4119
+ }
4120
+ subscribeAppConfirmationData(id, port) {
4121
+ const cb = (0, _subscriptions.createSubscription)(id, port);
4122
+ let ready = false;
4123
+ const callback = rs => {
4124
+ if (ready) {
4125
+ cb(rs);
4126
+ }
4127
+ };
4128
+ const subscription = this.#koniState.mktCampaignService.subscribeConfirmationsData(callback);
4129
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
4130
+ port.onDisconnect.addListener(() => {
4131
+ this.cancelSubscription(id);
4132
+ });
4133
+ ready = true;
4134
+ return this.#koniState.mktCampaignService.getAppConfirmationsData();
4135
+ }
4086
4136
 
4087
4137
  /* Campaign */
4088
4138
 
@@ -4709,6 +4759,12 @@ class KoniExtension {
4709
4759
  return this.subscribeCampaignPopupVisibility(id, port);
4710
4760
  case 'pri(campaign.popup.toggle)':
4711
4761
  return this.toggleCampaignPopup(request);
4762
+ case 'pri(campaign.popups.subscribe)':
4763
+ return this.subscribeAppPopupData(id, port);
4764
+ case 'pri(campaign.banners.subscribe)':
4765
+ return this.subscribeAppBannerData(id, port);
4766
+ case 'pri(campaign.confirmations.subscribe)':
4767
+ return this.subscribeAppConfirmationData(id, port);
4712
4768
 
4713
4769
  /* Campaign */
4714
4770
 
@@ -25,6 +25,7 @@ var _historyService = require("@subwallet/extension-base/services/history-servic
25
25
  var _keyringService = require("@subwallet/extension-base/services/keyring-service");
26
26
  var _migrationService = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service"));
27
27
  var _mintCampaignService = _interopRequireDefault(require("@subwallet/extension-base/services/mint-campaign-service"));
28
+ var _mktCampaignService = _interopRequireDefault(require("@subwallet/extension-base/services/mkt-campaign-service"));
28
29
  var _NotificationService = _interopRequireDefault(require("@subwallet/extension-base/services/notification-service/NotificationService"));
29
30
  var _priceService = require("@subwallet/extension-base/services/price-service");
30
31
  var _requestService = _interopRequireDefault(require("@subwallet/extension-base/services/request-service"));
@@ -110,6 +111,7 @@ class KoniState {
110
111
  this.walletConnectService = new _walletConnectService.default(this, this.requestService);
111
112
  this.migrationService = new _migrationService.default(this, this.eventService);
112
113
  this.campaignService = new _campaignService.default(this);
114
+ this.mktCampaignService = new _mktCampaignService.default(this);
113
115
  this.buyService = new _buyService.default(this);
114
116
  this.transactionService = new _transactionService.default(this);
115
117
  this.earningService = new _service.default(this);
@@ -235,6 +237,7 @@ class KoniState {
235
237
  this.afterChainServiceInit();
236
238
  await this.migrationService.run();
237
239
  this.campaignService.init();
240
+ this.mktCampaignService.init();
238
241
  this.eventService.emit('chain.ready', true);
239
242
  await this.balanceService.init();
240
243
  await this.earningService.init();
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '1.2.23-0'
16
+ version: '1.2.24-1'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -27,7 +27,7 @@ const subscribeEquilibriumTokenBalance = async _ref => {
27
27
  const tokenTypes = includeNativeToken ? [_types._AssetType.NATIVE, _types._AssetType.LOCAL] : [_types._AssetType.LOCAL];
28
28
  const tokenMap = (0, _utils2.filterAssetsByChainAndType)(assetMap, chain, tokenTypes);
29
29
  try {
30
- const unsub = await substrateApi.query.system.account.multi(addresses, balances => {
30
+ const unsub = await substrateApi.api.query.system.account.multi(addresses, balances => {
31
31
  // Equilibrium customizes the SystemAccount pallet
32
32
  Object.values(tokenMap).forEach(tokenInfo => {
33
33
  const assetId = (0, _utils._getTokenOnChainAssetId)(tokenInfo);
@@ -91,7 +91,7 @@ const subscribeEqBalanceAccountPallet = async _ref2 => {
91
91
  const unsubList = Object.values(tokenMap).map(async tokenInfo => {
92
92
  try {
93
93
  const assetId = (0, _utils._getTokenOnChainAssetId)(tokenInfo);
94
- const unsub = await substrateApi.query.eqBalances.account.multi(addresses.map(address => [address, [assetId]]), balances => {
94
+ const unsub = await substrateApi.api.query.eqBalances.account.multi(addresses.map(address => [address, [assetId]]), balances => {
95
95
  const items = balances.map((balance, index) => {
96
96
  return {
97
97
  address: addresses[index],