@subwallet/extension-base 1.2.25-0 → 1.2.26-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 +9 -0
- package/background/errors/EvmProviderError.d.ts +1 -1
- package/background/errors/EvmProviderError.js +2 -2
- package/background/errors/SWError.d.ts +1 -1
- package/background/errors/SWError.js +4 -1
- package/background/errors/TransactionError.d.ts +1 -1
- package/background/errors/TransactionError.js +2 -2
- package/cjs/background/errors/EvmProviderError.js +2 -2
- package/cjs/background/errors/SWError.js +4 -1
- package/cjs/background/errors/TransactionError.js +2 -2
- package/cjs/core/logic-validation/index.js +49 -0
- package/cjs/core/logic-validation/request.js +488 -0
- package/cjs/core/logic-validation/transfer.js +25 -8
- package/cjs/koni/api/staking/bonding/utils.js +2 -2
- package/cjs/koni/background/handlers/Extension.js +33 -8
- package/cjs/koni/background/handlers/State.js +41 -160
- package/cjs/koni/background/handlers/Tabs.js +35 -33
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +16 -8
- package/cjs/services/chain-service/constants.js +6 -1
- package/cjs/services/chain-service/index.js +32 -2
- package/cjs/services/chain-service/utils/index.js +2 -2
- package/cjs/services/earning-service/constants/chains.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +4 -3
- package/cjs/services/event-service/index.js +1 -0
- package/cjs/services/request-service/handler/EvmRequestHandler.js +2 -1
- package/cjs/services/transaction-service/index.js +11 -7
- package/cjs/services/wallet-connect-service/handler/Eip155RequestHandler.js +12 -36
- package/core/logic-validation/index.d.ts +4 -0
- package/core/logic-validation/index.js +7 -0
- package/core/logic-validation/request.d.ts +23 -0
- package/core/logic-validation/request.js +475 -0
- package/core/logic-validation/transfer.d.ts +1 -1
- package/core/logic-validation/transfer.js +25 -8
- package/koni/api/staking/bonding/utils.js +2 -2
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +33 -8
- package/koni/background/handlers/State.d.ts +2 -2
- package/koni/background/handlers/State.js +42 -161
- package/koni/background/handlers/Tabs.d.ts +0 -1
- package/koni/background/handlers/Tabs.js +36 -34
- package/package.json +16 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +16 -8
- package/services/chain-service/constants.js +6 -1
- package/services/chain-service/index.d.ts +9 -0
- package/services/chain-service/index.js +32 -2
- package/services/chain-service/utils/index.js +2 -2
- package/services/earning-service/constants/chains.js +2 -2
- package/services/earning-service/handlers/native-staking/relay-chain.js +4 -3
- package/services/event-service/index.d.ts +1 -0
- package/services/event-service/index.js +1 -0
- package/services/event-service/types.d.ts +1 -0
- package/services/request-service/handler/EvmRequestHandler.js +2 -1
- package/services/transaction-service/index.js +11 -7
- package/services/wallet-connect-service/handler/Eip155RequestHandler.js +9 -33
|
@@ -112,29 +112,37 @@ const subscribeWithSystemAccountPallet = async ({
|
|
|
112
112
|
extrinsicType,
|
|
113
113
|
substrateApi
|
|
114
114
|
}) => {
|
|
115
|
+
var _substrateApi$api$tx, _substrateApi$api$tx$;
|
|
115
116
|
const systemAccountKey = 'query_system_account';
|
|
116
117
|
const poolMembersKey = 'query_nominationPools_poolMembers';
|
|
118
|
+
const isNominationPoolMigrated = !!((_substrateApi$api$tx = substrateApi.api.tx) !== null && _substrateApi$api$tx !== void 0 && (_substrateApi$api$tx$ = _substrateApi$api$tx.nominationPools) !== null && _substrateApi$api$tx$ !== void 0 && _substrateApi$api$tx$.migrateDelegation);
|
|
117
119
|
const params = [{
|
|
118
120
|
section: 'query',
|
|
119
121
|
module: systemAccountKey.split('_')[1],
|
|
120
122
|
method: systemAccountKey.split('_')[2],
|
|
121
123
|
args: addresses
|
|
122
|
-
}, {
|
|
123
|
-
section: 'query',
|
|
124
|
-
module: poolMembersKey.split('_')[1],
|
|
125
|
-
method: poolMembersKey.split('_')[2],
|
|
126
|
-
args: addresses
|
|
127
124
|
}];
|
|
125
|
+
if (!isNominationPoolMigrated) {
|
|
126
|
+
params.push({
|
|
127
|
+
section: 'query',
|
|
128
|
+
module: poolMembersKey.split('_')[1],
|
|
129
|
+
method: poolMembersKey.split('_')[2],
|
|
130
|
+
args: addresses
|
|
131
|
+
});
|
|
132
|
+
}
|
|
128
133
|
const subscription = substrateApi.subscribeDataWithMulti(params, rs => {
|
|
129
134
|
const balances = rs[systemAccountKey];
|
|
130
135
|
const poolMemberInfos = rs[poolMembersKey];
|
|
131
136
|
const items = balances.map((_balance, index) => {
|
|
132
137
|
const balanceInfo = _balance;
|
|
133
|
-
const poolMemberInfo = poolMemberInfos[index];
|
|
134
|
-
const nominationPoolBalance = poolMemberInfo ? _getTotalStakeInNominationPool(poolMemberInfo) : BigInt(0);
|
|
135
138
|
const transferableBalance = _getSystemPalletTransferable(balanceInfo, _getChainExistentialDeposit(chainInfo), extrinsicType);
|
|
136
139
|
const totalBalance = _getSystemPalletTotalBalance(balanceInfo);
|
|
137
|
-
|
|
140
|
+
let totalLockedFromTransfer = totalBalance - transferableBalance;
|
|
141
|
+
if (!isNominationPoolMigrated) {
|
|
142
|
+
const poolMemberInfo = poolMemberInfos[index];
|
|
143
|
+
const nominationPoolBalance = poolMemberInfo ? _getTotalStakeInNominationPool(poolMemberInfo) : BigInt(0);
|
|
144
|
+
totalLockedFromTransfer += nominationPoolBalance;
|
|
145
|
+
}
|
|
138
146
|
return {
|
|
139
147
|
address: addresses[index],
|
|
140
148
|
tokenSlug: _getChainNativeTokenSlug(chainInfo),
|
|
@@ -129,7 +129,8 @@ export const _EXPECTED_BLOCK_TIME = {
|
|
|
129
129
|
manta_network: 12,
|
|
130
130
|
enjin_relaychain: 6,
|
|
131
131
|
availTuringTest: 20,
|
|
132
|
-
avail_mainnet: 20
|
|
132
|
+
avail_mainnet: 20,
|
|
133
|
+
dentnet: 3
|
|
133
134
|
};
|
|
134
135
|
export const _PARACHAIN_INFLATION_DISTRIBUTION = {
|
|
135
136
|
moonbeam: {
|
|
@@ -226,6 +227,10 @@ export const _KNOWN_CHAIN_INFLATION_PARAMS = {
|
|
|
226
227
|
..._SUBSTRATE_DEFAULT_INFLATION_PARAMS,
|
|
227
228
|
maxInflation: 0.05,
|
|
228
229
|
minInflation: 0.01
|
|
230
|
+
},
|
|
231
|
+
dentnet: {
|
|
232
|
+
..._SUBSTRATE_DEFAULT_INFLATION_PARAMS,
|
|
233
|
+
falloff: 0.5
|
|
229
234
|
}
|
|
230
235
|
};
|
|
231
236
|
|
|
@@ -27,12 +27,19 @@ export declare class ChainService {
|
|
|
27
27
|
private swapRefMapSubject;
|
|
28
28
|
private assetLogoMapSubject;
|
|
29
29
|
private chainLogoMapSubject;
|
|
30
|
+
private ledgerGenericAllowChainsSubject;
|
|
30
31
|
private assetMapPatch;
|
|
31
32
|
private assetLogoPatch;
|
|
32
33
|
private store;
|
|
33
34
|
private assetSettingSubject;
|
|
34
35
|
private logger;
|
|
35
36
|
constructor(dbService: DatabaseService, eventService: EventService);
|
|
37
|
+
get value(): {
|
|
38
|
+
readonly ledgerGenericAllowChains: string[];
|
|
39
|
+
};
|
|
40
|
+
get observable(): {
|
|
41
|
+
readonly ledgerGenericAllowChains: import("rxjs").Observable<string[]>;
|
|
42
|
+
};
|
|
36
43
|
subscribeSwapRefMap(): Subject<Record<string, _AssetRef>>;
|
|
37
44
|
get xcmRefMap(): Record<string, _AssetRef>;
|
|
38
45
|
get swapRefMap(): Record<string, _AssetRef>;
|
|
@@ -92,6 +99,7 @@ export declare class ChainService {
|
|
|
92
99
|
handleLatestPriceId(latestPriceIds: Record<string, string | null>): void;
|
|
93
100
|
handleLatestAssetData(latestAssetInfo: Record<string, _ChainAsset> | null, latestAssetLogoMap: Record<string, string> | null): void;
|
|
94
101
|
autoEnableTokens(): Promise<void>;
|
|
102
|
+
handleLatestLedgerGenericAllowChains(latestledgerGenericAllowChains: string[]): void;
|
|
95
103
|
handleLatestData(): void;
|
|
96
104
|
private initApis;
|
|
97
105
|
initSingleApi(slug: string): Promise<boolean>;
|
|
@@ -106,6 +114,7 @@ export declare class ChainService {
|
|
|
106
114
|
private fetchLatestAssetData;
|
|
107
115
|
private fetchLatestPriceIdsData;
|
|
108
116
|
private fetchLatestAssetRef;
|
|
117
|
+
private fetchLatestLedgerGenericAllowChains;
|
|
109
118
|
private initChains;
|
|
110
119
|
private initAssetRegistry;
|
|
111
120
|
private updateChainStateMapSubscription;
|
|
@@ -18,7 +18,7 @@ import { logger as createLogger } from '@polkadot/util/logger';
|
|
|
18
18
|
const filterChainInfoMap = (data, ignoredChains) => {
|
|
19
19
|
return Object.fromEntries(Object.entries(data).filter(([slug, info]) => !info.bitcoinInfo && !ignoredChains.includes(slug)));
|
|
20
20
|
};
|
|
21
|
-
const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest', 'syscoin_evm', 'syscoin_evm_testnet', 'rollux_evm', 'rollux_testnet', 'boolAlpha', 'boolBeta_testnet', 'core', 'satoshivm', 'satoshivm_testnet'];
|
|
21
|
+
const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest', 'syscoin_evm', 'syscoin_evm_testnet', 'rollux_evm', 'rollux_testnet', 'boolAlpha', 'boolBeta_testnet', 'core', 'satoshivm', 'satoshivm_testnet', 'ton', 'ton_testnet'];
|
|
22
22
|
const filterAssetInfoMap = (chainInfo, assets) => {
|
|
23
23
|
return Object.fromEntries(Object.entries(assets).filter(([, info]) => chainInfo[info.originChain]));
|
|
24
24
|
};
|
|
@@ -62,6 +62,7 @@ export class ChainService {
|
|
|
62
62
|
swapRefMapSubject = new Subject();
|
|
63
63
|
assetLogoMapSubject = new BehaviorSubject(AssetLogoMap);
|
|
64
64
|
chainLogoMapSubject = new BehaviorSubject(ChainLogoMap);
|
|
65
|
+
ledgerGenericAllowChainsSubject = new BehaviorSubject([]);
|
|
65
66
|
assetMapPatch = JSON.stringify({});
|
|
66
67
|
assetLogoPatch = JSON.stringify({});
|
|
67
68
|
|
|
@@ -84,6 +85,22 @@ export class ChainService {
|
|
|
84
85
|
this.evmChainHandler = new EvmChainHandler(this);
|
|
85
86
|
this.logger = createLogger('chain-service');
|
|
86
87
|
}
|
|
88
|
+
get value() {
|
|
89
|
+
const ledgerGenericAllowChains = this.ledgerGenericAllowChainsSubject;
|
|
90
|
+
return {
|
|
91
|
+
get ledgerGenericAllowChains() {
|
|
92
|
+
return ledgerGenericAllowChains.value;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
get observable() {
|
|
97
|
+
const ledgerGenericAllowChains = this.ledgerGenericAllowChainsSubject;
|
|
98
|
+
return {
|
|
99
|
+
get ledgerGenericAllowChains() {
|
|
100
|
+
return ledgerGenericAllowChains.asObservable();
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
87
104
|
subscribeSwapRefMap() {
|
|
88
105
|
return this.swapRefMapSubject;
|
|
89
106
|
}
|
|
@@ -600,6 +617,11 @@ export class ChainService {
|
|
|
600
617
|
}
|
|
601
618
|
}
|
|
602
619
|
}
|
|
620
|
+
handleLatestLedgerGenericAllowChains(latestledgerGenericAllowChains) {
|
|
621
|
+
this.ledgerGenericAllowChainsSubject.next(latestledgerGenericAllowChains);
|
|
622
|
+
this.eventService.emit('ledger.ready', true);
|
|
623
|
+
this.logger.log('Finished updating latest ledger generic allow chains');
|
|
624
|
+
}
|
|
603
625
|
handleLatestData() {
|
|
604
626
|
this.fetchLatestAssetData().then(([latestAssetInfo, latestAssetLogoMap]) => {
|
|
605
627
|
this.eventService.waitAssetReady.then(() => {
|
|
@@ -615,6 +637,9 @@ export class ChainService {
|
|
|
615
637
|
this.fetchLatestPriceIdsData().then(latestPriceIds => {
|
|
616
638
|
this.handleLatestPriceId(latestPriceIds);
|
|
617
639
|
}).catch(console.error);
|
|
640
|
+
this.fetchLatestLedgerGenericAllowChains().then(latestledgerGenericAllowChains => {
|
|
641
|
+
this.handleLatestLedgerGenericAllowChains(latestledgerGenericAllowChains);
|
|
642
|
+
}).catch(console.error);
|
|
618
643
|
}
|
|
619
644
|
async initApis() {
|
|
620
645
|
const chainInfoMap = this.getChainInfoMap();
|
|
@@ -870,6 +895,9 @@ export class ChainService {
|
|
|
870
895
|
async fetchLatestAssetRef() {
|
|
871
896
|
return await Promise.all([fetchStaticData('chain-assets/disabled-xcm-channels'), fetchPatchData('AssetRef.json')]);
|
|
872
897
|
}
|
|
898
|
+
async fetchLatestLedgerGenericAllowChains() {
|
|
899
|
+
return (await fetchStaticData('chains/ledger-generic-allow-chains')) || [];
|
|
900
|
+
}
|
|
873
901
|
async initChains() {
|
|
874
902
|
const storedChainSettings = await this.dbService.getAllChainStore();
|
|
875
903
|
const defaultChainInfoMap = filterChainInfoMap(ChainInfoMap, ignoredList);
|
|
@@ -982,7 +1010,7 @@ export class ChainService {
|
|
|
982
1010
|
deprecatedChainMap[storedSlug] = duplicatedDefaultSlug;
|
|
983
1011
|
deprecatedChains.push(storedSlug);
|
|
984
1012
|
} else {
|
|
985
|
-
var _storedChainInfo$bitc;
|
|
1013
|
+
var _storedChainInfo$bitc, _storedChainInfo$tonI;
|
|
986
1014
|
mergedChainInfoMap[storedSlug] = {
|
|
987
1015
|
slug: storedSlug,
|
|
988
1016
|
name: storedChainInfo.name,
|
|
@@ -991,6 +1019,7 @@ export class ChainService {
|
|
|
991
1019
|
evmInfo: storedChainInfo.evmInfo,
|
|
992
1020
|
substrateInfo: storedChainInfo.substrateInfo,
|
|
993
1021
|
bitcoinInfo: (_storedChainInfo$bitc = storedChainInfo.bitcoinInfo) !== null && _storedChainInfo$bitc !== void 0 ? _storedChainInfo$bitc : null,
|
|
1022
|
+
tonInfo: (_storedChainInfo$tonI = storedChainInfo.tonInfo) !== null && _storedChainInfo$tonI !== void 0 ? _storedChainInfo$tonI : null,
|
|
994
1023
|
isTestnet: storedChainInfo.isTestnet,
|
|
995
1024
|
chainStatus: storedChainInfo.chainStatus,
|
|
996
1025
|
icon: storedChainInfo.icon,
|
|
@@ -1204,6 +1233,7 @@ export class ChainService {
|
|
|
1204
1233
|
substrateInfo,
|
|
1205
1234
|
evmInfo,
|
|
1206
1235
|
bitcoinInfo: null,
|
|
1236
|
+
tonInfo: null,
|
|
1207
1237
|
isTestnet: false,
|
|
1208
1238
|
chainStatus: _ChainStatus.ACTIVE,
|
|
1209
1239
|
icon: '',
|
|
@@ -47,10 +47,10 @@ export function _isEqualSmartContractAsset(asset1, asset2) {
|
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
49
|
export function _isPureEvmChain(chainInfo) {
|
|
50
|
-
return chainInfo.evmInfo
|
|
50
|
+
return !!chainInfo.evmInfo && !chainInfo.substrateInfo;
|
|
51
51
|
}
|
|
52
52
|
export function _isPureSubstrateChain(chainInfo) {
|
|
53
|
-
return chainInfo.evmInfo
|
|
53
|
+
return !chainInfo.evmInfo && !!chainInfo.substrateInfo;
|
|
54
54
|
}
|
|
55
55
|
export function _getOriginChainOfAsset(assetSlug) {
|
|
56
56
|
if (assetSlug.startsWith(_CUSTOM_PREFIX)) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
export const _STAKING_CHAIN_GROUP = {
|
|
5
|
-
relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet', 'availTuringTest', 'avail_mainnet', 'vara_testnet'],
|
|
5
|
+
relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet', 'availTuringTest', 'avail_mainnet', 'vara_testnet', 'dentnet'],
|
|
6
6
|
para: ['moonbeam', 'moonriver', 'moonbase', 'turing', 'turingStaging', 'bifrost', 'bifrost_testnet', 'calamari_test', 'calamari', 'manta_network', 'polimec'],
|
|
7
7
|
astar: ['astar', 'shiden', 'shibuya'],
|
|
8
8
|
amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum', 'krest_network'],
|
|
@@ -18,7 +18,7 @@ export const _STAKING_CHAIN_GROUP = {
|
|
|
18
18
|
krest_network: ['krest_network'],
|
|
19
19
|
manta: ['manta_network']
|
|
20
20
|
};
|
|
21
|
-
export const _UPDATED_RUNTIME_STAKING_GROUP = ['kusama', 'polkadot', 'westend', 'availTuringTest', 'avail_mainnet'];
|
|
21
|
+
export const _UPDATED_RUNTIME_STAKING_GROUP = ['kusama', 'polkadot', 'westend', 'availTuringTest', 'avail_mainnet', 'dentnet'];
|
|
22
22
|
export const MaxEraRewardPointsEras = 14;
|
|
23
23
|
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
@@ -301,7 +301,7 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
301
301
|
const endEraForPoints = parseInt(activeEra) - 1;
|
|
302
302
|
const startEraForPoints = Math.max(endEraForPoints - maxEraRewardPointsEras + 1, 0);
|
|
303
303
|
let _eraStakersPromise;
|
|
304
|
-
if (
|
|
304
|
+
if (chainApi.api.query.staking.erasStakersOverview) {
|
|
305
305
|
// todo: review all relaychains later
|
|
306
306
|
_eraStakersPromise = chainApi.api.query.staking.erasStakersOverview.entries(parseInt(currentEra));
|
|
307
307
|
} else {
|
|
@@ -318,8 +318,9 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
318
318
|
const waitingValidatorLedger = {};
|
|
319
319
|
if (_waitingValidatorLedger) {
|
|
320
320
|
waitingValidatorList.forEach((validator, i) => {
|
|
321
|
-
|
|
322
|
-
|
|
321
|
+
var _waitingValidatorLedg;
|
|
322
|
+
const validatorLedger = (_waitingValidatorLedg = _waitingValidatorLedger[i]) === null || _waitingValidatorLedg === void 0 ? void 0 : _waitingValidatorLedg.toPrimitive();
|
|
323
|
+
waitingValidatorLedger[validator] = new BigN((validatorLedger === null || validatorLedger === void 0 ? void 0 : validatorLedger.total) || 0).toFixed();
|
|
323
324
|
});
|
|
324
325
|
}
|
|
325
326
|
const unlimitedNominatorRewarded = chainApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
@@ -17,6 +17,7 @@ export declare class EventService extends EventEmitter<EventRegistry> {
|
|
|
17
17
|
readonly waitBuyTokenReady: Promise<boolean>;
|
|
18
18
|
readonly waitBuyServiceReady: Promise<boolean>;
|
|
19
19
|
readonly waitEarningReady: Promise<boolean>;
|
|
20
|
+
readonly waitLedgerReady: Promise<boolean>;
|
|
20
21
|
constructor();
|
|
21
22
|
private generateWaitPromise;
|
|
22
23
|
private setLazyTimeout;
|
|
@@ -28,6 +28,7 @@ export class EventService extends EventEmitter {
|
|
|
28
28
|
this.waitBuyTokenReady = this.generateWaitPromise('buy.tokens.ready');
|
|
29
29
|
this.waitBuyServiceReady = this.generateWaitPromise('buy.services.ready');
|
|
30
30
|
this.waitEarningReady = this.generateWaitPromise('earning.ready');
|
|
31
|
+
this.waitLedgerReady = this.generateWaitPromise('ledger.ready');
|
|
31
32
|
}
|
|
32
33
|
generateWaitPromise(eventType) {
|
|
33
34
|
return new Promise(resolve => {
|
|
@@ -39,6 +39,7 @@ export interface EventRegistry {
|
|
|
39
39
|
'buy.services.ready': [boolean];
|
|
40
40
|
'earning.ready': [boolean];
|
|
41
41
|
'swap.ready': [boolean];
|
|
42
|
+
'ledger.ready': [boolean];
|
|
42
43
|
}
|
|
43
44
|
export declare type EventType = keyof EventRegistry;
|
|
44
45
|
export declare const COMMON_RELOAD_EVENTS: EventType[];
|
|
@@ -22,7 +22,8 @@ export default class EvmRequestHandler {
|
|
|
22
22
|
switchNetworkRequest: {},
|
|
23
23
|
evmSignatureRequest: {},
|
|
24
24
|
evmSendTransactionRequest: {},
|
|
25
|
-
evmWatchTransactionRequest: {}
|
|
25
|
+
evmWatchTransactionRequest: {},
|
|
26
|
+
errorConnectNetwork: {}
|
|
26
27
|
});
|
|
27
28
|
confirmationsPromiseMap = {};
|
|
28
29
|
constructor(requestService) {
|
|
@@ -821,6 +821,7 @@ export default class TransactionService {
|
|
|
821
821
|
const payload = transaction;
|
|
822
822
|
const evmApi = this.state.chainService.getEvmApi(chain);
|
|
823
823
|
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
824
|
+
const hasError = !!(payload.errors && payload.errors.length > 0);
|
|
824
825
|
const accountPair = keyring.getPair(address);
|
|
825
826
|
const account = {
|
|
826
827
|
address,
|
|
@@ -835,9 +836,9 @@ export default class TransactionService {
|
|
|
835
836
|
|
|
836
837
|
// Fill contract info
|
|
837
838
|
if (!payload.parseData) {
|
|
838
|
-
const isToContract = await isContractAddress(payload.to || '', evmApi);
|
|
839
|
-
payload.isToContract = isToContract;
|
|
840
839
|
try {
|
|
840
|
+
const isToContract = await isContractAddress(payload.to || '', evmApi);
|
|
841
|
+
payload.isToContract = isToContract;
|
|
841
842
|
payload.parseData = isToContract ? payload.data ? (await parseContractInput(payload.data || '', payload.to || '', chainInfo)).result : '' : payload.data || '';
|
|
842
843
|
} catch (e) {
|
|
843
844
|
console.warn('Unable to parse contract input data');
|
|
@@ -851,11 +852,13 @@ export default class TransactionService {
|
|
|
851
852
|
// Set unique nonce to avoid transaction errors
|
|
852
853
|
if (!payload.nonce) {
|
|
853
854
|
const evmApi = this.state.chainService.getEvmApi(chain);
|
|
854
|
-
|
|
855
|
+
if (evmApi.isApiConnected) {
|
|
856
|
+
payload.nonce = await (evmApi === null || evmApi === void 0 ? void 0 : evmApi.api.eth.getTransactionCount(address));
|
|
857
|
+
}
|
|
855
858
|
}
|
|
856
859
|
if (!payload.chainId) {
|
|
857
860
|
var _chainInfo$evmInfo$ev, _chainInfo$evmInfo;
|
|
858
|
-
payload.chainId = (_chainInfo$evmInfo$ev = (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId) !== null && _chainInfo$evmInfo$ev !== void 0 ? _chainInfo$evmInfo$ev : 1;
|
|
861
|
+
payload.chainId = (_chainInfo$evmInfo$ev = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId) !== null && _chainInfo$evmInfo$ev !== void 0 ? _chainInfo$evmInfo$ev : 1;
|
|
859
862
|
}
|
|
860
863
|
|
|
861
864
|
// Autofill from
|
|
@@ -864,9 +867,10 @@ export default class TransactionService {
|
|
|
864
867
|
}
|
|
865
868
|
const isExternal = !!account.isExternal;
|
|
866
869
|
const isInjected = !!account.isInjected;
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
+
if (!hasError) {
|
|
871
|
+
// generate hashPayload for EVM transaction
|
|
872
|
+
payload.hashPayload = this.generateHashPayload(chain, payload);
|
|
873
|
+
}
|
|
870
874
|
const emitter = new EventEmitter();
|
|
871
875
|
const txObject = {
|
|
872
876
|
nonce: (_payload$nonce = payload.nonce) !== null && _payload$nonce !== void 0 ? _payload$nonce : 0,
|
|
@@ -4,22 +4,17 @@ import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateF
|
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
|
|
6
6
|
import { formatJsonRpcError, formatJsonRpcResult } from '@json-rpc-tools/utils';
|
|
7
|
-
import {
|
|
7
|
+
import { getWCId, parseRequestParams } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
8
8
|
import { EIP155_SIGNING_METHODS } from '@subwallet/extension-base/services/wallet-connect-service/types';
|
|
9
|
-
import { isSameAddress } from '@subwallet/extension-base/utils';
|
|
10
9
|
import { getSdkError } from '@walletconnect/utils';
|
|
11
10
|
var _walletConnectService = /*#__PURE__*/_classPrivateFieldLooseKey("walletConnectService");
|
|
12
11
|
var _koniState = /*#__PURE__*/_classPrivateFieldLooseKey("koniState");
|
|
13
|
-
var _checkAccount = /*#__PURE__*/_classPrivateFieldLooseKey("checkAccount");
|
|
14
12
|
var _handleError = /*#__PURE__*/_classPrivateFieldLooseKey("handleError");
|
|
15
13
|
export default class Eip155RequestHandler {
|
|
16
14
|
constructor(koniState, walletConnectService) {
|
|
17
15
|
Object.defineProperty(this, _handleError, {
|
|
18
16
|
value: _handleError2
|
|
19
17
|
});
|
|
20
|
-
Object.defineProperty(this, _checkAccount, {
|
|
21
|
-
value: _checkAccount2
|
|
22
|
-
});
|
|
23
18
|
Object.defineProperty(this, _walletConnectService, {
|
|
24
19
|
writable: true,
|
|
25
20
|
value: void 0
|
|
@@ -44,11 +39,8 @@ export default class Eip155RequestHandler {
|
|
|
44
39
|
const method = request.method;
|
|
45
40
|
const requestSession = _classPrivateFieldLooseBase(this, _walletConnectService)[_walletConnectService].getSession(topic);
|
|
46
41
|
const url = requestSession.peer.metadata.url;
|
|
47
|
-
const sessionAccounts = requestSession.namespaces.eip155.accounts.map(account => account.split(':')[2]);
|
|
48
42
|
if ([EIP155_SIGNING_METHODS.PERSONAL_SIGN, EIP155_SIGNING_METHODS.ETH_SIGN, EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA, EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA_V3, EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA_V4].includes(method)) {
|
|
49
|
-
|
|
50
|
-
_classPrivateFieldLooseBase(this, _checkAccount)[_checkAccount](address, sessionAccounts);
|
|
51
|
-
_classPrivateFieldLooseBase(this, _koniState)[_koniState].evmSign(getWCId(id), url, method === EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA ? EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA_V4 : method, request.params, sessionAccounts).then(async signature => {
|
|
43
|
+
_classPrivateFieldLooseBase(this, _koniState)[_koniState].evmSign(getWCId(id), url, method === EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA ? EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA_V4 : method, request.params, topic).then(async signature => {
|
|
52
44
|
await _classPrivateFieldLooseBase(this, _walletConnectService)[_walletConnectService].responseRequest({
|
|
53
45
|
topic: topic,
|
|
54
46
|
response: formatJsonRpcResult(id, signature)
|
|
@@ -59,40 +51,24 @@ export default class Eip155RequestHandler {
|
|
|
59
51
|
} else if (method === EIP155_SIGNING_METHODS.ETH_SEND_TRANSACTION) {
|
|
60
52
|
const [tx] = parseRequestParams(request.params);
|
|
61
53
|
const address = tx.from;
|
|
62
|
-
_classPrivateFieldLooseBase(this, _checkAccount)[_checkAccount](address, sessionAccounts);
|
|
63
54
|
const chainId = parseInt(_chainId.split(':')[1]);
|
|
64
55
|
const [networkKey, chainInfo] = _classPrivateFieldLooseBase(this, _koniState)[_koniState].findNetworkKeyByChainId(chainId);
|
|
65
56
|
if (!networkKey || !chainInfo) {
|
|
66
57
|
throw new Error(getSdkError('UNSUPPORTED_CHAINS').message + ' ' + address);
|
|
67
58
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
topic: topic,
|
|
73
|
-
response: formatJsonRpcResult(id, signature)
|
|
74
|
-
});
|
|
75
|
-
}).catch(e => {
|
|
76
|
-
_classPrivateFieldLooseBase(this, _handleError)[_handleError](topic, id, e);
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
if (!chainState.active) {
|
|
80
|
-
_classPrivateFieldLooseBase(this, _koniState)[_koniState].chainService.enableChain(networkKey).then(createRequest).catch(() => {
|
|
81
|
-
throw new Error(getSdkError('USER_REJECTED').message + ' Can not active chain: ' + chainInfo.name);
|
|
59
|
+
_classPrivateFieldLooseBase(this, _koniState)[_koniState].evmSendTransaction(getWCId(id), url, tx, networkKey, topic).then(async signature => {
|
|
60
|
+
await _classPrivateFieldLooseBase(this, _walletConnectService)[_walletConnectService].responseRequest({
|
|
61
|
+
topic: topic,
|
|
62
|
+
response: formatJsonRpcResult(id, signature)
|
|
82
63
|
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
}
|
|
64
|
+
}).catch(e => {
|
|
65
|
+
_classPrivateFieldLooseBase(this, _handleError)[_handleError](topic, id, e);
|
|
66
|
+
});
|
|
86
67
|
} else {
|
|
87
68
|
throw Error(getSdkError('INVALID_METHOD').message + ' ' + method);
|
|
88
69
|
}
|
|
89
70
|
}
|
|
90
71
|
}
|
|
91
|
-
function _checkAccount2(address, accounts) {
|
|
92
|
-
if (!accounts.find(account => isSameAddress(account, address))) {
|
|
93
|
-
throw new Error(getSdkError('UNSUPPORTED_ACCOUNTS').message + ' ' + address);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
72
|
function _handleError2(topic, id, e) {
|
|
97
73
|
console.log(e);
|
|
98
74
|
let message = e.message;
|