@subwallet/extension-base 1.3.14-2 → 1.3.15-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/packageInfo.js +1 -1
- package/cjs/services/chain-online-service/index.js +17 -1
- package/cjs/services/chain-service/index.js +47 -48
- package/cjs/services/earning-service/handlers/native-staking/tao.js +20 -8
- package/package.json +5 -5
- package/packageInfo.js +1 -1
- package/services/chain-online-service/index.d.ts +1 -0
- package/services/chain-online-service/index.js +17 -1
- package/services/chain-service/index.js +46 -48
- package/services/earning-service/handlers/native-staking/tao.d.ts +8 -2
- package/services/earning-service/handlers/native-staking/tao.js +15 -7
package/cjs/packageInfo.js
CHANGED
|
@@ -59,6 +59,22 @@ class ChainOnlineService {
|
|
|
59
59
|
}
|
|
60
60
|
return true;
|
|
61
61
|
}
|
|
62
|
+
mergeChainList(oldChainInfoMap, latestChainInfo) {
|
|
63
|
+
const rs = structuredClone(oldChainInfoMap);
|
|
64
|
+
for (const [slug, _info] of Object.entries(latestChainInfo)) {
|
|
65
|
+
var _rs$slug;
|
|
66
|
+
const {
|
|
67
|
+
providers: _providers,
|
|
68
|
+
...info
|
|
69
|
+
} = _info;
|
|
70
|
+
const providers = Object.assign(((_rs$slug = rs[slug]) === null || _rs$slug === void 0 ? void 0 : _rs$slug.providers) || {}, _providers);
|
|
71
|
+
rs[slug] = {
|
|
72
|
+
...info,
|
|
73
|
+
providers
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return rs;
|
|
77
|
+
}
|
|
62
78
|
async handleLatestPatch(latestPatch) {
|
|
63
79
|
try {
|
|
64
80
|
var _await$this$settingSe;
|
|
@@ -84,7 +100,7 @@ class ChainOnlineService {
|
|
|
84
100
|
|
|
85
101
|
// 2. merge data map
|
|
86
102
|
if (latestChainInfo && Object.keys(latestChainInfo).length > 0) {
|
|
87
|
-
chainInfoMap =
|
|
103
|
+
chainInfoMap = this.mergeChainList(oldChainInfoMap, latestChainInfo);
|
|
88
104
|
const [currentChainStateKey, newChainKey] = [Object.keys(currentChainStateMap), Object.keys(chainInfoMap)];
|
|
89
105
|
addedChain = newChainKey.filter(chain => !currentChainStateKey.includes(chain));
|
|
90
106
|
addedChain.forEach(key => {
|
|
@@ -658,7 +658,7 @@ class ChainService {
|
|
|
658
658
|
/**
|
|
659
659
|
* Disable chain if not found provider
|
|
660
660
|
* */
|
|
661
|
-
if (!endpoint
|
|
661
|
+
if (!endpoint || !providerName) {
|
|
662
662
|
this.disableChain(chainInfo.slug);
|
|
663
663
|
return;
|
|
664
664
|
}
|
|
@@ -919,6 +919,34 @@ class ChainService {
|
|
|
919
919
|
});
|
|
920
920
|
} else {
|
|
921
921
|
const mergedChainInfoMap = defaultChainInfoMap;
|
|
922
|
+
|
|
923
|
+
// Reselect provider for chain
|
|
924
|
+
const updateCurrentProvider = function (providers, storedChainInfo, storeSlug, active) {
|
|
925
|
+
let forceFistProvider = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
926
|
+
const manualTurnOff = !!storedChainInfo.manualTurnOff;
|
|
927
|
+
// For case only custom providers in list, randomize function will infinite loop, so force select first provider
|
|
928
|
+
const {
|
|
929
|
+
providerKey
|
|
930
|
+
} = forceFistProvider ? {
|
|
931
|
+
providerKey: Object.keys(providers)[0]
|
|
932
|
+
} : (0, _utils.randomizeProvider)(providers);
|
|
933
|
+
let selectedProvider = providerKey;
|
|
934
|
+
const storedProviderKey = storedChainInfo.currentProvider;
|
|
935
|
+
const storedProviderValue = storedChainInfo.providers[storedProviderKey] || '';
|
|
936
|
+
if (storedProviderValue !== null && storedProviderValue !== void 0 && storedProviderValue.startsWith('light') || storedProviderKey !== null && storedProviderKey !== void 0 && storedProviderKey.startsWith(_types3._CUSTOM_PREFIX)) {
|
|
937
|
+
const savedProviderKey = Object.keys(providers).find(key => providers[key] === storedProviderValue);
|
|
938
|
+
if (savedProviderKey) {
|
|
939
|
+
selectedProvider = savedProviderKey;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
newStorageData.push({
|
|
943
|
+
...mergedChainInfoMap[storeSlug],
|
|
944
|
+
active,
|
|
945
|
+
currentProvider: selectedProvider,
|
|
946
|
+
manualTurnOff
|
|
947
|
+
});
|
|
948
|
+
return selectedProvider;
|
|
949
|
+
};
|
|
922
950
|
for (const [storedSlug, storedChainInfo] of Object.entries(storedChainSettingMap)) {
|
|
923
951
|
const chainInfo = defaultChainInfoMap[storedSlug];
|
|
924
952
|
const manualTurnOff = !!storedChainInfo.manualTurnOff;
|
|
@@ -938,18 +966,6 @@ class ChainService {
|
|
|
938
966
|
}
|
|
939
967
|
}
|
|
940
968
|
mergedChainInfoMap[storedSlug].providers = providers;
|
|
941
|
-
const {
|
|
942
|
-
providerKey
|
|
943
|
-
} = (0, _utils.randomizeProvider)(providers);
|
|
944
|
-
let selectedProvider = providerKey;
|
|
945
|
-
const storedProviderKey = storedChainInfo.currentProvider;
|
|
946
|
-
const storedProviderValue = storedChainInfo.providers[storedProviderKey] || '';
|
|
947
|
-
if (storedProviderValue !== null && storedProviderValue !== void 0 && storedProviderValue.startsWith('light') || storedProviderKey !== null && storedProviderKey !== void 0 && storedProviderKey.startsWith(_types3._CUSTOM_PREFIX)) {
|
|
948
|
-
const savedProviderKey = Object.keys(providers).find(key => providers[key] === storedProviderValue);
|
|
949
|
-
if (savedProviderKey) {
|
|
950
|
-
selectedProvider = savedProviderKey;
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
969
|
|
|
954
970
|
// Merge current provider
|
|
955
971
|
// let currentProvider = storedChainInfo.currentProvider;
|
|
@@ -957,6 +973,7 @@ class ChainService {
|
|
|
957
973
|
|
|
958
974
|
const hasProvider = Object.values(providers).length > 0;
|
|
959
975
|
const canActive = hasProvider && chainInfo.chainStatus === _types._ChainStatus.ACTIVE;
|
|
976
|
+
const selectedProvider = updateCurrentProvider(providers, storedChainInfo, storedSlug, canActive && storedChainInfo.active);
|
|
960
977
|
this.dataMap.chainStateMap[storedSlug] = {
|
|
961
978
|
currentProvider: selectedProvider,
|
|
962
979
|
slug: storedSlug,
|
|
@@ -964,12 +981,6 @@ class ChainService {
|
|
|
964
981
|
manualTurnOff
|
|
965
982
|
};
|
|
966
983
|
this.updateChainConnectionStatus(storedSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
967
|
-
newStorageData.push({
|
|
968
|
-
...mergedChainInfoMap[storedSlug],
|
|
969
|
-
active: canActive && storedChainInfo.active,
|
|
970
|
-
currentProvider: selectedProvider,
|
|
971
|
-
manualTurnOff
|
|
972
|
-
});
|
|
973
984
|
} else if ((0, _utils._isCustomChain)(storedSlug)) {
|
|
974
985
|
var _storedChainInfo$subs, _storedChainInfo$evmI;
|
|
975
986
|
// only custom chains are left
|
|
@@ -977,23 +988,19 @@ class ChainService {
|
|
|
977
988
|
const duplicatedDefaultSlug = this.checkExistedPredefinedChain(defaultChainInfoMap, (_storedChainInfo$subs = storedChainInfo.substrateInfo) === null || _storedChainInfo$subs === void 0 ? void 0 : _storedChainInfo$subs.genesisHash, (_storedChainInfo$evmI = storedChainInfo.evmInfo) === null || _storedChainInfo$evmI === void 0 ? void 0 : _storedChainInfo$evmI.evmChainId);
|
|
978
989
|
if (duplicatedDefaultSlug.length > 0) {
|
|
979
990
|
// merge custom chain with existed chain
|
|
980
|
-
|
|
991
|
+
const providers = {
|
|
981
992
|
...storedChainInfo.providers,
|
|
982
993
|
...mergedChainInfoMap[duplicatedDefaultSlug].providers
|
|
983
994
|
};
|
|
995
|
+
mergedChainInfoMap[duplicatedDefaultSlug].providers = providers;
|
|
996
|
+
const selectedProvider = updateCurrentProvider(providers, storedChainInfo, duplicatedDefaultSlug, storedChainInfo.active);
|
|
984
997
|
this.dataMap.chainStateMap[duplicatedDefaultSlug] = {
|
|
985
|
-
currentProvider:
|
|
998
|
+
currentProvider: selectedProvider,
|
|
986
999
|
slug: duplicatedDefaultSlug,
|
|
987
1000
|
active: storedChainInfo.active,
|
|
988
1001
|
manualTurnOff
|
|
989
1002
|
};
|
|
990
1003
|
this.updateChainConnectionStatus(duplicatedDefaultSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
991
|
-
newStorageData.push({
|
|
992
|
-
...mergedChainInfoMap[duplicatedDefaultSlug],
|
|
993
|
-
active: storedChainInfo.active,
|
|
994
|
-
currentProvider: storedChainInfo.currentProvider,
|
|
995
|
-
manualTurnOff
|
|
996
|
-
});
|
|
997
1004
|
deprecatedChainMap[storedSlug] = duplicatedDefaultSlug;
|
|
998
1005
|
deprecatedChains.push(storedSlug);
|
|
999
1006
|
} else {
|
|
@@ -1012,38 +1019,21 @@ class ChainService {
|
|
|
1012
1019
|
icon: storedChainInfo.icon,
|
|
1013
1020
|
extraInfo: storedChainInfo.extraInfo
|
|
1014
1021
|
};
|
|
1022
|
+
const providers = storedChainInfo.providers;
|
|
1023
|
+
// This case, providers are all custom providers, need force select first provider
|
|
1024
|
+
const selectedProvider = updateCurrentProvider(providers, storedChainInfo, storedSlug, storedChainInfo.active, true);
|
|
1015
1025
|
this.dataMap.chainStateMap[storedSlug] = {
|
|
1016
|
-
currentProvider:
|
|
1026
|
+
currentProvider: selectedProvider,
|
|
1017
1027
|
// TODO: review
|
|
1018
1028
|
slug: storedSlug,
|
|
1019
1029
|
active: storedChainInfo.active,
|
|
1020
1030
|
manualTurnOff
|
|
1021
1031
|
};
|
|
1022
1032
|
this.updateChainConnectionStatus(storedSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
1023
|
-
newStorageData.push({
|
|
1024
|
-
...mergedChainInfoMap[storedSlug],
|
|
1025
|
-
active: storedChainInfo.active,
|
|
1026
|
-
currentProvider: storedChainInfo.currentProvider,
|
|
1027
|
-
// TODO: review
|
|
1028
|
-
manualTurnOff
|
|
1029
|
-
});
|
|
1030
1033
|
}
|
|
1031
1034
|
} else {
|
|
1032
1035
|
var _storedChainInfo$bitc2;
|
|
1033
1036
|
// added chain from patch
|
|
1034
|
-
this.dataMap.chainStateMap[storedSlug] = {
|
|
1035
|
-
currentProvider: storedChainInfo.currentProvider,
|
|
1036
|
-
slug: storedSlug,
|
|
1037
|
-
active: storedChainInfo.active,
|
|
1038
|
-
manualTurnOff
|
|
1039
|
-
};
|
|
1040
|
-
this.updateChainConnectionStatus(storedSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
1041
|
-
newStorageData.push({
|
|
1042
|
-
...storedChainSettingMap[storedSlug],
|
|
1043
|
-
active: storedChainInfo.active,
|
|
1044
|
-
currentProvider: storedChainInfo.currentProvider,
|
|
1045
|
-
manualTurnOff
|
|
1046
|
-
});
|
|
1047
1037
|
mergedChainInfoMap[storedSlug] = {
|
|
1048
1038
|
slug: storedSlug,
|
|
1049
1039
|
name: storedChainInfo.name,
|
|
@@ -1057,6 +1047,15 @@ class ChainService {
|
|
|
1057
1047
|
icon: storedChainInfo.icon,
|
|
1058
1048
|
extraInfo: storedChainInfo.extraInfo
|
|
1059
1049
|
};
|
|
1050
|
+
const providers = storedChainInfo.providers;
|
|
1051
|
+
const selectedProvider = updateCurrentProvider(providers, storedChainInfo, storedSlug, storedChainInfo.active);
|
|
1052
|
+
this.dataMap.chainStateMap[storedSlug] = {
|
|
1053
|
+
currentProvider: selectedProvider,
|
|
1054
|
+
slug: storedSlug,
|
|
1055
|
+
active: storedChainInfo.active,
|
|
1056
|
+
manualTurnOff
|
|
1057
|
+
};
|
|
1058
|
+
this.updateChainConnectionStatus(storedSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
1060
1059
|
deprecatedChainMap[storedSlug] = storedSlug; // todo: set a better name
|
|
1061
1060
|
}
|
|
1062
1061
|
}
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.default = exports.bittensorApiKey = exports.BITTENSOR_API_KEY_6 = exports.BITTENSOR_API_KEY_5 = exports.BITTENSOR_API_KEY_4 = exports.BITTENSOR_API_KEY_3 = exports.BITTENSOR_API_KEY_2 = exports.BITTENSOR_API_KEY_1 = void 0;
|
|
7
|
+
exports.default = exports.bittensorApiKey = exports.BITTENSOR_API_KEY_9 = exports.BITTENSOR_API_KEY_8 = exports.BITTENSOR_API_KEY_7 = exports.BITTENSOR_API_KEY_6 = exports.BITTENSOR_API_KEY_5 = exports.BITTENSOR_API_KEY_4 = exports.BITTENSOR_API_KEY_3 = exports.BITTENSOR_API_KEY_2 = exports.BITTENSOR_API_KEY_10 = exports.BITTENSOR_API_KEY_1 = void 0;
|
|
8
8
|
exports.fetchDelegates = fetchDelegates;
|
|
9
9
|
exports.fetchTaoDelegateState = fetchTaoDelegateState;
|
|
10
10
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
@@ -32,6 +32,14 @@ const BITTENSOR_API_KEY_5 = process.env.BITTENSOR_API_KEY_5 || '';
|
|
|
32
32
|
exports.BITTENSOR_API_KEY_5 = BITTENSOR_API_KEY_5;
|
|
33
33
|
const BITTENSOR_API_KEY_6 = process.env.BITTENSOR_API_KEY_6 || '';
|
|
34
34
|
exports.BITTENSOR_API_KEY_6 = BITTENSOR_API_KEY_6;
|
|
35
|
+
const BITTENSOR_API_KEY_7 = process.env.BITTENSOR_API_KEY_7 || '';
|
|
36
|
+
exports.BITTENSOR_API_KEY_7 = BITTENSOR_API_KEY_7;
|
|
37
|
+
const BITTENSOR_API_KEY_8 = process.env.BITTENSOR_API_KEY_8 || '';
|
|
38
|
+
exports.BITTENSOR_API_KEY_8 = BITTENSOR_API_KEY_8;
|
|
39
|
+
const BITTENSOR_API_KEY_9 = process.env.BITTENSOR_API_KEY_9 || '';
|
|
40
|
+
exports.BITTENSOR_API_KEY_9 = BITTENSOR_API_KEY_9;
|
|
41
|
+
const BITTENSOR_API_KEY_10 = process.env.BITTENSOR_API_KEY_10 || '';
|
|
42
|
+
exports.BITTENSOR_API_KEY_10 = BITTENSOR_API_KEY_10;
|
|
35
43
|
function random() {
|
|
36
44
|
for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
37
45
|
keys[_key] = arguments[_key];
|
|
@@ -49,7 +57,7 @@ exports.bittensorApiKey = bittensorApiKey;
|
|
|
49
57
|
async function fetchDelegates() {
|
|
50
58
|
const apiKey = bittensorApiKey();
|
|
51
59
|
return new Promise(function (resolve) {
|
|
52
|
-
fetch('https://api
|
|
60
|
+
fetch('https://api.taostats.io/api/validator/latest/v1', {
|
|
53
61
|
method: 'GET',
|
|
54
62
|
headers: {
|
|
55
63
|
'Content-Type': 'application/json',
|
|
@@ -63,7 +71,7 @@ async function fetchDelegates() {
|
|
|
63
71
|
async function fetchTaoDelegateState(address) {
|
|
64
72
|
const apiKey = bittensorApiKey();
|
|
65
73
|
return new Promise(function (resolve) {
|
|
66
|
-
fetch(`https://api
|
|
74
|
+
fetch(`https://api.taostats.io/api/stake_balance/latest/v1?coldkey=${address}`, {
|
|
67
75
|
method: 'GET',
|
|
68
76
|
headers: {
|
|
69
77
|
'Content-Type': 'application/json',
|
|
@@ -174,7 +182,8 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
|
|
|
174
182
|
chain: chainInfo.slug,
|
|
175
183
|
validatorAddress: delegate.owner,
|
|
176
184
|
activeStake: activeStake,
|
|
177
|
-
validatorMinStake: minDelegatorStake
|
|
185
|
+
validatorMinStake: minDelegatorStake,
|
|
186
|
+
validatorIdentity: delegate.identity
|
|
178
187
|
});
|
|
179
188
|
}
|
|
180
189
|
}
|
|
@@ -205,7 +214,8 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
|
|
|
205
214
|
bnTotalBalance = bnTotalBalance.add(bnStakeAmount);
|
|
206
215
|
delegatorState.push({
|
|
207
216
|
owner: testnetAddress,
|
|
208
|
-
amount: bnStakeAmount.toString()
|
|
217
|
+
amount: bnStakeAmount.toString(),
|
|
218
|
+
identity: testnetAddress
|
|
209
219
|
});
|
|
210
220
|
rsCallback({
|
|
211
221
|
...defaultInfo,
|
|
@@ -237,10 +247,12 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
|
|
|
237
247
|
let bnTotalBalance = _util.BN_ZERO;
|
|
238
248
|
const delegateStateInfo = rawDelegateStateInfo.data;
|
|
239
249
|
for (const delegate of delegateStateInfo) {
|
|
240
|
-
|
|
250
|
+
const name = delegate.hotkey_name || delegate.hotkey.ss58;
|
|
251
|
+
bnTotalBalance = bnTotalBalance.add(new _util.BN(delegate.stake));
|
|
241
252
|
delegatorState.push({
|
|
242
|
-
owner: delegate.
|
|
243
|
-
amount: delegate.
|
|
253
|
+
owner: delegate.hotkey.ss58,
|
|
254
|
+
amount: delegate.stake,
|
|
255
|
+
identity: name
|
|
244
256
|
});
|
|
245
257
|
}
|
|
246
258
|
if (delegateStateInfo && delegateStateInfo.length > 0) {
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.3.
|
|
20
|
+
"version": "1.3.15-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -2514,10 +2514,10 @@
|
|
|
2514
2514
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2515
2515
|
"@substrate/connect": "^0.8.9",
|
|
2516
2516
|
"@subwallet/chain-list": "0.2.98",
|
|
2517
|
-
"@subwallet/extension-base": "^1.3.
|
|
2518
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2519
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2520
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2517
|
+
"@subwallet/extension-base": "^1.3.15-0",
|
|
2518
|
+
"@subwallet/extension-chains": "^1.3.15-0",
|
|
2519
|
+
"@subwallet/extension-dapp": "^1.3.15-0",
|
|
2520
|
+
"@subwallet/extension-inject": "^1.3.15-0",
|
|
2521
2521
|
"@subwallet/keyring": "^0.1.8-beta.0",
|
|
2522
2522
|
"@subwallet/ui-keyring": "^0.1.8-beta.0",
|
|
2523
2523
|
"@ton/core": "^0.56.3",
|
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.3.
|
|
10
|
+
version: '1.3.15-0'
|
|
11
11
|
};
|
|
@@ -15,6 +15,7 @@ export declare class ChainOnlineService {
|
|
|
15
15
|
constructor(chainService: ChainService, settingService: SettingService, eventService: EventService, dbService: DatabaseService);
|
|
16
16
|
validatePatchWithHash(latestPatch: PatchInfo): boolean;
|
|
17
17
|
validatePatchBeforeStore(candidateChainInfoMap: Record<string, _ChainInfo>, candidateAssetRegistry: Record<string, _ChainAsset>, latestPatch: PatchInfo): boolean;
|
|
18
|
+
mergeChainList(oldChainInfoMap: Record<string, _ChainInfo>, latestChainInfo: Record<string, _ChainInfo>): Record<string, _ChainInfo>;
|
|
18
19
|
handleLatestPatch(latestPatch: PatchInfo): Promise<void>;
|
|
19
20
|
private fetchLatestPatchData;
|
|
20
21
|
handleLatestPatchData(): void;
|
|
@@ -53,6 +53,22 @@ export class ChainOnlineService {
|
|
|
53
53
|
}
|
|
54
54
|
return true;
|
|
55
55
|
}
|
|
56
|
+
mergeChainList(oldChainInfoMap, latestChainInfo) {
|
|
57
|
+
const rs = structuredClone(oldChainInfoMap);
|
|
58
|
+
for (const [slug, _info] of Object.entries(latestChainInfo)) {
|
|
59
|
+
var _rs$slug;
|
|
60
|
+
const {
|
|
61
|
+
providers: _providers,
|
|
62
|
+
...info
|
|
63
|
+
} = _info;
|
|
64
|
+
const providers = Object.assign(((_rs$slug = rs[slug]) === null || _rs$slug === void 0 ? void 0 : _rs$slug.providers) || {}, _providers);
|
|
65
|
+
rs[slug] = {
|
|
66
|
+
...info,
|
|
67
|
+
providers
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return rs;
|
|
71
|
+
}
|
|
56
72
|
async handleLatestPatch(latestPatch) {
|
|
57
73
|
try {
|
|
58
74
|
var _await$this$settingSe;
|
|
@@ -78,7 +94,7 @@ export class ChainOnlineService {
|
|
|
78
94
|
|
|
79
95
|
// 2. merge data map
|
|
80
96
|
if (latestChainInfo && Object.keys(latestChainInfo).length > 0) {
|
|
81
|
-
chainInfoMap =
|
|
97
|
+
chainInfoMap = this.mergeChainList(oldChainInfoMap, latestChainInfo);
|
|
82
98
|
const [currentChainStateKey, newChainKey] = [Object.keys(currentChainStateMap), Object.keys(chainInfoMap)];
|
|
83
99
|
addedChain = newChainKey.filter(chain => !currentChainStateKey.includes(chain));
|
|
84
100
|
addedChain.forEach(key => {
|
|
@@ -632,7 +632,7 @@ export class ChainService {
|
|
|
632
632
|
/**
|
|
633
633
|
* Disable chain if not found provider
|
|
634
634
|
* */
|
|
635
|
-
if (!endpoint
|
|
635
|
+
if (!endpoint || !providerName) {
|
|
636
636
|
this.disableChain(chainInfo.slug);
|
|
637
637
|
return;
|
|
638
638
|
}
|
|
@@ -893,6 +893,33 @@ export class ChainService {
|
|
|
893
893
|
});
|
|
894
894
|
} else {
|
|
895
895
|
const mergedChainInfoMap = defaultChainInfoMap;
|
|
896
|
+
|
|
897
|
+
// Reselect provider for chain
|
|
898
|
+
const updateCurrentProvider = (providers, storedChainInfo, storeSlug, active, forceFistProvider = false) => {
|
|
899
|
+
const manualTurnOff = !!storedChainInfo.manualTurnOff;
|
|
900
|
+
// For case only custom providers in list, randomize function will infinite loop, so force select first provider
|
|
901
|
+
const {
|
|
902
|
+
providerKey
|
|
903
|
+
} = forceFistProvider ? {
|
|
904
|
+
providerKey: Object.keys(providers)[0]
|
|
905
|
+
} : randomizeProvider(providers);
|
|
906
|
+
let selectedProvider = providerKey;
|
|
907
|
+
const storedProviderKey = storedChainInfo.currentProvider;
|
|
908
|
+
const storedProviderValue = storedChainInfo.providers[storedProviderKey] || '';
|
|
909
|
+
if (storedProviderValue !== null && storedProviderValue !== void 0 && storedProviderValue.startsWith('light') || storedProviderKey !== null && storedProviderKey !== void 0 && storedProviderKey.startsWith(_CUSTOM_PREFIX)) {
|
|
910
|
+
const savedProviderKey = Object.keys(providers).find(key => providers[key] === storedProviderValue);
|
|
911
|
+
if (savedProviderKey) {
|
|
912
|
+
selectedProvider = savedProviderKey;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
newStorageData.push({
|
|
916
|
+
...mergedChainInfoMap[storeSlug],
|
|
917
|
+
active,
|
|
918
|
+
currentProvider: selectedProvider,
|
|
919
|
+
manualTurnOff
|
|
920
|
+
});
|
|
921
|
+
return selectedProvider;
|
|
922
|
+
};
|
|
896
923
|
for (const [storedSlug, storedChainInfo] of Object.entries(storedChainSettingMap)) {
|
|
897
924
|
const chainInfo = defaultChainInfoMap[storedSlug];
|
|
898
925
|
const manualTurnOff = !!storedChainInfo.manualTurnOff;
|
|
@@ -912,18 +939,6 @@ export class ChainService {
|
|
|
912
939
|
}
|
|
913
940
|
}
|
|
914
941
|
mergedChainInfoMap[storedSlug].providers = providers;
|
|
915
|
-
const {
|
|
916
|
-
providerKey
|
|
917
|
-
} = randomizeProvider(providers);
|
|
918
|
-
let selectedProvider = providerKey;
|
|
919
|
-
const storedProviderKey = storedChainInfo.currentProvider;
|
|
920
|
-
const storedProviderValue = storedChainInfo.providers[storedProviderKey] || '';
|
|
921
|
-
if (storedProviderValue !== null && storedProviderValue !== void 0 && storedProviderValue.startsWith('light') || storedProviderKey !== null && storedProviderKey !== void 0 && storedProviderKey.startsWith(_CUSTOM_PREFIX)) {
|
|
922
|
-
const savedProviderKey = Object.keys(providers).find(key => providers[key] === storedProviderValue);
|
|
923
|
-
if (savedProviderKey) {
|
|
924
|
-
selectedProvider = savedProviderKey;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
942
|
|
|
928
943
|
// Merge current provider
|
|
929
944
|
// let currentProvider = storedChainInfo.currentProvider;
|
|
@@ -931,6 +946,7 @@ export class ChainService {
|
|
|
931
946
|
|
|
932
947
|
const hasProvider = Object.values(providers).length > 0;
|
|
933
948
|
const canActive = hasProvider && chainInfo.chainStatus === _ChainStatus.ACTIVE;
|
|
949
|
+
const selectedProvider = updateCurrentProvider(providers, storedChainInfo, storedSlug, canActive && storedChainInfo.active);
|
|
934
950
|
this.dataMap.chainStateMap[storedSlug] = {
|
|
935
951
|
currentProvider: selectedProvider,
|
|
936
952
|
slug: storedSlug,
|
|
@@ -938,12 +954,6 @@ export class ChainService {
|
|
|
938
954
|
manualTurnOff
|
|
939
955
|
};
|
|
940
956
|
this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
941
|
-
newStorageData.push({
|
|
942
|
-
...mergedChainInfoMap[storedSlug],
|
|
943
|
-
active: canActive && storedChainInfo.active,
|
|
944
|
-
currentProvider: selectedProvider,
|
|
945
|
-
manualTurnOff
|
|
946
|
-
});
|
|
947
957
|
} else if (_isCustomChain(storedSlug)) {
|
|
948
958
|
var _storedChainInfo$subs, _storedChainInfo$evmI;
|
|
949
959
|
// only custom chains are left
|
|
@@ -951,23 +961,19 @@ export class ChainService {
|
|
|
951
961
|
const duplicatedDefaultSlug = this.checkExistedPredefinedChain(defaultChainInfoMap, (_storedChainInfo$subs = storedChainInfo.substrateInfo) === null || _storedChainInfo$subs === void 0 ? void 0 : _storedChainInfo$subs.genesisHash, (_storedChainInfo$evmI = storedChainInfo.evmInfo) === null || _storedChainInfo$evmI === void 0 ? void 0 : _storedChainInfo$evmI.evmChainId);
|
|
952
962
|
if (duplicatedDefaultSlug.length > 0) {
|
|
953
963
|
// merge custom chain with existed chain
|
|
954
|
-
|
|
964
|
+
const providers = {
|
|
955
965
|
...storedChainInfo.providers,
|
|
956
966
|
...mergedChainInfoMap[duplicatedDefaultSlug].providers
|
|
957
967
|
};
|
|
968
|
+
mergedChainInfoMap[duplicatedDefaultSlug].providers = providers;
|
|
969
|
+
const selectedProvider = updateCurrentProvider(providers, storedChainInfo, duplicatedDefaultSlug, storedChainInfo.active);
|
|
958
970
|
this.dataMap.chainStateMap[duplicatedDefaultSlug] = {
|
|
959
|
-
currentProvider:
|
|
971
|
+
currentProvider: selectedProvider,
|
|
960
972
|
slug: duplicatedDefaultSlug,
|
|
961
973
|
active: storedChainInfo.active,
|
|
962
974
|
manualTurnOff
|
|
963
975
|
};
|
|
964
976
|
this.updateChainConnectionStatus(duplicatedDefaultSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
965
|
-
newStorageData.push({
|
|
966
|
-
...mergedChainInfoMap[duplicatedDefaultSlug],
|
|
967
|
-
active: storedChainInfo.active,
|
|
968
|
-
currentProvider: storedChainInfo.currentProvider,
|
|
969
|
-
manualTurnOff
|
|
970
|
-
});
|
|
971
977
|
deprecatedChainMap[storedSlug] = duplicatedDefaultSlug;
|
|
972
978
|
deprecatedChains.push(storedSlug);
|
|
973
979
|
} else {
|
|
@@ -986,38 +992,21 @@ export class ChainService {
|
|
|
986
992
|
icon: storedChainInfo.icon,
|
|
987
993
|
extraInfo: storedChainInfo.extraInfo
|
|
988
994
|
};
|
|
995
|
+
const providers = storedChainInfo.providers;
|
|
996
|
+
// This case, providers are all custom providers, need force select first provider
|
|
997
|
+
const selectedProvider = updateCurrentProvider(providers, storedChainInfo, storedSlug, storedChainInfo.active, true);
|
|
989
998
|
this.dataMap.chainStateMap[storedSlug] = {
|
|
990
|
-
currentProvider:
|
|
999
|
+
currentProvider: selectedProvider,
|
|
991
1000
|
// TODO: review
|
|
992
1001
|
slug: storedSlug,
|
|
993
1002
|
active: storedChainInfo.active,
|
|
994
1003
|
manualTurnOff
|
|
995
1004
|
};
|
|
996
1005
|
this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
997
|
-
newStorageData.push({
|
|
998
|
-
...mergedChainInfoMap[storedSlug],
|
|
999
|
-
active: storedChainInfo.active,
|
|
1000
|
-
currentProvider: storedChainInfo.currentProvider,
|
|
1001
|
-
// TODO: review
|
|
1002
|
-
manualTurnOff
|
|
1003
|
-
});
|
|
1004
1006
|
}
|
|
1005
1007
|
} else {
|
|
1006
1008
|
var _storedChainInfo$bitc2;
|
|
1007
1009
|
// added chain from patch
|
|
1008
|
-
this.dataMap.chainStateMap[storedSlug] = {
|
|
1009
|
-
currentProvider: storedChainInfo.currentProvider,
|
|
1010
|
-
slug: storedSlug,
|
|
1011
|
-
active: storedChainInfo.active,
|
|
1012
|
-
manualTurnOff
|
|
1013
|
-
};
|
|
1014
|
-
this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
1015
|
-
newStorageData.push({
|
|
1016
|
-
...storedChainSettingMap[storedSlug],
|
|
1017
|
-
active: storedChainInfo.active,
|
|
1018
|
-
currentProvider: storedChainInfo.currentProvider,
|
|
1019
|
-
manualTurnOff
|
|
1020
|
-
});
|
|
1021
1010
|
mergedChainInfoMap[storedSlug] = {
|
|
1022
1011
|
slug: storedSlug,
|
|
1023
1012
|
name: storedChainInfo.name,
|
|
@@ -1031,6 +1020,15 @@ export class ChainService {
|
|
|
1031
1020
|
icon: storedChainInfo.icon,
|
|
1032
1021
|
extraInfo: storedChainInfo.extraInfo
|
|
1033
1022
|
};
|
|
1023
|
+
const providers = storedChainInfo.providers;
|
|
1024
|
+
const selectedProvider = updateCurrentProvider(providers, storedChainInfo, storedSlug, storedChainInfo.active);
|
|
1025
|
+
this.dataMap.chainStateMap[storedSlug] = {
|
|
1026
|
+
currentProvider: selectedProvider,
|
|
1027
|
+
slug: storedSlug,
|
|
1028
|
+
active: storedChainInfo.active,
|
|
1029
|
+
manualTurnOff
|
|
1030
|
+
};
|
|
1031
|
+
this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
1034
1032
|
deprecatedChainMap[storedSlug] = storedSlug; // todo: set a better name
|
|
1035
1033
|
}
|
|
1036
1034
|
}
|
|
@@ -5,13 +5,15 @@ import { BaseYieldPositionInfo, StakeCancelWithdrawalParams, SubmitJoinNativeSta
|
|
|
5
5
|
interface TaoStakingStakeOption {
|
|
6
6
|
owner: string;
|
|
7
7
|
amount: string;
|
|
8
|
+
identity: string;
|
|
8
9
|
}
|
|
9
10
|
export interface RawDelegateState {
|
|
10
11
|
data: Array<{
|
|
11
|
-
|
|
12
|
+
hotkey_name: string;
|
|
13
|
+
hotkey: {
|
|
12
14
|
ss58: string;
|
|
13
15
|
};
|
|
14
|
-
|
|
16
|
+
stake: string;
|
|
15
17
|
}>;
|
|
16
18
|
}
|
|
17
19
|
interface ValidatorResponse {
|
|
@@ -34,6 +36,10 @@ export declare const BITTENSOR_API_KEY_3: string;
|
|
|
34
36
|
export declare const BITTENSOR_API_KEY_4: string;
|
|
35
37
|
export declare const BITTENSOR_API_KEY_5: string;
|
|
36
38
|
export declare const BITTENSOR_API_KEY_6: string;
|
|
39
|
+
export declare const BITTENSOR_API_KEY_7: string;
|
|
40
|
+
export declare const BITTENSOR_API_KEY_8: string;
|
|
41
|
+
export declare const BITTENSOR_API_KEY_9: string;
|
|
42
|
+
export declare const BITTENSOR_API_KEY_10: string;
|
|
37
43
|
export declare const bittensorApiKey: () => string;
|
|
38
44
|
export declare function fetchDelegates(): Promise<ValidatorResponse>;
|
|
39
45
|
export declare function fetchTaoDelegateState(address: string): Promise<RawDelegateState>;
|
|
@@ -17,6 +17,10 @@ export const BITTENSOR_API_KEY_3 = process.env.BITTENSOR_API_KEY_3 || '';
|
|
|
17
17
|
export const BITTENSOR_API_KEY_4 = process.env.BITTENSOR_API_KEY_4 || '';
|
|
18
18
|
export const BITTENSOR_API_KEY_5 = process.env.BITTENSOR_API_KEY_5 || '';
|
|
19
19
|
export const BITTENSOR_API_KEY_6 = process.env.BITTENSOR_API_KEY_6 || '';
|
|
20
|
+
export const BITTENSOR_API_KEY_7 = process.env.BITTENSOR_API_KEY_7 || '';
|
|
21
|
+
export const BITTENSOR_API_KEY_8 = process.env.BITTENSOR_API_KEY_8 || '';
|
|
22
|
+
export const BITTENSOR_API_KEY_9 = process.env.BITTENSOR_API_KEY_9 || '';
|
|
23
|
+
export const BITTENSOR_API_KEY_10 = process.env.BITTENSOR_API_KEY_10 || '';
|
|
20
24
|
function random(...keys) {
|
|
21
25
|
const validKeys = keys.filter(key => key);
|
|
22
26
|
const randomIndex = Math.floor(Math.random() * validKeys.length);
|
|
@@ -31,7 +35,7 @@ export const bittensorApiKey = () => {
|
|
|
31
35
|
export async function fetchDelegates() {
|
|
32
36
|
const apiKey = bittensorApiKey();
|
|
33
37
|
return new Promise(function (resolve) {
|
|
34
|
-
fetch('https://api
|
|
38
|
+
fetch('https://api.taostats.io/api/validator/latest/v1', {
|
|
35
39
|
method: 'GET',
|
|
36
40
|
headers: {
|
|
37
41
|
'Content-Type': 'application/json',
|
|
@@ -45,7 +49,7 @@ export async function fetchDelegates() {
|
|
|
45
49
|
export async function fetchTaoDelegateState(address) {
|
|
46
50
|
const apiKey = bittensorApiKey();
|
|
47
51
|
return new Promise(function (resolve) {
|
|
48
|
-
fetch(`https://api
|
|
52
|
+
fetch(`https://api.taostats.io/api/stake_balance/latest/v1?coldkey=${address}`, {
|
|
49
53
|
method: 'GET',
|
|
50
54
|
headers: {
|
|
51
55
|
'Content-Type': 'application/json',
|
|
@@ -156,7 +160,8 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
156
160
|
chain: chainInfo.slug,
|
|
157
161
|
validatorAddress: delegate.owner,
|
|
158
162
|
activeStake: activeStake,
|
|
159
|
-
validatorMinStake: minDelegatorStake
|
|
163
|
+
validatorMinStake: minDelegatorStake,
|
|
164
|
+
validatorIdentity: delegate.identity
|
|
160
165
|
});
|
|
161
166
|
}
|
|
162
167
|
}
|
|
@@ -187,7 +192,8 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
187
192
|
bnTotalBalance = bnTotalBalance.add(bnStakeAmount);
|
|
188
193
|
delegatorState.push({
|
|
189
194
|
owner: testnetAddress,
|
|
190
|
-
amount: bnStakeAmount.toString()
|
|
195
|
+
amount: bnStakeAmount.toString(),
|
|
196
|
+
identity: testnetAddress
|
|
191
197
|
});
|
|
192
198
|
rsCallback({
|
|
193
199
|
...defaultInfo,
|
|
@@ -219,10 +225,12 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
219
225
|
let bnTotalBalance = BN_ZERO;
|
|
220
226
|
const delegateStateInfo = rawDelegateStateInfo.data;
|
|
221
227
|
for (const delegate of delegateStateInfo) {
|
|
222
|
-
|
|
228
|
+
const name = delegate.hotkey_name || delegate.hotkey.ss58;
|
|
229
|
+
bnTotalBalance = bnTotalBalance.add(new BN(delegate.stake));
|
|
223
230
|
delegatorState.push({
|
|
224
|
-
owner: delegate.
|
|
225
|
-
amount: delegate.
|
|
231
|
+
owner: delegate.hotkey.ss58,
|
|
232
|
+
amount: delegate.stake,
|
|
233
|
+
identity: name
|
|
226
234
|
});
|
|
227
235
|
}
|
|
228
236
|
if (delegateStateInfo && delegateStateInfo.length > 0) {
|