@subwallet/extension-base 1.3.27-1 → 1.3.28-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 (41) hide show
  1. package/background/KoniTypes.d.ts +7 -1
  2. package/cjs/constants/index.js +1 -1
  3. package/cjs/koni/background/handlers/Extension.js +13 -0
  4. package/cjs/packageInfo.js +1 -1
  5. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +89 -33
  6. package/cjs/services/chain-service/constants.js +2 -1
  7. package/cjs/services/chain-service/utils/index.js +11 -2
  8. package/cjs/services/earning-service/handlers/base.js +3 -0
  9. package/cjs/services/earning-service/handlers/native-staking/dtao.js +97 -36
  10. package/cjs/services/earning-service/handlers/native-staking/tao.js +34 -4
  11. package/cjs/services/earning-service/service.js +13 -1
  12. package/cjs/services/migration-service/index.js +2 -5
  13. package/cjs/services/migration-service/scripts/index.js +4 -8
  14. package/cjs/services/price-service/coingecko.js +49 -0
  15. package/cjs/utils/asset.js +17 -2
  16. package/constants/index.d.ts +1 -1
  17. package/constants/index.js +1 -1
  18. package/koni/background/handlers/Extension.d.ts +1 -0
  19. package/koni/background/handlers/Extension.js +13 -0
  20. package/package.json +7 -7
  21. package/packageInfo.js +1 -1
  22. package/services/balance-service/helpers/subscribe/substrate/index.js +76 -23
  23. package/services/chain-service/constants.d.ts +1 -0
  24. package/services/chain-service/constants.js +2 -1
  25. package/services/chain-service/utils/index.d.ts +1 -0
  26. package/services/chain-service/utils/index.js +6 -0
  27. package/services/earning-service/handlers/base.d.ts +3 -2
  28. package/services/earning-service/handlers/base.js +3 -0
  29. package/services/earning-service/handlers/native-staking/dtao.d.ts +7 -2
  30. package/services/earning-service/handlers/native-staking/dtao.js +89 -31
  31. package/services/earning-service/handlers/native-staking/tao.d.ts +4 -1
  32. package/services/earning-service/handlers/native-staking/tao.js +31 -1
  33. package/services/earning-service/service.d.ts +2 -1
  34. package/services/earning-service/service.js +13 -1
  35. package/services/migration-service/index.js +2 -5
  36. package/services/migration-service/scripts/index.js +4 -8
  37. package/services/price-service/coingecko.js +48 -0
  38. package/types/yield/actions/join/submit.d.ts +3 -0
  39. package/types/yield/actions/others.d.ts +7 -0
  40. package/utils/asset.d.ts +1 -0
  41. package/utils/asset.js +14 -0
@@ -17,11 +17,8 @@ export default class MigrationService {
17
17
  const JobClass = MigrationScripts[keys[i]];
18
18
  const key = keys[i];
19
19
  const name = JobClass.name;
20
- const check = await this.state.dbService.stores.migration.table.where({
21
- name,
22
- key
23
- }).first();
24
- if (!check || key.startsWith(EVERYTIME)) {
20
+ const existed = await this.state.dbService.hasRunScript(key);
21
+ if (!existed || key.startsWith(EVERYTIME)) {
25
22
  const job = new JobClass(this.state);
26
23
  await job.run();
27
24
  await this.state.dbService.stores.migration.table.put({
@@ -15,17 +15,13 @@ import MigrateEthProvider from "./providers/MigrateEthProvider.js";
15
15
  import MigratePioneerProvider from "./providers/MigratePioneerProvider.js";
16
16
  import MigrateProvidersV1M1P24 from "./providers/MigrateProvidersV1M1P24.js";
17
17
  import MigratePolygonUSDCProvider from "./tokens/MigratePolygonUSDCProvider.js";
18
- import AutoEnableChainsTokens from "./AutoEnableChainsTokens.js";
19
18
  import DeleteChain from "./DeleteChain.js";
20
19
  import DeleteChainStaking from "./DeleteChainStaking.js";
21
20
  import DeleteEarningData from "./DeleteEarningData.js";
22
21
  import EnableVaraChain from "./EnableVaraChain.js";
23
22
  import MigrateAuthUrls from "./MigrateAuthUrls.js";
24
- import MigrateAutoLock from "./MigrateAutoLock.js";
25
- import MigrateChainPatrol from "./MigrateChainPatrol.js";
26
23
  import MigrateImportedToken from "./MigrateImportedToken.js";
27
24
  import MigrateNetworkSettings from "./MigrateNetworkSettings.js";
28
- import MigrateSettings from "./MigrateSettings.js";
29
25
  import MigrateTokenDecimals from "./MigrateTokenDecimals.js";
30
26
  import MigrateTransactionHistory from "./MigrateTransactionHistory.js";
31
27
  import MigrateTransactionHistoryBridge from "./MigrateTransactionHistoryBridge.js";
@@ -37,11 +33,11 @@ export default {
37
33
  '1.0.1-11': MigrateNetworkSettings,
38
34
  '1.0.1-20': MigrateImportedToken,
39
35
  '1.0.1-30': MigrateTransactionHistory,
40
- '1.0.1-40': AutoEnableChainsTokens,
41
- '1.0.1-50': MigrateSettings,
36
+ // '1.0.1-40': AutoEnableChainsTokens,
37
+ // '1.0.1-50': MigrateSettings,
42
38
  '1.0.1-60': MigrateAuthUrls,
43
- '1.0.3-01': MigrateAutoLock,
44
- '1.0.3-02': MigrateChainPatrol,
39
+ // '1.0.3-01': MigrateAutoLock,
40
+ // '1.0.3-02': MigrateChainPatrol,
45
41
  '1.0.9-01': MigrateLedgerAccount,
46
42
  '1.0.12-02': MigrateEthProvider,
47
43
  '1.1.6-01': MigrateWalletReference,
@@ -1,10 +1,13 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { isProductionMode } from '@subwallet/extension-base/constants';
4
5
  import { staticData, StaticKey } from '@subwallet/extension-base/utils/staticData';
5
6
  import { isArray } from '@polkadot/util';
6
7
  const DEFAULT_CURRENCY = 'USD';
8
+ const DERIVATIVE_TOKEN_SLUG_LIST = ['susds', 'savings-dai'];
7
9
  let useBackupApi = false;
10
+ const apiCacheDomain = isProductionMode ? 'https://api-cache.subwallet.app' : 'https://api-cache-dev.subwallet.app';
8
11
  export const getExchangeRateMap = async () => {
9
12
  let response;
10
13
  try {
@@ -33,11 +36,44 @@ export const getExchangeRateMap = async () => {
33
36
  return {};
34
37
  }
35
38
  };
39
+ const fetchDerivativeTokenSlugs = async () => {
40
+ try {
41
+ const response = await fetch(`${apiCacheDomain}/api/price/derivative-list`);
42
+ if (!response.ok) {
43
+ throw new Error(`HTTP error! Status: ${response.status}`);
44
+ }
45
+ const data = await response.json();
46
+ const apiSlugs = Array.isArray(data) && data.every(item => typeof item === 'string') ? data : [];
47
+ return new Set(apiSlugs.length > 0 ? apiSlugs : DERIVATIVE_TOKEN_SLUG_LIST);
48
+ } catch (error) {
49
+ console.error('Error fetching derivative token slugs from API:', error);
50
+ return new Set(DERIVATIVE_TOKEN_SLUG_LIST);
51
+ }
52
+ };
36
53
  export const getPriceMap = async (priceIds, currency = 'USD') => {
37
54
  const idStr = Array.from(priceIds).join(',');
38
55
  let response;
39
56
  try {
40
57
  var _response3, _response5;
58
+ const derivativePriceMap = {};
59
+ let derivativeApiError = false;
60
+ try {
61
+ const responseDerivativeTokens = await fetch(`${apiCacheDomain}/api/price/derivative-get`);
62
+ const generateDerivativePriceRaw = (await (responseDerivativeTokens === null || responseDerivativeTokens === void 0 ? void 0 : responseDerivativeTokens.json())) || [];
63
+ if (Array.isArray(generateDerivativePriceRaw)) {
64
+ generateDerivativePriceRaw.forEach(token => {
65
+ if (token.id) {
66
+ derivativePriceMap[token.id] = token.derived_price;
67
+ }
68
+ });
69
+ } else {
70
+ console.warn('Invalid data from derivative API:', generateDerivativePriceRaw);
71
+ derivativeApiError = true;
72
+ }
73
+ } catch (error) {
74
+ console.error('Error fetching derivative API:', error);
75
+ derivativeApiError = true;
76
+ }
41
77
  if (!useBackupApi) {
42
78
  try {
43
79
  response = await fetch(`https://api.coingecko.com/api/v3/coins/markets?vs_currency=${currency.toLowerCase()}&per_page=250&ids=${idStr}`);
@@ -71,6 +107,18 @@ export const getPriceMap = async (priceIds, currency = 'USD') => {
71
107
  priceMap[val.id] = currentPrice;
72
108
  price24hMap[val.id] = price24h;
73
109
  });
110
+ const derivativeTokenSlugs = await fetchDerivativeTokenSlugs();
111
+
112
+ // TODO: The API for derivatives does not provide a 24-hour price change value.
113
+ if (derivativeApiError) {
114
+ derivativeTokenSlugs.forEach(slug => {
115
+ priceMap[slug] = 0;
116
+ });
117
+ } else {
118
+ Object.entries(derivativePriceMap).forEach(([slug, derivedPrice]) => {
119
+ priceMap[slug] = derivedPrice;
120
+ });
121
+ }
74
122
  return {
75
123
  currency,
76
124
  currencyData,
@@ -16,6 +16,9 @@ export interface AbstractSubmitYieldJoinData {
16
16
  address: string;
17
17
  }
18
18
  export interface SubmitJoinNativeStaking extends AbstractSubmitYieldJoinData {
19
+ selectedPool?: {
20
+ mindBond: string;
21
+ };
19
22
  selectedValidators: ValidatorInfo[];
20
23
  netuid?: number;
21
24
  }
@@ -1,3 +1,4 @@
1
+ import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
1
2
  import { BaseRequestSign, InternalRequestSign } from '../../transaction';
2
3
  import { BasePoolInfo, UnstakingInfo, YieldPoolInfo } from '../info';
3
4
  /**
@@ -83,3 +84,9 @@ export interface StakeClaimRewardParams extends BaseRequestSign {
83
84
  bondReward?: boolean;
84
85
  }
85
86
  export declare type RequestStakeClaimReward = InternalRequestSign<StakeClaimRewardParams>;
87
+ export interface RequestEarningSlippage {
88
+ slug: string;
89
+ value: string;
90
+ netuid: number;
91
+ type: ExtrinsicType;
92
+ }
package/utils/asset.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { _AssetType, _ChainAsset } from '@subwallet/chain-list/types';
2
2
  export declare const filterAssetsByChainAndType: (chainAssetMap: Record<string, _ChainAsset>, chain: string, assetTypes: _AssetType[]) => Record<string, _ChainAsset>;
3
+ export declare const filterAlphaAssetsByChain: (chainAssetMap: Record<string, _ChainAsset>, chain: string) => Record<string, _ChainAsset>;
package/utils/asset.js CHANGED
@@ -1,6 +1,8 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { _AssetType } from '@subwallet/chain-list/types';
5
+ import { _getAssetNetuid } from '@subwallet/extension-base/services/chain-service/utils';
4
6
  export const filterAssetsByChainAndType = (chainAssetMap, chain, assetTypes) => {
5
7
  const result = {};
6
8
  Object.values(chainAssetMap).forEach(assetInfo => {
@@ -9,4 +11,16 @@ export const filterAssetsByChainAndType = (chainAssetMap, chain, assetTypes) =>
9
11
  }
10
12
  });
11
13
  return result;
14
+ };
15
+ export const filterAlphaAssetsByChain = (chainAssetMap, chain) => {
16
+ const result = {};
17
+ Object.values(chainAssetMap).forEach(assetInfo => {
18
+ if (assetInfo.assetType === _AssetType.LOCAL && assetInfo.originChain === chain) {
19
+ const netuid = _getAssetNetuid(assetInfo);
20
+ if (netuid !== -1) {
21
+ result[assetInfo.slug] = assetInfo;
22
+ }
23
+ }
24
+ });
25
+ return result;
12
26
  };