@subwallet/extension-base 1.0.13-0 → 1.0.13-1
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 +37 -0
- package/background/KoniTypes.js +8 -1
- package/background/handlers/Extension.js +17 -2
- package/background/types.d.ts +6 -1
- package/cjs/background/KoniTypes.js +10 -2
- package/cjs/background/handlers/Extension.js +22 -6
- package/cjs/constants/index.js +7 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/api/dotsama/balance.js +5 -0
- package/cjs/koni/api/dotsama/transfer.js +6 -0
- package/cjs/koni/background/cron.js +12 -1
- package/cjs/koni/background/handlers/Extension.js +324 -147
- package/cjs/koni/background/handlers/State.js +222 -50
- package/cjs/koni/background/subscription.js +3 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +10 -4
- package/cjs/services/chain-service/handler/SubstrateApi.js +2 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -1
- package/cjs/services/chain-service/handler/manta/MantaPrivateHandler.js +147 -0
- package/cjs/services/chain-service/index.js +54 -5
- package/cjs/services/chain-service/utils.js +6 -1
- package/cjs/services/event-service/types.js +3 -1
- package/cjs/services/storage-service/DatabaseService.js +31 -1
- package/cjs/services/storage-service/databases/index.js +3 -0
- package/cjs/services/storage-service/db-stores/MantaPay.js +40 -0
- package/cjs/utils/index.js +12 -0
- package/cjs/utils/lazy.js +52 -0
- package/constants/index.d.ts +2 -0
- package/constants/index.js +2 -0
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/api/dotsama/balance.js +6 -1
- package/koni/api/dotsama/transfer.js +7 -1
- package/koni/background/cron.d.ts +1 -0
- package/koni/background/cron.js +13 -2
- package/koni/background/handlers/Extension.d.ts +5 -0
- package/koni/background/handlers/Extension.js +186 -11
- package/koni/background/handlers/State.d.ts +15 -3
- package/koni/background/handlers/State.js +224 -49
- package/koni/background/subscription.js +3 -0
- package/package.json +22 -5
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.d.ts +3 -0
- package/services/chain-service/constants.js +5 -2
- package/services/chain-service/handler/SubstrateApi.d.ts +1 -1
- package/services/chain-service/handler/SubstrateApi.js +2 -1
- package/services/chain-service/handler/SubstrateChainHandler.d.ts +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +3 -1
- package/services/chain-service/handler/manta/MantaPrivateHandler.d.ts +30 -0
- package/services/chain-service/handler/manta/MantaPrivateHandler.js +140 -0
- package/services/chain-service/handler/types.d.ts +2 -0
- package/services/chain-service/index.d.ts +7 -3
- package/services/chain-service/index.js +56 -7
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +5 -1
- package/services/event-service/types.d.ts +3 -0
- package/services/event-service/types.js +3 -1
- package/services/storage-service/DatabaseService.d.ts +10 -1
- package/services/storage-service/DatabaseService.js +31 -1
- package/services/storage-service/databases/index.d.ts +2 -0
- package/services/storage-service/databases/index.js +3 -0
- package/services/storage-service/db-stores/MantaPay.d.ts +9 -0
- package/services/storage-service/db-stores/MantaPay.js +32 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +2 -1
- package/utils/lazy.d.ts +2 -0
- package/utils/lazy.js +43 -0
|
@@ -44,6 +44,8 @@ var _subscription = require("../subscription");
|
|
|
44
44
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
45
45
|
// SPDX-License-Identifier: Apache-2.0
|
|
46
46
|
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
48
|
+
const passworder = require('browser-passworder');
|
|
47
49
|
const ETH_DERIVE_DEFAULT = '/m/44\'/60\'/0\'/0/0';
|
|
48
50
|
|
|
49
51
|
// List of providers passed into constructor. This is the list of providers
|
|
@@ -75,6 +77,8 @@ class KoniState {
|
|
|
75
77
|
crowdloanMap = generateDefaultCrowdloanMap();
|
|
76
78
|
crowdloanSubject = new _rxjs.Subject();
|
|
77
79
|
nftSubject = new _rxjs.Subject();
|
|
80
|
+
mantaPayConfigSubject = new _rxjs.Subject();
|
|
81
|
+
isMantaPayEnabled = false;
|
|
78
82
|
stakingSubject = new _rxjs.Subject();
|
|
79
83
|
chainStakingMetadataSubject = new _rxjs.Subject();
|
|
80
84
|
stakingNominatorMetadataSubject = new _rxjs.Subject();
|
|
@@ -217,11 +221,25 @@ class KoniState {
|
|
|
217
221
|
this.onAccountRemove();
|
|
218
222
|
await this.startSubscription();
|
|
219
223
|
}
|
|
224
|
+
async initMantaPay(password) {
|
|
225
|
+
const mantaPayConfig = await this.chainService.mantaPay.getMantaPayFirstConfig(_constants2._DEFAULT_MANTA_ZK_CHAIN);
|
|
226
|
+
if (mantaPayConfig && mantaPayConfig.enabled && !this.isMantaPayEnabled) {
|
|
227
|
+
// only init the first login
|
|
228
|
+
console.debug('Initiating MantaPay for', mantaPayConfig.address);
|
|
229
|
+
await this.enableMantaPay(false, mantaPayConfig.address, password);
|
|
230
|
+
console.debug('Initiated MantaPay for', mantaPayConfig.address);
|
|
231
|
+
this.isMantaPayEnabled = true;
|
|
232
|
+
this.eventService.emit('mantaPay.enable', mantaPayConfig.address);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
220
235
|
async startSubscription() {
|
|
221
236
|
await this.eventService.waitKeyringReady;
|
|
222
237
|
this.dbService.subscribeChainStakingMetadata([], data => {
|
|
223
238
|
this.chainStakingMetadataSubject.next(data);
|
|
224
239
|
});
|
|
240
|
+
this.dbService.subscribeMantaPayConfig(_constants2._DEFAULT_MANTA_ZK_CHAIN, data => {
|
|
241
|
+
this.mantaPayConfigSubject.next(data);
|
|
242
|
+
});
|
|
225
243
|
let unsub;
|
|
226
244
|
this.keyringService.accountSubject.subscribe(accounts => {
|
|
227
245
|
// TODO: improve this
|
|
@@ -297,6 +315,10 @@ class KoniState {
|
|
|
297
315
|
async getNominatorMetadata() {
|
|
298
316
|
return this.dbService.getNominatorMetadata();
|
|
299
317
|
}
|
|
318
|
+
async getMantaPayConfig(chain) {
|
|
319
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
320
|
+
return this.dbService.getMantaPayConfig(chain);
|
|
321
|
+
}
|
|
300
322
|
async getStaking() {
|
|
301
323
|
const addresses = this.getDecodedAddresses();
|
|
302
324
|
const stakings = await this.dbService.getStakings(addresses, this.activeChainSlugs);
|
|
@@ -318,6 +340,9 @@ class KoniState {
|
|
|
318
340
|
async getPooledStakingRecordsByAddress(addresses) {
|
|
319
341
|
return this.dbService.getPooledStakings(addresses, this.activeChainSlugs);
|
|
320
342
|
}
|
|
343
|
+
subscribeMantaPayConfig() {
|
|
344
|
+
return this.mantaPayConfigSubject;
|
|
345
|
+
}
|
|
321
346
|
subscribeStaking() {
|
|
322
347
|
return this.stakingSubject;
|
|
323
348
|
}
|
|
@@ -891,8 +916,13 @@ class KoniState {
|
|
|
891
916
|
return result;
|
|
892
917
|
};
|
|
893
918
|
async disableChain(chainSlug) {
|
|
894
|
-
// const defaultChains = this.getDefaultNetworkKeys();
|
|
895
919
|
await this.chainService.updateAssetSettingByChain(chainSlug, false);
|
|
920
|
+
if (_constants2._MANTA_ZK_CHAIN_GROUP.includes(chainSlug)) {
|
|
921
|
+
const mantaPayConfig = await this.chainService.mantaPay.getMantaPayFirstConfig(_constants2._DEFAULT_MANTA_ZK_CHAIN);
|
|
922
|
+
if (mantaPayConfig && mantaPayConfig.enabled && this.isMantaPayEnabled) {
|
|
923
|
+
await this.disableMantaPay(mantaPayConfig.address);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
896
926
|
return this.chainService.disableChain(chainSlug);
|
|
897
927
|
}
|
|
898
928
|
async enableChain(chainSlug) {
|
|
@@ -1327,50 +1357,51 @@ class KoniState {
|
|
|
1327
1357
|
return await this.requestService.completeConfirmation(request);
|
|
1328
1358
|
}
|
|
1329
1359
|
onInstall() {
|
|
1330
|
-
const singleModes = Object.values(
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
};
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
}
|
|
1360
|
+
// const singleModes = Object.values(_PREDEFINED_SINGLE_MODES);
|
|
1361
|
+
|
|
1362
|
+
// This logic is moved to installation.ts
|
|
1363
|
+
// try {
|
|
1364
|
+
// // Open expand page
|
|
1365
|
+
// const url = `${chrome.extension.getURL('index.html')}#/`;
|
|
1366
|
+
//
|
|
1367
|
+
// withErrorLog(() => chrome.tabs.create({ url }));
|
|
1368
|
+
// } catch (e) {
|
|
1369
|
+
// console.error(e);
|
|
1370
|
+
// }
|
|
1371
|
+
|
|
1372
|
+
// const setUpSingleMode = ({ networkKeys, theme }: SingleModeJson) => {
|
|
1373
|
+
// networkKeys.forEach((key) => {
|
|
1374
|
+
// this.enableChain(key).catch(console.error);
|
|
1375
|
+
// });
|
|
1376
|
+
//
|
|
1377
|
+
// const chainInfo = this.chainService.getChainInfoByKey(networkKeys[0]);
|
|
1378
|
+
// const genesisHash = _getSubstrateGenesisHash(chainInfo);
|
|
1379
|
+
//
|
|
1380
|
+
// this.setCurrentAccount({
|
|
1381
|
+
// address: ALL_ACCOUNT_KEY,
|
|
1382
|
+
// currentGenesisHash: genesisHash.length > 0 ? genesisHash : null
|
|
1383
|
+
// });
|
|
1384
|
+
// this.setTheme(theme);
|
|
1385
|
+
// };
|
|
1386
|
+
//
|
|
1387
|
+
// chrome.tabs.query({}, function (tabs) {
|
|
1388
|
+
// const openingUrls = tabs.map((t) => t.url);
|
|
1389
|
+
//
|
|
1390
|
+
// const singleMode = singleModes.find(({ autoTriggerDomain }) => {
|
|
1391
|
+
// const urlRegex = new RegExp(autoTriggerDomain);
|
|
1392
|
+
//
|
|
1393
|
+
// return Boolean(openingUrls.find((url) => {
|
|
1394
|
+
// return url && urlRegex.test(url);
|
|
1395
|
+
// }));
|
|
1396
|
+
// });
|
|
1397
|
+
//
|
|
1398
|
+
// if (singleMode) {
|
|
1399
|
+
// // Wait for everything is ready before enable single mode
|
|
1400
|
+
// setTimeout(() => {
|
|
1401
|
+
// setUpSingleMode(singleMode);
|
|
1402
|
+
// }, 999);
|
|
1403
|
+
// }
|
|
1404
|
+
// });
|
|
1374
1405
|
}
|
|
1375
1406
|
get activeNetworks() {
|
|
1376
1407
|
return this.chainService.getActiveChainInfos();
|
|
@@ -1458,9 +1489,6 @@ class KoniState {
|
|
|
1458
1489
|
createUnsubscriptionHandle(id, unsubscribe) {
|
|
1459
1490
|
this.unsubscriptionMap[id] = unsubscribe;
|
|
1460
1491
|
}
|
|
1461
|
-
updateChainConnectionStatus(chain, status) {
|
|
1462
|
-
this.chainService.setChainConnectionStatus(chain, status);
|
|
1463
|
-
}
|
|
1464
1492
|
async autoEnableChains(addresses) {
|
|
1465
1493
|
const assetMap = this.chainService.getAssetRegistry();
|
|
1466
1494
|
const promiseList = addresses.map(address => {
|
|
@@ -1475,7 +1503,7 @@ class KoniState {
|
|
|
1475
1503
|
const chainMap = this.chainService.getChainInfoMap();
|
|
1476
1504
|
const balanceDataList = await Promise.all(promiseList);
|
|
1477
1505
|
balanceDataList.forEach(balanceData => {
|
|
1478
|
-
balanceData && balanceData.forEach(
|
|
1506
|
+
balanceData && balanceData.forEach(_ref12 => {
|
|
1479
1507
|
var _currentAssetSettings;
|
|
1480
1508
|
let {
|
|
1481
1509
|
balance,
|
|
@@ -1484,7 +1512,7 @@ class KoniState {
|
|
|
1484
1512
|
locked,
|
|
1485
1513
|
network,
|
|
1486
1514
|
symbol
|
|
1487
|
-
} =
|
|
1515
|
+
} = _ref12;
|
|
1488
1516
|
const chain = _subscanChainMap.SUBSCAN_CHAIN_MAP_REVERSE[network];
|
|
1489
1517
|
const chainInfo = chain ? chainMap[chain] : null;
|
|
1490
1518
|
const balanceIsEmpty = (!balance || balance === '0') && (!locked || locked === '0') && (!bonded || bonded === '0');
|
|
@@ -1567,5 +1595,149 @@ class KoniState {
|
|
|
1567
1595
|
await this.walletConnectService.resetWallet(resetAll);
|
|
1568
1596
|
await this.chainService.init();
|
|
1569
1597
|
}
|
|
1598
|
+
async enableMantaPay(updateStore, address, password, seedPhrase) {
|
|
1599
|
+
var _this$chainService$ma, _this$chainService$ma6;
|
|
1600
|
+
if (!address || (0, _utilCrypto.isEthereumAddress)(address)) {
|
|
1601
|
+
return;
|
|
1602
|
+
}
|
|
1603
|
+
this.chainService.mantaPay.setCurrentAddress(address);
|
|
1604
|
+
await ((_this$chainService$ma = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma === void 0 ? void 0 : _this$chainService$ma.initialSigner());
|
|
1605
|
+
if (updateStore && seedPhrase) {
|
|
1606
|
+
var _this$chainService$ma2, _this$chainService$ma3, _this$chainService$ma4;
|
|
1607
|
+
// first time initiation
|
|
1608
|
+
await ((_this$chainService$ma2 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma2 === void 0 ? void 0 : _this$chainService$ma2.loadUserSeedPhrase(seedPhrase));
|
|
1609
|
+
const authContext = await ((_this$chainService$ma3 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma3 === void 0 ? void 0 : _this$chainService$ma3.getAuthorizationContext());
|
|
1610
|
+
await ((_this$chainService$ma4 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma4 === void 0 ? void 0 : _this$chainService$ma4.loadAuthorizationContext(authContext));
|
|
1611
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
1612
|
+
const encryptedData = await passworder.encrypt(password, authContext);
|
|
1613
|
+
await this.chainService.mantaPay.saveMantaAuthContext({
|
|
1614
|
+
chain: _constants2._DEFAULT_MANTA_ZK_CHAIN,
|
|
1615
|
+
address,
|
|
1616
|
+
data: encryptedData
|
|
1617
|
+
});
|
|
1618
|
+
} else {
|
|
1619
|
+
var _this$chainService$ma5;
|
|
1620
|
+
const authContext = await this.chainService.mantaPay.getMantaAuthContext(address, _constants2._DEFAULT_MANTA_ZK_CHAIN);
|
|
1621
|
+
|
|
1622
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
1623
|
+
const decryptedData = await passworder.decrypt(password, authContext.data);
|
|
1624
|
+
|
|
1625
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
1626
|
+
const proofAuthKey = new Uint8Array(Object.values(decryptedData.proof_authorization_key));
|
|
1627
|
+
await ((_this$chainService$ma5 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma5 === void 0 ? void 0 : _this$chainService$ma5.loadAuthorizationContext({
|
|
1628
|
+
proof_authorization_key: proofAuthKey
|
|
1629
|
+
}));
|
|
1630
|
+
}
|
|
1631
|
+
const zkAddress = await ((_this$chainService$ma6 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma6 === void 0 ? void 0 : _this$chainService$ma6.getZkAddress());
|
|
1632
|
+
if (updateStore) {
|
|
1633
|
+
var _this$chainService$ma7, _this$chainService$ma8;
|
|
1634
|
+
await this.chainService.mantaPay.saveMantaPayConfig({
|
|
1635
|
+
address,
|
|
1636
|
+
zkAddress: zkAddress,
|
|
1637
|
+
enabled: true,
|
|
1638
|
+
chain: (_this$chainService$ma7 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma7 === void 0 ? void 0 : (_this$chainService$ma8 = _this$chainService$ma7.network) === null || _this$chainService$ma8 === void 0 ? void 0 : _this$chainService$ma8.toLowerCase(),
|
|
1639
|
+
isInitialSync: false
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
this.isMantaPayEnabled = true;
|
|
1643
|
+
return zkAddress;
|
|
1644
|
+
}
|
|
1645
|
+
async disableMantaPay(address) {
|
|
1646
|
+
var _this$chainService$ma9, _this$chainService$ma10;
|
|
1647
|
+
const config = await this.chainService.mantaPay.getMantaPayConfig(address, _constants2._DEFAULT_MANTA_ZK_CHAIN);
|
|
1648
|
+
if (!config) {
|
|
1649
|
+
return false;
|
|
1650
|
+
}
|
|
1651
|
+
await ((_this$chainService$ma9 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma9 === void 0 ? void 0 : _this$chainService$ma9.dropAuthorizationContext());
|
|
1652
|
+
await ((_this$chainService$ma10 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma10 === void 0 ? void 0 : _this$chainService$ma10.dropUserSeedPhrase());
|
|
1653
|
+
// await this.chainService.mantaPay.privateWallet?.resetState();
|
|
1654
|
+
await this.chainService.mantaPay.deleteMantaPayConfig(address, _constants2._DEFAULT_MANTA_ZK_CHAIN);
|
|
1655
|
+
await this.chainService.mantaPay.deleteMantaAuthContext(address, _constants2._DEFAULT_MANTA_ZK_CHAIN);
|
|
1656
|
+
this.chainService.setMantaZkAssetSettings(false);
|
|
1657
|
+
this.isMantaPayEnabled = false;
|
|
1658
|
+
return true;
|
|
1659
|
+
}
|
|
1660
|
+
async initialSyncMantaPay(address) {
|
|
1661
|
+
var _this$chainService$ma11, _this$chainService$ma12, _this$chainService$ma13;
|
|
1662
|
+
if (!address || (0, _utilCrypto.isEthereumAddress)(address)) {
|
|
1663
|
+
return;
|
|
1664
|
+
}
|
|
1665
|
+
this.chainService.mantaPay.setCurrentAddress(address);
|
|
1666
|
+
await ((_this$chainService$ma11 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma11 === void 0 ? void 0 : (_this$chainService$ma12 = _this$chainService$ma11.baseWallet) === null || _this$chainService$ma12 === void 0 ? void 0 : _this$chainService$ma12.isApiReady());
|
|
1667
|
+
const syncResult = await ((_this$chainService$ma13 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma13 === void 0 ? void 0 : _this$chainService$ma13.initialWalletSync());
|
|
1668
|
+
await this.chainService.mantaPay.updateMantaPayConfig(address, _constants2._DEFAULT_MANTA_ZK_CHAIN, {
|
|
1669
|
+
isInitialSync: true
|
|
1670
|
+
});
|
|
1671
|
+
this.eventService.emit('mantaPay.initSync', undefined);
|
|
1672
|
+
return syncResult;
|
|
1673
|
+
}
|
|
1674
|
+
getMantaZkBalance() {
|
|
1675
|
+
var _this$chainService, _this$chainService$ma14, _this$chainService$ma15, _this$chainService2, _this$chainService2$m, _this$chainService$ma16;
|
|
1676
|
+
if (!this.chainService || !this.chainService.mantaPay) {
|
|
1677
|
+
return;
|
|
1678
|
+
}
|
|
1679
|
+
if (!((_this$chainService = this.chainService) !== null && _this$chainService !== void 0 && (_this$chainService$ma14 = _this$chainService.mantaPay) !== null && _this$chainService$ma14 !== void 0 && (_this$chainService$ma15 = _this$chainService$ma14.privateWallet) !== null && _this$chainService$ma15 !== void 0 && _this$chainService$ma15.initialSyncIsFinished)) {
|
|
1680
|
+
return;
|
|
1681
|
+
}
|
|
1682
|
+
const chain = (_this$chainService2 = this.chainService) === null || _this$chainService2 === void 0 ? void 0 : (_this$chainService2$m = _this$chainService2.mantaPay.privateWallet) === null || _this$chainService2$m === void 0 ? void 0 : _this$chainService2$m.network;
|
|
1683
|
+
if (!chain) {
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
const assetMap = this.chainService.getMantaZkAssets(chain === null || chain === void 0 ? void 0 : chain.toLowerCase());
|
|
1687
|
+
(_this$chainService$ma16 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma16 === void 0 ? void 0 : _this$chainService$ma16.getMultiZkBalance(Object.values(assetMap).map(tokenInfo => new _util.BN((0, _utils._getTokenOnChainAssetId)(tokenInfo)))).then(zkBalances => {
|
|
1688
|
+
const assetList = Object.values(assetMap);
|
|
1689
|
+
for (let i = 0; i < assetList.length; i++) {
|
|
1690
|
+
var _zkBalances$i;
|
|
1691
|
+
const balanceItem = {
|
|
1692
|
+
tokenSlug: assetList[i].slug,
|
|
1693
|
+
state: _KoniTypes.APIItemState.PENDING,
|
|
1694
|
+
free: '0',
|
|
1695
|
+
locked: '0'
|
|
1696
|
+
};
|
|
1697
|
+
balanceItem.free = ((_zkBalances$i = zkBalances[i]) === null || _zkBalances$i === void 0 ? void 0 : _zkBalances$i.toString()) || '0';
|
|
1698
|
+
balanceItem.state = _KoniTypes.APIItemState.READY;
|
|
1699
|
+
this.setBalanceItem(balanceItem.tokenSlug, balanceItem);
|
|
1700
|
+
}
|
|
1701
|
+
}).catch(console.warn);
|
|
1702
|
+
}
|
|
1703
|
+
subscribeMantaPayBalance() {
|
|
1704
|
+
let interval;
|
|
1705
|
+
this.chainService.mantaPay.getMantaPayConfig(this.keyringService.currentAccount.address, _constants2._DEFAULT_MANTA_ZK_CHAIN).then(config => {
|
|
1706
|
+
if (config && config.enabled && config.isInitialSync) {
|
|
1707
|
+
this.getMantaZkBalance();
|
|
1708
|
+
interval = setInterval(this.getMantaZkBalance, _constants.MANTA_PAY_BALANCE_INTERVAL);
|
|
1709
|
+
}
|
|
1710
|
+
}).catch(console.warn);
|
|
1711
|
+
return () => {
|
|
1712
|
+
interval && clearInterval(interval);
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
async syncMantaPay() {
|
|
1716
|
+
var _this$chainService3, _this$chainService3$m, _this$chainService3$m2;
|
|
1717
|
+
const config = await this.chainService.mantaPay.getMantaPayFirstConfig(_constants2._DEFAULT_MANTA_ZK_CHAIN);
|
|
1718
|
+
if (!config.isInitialSync) {
|
|
1719
|
+
return;
|
|
1720
|
+
}
|
|
1721
|
+
if ((_this$chainService3 = this.chainService) !== null && _this$chainService3 !== void 0 && (_this$chainService3$m = _this$chainService3.mantaPay) !== null && _this$chainService3$m !== void 0 && (_this$chainService3$m2 = _this$chainService3$m.privateWallet) !== null && _this$chainService3$m2 !== void 0 && _this$chainService3$m2.initialSyncIsFinished) {
|
|
1722
|
+
var _this$chainService4, _this$chainService4$m, _this$chainService4$m2;
|
|
1723
|
+
await ((_this$chainService4 = this.chainService) === null || _this$chainService4 === void 0 ? void 0 : (_this$chainService4$m = _this$chainService4.mantaPay) === null || _this$chainService4$m === void 0 ? void 0 : (_this$chainService4$m2 = _this$chainService4$m.privateWallet) === null || _this$chainService4$m2 === void 0 ? void 0 : _this$chainService4$m2.walletSync());
|
|
1724
|
+
} else {
|
|
1725
|
+
var _this$chainService5, _this$chainService5$m, _this$chainService5$m2;
|
|
1726
|
+
await ((_this$chainService5 = this.chainService) === null || _this$chainService5 === void 0 ? void 0 : (_this$chainService5$m = _this$chainService5.mantaPay) === null || _this$chainService5$m === void 0 ? void 0 : (_this$chainService5$m2 = _this$chainService5$m.privateWallet) === null || _this$chainService5$m2 === void 0 ? void 0 : _this$chainService5$m2.initialWalletSync());
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
async getMantaPayZkBalance(address, tokenInfo) {
|
|
1730
|
+
var _this$chainService$ma17;
|
|
1731
|
+
const bnAssetId = new _util.BN((0, _utils._getTokenOnChainAssetId)(tokenInfo));
|
|
1732
|
+
const balance = await ((_this$chainService$ma17 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma17 === void 0 ? void 0 : _this$chainService$ma17.getZkBalance(bnAssetId));
|
|
1733
|
+
return {
|
|
1734
|
+
decimals: tokenInfo.decimals || 0,
|
|
1735
|
+
symbol: tokenInfo.symbol,
|
|
1736
|
+
value: (balance === null || balance === void 0 ? void 0 : balance.toString()) || '0'
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
subscribeMantaPaySyncState() {
|
|
1740
|
+
return this.chainService.mantaPay.subscribeSyncState();
|
|
1741
|
+
}
|
|
1570
1742
|
}
|
|
1571
1743
|
exports.default = KoniState;
|
|
@@ -158,12 +158,15 @@ class KoniSubscription {
|
|
|
158
158
|
const unsub = (0, _balance.subscribeBalance)(addresses, filteredChainInfoMap, substrateApiMap, evmApiMap, result => {
|
|
159
159
|
this.state.setBalanceItem(result.tokenSlug, result);
|
|
160
160
|
});
|
|
161
|
+
const unsub2 = this.state.subscribeMantaPayBalance();
|
|
161
162
|
if (onlyRunOnFirstTime) {
|
|
162
163
|
unsub && unsub();
|
|
164
|
+
unsub2 && unsub2();
|
|
163
165
|
return;
|
|
164
166
|
}
|
|
165
167
|
return () => {
|
|
166
168
|
unsub && unsub();
|
|
169
|
+
unsub2 && unsub2();
|
|
167
170
|
};
|
|
168
171
|
}
|
|
169
172
|
initCrowdloanSubscription(addresses, substrateApiMap, onlyRunOnFirstTime) {
|
package/cjs/packageInfo.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports._XCM_TYPE = exports._XCM_CHAIN_GROUP = exports._TRANSFER_NOT_SUPPORTED_CHAINS = exports._TRANSFER_CHAIN_GROUP = exports._SUBSTRATE_DEFAULT_INFLATION_PARAMS = exports._STAKING_ERA_LENGTH_MAP = exports._STAKING_CHAIN_GROUP = exports._PURE_EVM_CHAINS = exports._PREDEFINED_SINGLE_MODES = exports._PARACHAIN_INFLATION_DISTRIBUTION = exports._NFT_CHAIN_GROUP = exports._MULTI_CHAIN_ASSET_SRC = exports._KNOWN_CHAIN_INFLATION_PARAMS = exports._DEFAULT_ACTIVE_CHAINS = exports._CHAIN_LOGO_MAP_SRC = exports._CHAIN_INFO_SRC = exports._CHAIN_ASSET_SRC = exports._BALANCE_TOKEN_GROUP = exports._BALANCE_PARSING_CHAIN_GROUP = exports._BALANCE_CHAIN_GROUP = exports._ASSET_REF_SRC = exports._ASSET_LOGO_MAP_SRC = exports._API_OPTIONS_CHAIN_GROUP = exports.API_MAX_RETRY = exports.API_CONNECT_TIMEOUT = exports.API_AUTO_CONNECT_MS = void 0;
|
|
6
|
+
exports._ZK_ASSET_PREFIX = exports._XCM_TYPE = exports._XCM_CHAIN_GROUP = exports._TRANSFER_NOT_SUPPORTED_CHAINS = exports._TRANSFER_CHAIN_GROUP = exports._SUBSTRATE_DEFAULT_INFLATION_PARAMS = exports._STAKING_ERA_LENGTH_MAP = exports._STAKING_CHAIN_GROUP = exports._PURE_EVM_CHAINS = exports._PREDEFINED_SINGLE_MODES = exports._PARACHAIN_INFLATION_DISTRIBUTION = exports._NFT_CHAIN_GROUP = exports._MULTI_CHAIN_ASSET_SRC = exports._MANTA_ZK_CHAIN_GROUP = exports._KNOWN_CHAIN_INFLATION_PARAMS = exports._DEFAULT_MANTA_ZK_CHAIN = exports._DEFAULT_ACTIVE_CHAINS = exports._CHAIN_LOGO_MAP_SRC = exports._CHAIN_INFO_SRC = exports._CHAIN_ASSET_SRC = exports._BALANCE_TOKEN_GROUP = exports._BALANCE_PARSING_CHAIN_GROUP = exports._BALANCE_CHAIN_GROUP = exports._ASSET_REF_SRC = exports._ASSET_LOGO_MAP_SRC = exports._API_OPTIONS_CHAIN_GROUP = exports.API_MAX_RETRY = exports.API_CONNECT_TIMEOUT = exports.API_AUTO_CONNECT_MS = void 0;
|
|
7
7
|
var _chainList = require("@subwallet/chain-list");
|
|
8
8
|
var _types = require("@subwallet/chain-list/types");
|
|
9
9
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
@@ -38,7 +38,7 @@ const _BALANCE_CHAIN_GROUP = {
|
|
|
38
38
|
genshiro: ['genshiro_testnet', 'genshiro'],
|
|
39
39
|
equilibrium_parachain: ['equilibrium_parachain'],
|
|
40
40
|
bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main'],
|
|
41
|
-
statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel'],
|
|
41
|
+
statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari'],
|
|
42
42
|
kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'] // perhaps there are some runtime updates
|
|
43
43
|
};
|
|
44
44
|
exports._BALANCE_CHAIN_GROUP = _BALANCE_CHAIN_GROUP;
|
|
@@ -207,9 +207,15 @@ exports._TRANSFER_CHAIN_GROUP = _TRANSFER_CHAIN_GROUP;
|
|
|
207
207
|
const _BALANCE_PARSING_CHAIN_GROUP = {
|
|
208
208
|
bobabeam: ['bobabeam', 'bobabase']
|
|
209
209
|
};
|
|
210
|
+
exports._BALANCE_PARSING_CHAIN_GROUP = _BALANCE_PARSING_CHAIN_GROUP;
|
|
211
|
+
const _MANTA_ZK_CHAIN_GROUP = ['calamari'];
|
|
212
|
+
exports._MANTA_ZK_CHAIN_GROUP = _MANTA_ZK_CHAIN_GROUP;
|
|
213
|
+
const _ZK_ASSET_PREFIX = 'zk';
|
|
214
|
+
exports._ZK_ASSET_PREFIX = _ZK_ASSET_PREFIX;
|
|
215
|
+
const _DEFAULT_MANTA_ZK_CHAIN = 'calamari';
|
|
210
216
|
|
|
211
217
|
// XCM------------------------------------------------------------------------------------------------------------------
|
|
212
|
-
exports.
|
|
218
|
+
exports._DEFAULT_MANTA_ZK_CHAIN = _DEFAULT_MANTA_ZK_CHAIN;
|
|
213
219
|
const _XCM_CHAIN_GROUP = {
|
|
214
220
|
polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain'],
|
|
215
221
|
xcmPallet: ['polkadot', 'kusama']
|
|
@@ -228,7 +234,7 @@ const _DEFAULT_ACTIVE_CHAINS = [..._chainList._DEFAULT_CHAINS];
|
|
|
228
234
|
|
|
229
235
|
// TODO: review
|
|
230
236
|
exports._DEFAULT_ACTIVE_CHAINS = _DEFAULT_ACTIVE_CHAINS;
|
|
231
|
-
const TARGET_BRANCH = process.env.NODE_ENV !== 'production' ? 'koni-
|
|
237
|
+
const TARGET_BRANCH = process.env.NODE_ENV !== 'production' ? 'koni/dev/issue-15' : 'master';
|
|
232
238
|
const _CHAIN_INFO_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainInfo.json`;
|
|
233
239
|
exports._CHAIN_INFO_SRC = _CHAIN_INFO_SRC;
|
|
234
240
|
const _CHAIN_ASSET_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainAsset.json`;
|
|
@@ -75,6 +75,7 @@ class SubstrateApi {
|
|
|
75
75
|
}
|
|
76
76
|
constructor(chainSlug, apiUrl) {
|
|
77
77
|
let {
|
|
78
|
+
externalApiPromise,
|
|
78
79
|
metadata,
|
|
79
80
|
providerName
|
|
80
81
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
@@ -84,7 +85,7 @@ class SubstrateApi {
|
|
|
84
85
|
this.registry = new _create.TypeRegistry();
|
|
85
86
|
this.metadata = metadata;
|
|
86
87
|
this.provider = this.createProvider(apiUrl);
|
|
87
|
-
this.api = this.createApi(this.provider);
|
|
88
|
+
this.api = externalApiPromise || this.createApi(this.provider);
|
|
88
89
|
this.handleApiReady = (0, _promise.createPromiseHandler)();
|
|
89
90
|
this.api.on('ready', this.onReady.bind(this));
|
|
90
91
|
this.api.on('connected', this.onConnect.bind(this));
|
|
@@ -182,6 +182,7 @@ class SubstrateChainHandler extends _AbstractChainHandler.AbstractChainHandler {
|
|
|
182
182
|
async initApi(chainSlug, apiUrl) {
|
|
183
183
|
var _this$parent2;
|
|
184
184
|
let {
|
|
185
|
+
externalApiPromise,
|
|
185
186
|
onUpdateStatus,
|
|
186
187
|
providerName
|
|
187
188
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
@@ -198,7 +199,8 @@ class SubstrateChainHandler extends _AbstractChainHandler.AbstractChainHandler {
|
|
|
198
199
|
const metadata = await ((_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.getMetadata(chainSlug));
|
|
199
200
|
const apiObject = new _SubstrateApi2.SubstrateApi(chainSlug, apiUrl, {
|
|
200
201
|
providerName,
|
|
201
|
-
metadata
|
|
202
|
+
metadata,
|
|
203
|
+
externalApiPromise
|
|
202
204
|
});
|
|
203
205
|
apiObject.isApiConnectedSubject.subscribe(this.handleConnect.bind(this, chainSlug));
|
|
204
206
|
onUpdateStatus && apiObject.isApiConnectedSubject.subscribe(onUpdateStatus);
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MantaPrivateHandler = void 0;
|
|
7
|
+
var _mantaExtensionSdk = require("manta-extension-sdk");
|
|
8
|
+
var _rxjs = require("rxjs");
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
class MantaPrivateHandler {
|
|
13
|
+
_privateWallet = undefined;
|
|
14
|
+
syncStateSubject = new _rxjs.Subject();
|
|
15
|
+
constructor(dbService) {
|
|
16
|
+
this.dbService = dbService;
|
|
17
|
+
this.syncState = {
|
|
18
|
+
isSyncing: false,
|
|
19
|
+
progress: 0
|
|
20
|
+
};
|
|
21
|
+
this.syncStateSubject.next(this.syncState);
|
|
22
|
+
}
|
|
23
|
+
setCurrentAddress(address) {
|
|
24
|
+
this.currentAddress = address;
|
|
25
|
+
}
|
|
26
|
+
getSyncState() {
|
|
27
|
+
return this.syncState;
|
|
28
|
+
}
|
|
29
|
+
get privateWallet() {
|
|
30
|
+
return this._privateWallet;
|
|
31
|
+
}
|
|
32
|
+
subscribeSyncState() {
|
|
33
|
+
return this.syncStateSubject;
|
|
34
|
+
}
|
|
35
|
+
async updateMantaPayConfig(address, chain, changes) {
|
|
36
|
+
await this.dbService.updateMantaPayData(`config_${chain}_${address}`, changes);
|
|
37
|
+
}
|
|
38
|
+
async saveMantaPayConfig(config) {
|
|
39
|
+
await this.dbService.setMantaPayData({
|
|
40
|
+
key: `config_${config.chain}_${config.address}`,
|
|
41
|
+
...config
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async getMantaPayConfig(address, chain) {
|
|
45
|
+
return this.dbService.getMantaPayData(`config_${chain}_${address}`);
|
|
46
|
+
}
|
|
47
|
+
async getMantaPayFirstConfig(chain) {
|
|
48
|
+
return this.dbService.getMantaPayFirstConfig(chain);
|
|
49
|
+
}
|
|
50
|
+
async deleteMantaPayConfig(address, chain) {
|
|
51
|
+
return this.dbService.deleteMantaPayConfig(`config_${chain}_${address}`);
|
|
52
|
+
}
|
|
53
|
+
async saveMantaAuthContext(context) {
|
|
54
|
+
await this.dbService.setMantaPayData({
|
|
55
|
+
key: `authContext_${context.chain}_${context.address}`,
|
|
56
|
+
...context
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async getMantaAuthContext(address, chain) {
|
|
60
|
+
return this.dbService.getMantaPayData(`authContext_${chain}_${address}`);
|
|
61
|
+
}
|
|
62
|
+
async deleteMantaAuthContext(address, chain) {
|
|
63
|
+
return this.dbService.deleteMantaPayConfig(`authContext_${chain}_${address}`);
|
|
64
|
+
}
|
|
65
|
+
async saveLedgerState(palletName, network, data) {
|
|
66
|
+
try {
|
|
67
|
+
const suffix = this.currentAddress ? `_${this.currentAddress}` : '';
|
|
68
|
+
await this.dbService.setMantaPayData({
|
|
69
|
+
key: `storage_state_${palletName}_${network}${suffix}`,
|
|
70
|
+
...data
|
|
71
|
+
});
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.error('manta-pay', e);
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
async getLedgerState(palletName, network) {
|
|
79
|
+
let result;
|
|
80
|
+
try {
|
|
81
|
+
const suffix = this.currentAddress ? `_${this.currentAddress}` : '';
|
|
82
|
+
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
84
|
+
result = await this.dbService.getMantaPayData(`storage_state_${palletName}_${network}${suffix}`);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.error(e);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
90
|
+
return result || null;
|
|
91
|
+
}
|
|
92
|
+
async initMantaPay(providerUrl, network) {
|
|
93
|
+
const networkParam = network.charAt(0).toUpperCase() + network.slice(1); // Manta || Calamari || Dolphin
|
|
94
|
+
|
|
95
|
+
const baseWallet = await _mantaExtensionSdk.BaseWallet.init({
|
|
96
|
+
apiEndpoint: providerUrl,
|
|
97
|
+
loggingEnabled: false,
|
|
98
|
+
provingFilePath: './manta-pay/proving',
|
|
99
|
+
parametersFilePath: './manta-pay/parameters',
|
|
100
|
+
saveStorageStateToLocal: this.saveLedgerState.bind(this),
|
|
101
|
+
getStorageStateFromLocal: this.getLedgerState.bind(this)
|
|
102
|
+
});
|
|
103
|
+
this._privateWallet = _mantaExtensionSdk.MantaPayWallet.init(networkParam, baseWallet);
|
|
104
|
+
return this._privateWallet.api;
|
|
105
|
+
}
|
|
106
|
+
async getCurrentLedgerState() {
|
|
107
|
+
var _this$_privateWallet;
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
109
|
+
const ledgerState = await this.getLedgerState('mantaPay', 'Calamari');
|
|
110
|
+
if (!ledgerState) {
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
115
|
+
return await ((_this$_privateWallet = this._privateWallet) === null || _this$_privateWallet === void 0 ? void 0 : _this$_privateWallet.getLedgerCurrentCount(ledgerState.checkpoint));
|
|
116
|
+
}
|
|
117
|
+
setSyncState(data) {
|
|
118
|
+
this.syncState = data;
|
|
119
|
+
this.syncStateSubject.next(this.syncState);
|
|
120
|
+
}
|
|
121
|
+
async subscribeSyncProgress() {
|
|
122
|
+
var _this$_privateWallet2;
|
|
123
|
+
const ledgerTotalCount = await ((_this$_privateWallet2 = this._privateWallet) === null || _this$_privateWallet2 === void 0 ? void 0 : _this$_privateWallet2.getLedgerTotalCount());
|
|
124
|
+
const interval = setInterval(() => {
|
|
125
|
+
this.getCurrentLedgerState().then(currentCount => {
|
|
126
|
+
const progress = Math.floor(currentCount / ledgerTotalCount * 100);
|
|
127
|
+
if (progress === 100) {
|
|
128
|
+
this.syncState = {
|
|
129
|
+
isSyncing: false,
|
|
130
|
+
progress
|
|
131
|
+
};
|
|
132
|
+
clearInterval(interval);
|
|
133
|
+
} else {
|
|
134
|
+
this.syncState = {
|
|
135
|
+
isSyncing: true,
|
|
136
|
+
progress
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
this.syncStateSubject.next(this.syncState);
|
|
140
|
+
}).catch(console.error);
|
|
141
|
+
}, 1000);
|
|
142
|
+
return () => {
|
|
143
|
+
interval && clearInterval(interval);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.MantaPrivateHandler = MantaPrivateHandler;
|