@subwallet/extension-base 1.1.56-0 → 1.1.57-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/koni/background/handlers/State.js +20 -3
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/index.js +9 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +28 -7
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +8 -14
- package/cjs/services/earning-service/utils/index.js +2 -2
- package/cjs/utils/fetchStaticCache.js +4 -1
- package/koni/background/handlers/State.js +21 -4
- package/package.json +5 -5
- package/packageInfo.js +1 -1
- package/services/chain-service/index.d.ts +1 -0
- package/services/chain-service/index.js +9 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +28 -7
- package/services/earning-service/handlers/nomination-pool/index.js +8 -14
- package/services/earning-service/utils/index.js +2 -2
- package/utils/fetchStaticCache.js +4 -1
|
@@ -1227,17 +1227,34 @@ class KoniState {
|
|
|
1227
1227
|
maxFeePerGas: autoFormatNumber(transactionParams.maxFeePerGas),
|
|
1228
1228
|
data: transactionParams.data
|
|
1229
1229
|
};
|
|
1230
|
+
const getTransactionGas = async () => {
|
|
1231
|
+
try {
|
|
1232
|
+
transaction.gas = await web3.eth.estimateGas({
|
|
1233
|
+
...transaction
|
|
1234
|
+
});
|
|
1235
|
+
} catch (e) {
|
|
1236
|
+
// @ts-ignore
|
|
1237
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1238
|
+
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1230
1241
|
|
|
1231
1242
|
// Calculate transaction data
|
|
1232
1243
|
try {
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1244
|
+
await Promise.race([getTransactionGas(), (0, _utils3.wait)(3000).then(async () => {
|
|
1245
|
+
if (!transaction.gas) {
|
|
1246
|
+
await this.chainService.initSingleApi(networkKey);
|
|
1247
|
+
await getTransactionGas();
|
|
1248
|
+
}
|
|
1249
|
+
})]);
|
|
1236
1250
|
} catch (e) {
|
|
1237
1251
|
// @ts-ignore
|
|
1238
1252
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1239
1253
|
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
|
|
1240
1254
|
}
|
|
1255
|
+
if (!transaction.gas) {
|
|
1256
|
+
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS);
|
|
1257
|
+
}
|
|
1241
1258
|
let estimateGas;
|
|
1242
1259
|
|
|
1243
1260
|
// TODO: Review, If not override, transaction maybe fail because fee too low
|
package/cjs/packageInfo.js
CHANGED
|
@@ -631,6 +631,15 @@ class ChainService {
|
|
|
631
631
|
}
|
|
632
632
|
}));
|
|
633
633
|
}
|
|
634
|
+
async initSingleApi(slug) {
|
|
635
|
+
const chainInfoMap = this.getChainInfoMap();
|
|
636
|
+
const chainStateMap = this.getChainStateMap();
|
|
637
|
+
if (!chainStateMap[slug].active) {
|
|
638
|
+
return false;
|
|
639
|
+
}
|
|
640
|
+
await this.initApiForChain(chainInfoMap[slug]);
|
|
641
|
+
return true;
|
|
642
|
+
}
|
|
634
643
|
async initApiForChain(chainInfo) {
|
|
635
644
|
const {
|
|
636
645
|
endpoint,
|
|
@@ -51,13 +51,16 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
51
51
|
await defaultCallback();
|
|
52
52
|
await substrateApi.isReady;
|
|
53
53
|
const unsub = await ((_substrateApi$api$que = substrateApi.api.query.staking) === null || _substrateApi$api$que === void 0 ? void 0 : _substrateApi$api$que.currentEra(async _currentEra => {
|
|
54
|
-
var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$que2, _substrateApi$api$que3, _substrateApi$api$que4, _substrateApi$api$que5, _substrateApi$api$que6;
|
|
54
|
+
var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$cal, _substrateApi$api$que2, _substrateApi$api$que3, _substrateApi$api$que4, _substrateApi$api$que5, _substrateApi$api$que6;
|
|
55
55
|
if (cancel) {
|
|
56
56
|
unsub();
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
|
+
let maxNominations = ((_substrateApi$api$con = substrateApi.api.consts.staking) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.maxNominations) === null || _substrateApi$api$con2 === void 0 ? void 0 : _substrateApi$api$con2.toString()) || '16';
|
|
60
|
+
const _maxNominationsByNominationQuota = await ((_substrateApi$api$cal = substrateApi.api.call.stakingApi) === null || _substrateApi$api$cal === void 0 ? void 0 : _substrateApi$api$cal.nominationsQuota(0)); // todo: review param. Currently return constant for all param.
|
|
61
|
+
const maxNominationsByNominationQuota = _maxNominationsByNominationQuota === null || _maxNominationsByNominationQuota === void 0 ? void 0 : _maxNominationsByNominationQuota.toString();
|
|
62
|
+
maxNominations = maxNominationsByNominationQuota !== null && maxNominationsByNominationQuota !== void 0 ? maxNominationsByNominationQuota : maxNominations;
|
|
59
63
|
const currentEra = _currentEra.toString();
|
|
60
|
-
const maxNominations = ((_substrateApi$api$con = substrateApi.api.consts.staking) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.maxNominations) === null || _substrateApi$api$con2 === void 0 ? void 0 : _substrateApi$api$con2.toString()) || '16'; // TODO
|
|
61
64
|
const maxUnlockingChunks = substrateApi.api.consts.staking.maxUnlockingChunks.toString();
|
|
62
65
|
const unlockingEras = substrateApi.api.consts.staking.bondingDuration.toString();
|
|
63
66
|
const maxSupportedEras = substrateApi.api.consts.staking.historyDepth.toString();
|
|
@@ -146,9 +149,20 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
146
149
|
const validatorList = nominations.targets;
|
|
147
150
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
148
151
|
let nominationStatus = _types.EarningStatus.NOT_EARNING;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
let eraStakerOtherList = [];
|
|
153
|
+
let identity;
|
|
154
|
+
if (['kusama', 'polkadot', 'westend'].includes(this.chain)) {
|
|
155
|
+
// todo: review all relaychains later
|
|
156
|
+
const [[_identity], _eraStaker] = await Promise.all([(0, _utils3.parseIdentity)(substrateApi, validatorAddress), substrateApi.api.query.staking.erasStakersPaged.entries(currentEra, validatorAddress)]);
|
|
157
|
+
identity = _identity;
|
|
158
|
+
eraStakerOtherList = _eraStaker.flatMap(paged => paged[1].toPrimitive().others);
|
|
159
|
+
} else {
|
|
160
|
+
const [[_identity], _eraStaker] = await Promise.all([(0, _utils3.parseIdentity)(substrateApi, validatorAddress), substrateApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
161
|
+
identity = _identity;
|
|
162
|
+
const eraStaker = _eraStaker.toPrimitive();
|
|
163
|
+
eraStakerOtherList = eraStaker.others;
|
|
164
|
+
}
|
|
165
|
+
const sortedNominators = eraStakerOtherList.sort((a, b) => {
|
|
152
166
|
return new _bignumber.default(b.value).minus(a.value).toNumber();
|
|
153
167
|
});
|
|
154
168
|
const topNominators = sortedNominators.map(nominator => {
|
|
@@ -290,7 +304,14 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
290
304
|
const maxEraRewardPointsEras = _constants2.MaxEraRewardPointsEras;
|
|
291
305
|
const endEraForPoints = parseInt(activeEra) - 1;
|
|
292
306
|
let startEraForPoints = endEraForPoints - maxEraRewardPointsEras + 1;
|
|
293
|
-
|
|
307
|
+
let _eraStakersPromise;
|
|
308
|
+
if (['kusama', 'polkadot', 'westend'].includes(this.chain)) {
|
|
309
|
+
// todo: review all relaychains later
|
|
310
|
+
_eraStakersPromise = chainApi.api.query.staking.erasStakersOverview.entries(parseInt(currentEra));
|
|
311
|
+
} else {
|
|
312
|
+
_eraStakersPromise = chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra));
|
|
313
|
+
}
|
|
314
|
+
const [_totalEraStake, _eraStakers, _minBond, _stakingRewards, _validators, ..._eraRewardPoints] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), _eraStakersPromise, chainApi.api.query.staking.minNominatorBond(), ((_chainApi$api$query$s = chainApi.api.query.stakingRewards) === null || _chainApi$api$query$s === void 0 ? void 0 : _chainApi$api$query$s.data) && chainApi.api.query.stakingRewards.data(), chainApi.api.query.staking.validators.entries(), chainApi.api.query.staking.erasRewardPoints.multi([...Array(maxEraRewardPointsEras).keys()].map(i => i + startEraForPoints))]);
|
|
294
315
|
const eraRewardMap = {};
|
|
295
316
|
for (const item of _eraRewardPoints[0]) {
|
|
296
317
|
eraRewardMap[startEraForPoints] = item.toHuman();
|
|
@@ -316,11 +337,11 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
316
337
|
const unlimitedNominatorRewarded = chainApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
317
338
|
const maxNominatorRewarded = (chainApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
318
339
|
const bnTotalEraStake = new _util.BN(_totalEraStake.toString());
|
|
319
|
-
const eraStakers = _eraStakers;
|
|
320
340
|
const rawMinBond = _minBond.toHuman();
|
|
321
341
|
const minBond = rawMinBond.replaceAll(',', '');
|
|
322
342
|
const totalStakeMap = {};
|
|
323
343
|
const bnDecimals = new _util.BN((10 ** decimals).toString());
|
|
344
|
+
const eraStakers = _eraStakers;
|
|
324
345
|
for (const item of eraStakers) {
|
|
325
346
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
326
347
|
const rawValidatorInfo = item[0].toHuman();
|
|
@@ -166,25 +166,19 @@ class NominationPoolHandler extends _base.default {
|
|
|
166
166
|
if (nominations) {
|
|
167
167
|
const validatorList = nominations.targets;
|
|
168
168
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
169
|
-
let
|
|
170
|
-
if (['kusama'].includes(this.chain)) {
|
|
171
|
-
// todo:
|
|
169
|
+
let eraStakerOtherList = [];
|
|
170
|
+
if (['kusama', 'polkadot', 'westend'].includes(this.chain)) {
|
|
171
|
+
// todo: review all relaychains later
|
|
172
172
|
const _eraStaker = await substrateApi.api.query.staking.erasStakersPaged.entries(currentEra, validatorAddress);
|
|
173
|
-
|
|
174
|
-
_eraStaker.forEach(paged => {
|
|
175
|
-
const pagedExposure = paged[1].toPrimitive();
|
|
176
|
-
eraStakerOtherList.push(...pagedExposure.others);
|
|
177
|
-
});
|
|
178
|
-
sortedNominators = eraStakerOtherList.sort((a, b) => {
|
|
179
|
-
return new _bignumber.default(b.value).minus(a.value).toNumber();
|
|
180
|
-
});
|
|
173
|
+
eraStakerOtherList = _eraStaker.flatMap(paged => paged[1].toPrimitive().others);
|
|
181
174
|
} else {
|
|
182
175
|
const _eraStaker = await substrateApi.api.query.staking.erasStakers(currentEra, validatorAddress);
|
|
183
176
|
const eraStaker = _eraStaker.toPrimitive();
|
|
184
|
-
|
|
185
|
-
return new _bignumber.default(b.value).minus(a.value).toNumber();
|
|
186
|
-
});
|
|
177
|
+
eraStakerOtherList = eraStaker.others;
|
|
187
178
|
}
|
|
179
|
+
const sortedNominators = eraStakerOtherList.sort((a, b) => {
|
|
180
|
+
return new _bignumber.default(b.value).minus(a.value).toNumber();
|
|
181
|
+
});
|
|
188
182
|
const topNominators = sortedNominators.map(nominator => {
|
|
189
183
|
return nominator.who;
|
|
190
184
|
}).slice(0, unlimitedNominatorRewarded ? undefined : maxNominatorRewardedPerValidator);
|
|
@@ -81,12 +81,12 @@ async function parseIdentity(substrateApi, address, children) {
|
|
|
81
81
|
const _identity = await substrateApi.api.query.identity.identityOf(address);
|
|
82
82
|
const identityInfo = _identity.toHuman();
|
|
83
83
|
if (identityInfo) {
|
|
84
|
-
var _identityInfo$info, _identityInfo$info$di, _identityInfo$info2, _identityInfo$info2$w, _identityInfo$info3, _identityInfo$info3$r, _identityInfo$info4, _identityInfo$info4$t;
|
|
84
|
+
var _identityInfo$info, _identityInfo$info$di, _identityInfo$info2, _identityInfo$info2$w, _identityInfo$info3, _identityInfo$info3$r, _identityInfo$info4, _identityInfo$info4$t, _identityInfo$judgeme;
|
|
85
85
|
const displayName = (_identityInfo$info = identityInfo.info) === null || _identityInfo$info === void 0 ? void 0 : (_identityInfo$info$di = _identityInfo$info.display) === null || _identityInfo$info$di === void 0 ? void 0 : _identityInfo$info$di.Raw;
|
|
86
86
|
const web = (_identityInfo$info2 = identityInfo.info) === null || _identityInfo$info2 === void 0 ? void 0 : (_identityInfo$info2$w = _identityInfo$info2.web) === null || _identityInfo$info2$w === void 0 ? void 0 : _identityInfo$info2$w.Raw;
|
|
87
87
|
const riot = (_identityInfo$info3 = identityInfo.info) === null || _identityInfo$info3 === void 0 ? void 0 : (_identityInfo$info3$r = _identityInfo$info3.riot) === null || _identityInfo$info3$r === void 0 ? void 0 : _identityInfo$info3$r.Raw;
|
|
88
88
|
const twitter = (_identityInfo$info4 = identityInfo.info) === null || _identityInfo$info4 === void 0 ? void 0 : (_identityInfo$info4$t = _identityInfo$info4.twitter) === null || _identityInfo$info4$t === void 0 ? void 0 : _identityInfo$info4$t.Raw;
|
|
89
|
-
const isReasonable = identityInfo.judgements.length > 0;
|
|
89
|
+
const isReasonable = ((_identityInfo$judgeme = identityInfo.judgements) === null || _identityInfo$judgeme === void 0 ? void 0 : _identityInfo$judgeme.length) > 0;
|
|
90
90
|
if (displayName) {
|
|
91
91
|
identity = (0, _util.isHex)(displayName) ? (0, _util.hexToString)(displayName) : displayName;
|
|
92
92
|
} else {
|
|
@@ -9,10 +9,13 @@ var _axios = _interopRequireDefault(require("axios"));
|
|
|
9
9
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
10
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
11
|
|
|
12
|
+
const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
13
|
+
const branchName = process.env.BRANCH_NAME || 'koni-dev';
|
|
14
|
+
const fetchTarget = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://static-cache.subwallet.app' : 'https://dev.sw-static-cache.pages.dev';
|
|
12
15
|
async function fetchStaticCache(slug, defaultData) {
|
|
13
16
|
let timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 9000;
|
|
14
17
|
try {
|
|
15
|
-
const rs = await _axios.default.get(
|
|
18
|
+
const rs = await _axios.default.get(`${fetchTarget}/${slug}`, {
|
|
16
19
|
timeout
|
|
17
20
|
});
|
|
18
21
|
return rs.data;
|
|
@@ -32,7 +32,7 @@ import { SwapService } from '@subwallet/extension-base/services/swap-service';
|
|
|
32
32
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
33
33
|
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
34
34
|
import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
|
|
35
|
-
import { isAccountAll, stripUrl, TARGET_ENV } from '@subwallet/extension-base/utils';
|
|
35
|
+
import { isAccountAll, stripUrl, TARGET_ENV, wait } from '@subwallet/extension-base/utils';
|
|
36
36
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
37
37
|
import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
38
38
|
import { decodePair } from '@subwallet/keyring/pair/decode';
|
|
@@ -1204,17 +1204,34 @@ export default class KoniState {
|
|
|
1204
1204
|
maxFeePerGas: autoFormatNumber(transactionParams.maxFeePerGas),
|
|
1205
1205
|
data: transactionParams.data
|
|
1206
1206
|
};
|
|
1207
|
+
const getTransactionGas = async () => {
|
|
1208
|
+
try {
|
|
1209
|
+
transaction.gas = await web3.eth.estimateGas({
|
|
1210
|
+
...transaction
|
|
1211
|
+
});
|
|
1212
|
+
} catch (e) {
|
|
1213
|
+
// @ts-ignore
|
|
1214
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1215
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1207
1218
|
|
|
1208
1219
|
// Calculate transaction data
|
|
1209
1220
|
try {
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1221
|
+
await Promise.race([getTransactionGas(), wait(3000).then(async () => {
|
|
1222
|
+
if (!transaction.gas) {
|
|
1223
|
+
await this.chainService.initSingleApi(networkKey);
|
|
1224
|
+
await getTransactionGas();
|
|
1225
|
+
}
|
|
1226
|
+
})]);
|
|
1213
1227
|
} catch (e) {
|
|
1214
1228
|
// @ts-ignore
|
|
1215
1229
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1216
1230
|
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
|
|
1217
1231
|
}
|
|
1232
|
+
if (!transaction.gas) {
|
|
1233
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS);
|
|
1234
|
+
}
|
|
1218
1235
|
let estimateGas;
|
|
1219
1236
|
|
|
1220
1237
|
// TODO: Review, If not override, transaction maybe fail because fee too low
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.1.
|
|
20
|
+
"version": "1.1.57-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -1874,10 +1874,10 @@
|
|
|
1874
1874
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
1875
1875
|
"@substrate/connect": "^0.8.9",
|
|
1876
1876
|
"@subwallet/chain-list": "0.2.56",
|
|
1877
|
-
"@subwallet/extension-base": "^1.1.
|
|
1878
|
-
"@subwallet/extension-chains": "^1.1.
|
|
1879
|
-
"@subwallet/extension-dapp": "^1.1.
|
|
1880
|
-
"@subwallet/extension-inject": "^1.1.
|
|
1877
|
+
"@subwallet/extension-base": "^1.1.57-0",
|
|
1878
|
+
"@subwallet/extension-chains": "^1.1.57-0",
|
|
1879
|
+
"@subwallet/extension-dapp": "^1.1.57-0",
|
|
1880
|
+
"@subwallet/extension-inject": "^1.1.57-0",
|
|
1881
1881
|
"@subwallet/keyring": "^0.1.5",
|
|
1882
1882
|
"@subwallet/ui-keyring": "^0.1.5",
|
|
1883
1883
|
"@walletconnect/sign-client": "^2.8.4",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.1.
|
|
10
|
+
version: '1.1.57-0'
|
|
11
11
|
};
|
|
@@ -93,6 +93,7 @@ export declare class ChainService {
|
|
|
93
93
|
autoEnableTokens(): Promise<void>;
|
|
94
94
|
handleLatestData(): void;
|
|
95
95
|
private initApis;
|
|
96
|
+
initSingleApi(slug: string): Promise<boolean>;
|
|
96
97
|
private initApiForChain;
|
|
97
98
|
private destroyApiForChain;
|
|
98
99
|
enableChain(chainSlug: string): Promise<boolean>;
|
|
@@ -609,6 +609,15 @@ export class ChainService {
|
|
|
609
609
|
}
|
|
610
610
|
}));
|
|
611
611
|
}
|
|
612
|
+
async initSingleApi(slug) {
|
|
613
|
+
const chainInfoMap = this.getChainInfoMap();
|
|
614
|
+
const chainStateMap = this.getChainStateMap();
|
|
615
|
+
if (!chainStateMap[slug].active) {
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
await this.initApiForChain(chainInfoMap[slug]);
|
|
619
|
+
return true;
|
|
620
|
+
}
|
|
612
621
|
async initApiForChain(chainInfo) {
|
|
613
622
|
const {
|
|
614
623
|
endpoint,
|
|
@@ -44,13 +44,16 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
44
44
|
await defaultCallback();
|
|
45
45
|
await substrateApi.isReady;
|
|
46
46
|
const unsub = await ((_substrateApi$api$que = substrateApi.api.query.staking) === null || _substrateApi$api$que === void 0 ? void 0 : _substrateApi$api$que.currentEra(async _currentEra => {
|
|
47
|
-
var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$que2, _substrateApi$api$que3, _substrateApi$api$que4, _substrateApi$api$que5, _substrateApi$api$que6;
|
|
47
|
+
var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$cal, _substrateApi$api$que2, _substrateApi$api$que3, _substrateApi$api$que4, _substrateApi$api$que5, _substrateApi$api$que6;
|
|
48
48
|
if (cancel) {
|
|
49
49
|
unsub();
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
+
let maxNominations = ((_substrateApi$api$con = substrateApi.api.consts.staking) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.maxNominations) === null || _substrateApi$api$con2 === void 0 ? void 0 : _substrateApi$api$con2.toString()) || '16';
|
|
53
|
+
const _maxNominationsByNominationQuota = await ((_substrateApi$api$cal = substrateApi.api.call.stakingApi) === null || _substrateApi$api$cal === void 0 ? void 0 : _substrateApi$api$cal.nominationsQuota(0)); // todo: review param. Currently return constant for all param.
|
|
54
|
+
const maxNominationsByNominationQuota = _maxNominationsByNominationQuota === null || _maxNominationsByNominationQuota === void 0 ? void 0 : _maxNominationsByNominationQuota.toString();
|
|
55
|
+
maxNominations = maxNominationsByNominationQuota !== null && maxNominationsByNominationQuota !== void 0 ? maxNominationsByNominationQuota : maxNominations;
|
|
52
56
|
const currentEra = _currentEra.toString();
|
|
53
|
-
const maxNominations = ((_substrateApi$api$con = substrateApi.api.consts.staking) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.maxNominations) === null || _substrateApi$api$con2 === void 0 ? void 0 : _substrateApi$api$con2.toString()) || '16'; // TODO
|
|
54
57
|
const maxUnlockingChunks = substrateApi.api.consts.staking.maxUnlockingChunks.toString();
|
|
55
58
|
const unlockingEras = substrateApi.api.consts.staking.bondingDuration.toString();
|
|
56
59
|
const maxSupportedEras = substrateApi.api.consts.staking.historyDepth.toString();
|
|
@@ -139,9 +142,20 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
139
142
|
const validatorList = nominations.targets;
|
|
140
143
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
141
144
|
let nominationStatus = EarningStatus.NOT_EARNING;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
let eraStakerOtherList = [];
|
|
146
|
+
let identity;
|
|
147
|
+
if (['kusama', 'polkadot', 'westend'].includes(this.chain)) {
|
|
148
|
+
// todo: review all relaychains later
|
|
149
|
+
const [[_identity], _eraStaker] = await Promise.all([parseIdentity(substrateApi, validatorAddress), substrateApi.api.query.staking.erasStakersPaged.entries(currentEra, validatorAddress)]);
|
|
150
|
+
identity = _identity;
|
|
151
|
+
eraStakerOtherList = _eraStaker.flatMap(paged => paged[1].toPrimitive().others);
|
|
152
|
+
} else {
|
|
153
|
+
const [[_identity], _eraStaker] = await Promise.all([parseIdentity(substrateApi, validatorAddress), substrateApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
154
|
+
identity = _identity;
|
|
155
|
+
const eraStaker = _eraStaker.toPrimitive();
|
|
156
|
+
eraStakerOtherList = eraStaker.others;
|
|
157
|
+
}
|
|
158
|
+
const sortedNominators = eraStakerOtherList.sort((a, b) => {
|
|
145
159
|
return new BigN(b.value).minus(a.value).toNumber();
|
|
146
160
|
});
|
|
147
161
|
const topNominators = sortedNominators.map(nominator => {
|
|
@@ -283,7 +297,14 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
283
297
|
const maxEraRewardPointsEras = MaxEraRewardPointsEras;
|
|
284
298
|
const endEraForPoints = parseInt(activeEra) - 1;
|
|
285
299
|
let startEraForPoints = endEraForPoints - maxEraRewardPointsEras + 1;
|
|
286
|
-
|
|
300
|
+
let _eraStakersPromise;
|
|
301
|
+
if (['kusama', 'polkadot', 'westend'].includes(this.chain)) {
|
|
302
|
+
// todo: review all relaychains later
|
|
303
|
+
_eraStakersPromise = chainApi.api.query.staking.erasStakersOverview.entries(parseInt(currentEra));
|
|
304
|
+
} else {
|
|
305
|
+
_eraStakersPromise = chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra));
|
|
306
|
+
}
|
|
307
|
+
const [_totalEraStake, _eraStakers, _minBond, _stakingRewards, _validators, ..._eraRewardPoints] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), _eraStakersPromise, chainApi.api.query.staking.minNominatorBond(), ((_chainApi$api$query$s = chainApi.api.query.stakingRewards) === null || _chainApi$api$query$s === void 0 ? void 0 : _chainApi$api$query$s.data) && chainApi.api.query.stakingRewards.data(), chainApi.api.query.staking.validators.entries(), chainApi.api.query.staking.erasRewardPoints.multi([...Array(maxEraRewardPointsEras).keys()].map(i => i + startEraForPoints))]);
|
|
287
308
|
const eraRewardMap = {};
|
|
288
309
|
for (const item of _eraRewardPoints[0]) {
|
|
289
310
|
eraRewardMap[startEraForPoints] = item.toHuman();
|
|
@@ -309,11 +330,11 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
309
330
|
const unlimitedNominatorRewarded = chainApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
310
331
|
const maxNominatorRewarded = (chainApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
311
332
|
const bnTotalEraStake = new BN(_totalEraStake.toString());
|
|
312
|
-
const eraStakers = _eraStakers;
|
|
313
333
|
const rawMinBond = _minBond.toHuman();
|
|
314
334
|
const minBond = rawMinBond.replaceAll(',', '');
|
|
315
335
|
const totalStakeMap = {};
|
|
316
336
|
const bnDecimals = new BN((10 ** decimals).toString());
|
|
337
|
+
const eraStakers = _eraStakers;
|
|
317
338
|
for (const item of eraStakers) {
|
|
318
339
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
319
340
|
const rawValidatorInfo = item[0].toHuman();
|
|
@@ -158,25 +158,19 @@ export default class NominationPoolHandler extends BasePoolHandler {
|
|
|
158
158
|
if (nominations) {
|
|
159
159
|
const validatorList = nominations.targets;
|
|
160
160
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
161
|
-
let
|
|
162
|
-
if (['kusama'].includes(this.chain)) {
|
|
163
|
-
// todo:
|
|
161
|
+
let eraStakerOtherList = [];
|
|
162
|
+
if (['kusama', 'polkadot', 'westend'].includes(this.chain)) {
|
|
163
|
+
// todo: review all relaychains later
|
|
164
164
|
const _eraStaker = await substrateApi.api.query.staking.erasStakersPaged.entries(currentEra, validatorAddress);
|
|
165
|
-
|
|
166
|
-
_eraStaker.forEach(paged => {
|
|
167
|
-
const pagedExposure = paged[1].toPrimitive();
|
|
168
|
-
eraStakerOtherList.push(...pagedExposure.others);
|
|
169
|
-
});
|
|
170
|
-
sortedNominators = eraStakerOtherList.sort((a, b) => {
|
|
171
|
-
return new BigN(b.value).minus(a.value).toNumber();
|
|
172
|
-
});
|
|
165
|
+
eraStakerOtherList = _eraStaker.flatMap(paged => paged[1].toPrimitive().others);
|
|
173
166
|
} else {
|
|
174
167
|
const _eraStaker = await substrateApi.api.query.staking.erasStakers(currentEra, validatorAddress);
|
|
175
168
|
const eraStaker = _eraStaker.toPrimitive();
|
|
176
|
-
|
|
177
|
-
return new BigN(b.value).minus(a.value).toNumber();
|
|
178
|
-
});
|
|
169
|
+
eraStakerOtherList = eraStaker.others;
|
|
179
170
|
}
|
|
171
|
+
const sortedNominators = eraStakerOtherList.sort((a, b) => {
|
|
172
|
+
return new BigN(b.value).minus(a.value).toNumber();
|
|
173
|
+
});
|
|
180
174
|
const topNominators = sortedNominators.map(nominator => {
|
|
181
175
|
return nominator.who;
|
|
182
176
|
}).slice(0, unlimitedNominatorRewarded ? undefined : maxNominatorRewardedPerValidator);
|
|
@@ -69,12 +69,12 @@ export async function parseIdentity(substrateApi, address, children) {
|
|
|
69
69
|
const _identity = await substrateApi.api.query.identity.identityOf(address);
|
|
70
70
|
const identityInfo = _identity.toHuman();
|
|
71
71
|
if (identityInfo) {
|
|
72
|
-
var _identityInfo$info, _identityInfo$info$di, _identityInfo$info2, _identityInfo$info2$w, _identityInfo$info3, _identityInfo$info3$r, _identityInfo$info4, _identityInfo$info4$t;
|
|
72
|
+
var _identityInfo$info, _identityInfo$info$di, _identityInfo$info2, _identityInfo$info2$w, _identityInfo$info3, _identityInfo$info3$r, _identityInfo$info4, _identityInfo$info4$t, _identityInfo$judgeme;
|
|
73
73
|
const displayName = (_identityInfo$info = identityInfo.info) === null || _identityInfo$info === void 0 ? void 0 : (_identityInfo$info$di = _identityInfo$info.display) === null || _identityInfo$info$di === void 0 ? void 0 : _identityInfo$info$di.Raw;
|
|
74
74
|
const web = (_identityInfo$info2 = identityInfo.info) === null || _identityInfo$info2 === void 0 ? void 0 : (_identityInfo$info2$w = _identityInfo$info2.web) === null || _identityInfo$info2$w === void 0 ? void 0 : _identityInfo$info2$w.Raw;
|
|
75
75
|
const riot = (_identityInfo$info3 = identityInfo.info) === null || _identityInfo$info3 === void 0 ? void 0 : (_identityInfo$info3$r = _identityInfo$info3.riot) === null || _identityInfo$info3$r === void 0 ? void 0 : _identityInfo$info3$r.Raw;
|
|
76
76
|
const twitter = (_identityInfo$info4 = identityInfo.info) === null || _identityInfo$info4 === void 0 ? void 0 : (_identityInfo$info4$t = _identityInfo$info4.twitter) === null || _identityInfo$info4$t === void 0 ? void 0 : _identityInfo$info4$t.Raw;
|
|
77
|
-
const isReasonable = identityInfo.judgements.length > 0;
|
|
77
|
+
const isReasonable = ((_identityInfo$judgeme = identityInfo.judgements) === null || _identityInfo$judgeme === void 0 ? void 0 : _identityInfo$judgeme.length) > 0;
|
|
78
78
|
if (displayName) {
|
|
79
79
|
identity = isHex(displayName) ? hexToString(displayName) : displayName;
|
|
80
80
|
} else {
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import axios from 'axios';
|
|
5
|
+
const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
6
|
+
const branchName = process.env.BRANCH_NAME || 'koni-dev';
|
|
7
|
+
const fetchTarget = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://static-cache.subwallet.app' : 'https://dev.sw-static-cache.pages.dev';
|
|
5
8
|
export async function fetchStaticCache(slug, defaultData, timeout = 9000) {
|
|
6
9
|
try {
|
|
7
|
-
const rs = await axios.get(
|
|
10
|
+
const rs = await axios.get(`${fetchTarget}/${slug}`, {
|
|
8
11
|
timeout
|
|
9
12
|
});
|
|
10
13
|
return rs.data;
|