@subwallet/extension-base 1.3.51-0 → 1.3.52-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 (53) hide show
  1. package/cjs/constants/environment.js +3 -1
  2. package/cjs/koni/background/handlers/State.js +1 -5
  3. package/cjs/packageInfo.js +1 -1
  4. package/cjs/services/balance-service/index.js +3 -4
  5. package/cjs/services/balance-service/transfer/cardano-transfer.js +43 -11
  6. package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +13 -92
  7. package/cjs/services/balance-service/transfer/xcm/index.js +12 -4
  8. package/cjs/services/chain-service/utils/patch.js +3 -2
  9. package/cjs/services/earning-service/handlers/native-staking/dtao.js +28 -301
  10. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +4 -4
  11. package/cjs/services/earning-service/handlers/native-staking/tao.js +174 -148
  12. package/cjs/services/earning-service/handlers/nomination-pool/index.js +11 -5
  13. package/cjs/services/earning-service/service.js +5 -2
  14. package/cjs/services/fee-service/utils/tokenPayFee.js +17 -13
  15. package/cjs/services/price-service/coingecko.js +3 -3
  16. package/cjs/services/swap-service/handler/hydradx-handler.js +19 -13
  17. package/cjs/services/swap-service/index.js +8 -5
  18. package/cjs/services/transaction-service/utils.js +31 -22
  19. package/cjs/utils/index.js +12 -0
  20. package/cjs/utils/setup-api-sdk.js +27 -0
  21. package/constants/environment.d.ts +1 -0
  22. package/constants/environment.js +1 -0
  23. package/koni/background/handlers/State.js +3 -7
  24. package/package.json +12 -6
  25. package/packageInfo.js +1 -1
  26. package/services/balance-service/index.js +3 -4
  27. package/services/balance-service/transfer/cardano-transfer.js +42 -10
  28. package/services/balance-service/transfer/xcm/acrossBridge/index.js +14 -93
  29. package/services/balance-service/transfer/xcm/index.js +12 -4
  30. package/services/chain-service/utils/patch.d.ts +1 -0
  31. package/services/chain-service/utils/patch.js +1 -1
  32. package/services/earning-service/handlers/native-staking/dtao.d.ts +4 -36
  33. package/services/earning-service/handlers/native-staking/dtao.js +24 -298
  34. package/services/earning-service/handlers/native-staking/relay-chain.d.ts +1 -2
  35. package/services/earning-service/handlers/native-staking/relay-chain.js +4 -4
  36. package/services/earning-service/handlers/native-staking/tao.d.ts +25 -5
  37. package/services/earning-service/handlers/native-staking/tao.js +169 -149
  38. package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -2
  39. package/services/earning-service/handlers/nomination-pool/index.js +11 -5
  40. package/services/earning-service/service.d.ts +1 -0
  41. package/services/earning-service/service.js +4 -2
  42. package/services/fee-service/utils/tokenPayFee.js +17 -13
  43. package/services/price-service/coingecko.js +2 -3
  44. package/services/swap-service/handler/hydradx-handler.js +19 -13
  45. package/services/swap-service/index.js +8 -5
  46. package/services/transaction-service/utils.d.ts +0 -1
  47. package/services/transaction-service/utils.js +31 -21
  48. package/types/swap/index.d.ts +1 -1
  49. package/types/yield/info/chain/info.d.ts +1 -0
  50. package/utils/index.d.ts +1 -0
  51. package/utils/index.js +2 -1
  52. package/utils/setup-api-sdk.d.ts +1 -0
  53. package/utils/setup-api-sdk.js +20 -0
@@ -12,7 +12,7 @@ import { BasicTxErrorType, DynamicSwapType } from '@subwallet/extension-base/typ
12
12
  import { CommonStepType } from '@subwallet/extension-base/types/service-base';
13
13
  import { SwapErrorType, SwapFeeType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types/swap';
14
14
  import { _reformatAddressWithChain } from '@subwallet/extension-base/utils';
15
- import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
15
+ import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
16
16
  import BigN from 'bignumber.js';
17
17
  import { isHex } from '@polkadot/util';
18
18
  const HYDRADX_SUBWALLET_REFERRAL_CODE = 'WALLET';
@@ -137,21 +137,27 @@ export class HydradxHandler {
137
137
  let bnSendingValue = BigN(fromAmount);
138
138
  let bnExpectedReceive = BigN(selectedQuote.toAmount);
139
139
  if (needModifyData) {
140
- var _subwalletApiSdk$swap;
140
+ var _quotes;
141
141
  // override info if xcm-swap-xcm
142
142
  bnSendingValue = bnSendingValue.multipliedBy(DEFAULT_EXCESS_AMOUNT_WEIGHT);
143
143
  bnExpectedReceive = bnExpectedReceive.multipliedBy(DEFAULT_EXCESS_AMOUNT_WEIGHT);
144
- const quotes = await ((_subwalletApiSdk$swap = subwalletApiSdk.swapApi) === null || _subwalletApiSdk$swap === void 0 ? void 0 : _subwalletApiSdk$swap.fetchSwapQuoteData({
145
- address: sender,
146
- pair: {
147
- from: swapPairInfo.from,
148
- to: swapPairInfo.to,
149
- slug: swapPairInfo.slug
150
- },
151
- fromAmount: bnSendingValue.toFixed(0, 1),
152
- slippage: params.request.slippage
153
- }));
154
- const quoteAskResponse = quotes === null || quotes === void 0 ? void 0 : quotes.find(quote => quote.provider === this.providerSlug);
144
+ let quotes = []; // todo
145
+
146
+ try {
147
+ quotes = await subwalletApiSdk.swapApi.fetchSwapQuoteData({
148
+ address: sender,
149
+ pair: {
150
+ from: swapPairInfo.from,
151
+ to: swapPairInfo.to,
152
+ slug: swapPairInfo.slug
153
+ },
154
+ fromAmount: bnSendingValue.toFixed(0, 1),
155
+ slippage: params.request.slippage
156
+ });
157
+ } catch (error) {
158
+ throw new Error(`Failed to fetch swap quote: ${error.message}`);
159
+ }
160
+ const quoteAskResponse = (_quotes = quotes) === null || _quotes === void 0 ? void 0 : _quotes.find(quote => quote.provider === this.providerSlug);
155
161
  if (!quoteAskResponse || !quoteAskResponse.quote) {
156
162
  return Promise.resolve(undefined);
157
163
  }
@@ -17,7 +17,7 @@ import { BasicTxErrorType, DynamicSwapType } from '@subwallet/extension-base/typ
17
17
  import { DEFAULT_FIRST_STEP, MOCK_STEP_FEE } from '@subwallet/extension-base/types/service-base';
18
18
  import { _SUPPORTED_SWAP_PROVIDERS, SwapErrorType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types/swap';
19
19
  import { _reformatAddressWithChain, createPromiseHandler, reformatAddress } from '@subwallet/extension-base/utils';
20
- import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
20
+ import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
21
21
  import BigN from 'bignumber.js';
22
22
  import { t } from 'i18next';
23
23
  import { BehaviorSubject } from 'rxjs';
@@ -36,7 +36,6 @@ export class SwapService {
36
36
  this.chainService = state.chainService;
37
37
  }
38
38
  async askProvidersForQuote(_request) {
39
- var _subwalletApiSdk$swap;
40
39
  const availableQuotes = [];
41
40
 
42
41
  // hotfix // todo: remove later
@@ -44,7 +43,7 @@ export class SwapService {
44
43
  ..._request,
45
44
  isSupportKyberVersion: true
46
45
  };
47
- const quotes = await ((_subwalletApiSdk$swap = subwalletApiSdk.swapApi) === null || _subwalletApiSdk$swap === void 0 ? void 0 : _subwalletApiSdk$swap.fetchSwapQuoteData(request));
46
+ const quotes = await subwalletApiSdk.swapApi.fetchSwapQuoteData(request);
48
47
  if (Array.isArray(quotes)) {
49
48
  quotes.forEach(quoteData => {
50
49
  if (!_SUPPORTED_SWAP_PROVIDERS.includes(quoteData.provider)) {
@@ -265,8 +264,12 @@ export class SwapService {
265
264
  return [[], undefined];
266
265
  }
267
266
  async getLatestQuoteFromSwapRequest(request) {
268
- var _subwalletApiSdk$swap2;
269
- const availablePath = await ((_subwalletApiSdk$swap2 = subwalletApiSdk.swapApi) === null || _subwalletApiSdk$swap2 === void 0 ? void 0 : _subwalletApiSdk$swap2.findAvailablePath(request));
267
+ let availablePath;
268
+ try {
269
+ availablePath = await subwalletApiSdk.swapApi.findAvailablePath(request);
270
+ } catch (e) {
271
+ console.log('Error findAvailablePath', e);
272
+ }
270
273
  if (!availablePath) {
271
274
  return {
272
275
  path: [],
@@ -2,7 +2,6 @@ import { _ChainInfo } from '@subwallet/chain-list/types';
2
2
  import { ExtrinsicDataTypeMap, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
3
3
  import { ChainflipSwapTxData, SimpleSwapTxData } from '@subwallet/extension-base/types/swap';
4
4
  export declare function parseTransactionData<T extends ExtrinsicType>(data: unknown): ExtrinsicDataTypeMap[T];
5
- export declare function getTransactionId(value: string): Promise<string>;
6
5
  export declare function getExplorerLink(chainInfo: _ChainInfo, value: string, type: 'account' | 'tx'): string | undefined;
7
6
  export declare function getChainflipExplorerLink(data: ChainflipSwapTxData, chainInfo: _ChainInfo): string;
8
7
  export declare function getSimpleSwapExplorerLink(data: SimpleSwapTxData): string;
@@ -43,12 +43,18 @@ function getBlockExplorerAccountRoute(explorerLink) {
43
43
  if (explorerLink.includes('devnet-explorer.mosaicchain.io')) {
44
44
  return 'accounts';
45
45
  }
46
+ if (explorerLink.includes('pdexmon.com')) {
47
+ return 'holders';
48
+ }
46
49
  return 'address';
47
50
  }
48
51
  function getBlockExplorerTxRoute(chainInfo) {
49
52
  if (_isPureEvmChain(chainInfo) || _isPureBitcoinChain(chainInfo)) {
50
53
  return 'tx';
51
54
  }
55
+ if (['moonbeam'].includes(chainInfo.slug)) {
56
+ return 'tx';
57
+ }
52
58
  if (_isPureCardanoChain(chainInfo) || _isPureTonChain(chainInfo)) {
53
59
  return 'transaction';
54
60
  }
@@ -58,33 +64,38 @@ function getBlockExplorerTxRoute(chainInfo) {
58
64
  if (['gen6_public'].includes(chainInfo.slug)) {
59
65
  return '#/extrinsics';
60
66
  }
61
- if (['mosaicTest'].includes(chainInfo.slug)) {
67
+ if (['mosaicTest', 'polkadex'].includes(chainInfo.slug)) {
62
68
  return 'transactions';
63
69
  }
70
+ if (['autonomys'].includes(chainInfo.slug)) {
71
+ return 'extrinsics';
72
+ }
64
73
  const explorerLink = _getBlockExplorerFromChain(chainInfo);
65
74
  if (explorerLink && explorerLink.includes('statescan.io')) {
66
75
  return '#/extrinsics';
67
76
  }
68
77
  return 'extrinsic';
69
78
  }
70
- export function getTransactionId(value) {
71
- const query = `
72
- query ExtrinsicQuery {
73
- extrinsics(where: {hash_eq: ${value}}, limit: 1) {
74
- id
75
- }
76
- }`;
77
- const apiUrl = 'https://archive-explorer.truth-network.io/graphql';
78
- return fetch(apiUrl, {
79
- method: 'POST',
80
- headers: {
81
- 'Content-Type': 'application/json'
82
- },
83
- body: JSON.stringify({
84
- query
85
- })
86
- }).then(response => response.json()).then(result => result.data.extrinsics[0].id);
87
- }
79
+
80
+ // export function getTransactionId (value: string): Promise<string> {
81
+ // const query = `
82
+ // query ExtrinsicQuery {
83
+ // extrinsics(where: {hash_eq: ${value}}, limit: 1) {
84
+ // id
85
+ // }
86
+ // }`;
87
+ //
88
+ // const apiUrl = 'https://archive-explorer.truth-network.io/graphql';
89
+ //
90
+ // return fetch(apiUrl, {
91
+ // method: 'POST',
92
+ // headers: { 'Content-Type': 'application/json' },
93
+ // body: JSON.stringify({ query })
94
+ // })
95
+ // .then((response) => response.json())
96
+ // .then((result: SWApiResponse<ExtrinsicsDataResponse>) => result.data.extrinsics[0].id);
97
+ // }
98
+
88
99
  export function getExplorerLink(chainInfo, value, type) {
89
100
  const explorerLink = _getBlockExplorerFromChain(chainInfo);
90
101
  if (explorerLink && type === 'account') {
@@ -120,6 +131,5 @@ export function getChainflipExplorerLink(data, chainInfo) {
120
131
  return `${chainflipDomain}/channels/${data.depositChannelId}`;
121
132
  }
122
133
  export function getSimpleSwapExplorerLink(data) {
123
- const simpleswapDomain = SIMPLE_SWAP_EXPLORER;
124
- return `${simpleswapDomain}/exchange?id=${data.id}`;
134
+ return `${SIMPLE_SWAP_EXPLORER}/exchange?id=${data.id}`;
125
135
  }
@@ -117,7 +117,7 @@ export interface SimpleSwapValidationMetadata {
117
117
  maxSwap: AmountData;
118
118
  chain: _ChainInfo;
119
119
  }
120
- export interface QuoteAskResponse {
120
+ export interface ProcessedQuoteAskResponse {
121
121
  quote?: SwapQuote;
122
122
  error?: SwapError;
123
123
  }
@@ -90,6 +90,7 @@ export interface BaseYieldPoolMetadata {
90
90
  netuid: number;
91
91
  subnetSymbol: string;
92
92
  };
93
+ minValidate?: string;
93
94
  }
94
95
  /**
95
96
  * @interface NormalYieldPoolMetadata
package/utils/index.d.ts CHANGED
@@ -69,3 +69,4 @@ export * from './registry';
69
69
  export * from './swap';
70
70
  export * from './translate';
71
71
  export * from './bitcoin';
72
+ export * from './setup-api-sdk';
package/utils/index.js CHANGED
@@ -346,4 +346,5 @@ export * from "./promise.js";
346
346
  export * from "./registry.js";
347
347
  export * from "./swap.js";
348
348
  export * from "./translate.js";
349
- export * from "./bitcoin/index.js";
349
+ export * from "./bitcoin/index.js";
350
+ export * from "./setup-api-sdk.js";
@@ -0,0 +1 @@
1
+ export declare function setupApiSDK(): void;
@@ -0,0 +1,20 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { APP_VERSION, BACKEND_API_URL, BACKEND_PRICE_HISTORY_URL } from '@subwallet/extension-base/constants';
5
+ import { ChainListVersion } from '@subwallet/extension-base/services/chain-service/utils';
6
+ import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
7
+ import { TARGET_ENV } from "./environment.js";
8
+ export function setupApiSDK() {
9
+ subwalletApiSdk.updateConfig({
10
+ appVersion: APP_VERSION,
11
+ baseUrl: BACKEND_API_URL,
12
+ platform: TARGET_ENV,
13
+ chainListVersion: ChainListVersion
14
+ });
15
+
16
+ // Custom the price history API with other different base URL
17
+ subwalletApiSdk.priceHistoryApi.updateConfig({
18
+ baseUrl: BACKEND_PRICE_HISTORY_URL
19
+ });
20
+ }