@subwallet/extension-base 1.3.51-0 → 1.3.53-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.
- package/cjs/constants/environment.js +3 -1
- package/cjs/koni/background/handlers/State.js +1 -5
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/index.js +3 -4
- package/cjs/services/balance-service/transfer/cardano-transfer.js +43 -11
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +13 -92
- package/cjs/services/balance-service/transfer/xcm/index.js +12 -4
- package/cjs/services/chain-service/utils/patch.js +3 -2
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +28 -301
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +4 -4
- package/cjs/services/earning-service/handlers/native-staking/tao.js +174 -148
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +11 -5
- package/cjs/services/earning-service/service.js +5 -2
- package/cjs/services/fee-service/utils/tokenPayFee.js +17 -13
- package/cjs/services/keyring-service/context/handlers/Json.js +28 -3
- package/cjs/services/price-service/coingecko.js +3 -3
- package/cjs/services/swap-service/handler/hydradx-handler.js +19 -13
- package/cjs/services/swap-service/index.js +8 -5
- package/cjs/services/transaction-service/utils.js +31 -22
- package/cjs/services/wallet-connect-service/constants.js +6 -2
- package/cjs/services/wallet-connect-service/index.js +62 -45
- package/cjs/utils/index.js +12 -0
- package/cjs/utils/setup-api-sdk.js +27 -0
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +1 -0
- package/koni/background/handlers/State.js +3 -7
- package/package.json +34 -29
- package/packageInfo.js +1 -1
- package/services/balance-service/index.js +3 -4
- package/services/balance-service/transfer/cardano-transfer.js +42 -10
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +14 -93
- package/services/balance-service/transfer/xcm/index.js +12 -4
- package/services/chain-service/utils/patch.d.ts +1 -0
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/native-staking/dtao.d.ts +4 -36
- package/services/earning-service/handlers/native-staking/dtao.js +24 -298
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +1 -2
- package/services/earning-service/handlers/native-staking/relay-chain.js +4 -4
- package/services/earning-service/handlers/native-staking/tao.d.ts +25 -5
- package/services/earning-service/handlers/native-staking/tao.js +169 -149
- package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -2
- package/services/earning-service/handlers/nomination-pool/index.js +11 -5
- package/services/earning-service/service.d.ts +1 -0
- package/services/earning-service/service.js +4 -2
- package/services/fee-service/utils/tokenPayFee.js +17 -13
- package/services/keyring-service/context/handlers/Json.js +28 -3
- package/services/price-service/coingecko.js +2 -3
- package/services/swap-service/handler/hydradx-handler.js +19 -13
- package/services/swap-service/index.js +8 -5
- package/services/transaction-service/utils.d.ts +0 -1
- package/services/transaction-service/utils.js +31 -21
- package/services/wallet-connect-service/constants.d.ts +2 -0
- package/services/wallet-connect-service/constants.js +3 -1
- package/services/wallet-connect-service/index.js +50 -33
- package/types/swap/index.d.ts +1 -1
- package/types/yield/info/chain/info.d.ts +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +2 -1
- package/utils/setup-api-sdk.d.ts +1 -0
- package/utils/setup-api-sdk.js +20 -0
|
@@ -154,7 +154,17 @@ export class AccountJsonHandler extends AccountBaseHandler {
|
|
|
154
154
|
accountProxies,
|
|
155
155
|
modifyPairs
|
|
156
156
|
} = json;
|
|
157
|
-
const pairs = jsons.
|
|
157
|
+
const pairs = jsons.reduce((rs, pair) => {
|
|
158
|
+
try {
|
|
159
|
+
rs.push(keyring.createFromJson(pair));
|
|
160
|
+
} catch (e) {
|
|
161
|
+
console.error(e);
|
|
162
|
+
}
|
|
163
|
+
return rs;
|
|
164
|
+
}, []);
|
|
165
|
+
if (!(pairs !== null && pairs !== void 0 && pairs.length)) {
|
|
166
|
+
throw new Error(t('No valid accounts found to import'));
|
|
167
|
+
}
|
|
158
168
|
const accountProxyMap = combineAccountsWithKeyPair(pairs, modifyPairs, accountProxies);
|
|
159
169
|
const result = Object.values(accountProxyMap).map(proxy => {
|
|
160
170
|
const rs = {
|
|
@@ -196,9 +206,24 @@ export class AccountJsonHandler extends AccountBaseHandler {
|
|
|
196
206
|
try {
|
|
197
207
|
const {
|
|
198
208
|
accountProxies,
|
|
199
|
-
modifyPairs
|
|
209
|
+
modifyPairs: modifyPairsRestored
|
|
200
210
|
} = file;
|
|
201
|
-
const
|
|
211
|
+
const modifyPairs = {};
|
|
212
|
+
const pairs = jsons.reduce((rs, pairJson) => {
|
|
213
|
+
try {
|
|
214
|
+
const pair = keyring.createFromJson(pairJson);
|
|
215
|
+
if (modifyPairsRestored !== null && modifyPairsRestored !== void 0 && modifyPairsRestored[pair.address]) {
|
|
216
|
+
modifyPairs[pair.address] = modifyPairsRestored[pair.address];
|
|
217
|
+
}
|
|
218
|
+
rs.push(pair);
|
|
219
|
+
} catch (e) {
|
|
220
|
+
console.error(e);
|
|
221
|
+
}
|
|
222
|
+
return rs;
|
|
223
|
+
}, []);
|
|
224
|
+
if (!(pairs !== null && pairs !== void 0 && pairs.length)) {
|
|
225
|
+
throw new Error(t('No valid accounts found to import'));
|
|
226
|
+
}
|
|
202
227
|
const accountProxyMap = combineAccountsWithKeyPair(pairs, modifyPairs, accountProxies);
|
|
203
228
|
const rawProxyIds = _proxyIds && _proxyIds.length ? _proxyIds : Object.keys(accountProxyMap);
|
|
204
229
|
let _exists;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { isProductionMode } from '@subwallet/extension-base/constants';
|
|
5
5
|
import { staticData, StaticKey } from '@subwallet/extension-base/utils/staticData';
|
|
6
|
-
import
|
|
6
|
+
import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
|
|
7
7
|
import { isArray } from '@polkadot/util';
|
|
8
8
|
const DEFAULT_CURRENCY = 'USD';
|
|
9
9
|
const DERIVATIVE_TOKEN_SLUG_LIST = ['susds', 'savings-dai'];
|
|
@@ -141,8 +141,7 @@ export const getPriceMap = async (priceIds, currency = 'USD', skipDerivativePric
|
|
|
141
141
|
};
|
|
142
142
|
export const getHistoryPrice = async (priceId, type) => {
|
|
143
143
|
try {
|
|
144
|
-
|
|
145
|
-
const response = await ((_subwalletApiSdk$pric = subwalletApiSdk.priceHistoryApi) === null || _subwalletApiSdk$pric === void 0 ? void 0 : _subwalletApiSdk$pric.getPriceHistory(priceId, type));
|
|
144
|
+
const response = await subwalletApiSdk.priceHistoryApi.getPriceHistory(priceId, type);
|
|
146
145
|
if (response) {
|
|
147
146
|
return response;
|
|
148
147
|
}
|
|
@@ -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-
|
|
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
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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-
|
|
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
|
|
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
|
-
|
|
269
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
124
|
-
return `${simpleswapDomain}/exchange?id=${data.id}`;
|
|
134
|
+
return `${SIMPLE_SWAP_EXPLORER}/exchange?id=${data.id}`;
|
|
125
135
|
}
|
|
@@ -3,6 +3,7 @@ import { SignClientTypes } from '@walletconnect/types';
|
|
|
3
3
|
export declare const PROJECT_ID_EXTENSION = "6da34c0b48164d27681924dd9a46d6be";
|
|
4
4
|
export declare const PROJECT_ID_MOBILE = "6da34c0b48164d27681924dd9a46d6be";
|
|
5
5
|
export declare const RELAY_URL = "wss://relay.walletconnect.com";
|
|
6
|
+
export declare const RELAY_FALLBACK_URL = "wss://relay.walletconnect.org";
|
|
6
7
|
export declare const DEFAULT_WALLET_CONNECT_OPTIONS: SignClientTypes.Options;
|
|
7
8
|
export declare const ALL_WALLET_CONNECT_EVENT: SignClientTypes.Event[];
|
|
8
9
|
export declare const WALLET_CONNECT_SUPPORTED_METHODS: WalletConnectSigningMethod[];
|
|
@@ -10,3 +11,4 @@ export declare const WALLET_CONNECT_REQUEST_KEY = "wallet-connect";
|
|
|
10
11
|
export declare const WALLET_CONNECT_EIP155_NAMESPACE = "eip155";
|
|
11
12
|
export declare const WALLET_CONNECT_POLKADOT_NAMESPACE = "polkadot";
|
|
12
13
|
export declare const WALLET_CONNECT_SUPPORT_NAMESPACES: string[];
|
|
14
|
+
export declare const WALLET_CONNECT_SESSION_TIMEOUT = 20000;
|
|
@@ -6,6 +6,7 @@ import { targetIsMobile } from '@subwallet/extension-base/utils';
|
|
|
6
6
|
export const PROJECT_ID_EXTENSION = '6da34c0b48164d27681924dd9a46d6be';
|
|
7
7
|
export const PROJECT_ID_MOBILE = '6da34c0b48164d27681924dd9a46d6be';
|
|
8
8
|
export const RELAY_URL = 'wss://relay.walletconnect.com';
|
|
9
|
+
export const RELAY_FALLBACK_URL = 'wss://relay.walletconnect.org';
|
|
9
10
|
export const DEFAULT_WALLET_CONNECT_OPTIONS = {
|
|
10
11
|
logger: 'error',
|
|
11
12
|
projectId: targetIsMobile ? PROJECT_ID_MOBILE : PROJECT_ID_EXTENSION,
|
|
@@ -22,4 +23,5 @@ export const WALLET_CONNECT_SUPPORTED_METHODS = [POLKADOT_SIGNING_METHODS.POLKAD
|
|
|
22
23
|
export const WALLET_CONNECT_REQUEST_KEY = 'wallet-connect';
|
|
23
24
|
export const WALLET_CONNECT_EIP155_NAMESPACE = 'eip155';
|
|
24
25
|
export const WALLET_CONNECT_POLKADOT_NAMESPACE = 'polkadot';
|
|
25
|
-
export const WALLET_CONNECT_SUPPORT_NAMESPACES = [WALLET_CONNECT_EIP155_NAMESPACE, WALLET_CONNECT_POLKADOT_NAMESPACE];
|
|
26
|
+
export const WALLET_CONNECT_SUPPORT_NAMESPACES = [WALLET_CONNECT_EIP155_NAMESPACE, WALLET_CONNECT_POLKADOT_NAMESPACE];
|
|
27
|
+
export const WALLET_CONNECT_SESSION_TIMEOUT = 20000; // 20 seconds
|
|
@@ -6,11 +6,12 @@ import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateF
|
|
|
6
6
|
import { formatJsonRpcError } from '@json-rpc-tools/utils';
|
|
7
7
|
import Eip155RequestHandler from '@subwallet/extension-base/services/wallet-connect-service/handler/Eip155RequestHandler';
|
|
8
8
|
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
9
|
+
import { wait } from '@subwallet/extension-base/utils';
|
|
9
10
|
import SignClient from '@walletconnect/sign-client';
|
|
10
11
|
import { getInternalError, getSdkError } from '@walletconnect/utils';
|
|
11
12
|
import { BehaviorSubject } from 'rxjs';
|
|
12
13
|
import PolkadotRequestHandler from "./handler/PolkadotRequestHandler.js";
|
|
13
|
-
import { ALL_WALLET_CONNECT_EVENT, DEFAULT_WALLET_CONNECT_OPTIONS, WALLET_CONNECT_EIP155_NAMESPACE, WALLET_CONNECT_SUPPORTED_METHODS } from "./constants.js";
|
|
14
|
+
import { ALL_WALLET_CONNECT_EVENT, DEFAULT_WALLET_CONNECT_OPTIONS, RELAY_FALLBACK_URL, RELAY_URL, WALLET_CONNECT_EIP155_NAMESPACE, WALLET_CONNECT_SESSION_TIMEOUT, WALLET_CONNECT_SUPPORTED_METHODS } from "./constants.js";
|
|
14
15
|
import { convertConnectRequest, convertNotSupportRequest, isSupportWalletConnectChain } from "./helpers.js";
|
|
15
16
|
import { EIP155_SIGNING_METHODS, POLKADOT_SIGNING_METHODS } from "./types.js";
|
|
16
17
|
const storage = SWStorage.instance;
|
|
@@ -116,7 +117,19 @@ export default class WalletConnectService {
|
|
|
116
117
|
async initClient(force) {
|
|
117
118
|
_classPrivateFieldLooseBase(this, _removeListener)[_removeListener]();
|
|
118
119
|
if (force || (await this.haveData())) {
|
|
119
|
-
|
|
120
|
+
try {
|
|
121
|
+
_classPrivateFieldLooseBase(this, _client)[_client] = await SignClient.init(_classPrivateFieldLooseBase(this, _option)[_option]);
|
|
122
|
+
} catch (e) {
|
|
123
|
+
if (_classPrivateFieldLooseBase(this, _option)[_option].relayUrl === RELAY_URL) {
|
|
124
|
+
_classPrivateFieldLooseBase(this, _option)[_option] = {
|
|
125
|
+
..._classPrivateFieldLooseBase(this, _option)[_option],
|
|
126
|
+
relayUrl: RELAY_FALLBACK_URL
|
|
127
|
+
};
|
|
128
|
+
_classPrivateFieldLooseBase(this, _client)[_client] = await SignClient.init(_classPrivateFieldLooseBase(this, _option)[_option]);
|
|
129
|
+
} else {
|
|
130
|
+
throw e;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
120
133
|
}
|
|
121
134
|
_classPrivateFieldLooseBase(this, _updateSessions)[_updateSessions]();
|
|
122
135
|
_classPrivateFieldLooseBase(this, _createListener)[_createListener]();
|
|
@@ -139,17 +152,21 @@ export default class WalletConnectService {
|
|
|
139
152
|
await this.initClient();
|
|
140
153
|
}
|
|
141
154
|
async connect(uri) {
|
|
142
|
-
var _classPrivateFieldLoo3;
|
|
143
|
-
if (!(await this.haveData())) {
|
|
155
|
+
var _classPrivateFieldLoo3, _classPrivateFieldLoo4;
|
|
156
|
+
if (!(await this.haveData()) || !((_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(this, _client)[_client]) !== null && _classPrivateFieldLoo3 !== void 0 && _classPrivateFieldLoo3.core.relayer.connected)) {
|
|
144
157
|
await this.initClient(true);
|
|
145
158
|
}
|
|
146
159
|
_classPrivateFieldLooseBase(this, _checkClient)[_checkClient]();
|
|
147
|
-
|
|
160
|
+
|
|
161
|
+
// The purpose of designing a timeout for pairing is to prevent the promise from not being resolved if there are issues during the pairing process.
|
|
162
|
+
await Promise.race([(_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo4 === void 0 ? void 0 : _classPrivateFieldLoo4.pair({
|
|
148
163
|
uri
|
|
149
|
-
}))
|
|
164
|
+
}), wait(WALLET_CONNECT_SESSION_TIMEOUT).then(() => {
|
|
165
|
+
throw new Error(getInternalError('EXPIRED').message);
|
|
166
|
+
})]);
|
|
150
167
|
}
|
|
151
168
|
async approveSession(result) {
|
|
152
|
-
var
|
|
169
|
+
var _classPrivateFieldLoo5;
|
|
153
170
|
_classPrivateFieldLooseBase(this, _checkClient)[_checkClient]();
|
|
154
171
|
Object.entries(result.namespaces).forEach(([namespace, {
|
|
155
172
|
methods
|
|
@@ -157,32 +174,32 @@ export default class WalletConnectService {
|
|
|
157
174
|
methods = [...methods, ...this.findMethodsMissing(WALLET_CONNECT_EIP155_NAMESPACE === namespace ? methodEVMRequire : methodDOTRequire, methods)];
|
|
158
175
|
result.namespaces[namespace].methods = methods;
|
|
159
176
|
});
|
|
160
|
-
await ((
|
|
177
|
+
await ((_classPrivateFieldLoo5 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo5 === void 0 ? void 0 : _classPrivateFieldLoo5.approve(result));
|
|
161
178
|
_classPrivateFieldLooseBase(this, _updateSessions)[_updateSessions]();
|
|
162
179
|
}
|
|
163
180
|
async rejectSession(id) {
|
|
164
|
-
var
|
|
181
|
+
var _classPrivateFieldLoo6;
|
|
165
182
|
_classPrivateFieldLooseBase(this, _checkClient)[_checkClient]();
|
|
166
|
-
await ((
|
|
183
|
+
await ((_classPrivateFieldLoo6 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo6 === void 0 ? void 0 : _classPrivateFieldLoo6.reject({
|
|
167
184
|
id: id,
|
|
168
185
|
reason: getSdkError('USER_REJECTED')
|
|
169
186
|
}));
|
|
170
187
|
}
|
|
171
188
|
async responseRequest(response) {
|
|
172
|
-
var
|
|
189
|
+
var _classPrivateFieldLoo7;
|
|
173
190
|
_classPrivateFieldLooseBase(this, _checkClient)[_checkClient]();
|
|
174
|
-
await ((
|
|
191
|
+
await ((_classPrivateFieldLoo7 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo7 === void 0 ? void 0 : _classPrivateFieldLoo7.respond(response));
|
|
175
192
|
}
|
|
176
193
|
async resetWallet(resetAll) {
|
|
177
|
-
var
|
|
194
|
+
var _classPrivateFieldLoo8, _classPrivateFieldLoo10, _classPrivateFieldLoo12;
|
|
178
195
|
_classPrivateFieldLooseBase(this, _removeListener)[_removeListener]();
|
|
179
196
|
|
|
180
197
|
// Disconnect session
|
|
181
|
-
const sessions = ((
|
|
198
|
+
const sessions = ((_classPrivateFieldLoo8 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo8 === void 0 ? void 0 : _classPrivateFieldLoo8.session.values) || [];
|
|
182
199
|
for (const session of sessions) {
|
|
183
200
|
try {
|
|
184
|
-
var
|
|
185
|
-
await ((
|
|
201
|
+
var _classPrivateFieldLoo9;
|
|
202
|
+
await ((_classPrivateFieldLoo9 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo9 === void 0 ? void 0 : _classPrivateFieldLoo9.disconnect({
|
|
186
203
|
topic: session.topic,
|
|
187
204
|
reason: getSdkError('USER_DISCONNECTED')
|
|
188
205
|
}));
|
|
@@ -192,11 +209,11 @@ export default class WalletConnectService {
|
|
|
192
209
|
}
|
|
193
210
|
|
|
194
211
|
// Disconnect pair
|
|
195
|
-
const pairs = ((
|
|
212
|
+
const pairs = ((_classPrivateFieldLoo10 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo10 === void 0 ? void 0 : _classPrivateFieldLoo10.pairing.values) || [];
|
|
196
213
|
for (const pair of pairs) {
|
|
197
214
|
try {
|
|
198
|
-
var
|
|
199
|
-
await ((
|
|
215
|
+
var _classPrivateFieldLoo11;
|
|
216
|
+
await ((_classPrivateFieldLoo11 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo11 === void 0 ? void 0 : _classPrivateFieldLoo11.disconnect({
|
|
200
217
|
topic: pair.topic,
|
|
201
218
|
reason: getSdkError('USER_DISCONNECTED')
|
|
202
219
|
}));
|
|
@@ -204,12 +221,12 @@ export default class WalletConnectService {
|
|
|
204
221
|
console.error(e);
|
|
205
222
|
}
|
|
206
223
|
}
|
|
207
|
-
const keys = (await ((
|
|
224
|
+
const keys = (await ((_classPrivateFieldLoo12 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo12 === void 0 ? void 0 : _classPrivateFieldLoo12.core.storage.getKeys())) || [];
|
|
208
225
|
const deleteKeys = resetAll ? keys : keys.filter(key => key.startsWith('wc@'));
|
|
209
226
|
for (const key of deleteKeys) {
|
|
210
227
|
try {
|
|
211
|
-
var
|
|
212
|
-
await ((
|
|
228
|
+
var _classPrivateFieldLoo13;
|
|
229
|
+
await ((_classPrivateFieldLoo13 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo13 === void 0 ? void 0 : _classPrivateFieldLoo13.core.storage.removeItem(key));
|
|
213
230
|
} catch (e) {
|
|
214
231
|
console.error(e);
|
|
215
232
|
}
|
|
@@ -218,8 +235,8 @@ export default class WalletConnectService {
|
|
|
218
235
|
_classPrivateFieldLooseBase(this, _updateSessions)[_updateSessions]();
|
|
219
236
|
}
|
|
220
237
|
async disconnect(topic) {
|
|
221
|
-
var
|
|
222
|
-
await ((
|
|
238
|
+
var _classPrivateFieldLoo14;
|
|
239
|
+
await ((_classPrivateFieldLoo14 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo14 === void 0 ? void 0 : _classPrivateFieldLoo14.disconnect({
|
|
223
240
|
topic: topic,
|
|
224
241
|
reason: getSdkError('USER_DISCONNECTED')
|
|
225
242
|
}));
|
|
@@ -326,18 +343,18 @@ async function _onPingReply2({
|
|
|
326
343
|
}
|
|
327
344
|
}
|
|
328
345
|
function _createListener2() {
|
|
329
|
-
var
|
|
330
|
-
(
|
|
331
|
-
(
|
|
332
|
-
(
|
|
333
|
-
(
|
|
334
|
-
(
|
|
335
|
-
(
|
|
346
|
+
var _classPrivateFieldLoo15, _classPrivateFieldLoo16, _classPrivateFieldLoo17, _classPrivateFieldLoo18, _classPrivateFieldLoo19, _classPrivateFieldLoo20;
|
|
347
|
+
(_classPrivateFieldLoo15 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo15 === void 0 ? void 0 : _classPrivateFieldLoo15.on('session_proposal', _classPrivateFieldLooseBase(this, _onSessionProposal)[_onSessionProposal].bind(this));
|
|
348
|
+
(_classPrivateFieldLoo16 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo16 === void 0 ? void 0 : _classPrivateFieldLoo16.on('session_request', _classPrivateFieldLooseBase(this, _onSessionRequest)[_onSessionRequest].bind(this));
|
|
349
|
+
(_classPrivateFieldLoo17 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo17 === void 0 ? void 0 : _classPrivateFieldLoo17.on('session_ping', _classPrivateFieldLooseBase(this, _onPingReply)[_onPingReply].bind(this));
|
|
350
|
+
(_classPrivateFieldLoo18 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo18 === void 0 ? void 0 : _classPrivateFieldLoo18.on('session_event', data => console.log('event', data));
|
|
351
|
+
(_classPrivateFieldLoo19 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo19 === void 0 ? void 0 : _classPrivateFieldLoo19.on('session_update', data => console.log('update', data));
|
|
352
|
+
(_classPrivateFieldLoo20 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo20 === void 0 ? void 0 : _classPrivateFieldLoo20.on('session_delete', _classPrivateFieldLooseBase(this, _updateSessions)[_updateSessions].bind(this));
|
|
336
353
|
}
|
|
337
354
|
function _removeListener2() {
|
|
338
355
|
ALL_WALLET_CONNECT_EVENT.forEach(event => {
|
|
339
|
-
var
|
|
340
|
-
(
|
|
356
|
+
var _classPrivateFieldLoo21;
|
|
357
|
+
(_classPrivateFieldLoo21 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo21 === void 0 ? void 0 : _classPrivateFieldLoo21.removeAllListeners(event);
|
|
341
358
|
});
|
|
342
359
|
}
|
|
343
360
|
function _checkClient2() {
|
package/types/swap/index.d.ts
CHANGED
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
|
@@ -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
|
+
}
|