@subwallet/extension-base 1.1.38-1 → 1.1.40-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/background/KoniTypes.d.ts +1 -0
- package/background/types.d.ts +1 -0
- package/cjs/koni/api/nft/unique_network_nft/index.js +4 -0
- package/cjs/koni/background/handlers/Extension.js +48 -12
- package/cjs/koni/background/handlers/State.js +6 -5
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/balance.js +1 -1
- package/cjs/services/chain-service/health-check/constants/index.js +36 -0
- package/cjs/services/chain-service/health-check/utils/asset-info.js +282 -0
- package/cjs/services/chain-service/health-check/utils/chain-info.js +36 -0
- package/cjs/services/chain-service/health-check/utils/index.js +38 -0
- package/cjs/services/chain-service/health-check/utils/provider.js +186 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +42 -26
- package/cjs/services/earning-service/service.js +9 -2
- package/cjs/services/transaction-service/index.js +6 -4
- package/cjs/utils/eth/mergeTransactionAndSignature.js +8 -3
- package/cjs/utils/index.js +6 -5
- package/cjs/utils/staticData/index.js +5 -5
- package/koni/api/nft/unique_network_nft/index.d.ts +1 -0
- package/koni/api/nft/unique_network_nft/index.js +5 -1
- package/koni/api/staking/bonding/utils.d.ts +0 -1
- package/koni/background/handlers/Extension.js +48 -12
- package/koni/background/handlers/State.js +2 -1
- package/package.json +41 -16
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/balance.js +1 -1
- package/services/chain-service/health-check/constants/index.d.ts +4 -0
- package/services/chain-service/health-check/constants/index.js +26 -0
- package/services/chain-service/health-check/utils/asset-info.d.ts +14 -0
- package/services/chain-service/health-check/utils/asset-info.js +269 -0
- package/services/chain-service/health-check/utils/chain-info.d.ts +8 -0
- package/services/chain-service/health-check/utils/chain-info.js +28 -0
- package/services/chain-service/health-check/utils/index.d.ts +3 -0
- package/services/chain-service/health-check/utils/index.js +6 -0
- package/services/chain-service/health-check/utils/provider.d.ts +25 -0
- package/services/chain-service/health-check/utils/provider.js +172 -0
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +0 -1
- package/services/earning-service/handlers/native-staking/relay-chain.js +42 -26
- package/services/earning-service/handlers/special.d.ts +0 -1
- package/services/earning-service/service.js +10 -3
- package/services/transaction-service/index.js +6 -4
- package/types/balance.d.ts +0 -1
- package/types/yield/info/pallet.d.ts +4 -1
- package/utils/eth/mergeTransactionAndSignature.js +8 -3
- package/utils/index.d.ts +1 -2
- package/utils/index.js +6 -5
- package/utils/staticData/buyServiceInfos.json +0 -1
- package/utils/staticData/buyTokenConfigs.json +0 -15
- package/utils/staticData/chains.json +192 -89
- package/utils/staticData/crowdloanFunds.json +433 -58
- package/utils/staticData/index.d.ts +1 -2
- package/utils/staticData/index.js +4 -3
- package/utils/staticData/marketingCampaigns.json +1 -298
- package/utils/staticData/termAndCondition.json +1 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.timeoutMessage = exports.substrateHandleConnectChain = exports.handleSubstrateProvider = exports.handleEvmProvider = exports.failedMessage = exports.evmHandleConnectChain = void 0;
|
|
7
|
+
var _EvmApi2 = require("@subwallet/extension-base/services/chain-service/handler/EvmApi");
|
|
8
|
+
var _api2 = require("@polkadot/api");
|
|
9
|
+
var _util = require("@polkadot/util");
|
|
10
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
11
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
13
|
+
const failedMessage = 'Connect failed';
|
|
14
|
+
exports.failedMessage = failedMessage;
|
|
15
|
+
const timeoutMessage = 'Connect timeout';
|
|
16
|
+
exports.timeoutMessage = timeoutMessage;
|
|
17
|
+
const substrateHandleConnectChain = async (chain, key, provider, hash) => {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises,no-async-promise-executor
|
|
19
|
+
return new Promise(async resolve => {
|
|
20
|
+
console.log('start', chain, key, provider);
|
|
21
|
+
const _api = new _api2.ApiPromise({
|
|
22
|
+
provider: new _api2.WsProvider(provider)
|
|
23
|
+
});
|
|
24
|
+
let logFail = true;
|
|
25
|
+
const handlerOnFail = e => {
|
|
26
|
+
if (logFail) {
|
|
27
|
+
console.log('error', chain, key);
|
|
28
|
+
resolve([_api, (e === null || e === void 0 ? void 0 : e.message) || failedMessage]);
|
|
29
|
+
}
|
|
30
|
+
logFail = false;
|
|
31
|
+
};
|
|
32
|
+
const timeout = setTimeout(() => {
|
|
33
|
+
console.log('timeout', chain, key);
|
|
34
|
+
resolve([_api, timeoutMessage]);
|
|
35
|
+
logFail = false;
|
|
36
|
+
_api.disconnect().catch(console.error);
|
|
37
|
+
_api.off('disconnected', handlerOnFail);
|
|
38
|
+
_api.off('error', handlerOnFail);
|
|
39
|
+
}, 30 * 1000);
|
|
40
|
+
_api.on('disconnected', handlerOnFail);
|
|
41
|
+
_api.on('error', handlerOnFail);
|
|
42
|
+
const temp = await _api.isReady;
|
|
43
|
+
logFail = false;
|
|
44
|
+
const tempHash = temp.genesisHash.toHex();
|
|
45
|
+
if (hash && hash !== tempHash) {
|
|
46
|
+
resolve([_api, `Wrong genesisHash: current - ${hash}, onChain - ${tempHash}`]);
|
|
47
|
+
}
|
|
48
|
+
await _api.query.system.number();
|
|
49
|
+
_api.off('disconnected', handlerOnFail);
|
|
50
|
+
_api.off('error', handlerOnFail);
|
|
51
|
+
clearTimeout(timeout);
|
|
52
|
+
resolve([_api, '']);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.substrateHandleConnectChain = substrateHandleConnectChain;
|
|
56
|
+
const evmHandleConnectChain = async (chain, key, provider, chainId) => {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises,no-async-promise-executor
|
|
58
|
+
return new Promise(async resolve => {
|
|
59
|
+
console.log('start', chain, key, provider);
|
|
60
|
+
let api = null;
|
|
61
|
+
const _api = new _EvmApi2.EvmApi(chain, provider, {
|
|
62
|
+
providerName: key
|
|
63
|
+
});
|
|
64
|
+
let logFail = true;
|
|
65
|
+
const handlerOnFail = e => {
|
|
66
|
+
if (logFail) {
|
|
67
|
+
console.log('error', chain, key);
|
|
68
|
+
resolve([api, (e === null || e === void 0 ? void 0 : e.message) || failedMessage]);
|
|
69
|
+
}
|
|
70
|
+
logFail = false;
|
|
71
|
+
};
|
|
72
|
+
const timeout = setTimeout(() => {
|
|
73
|
+
console.log('timeout', chain, key);
|
|
74
|
+
resolve([api, timeoutMessage]);
|
|
75
|
+
logFail = false;
|
|
76
|
+
_api.destroy().catch(console.error);
|
|
77
|
+
}, 60 * 1000);
|
|
78
|
+
try {
|
|
79
|
+
api = await _api.isReady;
|
|
80
|
+
} catch (e) {
|
|
81
|
+
handlerOnFail(e);
|
|
82
|
+
}
|
|
83
|
+
logFail = false;
|
|
84
|
+
clearTimeout(timeout);
|
|
85
|
+
const tempId = await _api.api.eth.getChainId();
|
|
86
|
+
if (tempId !== chainId) {
|
|
87
|
+
resolve([api, `Wrong chain id: current - ${chainId}, onChain - ${tempId}`]);
|
|
88
|
+
}
|
|
89
|
+
resolve([api, '']);
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
exports.evmHandleConnectChain = evmHandleConnectChain;
|
|
93
|
+
const handleSubstrateProvider = _ref => {
|
|
94
|
+
let {
|
|
95
|
+
awaitDisconnect,
|
|
96
|
+
chain,
|
|
97
|
+
genHash,
|
|
98
|
+
key,
|
|
99
|
+
onError,
|
|
100
|
+
onSuccess,
|
|
101
|
+
onTimeout,
|
|
102
|
+
provider
|
|
103
|
+
} = _ref;
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises,no-async-promise-executor
|
|
105
|
+
return new Promise(async resolve => {
|
|
106
|
+
try {
|
|
107
|
+
const timeHandler = () => {
|
|
108
|
+
onTimeout();
|
|
109
|
+
resolve();
|
|
110
|
+
};
|
|
111
|
+
const timeout = setTimeout(() => {
|
|
112
|
+
timeHandler();
|
|
113
|
+
}, 2 * 60 * 1000);
|
|
114
|
+
const [api, message] = await substrateHandleConnectChain(chain, key, provider, genHash);
|
|
115
|
+
const disconnectApi = async api => {
|
|
116
|
+
if (awaitDisconnect) {
|
|
117
|
+
await (api === null || api === void 0 ? void 0 : api.disconnect());
|
|
118
|
+
} else {
|
|
119
|
+
api === null || api === void 0 ? void 0 : api.disconnect().finally(_util.noop);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
clearTimeout(timeout);
|
|
123
|
+
if (message) {
|
|
124
|
+
await onError(message);
|
|
125
|
+
await disconnectApi(api);
|
|
126
|
+
resolve();
|
|
127
|
+
}
|
|
128
|
+
await onSuccess(api);
|
|
129
|
+
await disconnectApi(api);
|
|
130
|
+
resolve();
|
|
131
|
+
} catch (e) {
|
|
132
|
+
await onError(e.message);
|
|
133
|
+
resolve();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
exports.handleSubstrateProvider = handleSubstrateProvider;
|
|
138
|
+
const handleEvmProvider = _ref2 => {
|
|
139
|
+
let {
|
|
140
|
+
awaitDisconnect,
|
|
141
|
+
chain,
|
|
142
|
+
chainId,
|
|
143
|
+
key,
|
|
144
|
+
onError,
|
|
145
|
+
onSuccess,
|
|
146
|
+
onTimeout,
|
|
147
|
+
provider
|
|
148
|
+
} = _ref2;
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises,no-async-promise-executor
|
|
150
|
+
return new Promise(async resolve => {
|
|
151
|
+
try {
|
|
152
|
+
const timeHandler = () => {
|
|
153
|
+
onTimeout();
|
|
154
|
+
resolve();
|
|
155
|
+
};
|
|
156
|
+
const timeout = setTimeout(() => {
|
|
157
|
+
timeHandler();
|
|
158
|
+
}, 2 * 60 * 1000);
|
|
159
|
+
const [_api, message] = await evmHandleConnectChain(chain, key, provider, chainId);
|
|
160
|
+
const disconnectApi = async _api => {
|
|
161
|
+
if (awaitDisconnect) {
|
|
162
|
+
await (_api === null || _api === void 0 ? void 0 : _api.destroy());
|
|
163
|
+
} else {
|
|
164
|
+
_api === null || _api === void 0 ? void 0 : _api.destroy().finally(_util.noop);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
console.log('connected', chain, key, provider);
|
|
168
|
+
clearTimeout(timeout);
|
|
169
|
+
if (message) {
|
|
170
|
+
await onError(message);
|
|
171
|
+
await disconnectApi(_api);
|
|
172
|
+
resolve();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
176
|
+
const api = _api;
|
|
177
|
+
await onSuccess(api);
|
|
178
|
+
await disconnectApi(_api);
|
|
179
|
+
resolve();
|
|
180
|
+
} catch (e) {
|
|
181
|
+
await onError(e.message);
|
|
182
|
+
resolve();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
exports.handleEvmProvider = handleEvmProvider;
|
|
@@ -287,7 +287,21 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
287
287
|
const currentEra = _era.toString();
|
|
288
288
|
const allValidators = [];
|
|
289
289
|
const validatorInfoList = [];
|
|
290
|
-
const [_totalEraStake, _eraStakers, _minBond, _stakingRewards] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra)), 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()]);
|
|
290
|
+
const [_totalEraStake, _eraStakers, _minBond, _stakingRewards, _validators] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra)), 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()]);
|
|
291
|
+
|
|
292
|
+
// filter blocked validators
|
|
293
|
+
const validators = _validators;
|
|
294
|
+
const blockValidatorList = [];
|
|
295
|
+
for (const validator of validators) {
|
|
296
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
297
|
+
const validatorAddress = validator[0].toHuman()[0];
|
|
298
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
299
|
+
const validatorPrefs = validator[1].toHuman();
|
|
300
|
+
const isBlocked = validatorPrefs.blocked;
|
|
301
|
+
if (isBlocked) {
|
|
302
|
+
blockValidatorList.push(validatorAddress);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
291
305
|
const stakingRewards = _stakingRewards === null || _stakingRewards === void 0 ? void 0 : _stakingRewards.toPrimitive();
|
|
292
306
|
const unlimitedNominatorRewarded = chainApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
293
307
|
const maxNominatorRewarded = (chainApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
@@ -303,32 +317,34 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
303
317
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
304
318
|
const rawValidatorStat = item[1].toHuman();
|
|
305
319
|
const validatorAddress = rawValidatorInfo[1];
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
320
|
+
if (!blockValidatorList.includes(validatorAddress)) {
|
|
321
|
+
const rawTotalStake = rawValidatorStat.total;
|
|
322
|
+
const rawOwnStake = rawValidatorStat.own;
|
|
323
|
+
const bnTotalStake = new _util.BN(rawTotalStake.replaceAll(',', ''));
|
|
324
|
+
const bnOwnStake = new _util.BN(rawOwnStake.replaceAll(',', ''));
|
|
325
|
+
const otherStake = bnTotalStake.sub(bnOwnStake);
|
|
326
|
+
totalStakeMap[validatorAddress] = bnTotalStake;
|
|
327
|
+
let nominatorCount = 0;
|
|
328
|
+
if ('others' in rawValidatorStat) {
|
|
329
|
+
const others = rawValidatorStat.others;
|
|
330
|
+
nominatorCount = others.length;
|
|
331
|
+
}
|
|
332
|
+
allValidators.push(validatorAddress);
|
|
333
|
+
validatorInfoList.push({
|
|
334
|
+
address: validatorAddress,
|
|
335
|
+
totalStake: bnTotalStake.toString(),
|
|
336
|
+
ownStake: bnOwnStake.toString(),
|
|
337
|
+
otherStake: otherStake.toString(),
|
|
338
|
+
nominatorCount,
|
|
339
|
+
// to be added later
|
|
340
|
+
commission: 0,
|
|
341
|
+
expectedReturn: 0,
|
|
342
|
+
blocked: false,
|
|
343
|
+
isVerified: false,
|
|
344
|
+
minBond,
|
|
345
|
+
isCrowded: unlimitedNominatorRewarded ? false : nominatorCount > parseInt(maxNominatorRewarded)
|
|
346
|
+
});
|
|
316
347
|
}
|
|
317
|
-
allValidators.push(validatorAddress);
|
|
318
|
-
validatorInfoList.push({
|
|
319
|
-
address: validatorAddress,
|
|
320
|
-
totalStake: bnTotalStake.toString(),
|
|
321
|
-
ownStake: bnOwnStake.toString(),
|
|
322
|
-
otherStake: otherStake.toString(),
|
|
323
|
-
nominatorCount,
|
|
324
|
-
// to be added later
|
|
325
|
-
commission: 0,
|
|
326
|
-
expectedReturn: 0,
|
|
327
|
-
blocked: false,
|
|
328
|
-
isVerified: false,
|
|
329
|
-
minBond,
|
|
330
|
-
isCrowded: unlimitedNominatorRewarded ? false : nominatorCount > parseInt(maxNominatorRewarded)
|
|
331
|
-
});
|
|
332
348
|
}
|
|
333
349
|
const extraInfoMap = {};
|
|
334
350
|
await Promise.all(allValidators.map(async address => {
|
|
@@ -134,13 +134,20 @@ class EarningService {
|
|
|
134
134
|
this.eventService.onLazy((events, eventTypes) => {
|
|
135
135
|
(async () => {
|
|
136
136
|
const removedAddresses = [];
|
|
137
|
+
const removeChains = [];
|
|
137
138
|
events.forEach(event => {
|
|
138
139
|
if (event.type === 'account.remove') {
|
|
139
140
|
removedAddresses.push(event.data[0]);
|
|
140
141
|
}
|
|
142
|
+
if (event.type === 'chain.updateState') {
|
|
143
|
+
const chainState = this.state.getChainStateByKey(event.data[0]);
|
|
144
|
+
if (chainState && !(0, _utils._isChainEnabled)(chainState)) {
|
|
145
|
+
removeChains.push(event.data[0]);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
141
148
|
});
|
|
142
|
-
if (
|
|
143
|
-
await this.removeYieldPositions(
|
|
149
|
+
if (removeChains.length || removedAddresses.length) {
|
|
150
|
+
await this.removeYieldPositions(removeChains, removedAddresses);
|
|
144
151
|
}
|
|
145
152
|
|
|
146
153
|
// Account changed or chain changed (active or inactive)
|
|
@@ -346,13 +346,14 @@ class TransactionService {
|
|
|
346
346
|
transactionToHistories(id, startBlock, nonce, eventLogs) {
|
|
347
347
|
const transaction = this.getTransaction(id);
|
|
348
348
|
const extrinsicType = transaction.extrinsicType;
|
|
349
|
+
const chainInfo = this.state.chainService.getChainInfoByKey(transaction.chain);
|
|
349
350
|
const formattedTransactionAddress = (0, _utils3.reformatAddress)(transaction.address);
|
|
350
351
|
const historyItem = {
|
|
351
352
|
origin: 'app',
|
|
352
353
|
chain: transaction.chain,
|
|
353
354
|
direction: _KoniTypes.TransactionDirection.SEND,
|
|
354
355
|
type: transaction.extrinsicType,
|
|
355
|
-
from:
|
|
356
|
+
from: transaction.address,
|
|
356
357
|
to: '',
|
|
357
358
|
chainType: transaction.chainType,
|
|
358
359
|
address: formattedTransactionAddress,
|
|
@@ -368,7 +369,6 @@ class TransactionService {
|
|
|
368
369
|
nonce: nonce !== null && nonce !== void 0 ? nonce : 0,
|
|
369
370
|
startBlock: startBlock || 0
|
|
370
371
|
};
|
|
371
|
-
const chainInfo = this.state.chainService.getChainInfoByKey(transaction.chain);
|
|
372
372
|
const nativeAsset = (0, _utils._getChainNativeTokenBasicInfo)(chainInfo);
|
|
373
373
|
const baseNativeAmount = {
|
|
374
374
|
value: '0',
|
|
@@ -874,7 +874,8 @@ class TransactionService {
|
|
|
874
874
|
to: transaction.to !== undefined ? transaction.to : '',
|
|
875
875
|
value: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.value).toString(16)),
|
|
876
876
|
data: transaction.data,
|
|
877
|
-
chainId: (0, _utils._getEvmChainId)(chainInfo)
|
|
877
|
+
chainId: (0, _utils._getEvmChainId)(chainInfo),
|
|
878
|
+
type: 2
|
|
878
879
|
};
|
|
879
880
|
} else {
|
|
880
881
|
var _transaction$nonce2;
|
|
@@ -885,7 +886,8 @@ class TransactionService {
|
|
|
885
886
|
to: transaction.to !== undefined ? transaction.to : '',
|
|
886
887
|
value: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.value).toString(16)),
|
|
887
888
|
data: transaction.data,
|
|
888
|
-
chainId: (0, _utils._getEvmChainId)(chainInfo)
|
|
889
|
+
chainId: (0, _utils._getEvmChainId)(chainInfo),
|
|
890
|
+
type: 0
|
|
889
891
|
};
|
|
890
892
|
}
|
|
891
893
|
return _ethers.ethers.Transaction.from(txObject).unsignedSerialized;
|
|
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.mergeTransactionAndSignature = void 0;
|
|
7
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
8
|
+
var _eth = require("@subwallet/extension-base/utils/eth");
|
|
7
9
|
var _ethereumjsUtil = require("ethereumjs-util");
|
|
8
10
|
var _ethers = require("ethers");
|
|
9
11
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
@@ -17,7 +19,8 @@ const mergeTransactionAndSignature = (tx, _rawSignature) => {
|
|
|
17
19
|
v: parseInt(`0x${_signature.substring(128)}`)
|
|
18
20
|
};
|
|
19
21
|
let transaction;
|
|
20
|
-
|
|
22
|
+
const max = (0, _eth.anyNumberToBN)(tx.maxFeePerGas);
|
|
23
|
+
if (max.gt(_utils.BN_ZERO)) {
|
|
21
24
|
transaction = {
|
|
22
25
|
nonce: tx.nonce,
|
|
23
26
|
maxFeePerGas: (0, _ethereumjsUtil.addHexPrefix)(tx.maxFeePerGas.toString(16)),
|
|
@@ -27,7 +30,8 @@ const mergeTransactionAndSignature = (tx, _rawSignature) => {
|
|
|
27
30
|
value: (0, _ethereumjsUtil.addHexPrefix)(tx.value.toString(16)),
|
|
28
31
|
data: tx.data,
|
|
29
32
|
chainId: tx.chainId,
|
|
30
|
-
signature: signature
|
|
33
|
+
signature: signature,
|
|
34
|
+
type: 2
|
|
31
35
|
};
|
|
32
36
|
} else {
|
|
33
37
|
transaction = {
|
|
@@ -38,7 +42,8 @@ const mergeTransactionAndSignature = (tx, _rawSignature) => {
|
|
|
38
42
|
value: (0, _ethereumjsUtil.addHexPrefix)(tx.value.toString(16)),
|
|
39
43
|
data: tx.data,
|
|
40
44
|
chainId: tx.chainId,
|
|
41
|
-
signature: signature
|
|
45
|
+
signature: signature,
|
|
46
|
+
type: 0
|
|
42
47
|
};
|
|
43
48
|
}
|
|
44
49
|
return _ethers.ethers.Transaction.from(transaction).serialized;
|
package/cjs/utils/index.js
CHANGED
|
@@ -510,7 +510,8 @@ const stripUrl = url => {
|
|
|
510
510
|
return parts[2];
|
|
511
511
|
};
|
|
512
512
|
exports.stripUrl = stripUrl;
|
|
513
|
-
const baseParseIPFSUrl = input => {
|
|
513
|
+
const baseParseIPFSUrl = (input, customDomain) => {
|
|
514
|
+
const selectedDomain = customDomain || (0, _config.getRandomIpfsGateway)();
|
|
514
515
|
if (!input || input.length === 0) {
|
|
515
516
|
return undefined;
|
|
516
517
|
}
|
|
@@ -521,17 +522,17 @@ const baseParseIPFSUrl = input => {
|
|
|
521
522
|
return input;
|
|
522
523
|
}
|
|
523
524
|
if (input.startsWith('/ipfs/')) {
|
|
524
|
-
return
|
|
525
|
+
return selectedDomain + input.split('/ipfs/')[1];
|
|
525
526
|
}
|
|
526
527
|
if (!input.includes('ipfs://') && !input.includes('ipfs://ipfs/')) {
|
|
527
528
|
// just the IPFS hash
|
|
528
|
-
return
|
|
529
|
+
return selectedDomain + input;
|
|
529
530
|
}
|
|
530
531
|
if (input.includes('ipfs://') && !input.includes('ipfs://ipfs/')) {
|
|
531
532
|
// starts with ipfs://
|
|
532
|
-
return
|
|
533
|
+
return selectedDomain + input.split('ipfs://')[1];
|
|
533
534
|
}
|
|
534
|
-
return
|
|
535
|
+
return selectedDomain + input.split('ipfs://ipfs/')[1]; // starts with ipfs://ipfs/
|
|
535
536
|
};
|
|
536
537
|
exports.baseParseIPFSUrl = baseParseIPFSUrl;
|
|
537
538
|
const swParseIPFSUrl = input => {
|
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.termAndCondition = exports.staticData = exports.marketingCampaigns = exports.crowdloanFunds = exports.
|
|
6
|
+
exports.termAndCondition = exports.staticData = exports.marketingCampaigns = exports.crowdloanFunds = exports.buyTokenConfigs = exports.buyServiceInfos = exports.StaticKey = void 0;
|
|
7
|
+
var _chainList = require("@subwallet/chain-list");
|
|
7
8
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
10
|
|
|
10
11
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-var-requires
|
|
11
14
|
const buyServiceInfos = require('./buyServiceInfos.json');
|
|
12
15
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
13
16
|
exports.buyServiceInfos = buyServiceInfos;
|
|
14
17
|
const buyTokenConfigs = require('./buyTokenConfigs.json');
|
|
15
18
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
16
19
|
exports.buyTokenConfigs = buyTokenConfigs;
|
|
17
|
-
const chains = require('./chains.json');
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
19
|
-
exports.chains = chains;
|
|
20
20
|
const crowdloanFunds = require('./crowdloanFunds.json');
|
|
21
21
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
22
22
|
exports.crowdloanFunds = crowdloanFunds;
|
|
@@ -36,7 +36,7 @@ exports.StaticKey = StaticKey;
|
|
|
36
36
|
StaticKey["BUY_TOKEN_CONFIGS"] = "buy-token-configs";
|
|
37
37
|
})(StaticKey || (exports.StaticKey = StaticKey = {}));
|
|
38
38
|
const staticData = {
|
|
39
|
-
[StaticKey.CHAINS]:
|
|
39
|
+
[StaticKey.CHAINS]: Object.values(_chainList.ChainInfoMap),
|
|
40
40
|
[StaticKey.BUY_SERVICE_INFOS]: buyServiceInfos,
|
|
41
41
|
[StaticKey.CROWDLOAN_FUNDS]: crowdloanFunds,
|
|
42
42
|
[StaticKey.MARKETING_CAMPAINGS]: marketingCampaigns,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseNftApi, HandleNftParams } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
2
2
|
export declare class UniqueNftApi extends BaseNftApi {
|
|
3
3
|
constructor(chain: string, addresses: string[]);
|
|
4
|
+
parseUrl(input: string): string | undefined;
|
|
4
5
|
private handleProperties;
|
|
5
6
|
private static parseNftRequest;
|
|
6
7
|
private getNftByAccount;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { OPAL_SCAN_ENDPOINT, QUARTZ_SCAN_ENDPOINT, UNIQUE_SCAN_ENDPOINT } from '@subwallet/extension-base/koni/api/nft/config';
|
|
4
|
+
import { OPAL_SCAN_ENDPOINT, QUARTZ_SCAN_ENDPOINT, UNIQUE_IPFS_GATEWAY, UNIQUE_SCAN_ENDPOINT } from '@subwallet/extension-base/koni/api/nft/config';
|
|
5
5
|
import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
6
|
+
import { baseParseIPFSUrl } from '@subwallet/extension-base/utils';
|
|
6
7
|
import fetch from 'cross-fetch';
|
|
7
8
|
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
|
|
8
9
|
export class UniqueNftApi extends BaseNftApi {
|
|
9
10
|
constructor(chain, addresses) {
|
|
10
11
|
super(chain, undefined, addresses);
|
|
11
12
|
}
|
|
13
|
+
parseUrl(input) {
|
|
14
|
+
return baseParseIPFSUrl(input, UNIQUE_IPFS_GATEWAY);
|
|
15
|
+
}
|
|
12
16
|
handleProperties(nft) {
|
|
13
17
|
const propertiesMap = {};
|
|
14
18
|
const attRecord = nft.attributes;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
3
2
|
import { NominationInfo, NominatorMetadata, StakingType, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
3
|
import { _SubstrateInflationParams } from '@subwallet/extension-base/services/chain-service/constants';
|
|
@@ -30,6 +30,7 @@ import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/reques
|
|
|
30
30
|
import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setting-service/constants';
|
|
31
31
|
import { WALLET_CONNECT_EIP155_NAMESPACE } from '@subwallet/extension-base/services/wallet-connect-service/constants';
|
|
32
32
|
import { isProposalExpired, isSupportWalletConnectChain, isSupportWalletConnectNamespace } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
33
|
+
import { AccountsStore } from '@subwallet/extension-base/stores';
|
|
33
34
|
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
34
35
|
import { convertSubjectInfoToAddresses, isSameAddress, reformatAddress, uniqueStringArray } from '@subwallet/extension-base/utils';
|
|
35
36
|
import { calculateGasFeeParams, createTransactionFromRLP, signatureToHex } from '@subwallet/extension-base/utils/eth';
|
|
@@ -517,11 +518,16 @@ export default class KoniExtension {
|
|
|
517
518
|
}
|
|
518
519
|
subscribeAddresses(id, port) {
|
|
519
520
|
const _cb = createSubscription(id, port);
|
|
521
|
+
let old = '';
|
|
520
522
|
const subscription = this.#koniState.keyringService.addressesSubject.subscribe(subjectInfo => {
|
|
521
523
|
const addresses = convertSubjectInfoToAddresses(subjectInfo);
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
524
|
+
const _new = JSON.stringify(addresses);
|
|
525
|
+
if (old !== _new) {
|
|
526
|
+
_cb({
|
|
527
|
+
addresses: addresses
|
|
528
|
+
});
|
|
529
|
+
old = _new;
|
|
530
|
+
}
|
|
525
531
|
});
|
|
526
532
|
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
527
533
|
port.onDisconnect.addListener(() => {
|
|
@@ -533,16 +539,42 @@ export default class KoniExtension {
|
|
|
533
539
|
};
|
|
534
540
|
}
|
|
535
541
|
saveRecentAccount({
|
|
536
|
-
accountId
|
|
542
|
+
accountId,
|
|
543
|
+
chain
|
|
537
544
|
}) {
|
|
538
545
|
if (isAddress(accountId)) {
|
|
539
546
|
const address = reformatAddress(accountId);
|
|
540
547
|
const account = keyring.getAccount(address);
|
|
541
|
-
const contact = keyring.getAddress(address);
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
548
|
+
const contact = keyring.getAddress(address, 'address');
|
|
549
|
+
if (account) {
|
|
550
|
+
return account;
|
|
551
|
+
} else {
|
|
552
|
+
let metadata;
|
|
553
|
+
if (contact) {
|
|
554
|
+
metadata = contact.meta;
|
|
555
|
+
} else {
|
|
556
|
+
const _new = keyring.saveRecent(address);
|
|
557
|
+
metadata = _new.json.meta;
|
|
558
|
+
}
|
|
559
|
+
if (contact && !metadata.isRecent) {
|
|
560
|
+
return contact;
|
|
561
|
+
}
|
|
562
|
+
const recentChainSlugs = metadata.recentChainSlugs || [];
|
|
563
|
+
if (chain) {
|
|
564
|
+
if (!recentChainSlugs.includes(chain)) {
|
|
565
|
+
recentChainSlugs.push(chain);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
metadata.recentChainSlugs = recentChainSlugs;
|
|
569
|
+
const result = keyring.addresses.add(new AccountsStore(), address, {
|
|
570
|
+
address: address,
|
|
571
|
+
meta: metadata
|
|
572
|
+
});
|
|
573
|
+
return {
|
|
574
|
+
...result.json,
|
|
575
|
+
publicKey: decodeAddress(address)
|
|
576
|
+
};
|
|
577
|
+
}
|
|
546
578
|
} else {
|
|
547
579
|
throw Error(t('This is not an address'));
|
|
548
580
|
}
|
|
@@ -1594,7 +1626,9 @@ export default class KoniExtension {
|
|
|
1594
1626
|
// Check ed for receiver
|
|
1595
1627
|
if (new BigN(receiverBalance).plus(transferAmount.value).lt(minAmount)) {
|
|
1596
1628
|
const atLeast = new BigN(minAmount).minus(receiverBalance).plus((tokenInfo.decimals || 0) === 0 ? 0 : 1);
|
|
1597
|
-
const atLeastStr = formatNumber(atLeast, tokenInfo.decimals || 0, balanceFormatter
|
|
1629
|
+
const atLeastStr = formatNumber(atLeast, tokenInfo.decimals || 0, balanceFormatter, {
|
|
1630
|
+
maxNumberFormat: tokenInfo.decimals || 6
|
|
1631
|
+
});
|
|
1598
1632
|
inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, t('You must transfer at least {{amount}} {{symbol}} to keep the destination account alive', {
|
|
1599
1633
|
replace: {
|
|
1600
1634
|
amount: atLeastStr,
|
|
@@ -1663,7 +1697,9 @@ export default class KoniExtension {
|
|
|
1663
1697
|
|
|
1664
1698
|
// Check ed for receiver
|
|
1665
1699
|
if (new BigN(value).lt(atLeast)) {
|
|
1666
|
-
const atLeastStr = formatNumber(atLeast, destinationTokenInfo.decimals || 0, balanceFormatter
|
|
1700
|
+
const atLeastStr = formatNumber(atLeast, destinationTokenInfo.decimals || 0, balanceFormatter, {
|
|
1701
|
+
maxNumberFormat: destinationTokenInfo.decimals || 6
|
|
1702
|
+
});
|
|
1667
1703
|
inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, t('You must transfer at least {{amount}} {{symbol}} to keep the destination account alive', {
|
|
1668
1704
|
replace: {
|
|
1669
1705
|
amount: atLeastStr,
|
|
@@ -2919,7 +2955,7 @@ export default class KoniExtension {
|
|
|
2919
2955
|
if (chainInfo && (_API_OPTIONS_CHAIN_GROUP.avail.includes(chainInfo.slug) || _API_OPTIONS_CHAIN_GROUP.goldberg.includes(chainInfo.slug))) {
|
|
2920
2956
|
const isChainActive = this.#koniState.getChainStateByKey(chainInfo.slug).active;
|
|
2921
2957
|
if (!isChainActive) {
|
|
2922
|
-
reject(new Error('Please
|
|
2958
|
+
reject(new Error('Please activate {{chain}} network before signing'.replaceAll('{{chain}}', chainInfo.name)));
|
|
2923
2959
|
return false;
|
|
2924
2960
|
} else {
|
|
2925
2961
|
registry = this.#koniState.getSubstrateApi(chainInfo.slug).api.registry;
|
|
@@ -37,10 +37,11 @@ import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
|
37
37
|
import { decodePair } from '@subwallet/keyring/pair/decode';
|
|
38
38
|
import { keyring } from '@subwallet/ui-keyring';
|
|
39
39
|
import BigN from 'bignumber.js';
|
|
40
|
+
import BN from 'bn.js';
|
|
40
41
|
import SimpleKeyring from 'eth-simple-keyring';
|
|
41
42
|
import { t } from 'i18next';
|
|
42
43
|
import { Subject } from 'rxjs';
|
|
43
|
-
import { assert,
|
|
44
|
+
import { assert, hexStripPrefix, hexToU8a, isHex, logger as createLogger, u8aToHex } from '@polkadot/util';
|
|
44
45
|
import { base64Decode, isEthereumAddress, keyExtractSuri } from '@polkadot/util-crypto';
|
|
45
46
|
import { KoniCron } from "../cron.js";
|
|
46
47
|
import { KoniSubscription } from "../subscription.js";
|