@subwallet/extension-base 1.1.25-0 → 1.1.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 +2 -2
- package/background/handlers/State.js +3 -2
- package/cjs/background/handlers/State.js +3 -2
- package/cjs/constants/staking.js +4 -2
- package/cjs/koni/api/dotsama/transfer.js +2 -2
- package/cjs/koni/api/nft/config.js +2 -1
- package/cjs/koni/api/staking/bonding/relayChain.js +48 -25
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/background/handlers/Extension.js +11 -8
- package/cjs/koni/background/handlers/Mobile.js +81 -5
- package/cjs/koni/background/handlers/State.js +45 -117
- package/cjs/koni/background/subscription.js +2 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/BalanceMapImpl.js +114 -0
- package/cjs/services/campaign-service/index.js +2 -0
- package/cjs/services/chain-service/constants.js +24 -3
- package/cjs/services/event-service/index.js +7 -7
- package/cjs/services/event-service/types.js +1 -1
- package/cjs/services/history-service/index.js +1 -0
- package/cjs/services/keyring-service/index.js +10 -6
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.js +16 -0
- package/cjs/services/migration-service/scripts/tokens/MigrateToken.js +33 -0
- package/cjs/services/setting-service/SettingService.js +2 -1
- package/cjs/services/setting-service/i18n/i18n.js +2 -1
- package/cjs/services/storage-service/DatabaseService.js +8 -19
- package/cjs/services/storage-service/db-stores/Balance.js +4 -13
- package/cjs/services/wallet-connect-service/index.js +6 -3
- package/cjs/storage/index.js +59 -0
- package/cjs/utils/array.js +27 -1
- package/constants/staking.d.ts +1 -0
- package/constants/staking.js +2 -1
- package/koni/api/dotsama/transfer.js +2 -2
- package/koni/api/nft/config.js +2 -1
- package/koni/api/staking/bonding/relayChain.js +40 -17
- package/koni/api/xcm/xTokens.js +1 -1
- package/koni/background/handlers/Extension.js +11 -8
- package/koni/background/handlers/Mobile.d.ts +6 -0
- package/koni/background/handlers/Mobile.js +75 -3
- package/koni/background/handlers/State.d.ts +7 -8
- package/koni/background/handlers/State.js +34 -104
- package/koni/background/subscription.js +2 -2
- package/package.json +40 -20
- package/packageInfo.js +1 -1
- package/services/balance-service/BalanceMapImpl.d.ts +17 -0
- package/services/balance-service/BalanceMapImpl.js +104 -0
- package/services/campaign-service/index.d.ts +1 -0
- package/services/campaign-service/index.js +2 -0
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +22 -2
- package/services/event-service/index.d.ts +1 -4
- package/services/event-service/index.js +8 -7
- package/services/event-service/types.js +1 -1
- package/services/history-service/index.js +1 -0
- package/services/keyring-service/index.js +10 -6
- package/services/migration-service/scripts/index.js +3 -1
- package/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.d.ts +5 -0
- package/services/migration-service/scripts/tokens/MigratePolygonUSDCProvider.js +8 -0
- package/services/migration-service/scripts/tokens/MigrateToken.d.ts +9 -0
- package/services/migration-service/scripts/tokens/MigrateToken.js +26 -0
- package/services/setting-service/SettingService.js +2 -1
- package/services/setting-service/i18n/i18n.js +2 -1
- package/services/storage-service/DatabaseService.d.ts +3 -1
- package/services/storage-service/DatabaseService.js +7 -19
- package/services/storage-service/db-stores/Balance.d.ts +3 -2
- package/services/storage-service/db-stores/Balance.js +4 -13
- package/services/wallet-connect-service/index.js +5 -3
- package/storage/index.d.ts +14 -0
- package/storage/index.js +52 -0
- package/utils/array.d.ts +1 -0
- package/utils/array.js +26 -1
|
@@ -12,7 +12,7 @@ import { KeyringPair$Json, KeyringPair$Meta } from '@subwallet/keyring/types';
|
|
|
12
12
|
import { KeyringOptions } from '@subwallet/ui-keyring/options/types';
|
|
13
13
|
import { KeyringAddress, KeyringPairs$Json } from '@subwallet/ui-keyring/types';
|
|
14
14
|
import { SessionTypes } from '@walletconnect/types/dist/types/sign-client/session';
|
|
15
|
-
import {
|
|
15
|
+
import { DexieExportJsonStructure } from 'dexie-export-import';
|
|
16
16
|
import Web3 from 'web3';
|
|
17
17
|
import { RequestArguments, TransactionConfig } from 'web3-core';
|
|
18
18
|
import { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers';
|
|
@@ -1784,7 +1784,7 @@ export interface KoniRequestSignatures {
|
|
|
1784
1784
|
'pri(buyService.services.subscribe)': [null, Record<string, BuyServiceInfo>, Record<string, BuyServiceInfo>];
|
|
1785
1785
|
'pri(database.export)': [null, string];
|
|
1786
1786
|
'pri(database.import)': [string, boolean];
|
|
1787
|
-
'pri(database.
|
|
1787
|
+
'pri(database.exportJson)': [null, DexieExportJsonStructure];
|
|
1788
1788
|
}
|
|
1789
1789
|
export interface ApplicationMetadataType {
|
|
1790
1790
|
version: string;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { DEFAULT_SETTING } from '@subwallet/extension-base/services/setting-service/constants';
|
|
5
|
+
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
5
6
|
import SettingsStore from '@subwallet/extension-base/stores/Settings';
|
|
6
7
|
import { stripUrl } from '@subwallet/extension-base/utils';
|
|
7
8
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
@@ -92,7 +93,7 @@ export default class State {
|
|
|
92
93
|
extractMetadata(this.#metaStore);
|
|
93
94
|
|
|
94
95
|
// retrieve previously set authorizations
|
|
95
|
-
const authString =
|
|
96
|
+
const authString = SWStorage.instance.getItem(AUTH_URLS_KEY) || '{}';
|
|
96
97
|
const previousAuth = JSON.parse(authString);
|
|
97
98
|
this.#authUrls = previousAuth;
|
|
98
99
|
}
|
|
@@ -231,7 +232,7 @@ export default class State {
|
|
|
231
232
|
};
|
|
232
233
|
};
|
|
233
234
|
saveCurrentAuthList() {
|
|
234
|
-
|
|
235
|
+
SWStorage.instance.setItem(AUTH_URLS_KEY, JSON.stringify(this.#authUrls));
|
|
235
236
|
}
|
|
236
237
|
metaComplete = (id, resolve, reject) => {
|
|
237
238
|
const complete = () => {
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = exports.NotificationOptions = void 0;
|
|
8
8
|
var _constants = require("@subwallet/extension-base/services/setting-service/constants");
|
|
9
|
+
var _storage = require("@subwallet/extension-base/storage");
|
|
9
10
|
var _Settings = _interopRequireDefault(require("@subwallet/extension-base/stores/Settings"));
|
|
10
11
|
var _utils = require("@subwallet/extension-base/utils");
|
|
11
12
|
var _getId = require("@subwallet/extension-base/utils/getId");
|
|
@@ -108,7 +109,7 @@ class State {
|
|
|
108
109
|
extractMetadata(this.#metaStore);
|
|
109
110
|
|
|
110
111
|
// retrieve previously set authorizations
|
|
111
|
-
const authString =
|
|
112
|
+
const authString = _storage.SWStorage.instance.getItem(AUTH_URLS_KEY) || '{}';
|
|
112
113
|
const previousAuth = JSON.parse(authString);
|
|
113
114
|
this.#authUrls = previousAuth;
|
|
114
115
|
}
|
|
@@ -257,7 +258,7 @@ class State {
|
|
|
257
258
|
};
|
|
258
259
|
};
|
|
259
260
|
saveCurrentAuthList() {
|
|
260
|
-
|
|
261
|
+
_storage.SWStorage.instance.setItem(AUTH_URLS_KEY, JSON.stringify(this.#authUrls));
|
|
261
262
|
}
|
|
262
263
|
metaComplete = (id, resolve, reject) => {
|
|
263
264
|
const complete = () => {
|
package/cjs/constants/staking.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.PREDEFINED_STAKING_POOL = void 0;
|
|
6
|
+
exports.PREDEFINED_STAKING_POOL = exports.MAX_NOMINATIONS = void 0;
|
|
7
7
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
|
|
@@ -12,4 +12,6 @@ const PREDEFINED_STAKING_POOL = {
|
|
|
12
12
|
polkadot: 39,
|
|
13
13
|
vara_network: 29
|
|
14
14
|
};
|
|
15
|
-
exports.PREDEFINED_STAKING_POOL = PREDEFINED_STAKING_POOL;
|
|
15
|
+
exports.PREDEFINED_STAKING_POOL = PREDEFINED_STAKING_POOL;
|
|
16
|
+
const MAX_NOMINATIONS = '16';
|
|
17
|
+
exports.MAX_NOMINATIONS = MAX_NOMINATIONS;
|
|
@@ -164,9 +164,9 @@ const createTransferExtrinsic = async _ref => {
|
|
|
164
164
|
}
|
|
165
165
|
} else if (_constants._TRANSFER_CHAIN_GROUP.pendulum.includes(networkKey) && isTxTokensSupported && !(0, _utils2._isNativeToken)(tokenInfo)) {
|
|
166
166
|
if (transferAll) {
|
|
167
|
-
transfer = api.tx.tokens.transferAll(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), false);
|
|
167
|
+
transfer = api.tx.tokens.transferAll(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo), false);
|
|
168
168
|
} else if (value) {
|
|
169
|
-
transfer = api.tx.tokens.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), new _util.BN(value));
|
|
169
|
+
transfer = api.tx.tokens.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo), new _util.BN(value));
|
|
170
170
|
}
|
|
171
171
|
} else if (_constants._TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey)
|
|
172
172
|
// && isTxEqBalancesSupported
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.W3S_IPFS = exports.VARA_SCAN_ENDPOINT = exports.UNIQUE_SCAN_ENDPOINT = exports.UNIQUE_IPFS_GATEWAY = exports.TRANSFER_CHAIN_ID = exports.SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME = exports.SUPPORTED_TRANSFER_EVM_CHAIN_NAME = exports.SUPPORTED_TRANSFER_EVM_CHAIN = exports.SUPPORTED_NFT_NETWORKS = exports.SUBWALLET_IPFS = exports.SINGULAR_V2_ENDPOINT = exports.SINGULAR_V2_COLLECTION_ENDPOINT = exports.SINGULAR_V1_ENDPOINT = exports.SINGULAR_V1_COLLECTION_ENDPOINT = exports.RMRK_PINATA_SERVER = exports.QUARTZ_SCAN_ENDPOINT = exports.PINATA_IPFS_GATEWAY = exports.NFT_STORAGE_GATEWAY = exports.KANARIA_EXTERNAL_SERVER = exports.KANARIA_ENDPOINT = exports.IPFS_W3S_LINK = exports.IPFS_IO = exports.IPFS_GATEWAY_4EVERLAND = exports.IPFS_FLEEK = exports.IPFS_ETH_ARAGON = exports.IPFS2_RMRK = exports.GATEWAY_IPFS_IO = exports.DWEB_LINK = exports.CLOUDFLARE_PINATA_SERVER = exports.CF_IPFS_GATEWAY = exports.BIT_COUNTRY_THUMBNAIL_RESOLVER = exports.BIT_COUNTRY_LAND_ESTATE_METADATA_API = exports.BIT_COUNTRY_IPFS_SERVER = void 0;
|
|
8
8
|
exports.getRandomIpfsGateway = getRandomIpfsGateway;
|
|
9
|
+
var _storage = require("@subwallet/extension-base/storage");
|
|
9
10
|
var _utils = require("@subwallet/extension-base/utils");
|
|
10
11
|
var _bowser = _interopRequireDefault(require("bowser"));
|
|
11
12
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
@@ -70,7 +71,7 @@ exports.IPFS_ETH_ARAGON = IPFS_ETH_ARAGON;
|
|
|
70
71
|
const SUBWALLET_IPFS = 'https://ipfs.subwallet.app/ipfs/'; // ???
|
|
71
72
|
exports.SUBWALLET_IPFS = SUBWALLET_IPFS;
|
|
72
73
|
const detectFirefox = () => {
|
|
73
|
-
return (
|
|
74
|
+
return (_storage.SWStorage.instance.getItem('browserInfo') || _bowser.default.getParser(window.navigator.userAgent).getBrowserName()).toLowerCase() === 'firefox';
|
|
74
75
|
};
|
|
75
76
|
const isFirefox = detectFirefox();
|
|
76
77
|
let SUPPORTED_NFT_NETWORKS;
|
|
@@ -25,8 +25,9 @@ exports.validateRelayBondingCondition = validateRelayBondingCondition;
|
|
|
25
25
|
exports.validateRelayUnbondingCondition = validateRelayUnbondingCondition;
|
|
26
26
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
27
27
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
28
|
+
var _constants = require("@subwallet/extension-base/constants");
|
|
28
29
|
var _utils = require("@subwallet/extension-base/koni/api/staking/bonding/utils");
|
|
29
|
-
var
|
|
30
|
+
var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
|
|
30
31
|
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
31
32
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
32
33
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
@@ -105,7 +106,7 @@ function subscribeRelayChainStakingMetadata(chainInfo, substrateApi, callback) {
|
|
|
105
106
|
return substrateApi.api.query.staking.currentEra(async _currentEra => {
|
|
106
107
|
var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$que, _substrateApi$api$que2, _substrateApi$api$que3, _substrateApi$api$que4, _substrateApi$api$que5, _substrateApi$api$que6, _substrateApi$api$que7;
|
|
107
108
|
const currentEra = _currentEra.toString();
|
|
108
|
-
const maxNominations = ((_substrateApi$api$con = substrateApi.api.consts.staking) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.maxNominations) === null || _substrateApi$api$con2 === void 0 ? void 0 : _substrateApi$api$con2.toString()) ||
|
|
109
|
+
const maxNominations = ((_substrateApi$api$con = substrateApi.api.consts.staking) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.maxNominations) === null || _substrateApi$api$con2 === void 0 ? void 0 : _substrateApi$api$con2.toString()) || _constants.MAX_NOMINATIONS; // TODO
|
|
109
110
|
const maxUnlockingChunks = substrateApi.api.consts.staking.maxUnlockingChunks.toString();
|
|
110
111
|
const unlockingEras = substrateApi.api.consts.staking.bondingDuration.toString();
|
|
111
112
|
const [_totalEraStake, _totalIssuance, _auctionCounter, _minNominatorBond, _minPoolJoin, _minimumActiveStake] = await Promise.all([substrateApi.api.query.staking.erasTotalStake(parseInt(currentEra)), substrateApi.api.query.balances.totalIssuance(), (_substrateApi$api$que = substrateApi.api.query.auctions) === null || _substrateApi$api$que === void 0 ? void 0 : _substrateApi$api$que.auctionCounter(), substrateApi.api.query.staking.minNominatorBond(), (_substrateApi$api$que2 = substrateApi.api.query) === null || _substrateApi$api$que2 === void 0 ? void 0 : (_substrateApi$api$que3 = _substrateApi$api$que2.nominationPools) === null || _substrateApi$api$que3 === void 0 ? void 0 : _substrateApi$api$que3.minJoinBond(), ((_substrateApi$api$que4 = substrateApi.api.query) === null || _substrateApi$api$que4 === void 0 ? void 0 : (_substrateApi$api$que5 = _substrateApi$api$que4.staking) === null || _substrateApi$api$que5 === void 0 ? void 0 : _substrateApi$api$que5.minimumActiveStake) && ((_substrateApi$api$que6 = substrateApi.api.query) === null || _substrateApi$api$que6 === void 0 ? void 0 : (_substrateApi$api$que7 = _substrateApi$api$que6.staking) === null || _substrateApi$api$que7 === void 0 ? void 0 : _substrateApi$api$que7.minimumActiveStake())]);
|
|
@@ -122,12 +123,12 @@ function subscribeRelayChainStakingMetadata(chainInfo, substrateApi, callback) {
|
|
|
122
123
|
const inflation = (0, _utils.calculateInflation)(bnTotalEraStake, bnTotalIssuance, numAuctions, chainInfo.slug);
|
|
123
124
|
const expectedReturn = (0, _utils.calculateChainStakedReturn)(inflation, bnTotalEraStake, bnTotalIssuance, chainInfo.slug);
|
|
124
125
|
const minPoolJoin = (_minPoolJoin === null || _minPoolJoin === void 0 ? void 0 : _minPoolJoin.toString()) || undefined;
|
|
125
|
-
const unlockingPeriod = parseInt(unlockingEras) * (
|
|
126
|
+
const unlockingPeriod = parseInt(unlockingEras) * (_constants2._STAKING_ERA_LENGTH_MAP[chainInfo.slug] || _constants2._STAKING_ERA_LENGTH_MAP.default); // in hours
|
|
126
127
|
|
|
127
128
|
callback(chainInfo.slug, {
|
|
128
129
|
chain: chainInfo.slug,
|
|
129
130
|
type: _KoniTypes.StakingType.NOMINATED,
|
|
130
|
-
expectedReturn: !
|
|
131
|
+
expectedReturn: !_constants2._STAKING_CHAIN_GROUP.ternoa.includes(chainInfo.slug) ? expectedReturn : undefined,
|
|
131
132
|
// in %, annually
|
|
132
133
|
inflation,
|
|
133
134
|
era: parseInt(currentEra),
|
|
@@ -177,13 +178,13 @@ async function getRelayChainStakingMetadata(chainInfo, substrateApi) {
|
|
|
177
178
|
const bnTotalIssuance = new _util.BN(rawTotalIssuance);
|
|
178
179
|
const inflation = (0, _utils.calculateInflation)(bnTotalEraStake, bnTotalIssuance, numAuctions, chain);
|
|
179
180
|
const expectedReturn = (0, _utils.calculateChainStakedReturn)(inflation, bnTotalEraStake, bnTotalIssuance, chain);
|
|
180
|
-
const unlockingPeriod = parseInt(unlockingEras) *
|
|
181
|
+
const unlockingPeriod = parseInt(unlockingEras) * _constants2._STAKING_ERA_LENGTH_MAP[chain]; // in hours
|
|
181
182
|
|
|
182
183
|
return {
|
|
183
184
|
chain,
|
|
184
185
|
type: _KoniTypes.StakingType.NOMINATED,
|
|
185
186
|
era: parseInt(currentEra),
|
|
186
|
-
expectedReturn: !
|
|
187
|
+
expectedReturn: !_constants2._STAKING_CHAIN_GROUP.ternoa.includes(chain) ? expectedReturn : undefined,
|
|
187
188
|
// in %, annually
|
|
188
189
|
inflation,
|
|
189
190
|
minStake: minStake.toString(),
|
|
@@ -196,16 +197,17 @@ async function getRelayChainStakingMetadata(chainInfo, substrateApi) {
|
|
|
196
197
|
};
|
|
197
198
|
}
|
|
198
199
|
async function subscribeRelayChainNominatorMetadata(chainInfo, address, substrateApi, ledger) {
|
|
199
|
-
var _chainApi$api$query4, _chainApi$api$query4$, _chainApi$api$query5, _chainApi$api$query5$, _chainApi$api$query6, _chainApi$api$query6$, _chainApi$api$query7, _chainApi$api$query7$, _chainApi$api$query8, _chainApi$api$query8$, _chainApi$api$query9, _chainApi$api$query9$;
|
|
200
|
+
var _chainApi$api$query4, _chainApi$api$query4$, _chainApi$api$query5, _chainApi$api$query5$, _chainApi$api$query6, _chainApi$api$query6$, _chainApi$api$query7, _chainApi$api$query7$, _chainApi$api$query8, _chainApi$api$query8$, _chainApi$api$query9, _chainApi$api$query9$, _chainApi$api$derive, _chainApi$api$derive$;
|
|
200
201
|
const chain = chainInfo.slug;
|
|
201
202
|
const chainApi = await substrateApi.isReady;
|
|
202
|
-
const [_nominations, _currentEra, _bonded, _minimumActiveStake, _minNominatorBond] = await Promise.all([(_chainApi$api$query4 = chainApi.api.query) === null || _chainApi$api$query4 === void 0 ? void 0 : (_chainApi$api$query4$ = _chainApi$api$query4.staking) === null || _chainApi$api$query4$ === void 0 ? void 0 : _chainApi$api$query4$.nominators(address), (_chainApi$api$query5 = chainApi.api.query) === null || _chainApi$api$query5 === void 0 ? void 0 : (_chainApi$api$query5$ = _chainApi$api$query5.staking) === null || _chainApi$api$query5$ === void 0 ? void 0 : _chainApi$api$query5$.currentEra(), (_chainApi$api$query6 = chainApi.api.query) === null || _chainApi$api$query6 === void 0 ? void 0 : (_chainApi$api$query6$ = _chainApi$api$query6.staking) === null || _chainApi$api$query6$ === void 0 ? void 0 : _chainApi$api$query6$.bonded(address), ((_chainApi$api$query7 = chainApi.api.query) === null || _chainApi$api$query7 === void 0 ? void 0 : (_chainApi$api$query7$ = _chainApi$api$query7.staking) === null || _chainApi$api$query7$ === void 0 ? void 0 : _chainApi$api$query7$.minimumActiveStake) && ((_chainApi$api$query8 = chainApi.api.query) === null || _chainApi$api$query8 === void 0 ? void 0 : (_chainApi$api$query8$ = _chainApi$api$query8.staking) === null || _chainApi$api$query8$ === void 0 ? void 0 : _chainApi$api$query8$.minimumActiveStake()), (_chainApi$api$query9 = chainApi.api.query) === null || _chainApi$api$query9 === void 0 ? void 0 : (_chainApi$api$query9$ = _chainApi$api$query9.staking) === null || _chainApi$api$query9$ === void 0 ? void 0 : _chainApi$api$query9$.minNominatorBond()]);
|
|
203
|
+
const [_nominations, _currentEra, _bonded, _minimumActiveStake, _minNominatorBond, _deriveSessionProgress] = await Promise.all([(_chainApi$api$query4 = chainApi.api.query) === null || _chainApi$api$query4 === void 0 ? void 0 : (_chainApi$api$query4$ = _chainApi$api$query4.staking) === null || _chainApi$api$query4$ === void 0 ? void 0 : _chainApi$api$query4$.nominators(address), (_chainApi$api$query5 = chainApi.api.query) === null || _chainApi$api$query5 === void 0 ? void 0 : (_chainApi$api$query5$ = _chainApi$api$query5.staking) === null || _chainApi$api$query5$ === void 0 ? void 0 : _chainApi$api$query5$.currentEra(), (_chainApi$api$query6 = chainApi.api.query) === null || _chainApi$api$query6 === void 0 ? void 0 : (_chainApi$api$query6$ = _chainApi$api$query6.staking) === null || _chainApi$api$query6$ === void 0 ? void 0 : _chainApi$api$query6$.bonded(address), ((_chainApi$api$query7 = chainApi.api.query) === null || _chainApi$api$query7 === void 0 ? void 0 : (_chainApi$api$query7$ = _chainApi$api$query7.staking) === null || _chainApi$api$query7$ === void 0 ? void 0 : _chainApi$api$query7$.minimumActiveStake) && ((_chainApi$api$query8 = chainApi.api.query) === null || _chainApi$api$query8 === void 0 ? void 0 : (_chainApi$api$query8$ = _chainApi$api$query8.staking) === null || _chainApi$api$query8$ === void 0 ? void 0 : _chainApi$api$query8$.minimumActiveStake()), (_chainApi$api$query9 = chainApi.api.query) === null || _chainApi$api$query9 === void 0 ? void 0 : (_chainApi$api$query9$ = _chainApi$api$query9.staking) === null || _chainApi$api$query9$ === void 0 ? void 0 : _chainApi$api$query9$.minNominatorBond(), (_chainApi$api$derive = chainApi.api.derive) === null || _chainApi$api$derive === void 0 ? void 0 : (_chainApi$api$derive$ = _chainApi$api$derive.session) === null || _chainApi$api$derive$ === void 0 ? void 0 : _chainApi$api$derive$.progress()]);
|
|
203
204
|
const minActiveStake = (_minimumActiveStake === null || _minimumActiveStake === void 0 ? void 0 : _minimumActiveStake.toString()) || '0';
|
|
204
205
|
const minNominatorBond = _minNominatorBond.toString();
|
|
205
206
|
const bnMinActiveStake = new _util.BN(minActiveStake);
|
|
206
207
|
const bnMinNominatorBond = new _util.BN(minNominatorBond);
|
|
207
208
|
const minStake = bnMinActiveStake.gt(bnMinNominatorBond) ? bnMinActiveStake : bnMinNominatorBond;
|
|
208
|
-
const
|
|
209
|
+
const unlimitedNominatorRewarded = chainApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
210
|
+
const _maxNominatorRewardedPerValidator = (chainApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
209
211
|
const maxNominatorRewardedPerValidator = parseInt(_maxNominatorRewardedPerValidator);
|
|
210
212
|
const nominations = _nominations.toPrimitive();
|
|
211
213
|
const currentEra = _currentEra.toString();
|
|
@@ -228,7 +230,7 @@ async function subscribeRelayChainNominatorMetadata(chainInfo, address, substrat
|
|
|
228
230
|
if (!topNominators.includes((0, _utils3.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
229
231
|
// if nominator has target but not in nominator list
|
|
230
232
|
nominationStatus = _KoniTypes.StakingStatus.WAITING;
|
|
231
|
-
} else if (topNominators.slice(0, maxNominatorRewardedPerValidator).includes((0, _utils3.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
233
|
+
} else if (topNominators.slice(0, unlimitedNominatorRewarded ? undefined : maxNominatorRewardedPerValidator).includes((0, _utils3.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
232
234
|
// if address in top nominators
|
|
233
235
|
nominationStatus = _KoniTypes.StakingStatus.EARNING_REWARD;
|
|
234
236
|
}
|
|
@@ -259,9 +261,17 @@ async function subscribeRelayChainNominatorMetadata(chainInfo, address, substrat
|
|
|
259
261
|
}
|
|
260
262
|
}
|
|
261
263
|
ledger.unlocking.forEach(unlockingChunk => {
|
|
264
|
+
// Calculate the remaining era
|
|
262
265
|
const isClaimable = unlockingChunk.era - parseInt(currentEra) < 0;
|
|
263
266
|
const remainingEra = unlockingChunk.era - parseInt(currentEra);
|
|
264
|
-
|
|
267
|
+
|
|
268
|
+
// Calculate the remaining time for current era ending
|
|
269
|
+
const expectedBlockTime = _constants2._EXPECTED_BLOCK_TIME[chain];
|
|
270
|
+
const eraLength = _deriveSessionProgress.eraLength.toNumber();
|
|
271
|
+
const eraProgress = _deriveSessionProgress.eraProgress.toNumber();
|
|
272
|
+
const remainingSlots = eraLength - eraProgress;
|
|
273
|
+
const remainingHours = expectedBlockTime * remainingSlots / 60 / 60;
|
|
274
|
+
const waitingTime = remainingEra * _constants2._STAKING_ERA_LENGTH_MAP[chain] + remainingHours;
|
|
265
275
|
unstakingList.push({
|
|
266
276
|
chain,
|
|
267
277
|
status: isClaimable ? _KoniTypes.UnstakingStatus.CLAIMABLE : _KoniTypes.UnstakingStatus.UNLOCKING,
|
|
@@ -297,7 +307,8 @@ async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi)
|
|
|
297
307
|
const bnMinActiveStake = new _util.BN(minActiveStake);
|
|
298
308
|
const bnMinNominatorBond = new _util.BN(minNominatorBond);
|
|
299
309
|
const minStake = bnMinActiveStake.gt(bnMinNominatorBond) ? bnMinActiveStake : bnMinNominatorBond;
|
|
300
|
-
const
|
|
310
|
+
const unlimitedNominatorRewarded = chainApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
311
|
+
const _maxNominatorRewardedPerValidator = (chainApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
301
312
|
const maxNominatorRewardedPerValidator = parseInt(_maxNominatorRewardedPerValidator);
|
|
302
313
|
const ledger = _ledger.toPrimitive();
|
|
303
314
|
const nominations = _nominations.toPrimitive();
|
|
@@ -332,7 +343,7 @@ async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi)
|
|
|
332
343
|
if (!topNominators.includes((0, _utils3.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
333
344
|
// if nominator has target but not in nominator list
|
|
334
345
|
nominationStatus = _KoniTypes.StakingStatus.WAITING;
|
|
335
|
-
} else if (topNominators.slice(0, maxNominatorRewardedPerValidator).includes((0, _utils3.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
346
|
+
} else if (topNominators.slice(0, unlimitedNominatorRewarded ? undefined : maxNominatorRewardedPerValidator).includes((0, _utils3.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
336
347
|
// if address in top nominators
|
|
337
348
|
nominationStatus = _KoniTypes.StakingStatus.EARNING_REWARD;
|
|
338
349
|
}
|
|
@@ -365,7 +376,7 @@ async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi)
|
|
|
365
376
|
ledger.unlocking.forEach(unlockingChunk => {
|
|
366
377
|
const isClaimable = unlockingChunk.era - parseInt(currentEra) < 0;
|
|
367
378
|
const remainingEra = unlockingChunk.era - parseInt(currentEra);
|
|
368
|
-
const waitingTime = remainingEra *
|
|
379
|
+
const waitingTime = remainingEra * _constants2._STAKING_ERA_LENGTH_MAP[chain];
|
|
369
380
|
unstakingList.push({
|
|
370
381
|
chain,
|
|
371
382
|
status: isClaimable ? _KoniTypes.UnstakingStatus.CLAIMABLE : _KoniTypes.UnstakingStatus.UNLOCKING,
|
|
@@ -385,11 +396,13 @@ async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi)
|
|
|
385
396
|
};
|
|
386
397
|
}
|
|
387
398
|
async function subscribeRelayChainPoolMemberMetadata(chainInfo, address, substrateApi, poolMemberInfo) {
|
|
388
|
-
|
|
399
|
+
var _substrateApi$api$der, _substrateApi$api$der2;
|
|
400
|
+
const unlimitedNominatorRewarded = substrateApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
401
|
+
const _maxNominatorRewardedPerValidator = (substrateApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
389
402
|
const maxNominatorRewardedPerValidator = parseInt(_maxNominatorRewardedPerValidator);
|
|
390
403
|
const poolsPalletId = substrateApi.api.consts.nominationPools.palletId.toString();
|
|
391
404
|
const poolStashAccount = (0, _utils.parsePoolStashAddress)(substrateApi.api, 0, poolMemberInfo.poolId, poolsPalletId);
|
|
392
|
-
const [_nominations, _poolMetadata, _currentEra] = await Promise.all([substrateApi.api.query.staking.nominators(poolStashAccount), substrateApi.api.query.nominationPools.metadata(poolMemberInfo.poolId), substrateApi.api.query.staking.currentEra()]);
|
|
405
|
+
const [_nominations, _poolMetadata, _currentEra, _deriveSessionProgress] = await Promise.all([substrateApi.api.query.staking.nominators(poolStashAccount), substrateApi.api.query.nominationPools.metadata(poolMemberInfo.poolId), substrateApi.api.query.staking.currentEra(), (_substrateApi$api$der = substrateApi.api.derive) === null || _substrateApi$api$der === void 0 ? void 0 : (_substrateApi$api$der2 = _substrateApi$api$der.session) === null || _substrateApi$api$der2 === void 0 ? void 0 : _substrateApi$api$der2.progress()]);
|
|
393
406
|
const poolMetadata = _poolMetadata.toPrimitive();
|
|
394
407
|
const currentEra = _currentEra.toString();
|
|
395
408
|
const nominations = _nominations.toJSON();
|
|
@@ -413,7 +426,7 @@ async function subscribeRelayChainPoolMemberMetadata(chainInfo, address, substra
|
|
|
413
426
|
});
|
|
414
427
|
const topNominators = sortedNominators.map(nominator => {
|
|
415
428
|
return nominator.who;
|
|
416
|
-
}).slice(0, maxNominatorRewardedPerValidator);
|
|
429
|
+
}).slice(0, unlimitedNominatorRewarded ? undefined : maxNominatorRewardedPerValidator);
|
|
417
430
|
if (topNominators.includes((0, _utils3.reformatAddress)(poolStashAccount, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
418
431
|
// if address in top nominators
|
|
419
432
|
stakingStatus = _KoniTypes.StakingStatus.EARNING_REWARD;
|
|
@@ -434,7 +447,15 @@ async function subscribeRelayChainPoolMemberMetadata(chainInfo, address, substra
|
|
|
434
447
|
let [unlockingEra, amount] = _ref;
|
|
435
448
|
const isClaimable = parseInt(unlockingEra) - parseInt(currentEra) < 0;
|
|
436
449
|
const remainingEra = parseInt(unlockingEra) - parseInt(currentEra);
|
|
437
|
-
const waitingTime = remainingEra *
|
|
450
|
+
// const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chainInfo.slug];
|
|
451
|
+
|
|
452
|
+
// Calculate the remaining time for current era ending
|
|
453
|
+
const expectedBlockTime = _constants2._EXPECTED_BLOCK_TIME[chainInfo.slug];
|
|
454
|
+
const eraLength = _deriveSessionProgress.eraLength.toNumber();
|
|
455
|
+
const eraProgress = _deriveSessionProgress.eraProgress.toNumber();
|
|
456
|
+
const remainingSlots = eraLength - eraProgress;
|
|
457
|
+
const remainingHours = expectedBlockTime * remainingSlots / 60 / 60;
|
|
458
|
+
const waitingTime = remainingEra * _constants2._STAKING_ERA_LENGTH_MAP[chainInfo.slug] + remainingHours;
|
|
438
459
|
unstakings.push({
|
|
439
460
|
chain: chainInfo.slug,
|
|
440
461
|
status: isClaimable ? _KoniTypes.UnstakingStatus.CLAIMABLE : _KoniTypes.UnstakingStatus.UNLOCKING,
|
|
@@ -464,7 +485,8 @@ async function subscribeRelayChainPoolMemberMetadata(chainInfo, address, substra
|
|
|
464
485
|
async function getRelayChainPoolMemberMetadata(chainInfo, address, substrateApi) {
|
|
465
486
|
const chainApi = await substrateApi.isReady;
|
|
466
487
|
const [_poolMemberInfo, _currentEra] = await Promise.all([chainApi.api.query.nominationPools.poolMembers(address), chainApi.api.query.staking.currentEra()]);
|
|
467
|
-
const
|
|
488
|
+
const unlimitedNominatorRewarded = chainApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
489
|
+
const _maxNominatorRewardedPerValidator = (chainApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
468
490
|
const maxNominatorRewardedPerValidator = parseInt(_maxNominatorRewardedPerValidator);
|
|
469
491
|
const poolsPalletId = chainApi.api.consts.nominationPools.palletId.toString();
|
|
470
492
|
const poolMemberInfo = _poolMemberInfo.toPrimitive();
|
|
@@ -506,7 +528,7 @@ async function getRelayChainPoolMemberMetadata(chainInfo, address, substrateApi)
|
|
|
506
528
|
});
|
|
507
529
|
const topNominators = sortedNominators.map(nominator => {
|
|
508
530
|
return nominator.who;
|
|
509
|
-
}).slice(0, maxNominatorRewardedPerValidator);
|
|
531
|
+
}).slice(0, unlimitedNominatorRewarded ? undefined : maxNominatorRewardedPerValidator);
|
|
510
532
|
if (topNominators.includes((0, _utils3.reformatAddress)(poolStashAccount, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
511
533
|
// if address in top nominators
|
|
512
534
|
stakingStatus = _KoniTypes.StakingStatus.EARNING_REWARD;
|
|
@@ -527,7 +549,7 @@ async function getRelayChainPoolMemberMetadata(chainInfo, address, substrateApi)
|
|
|
527
549
|
let [unlockingEra, amount] = _ref2;
|
|
528
550
|
const isClaimable = parseInt(unlockingEra) - parseInt(currentEra) < 0;
|
|
529
551
|
const remainingEra = parseInt(unlockingEra) - parseInt(currentEra);
|
|
530
|
-
const waitingTime = remainingEra *
|
|
552
|
+
const waitingTime = remainingEra * _constants2._STAKING_ERA_LENGTH_MAP[chainInfo.slug];
|
|
531
553
|
unstakings.push({
|
|
532
554
|
chain: chainInfo.slug,
|
|
533
555
|
status: isClaimable ? _KoniTypes.UnstakingStatus.CLAIMABLE : _KoniTypes.UnstakingStatus.UNLOCKING,
|
|
@@ -559,7 +581,8 @@ async function getRelayValidatorsInfo(chain, substrateApi, decimals, chainStakin
|
|
|
559
581
|
const validatorInfoList = [];
|
|
560
582
|
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$s2 = chainApi.api.query.stakingRewards) === null || _chainApi$api$query$s2 === void 0 ? void 0 : _chainApi$api$query$s2.data) && chainApi.api.query.stakingRewards.data()]);
|
|
561
583
|
const stakingRewards = _stakingRewards === null || _stakingRewards === void 0 ? void 0 : _stakingRewards.toPrimitive();
|
|
562
|
-
const
|
|
584
|
+
const unlimitedNominatorRewarded = chainApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
585
|
+
const maxNominatorRewarded = (chainApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
563
586
|
const bnTotalEraStake = new _util.BN(_totalEraStake.toString());
|
|
564
587
|
const eraStakers = _eraStakers;
|
|
565
588
|
const rawMinBond = _minBond.toHuman();
|
|
@@ -596,7 +619,7 @@ async function getRelayValidatorsInfo(chain, substrateApi, decimals, chainStakin
|
|
|
596
619
|
blocked: false,
|
|
597
620
|
isVerified: false,
|
|
598
621
|
minBond,
|
|
599
|
-
isCrowded: nominatorCount > parseInt(maxNominatorRewarded)
|
|
622
|
+
isCrowded: unlimitedNominatorRewarded ? false : nominatorCount > parseInt(maxNominatorRewarded)
|
|
600
623
|
});
|
|
601
624
|
}
|
|
602
625
|
const extraInfoMap = {};
|
|
@@ -615,9 +638,9 @@ async function getRelayValidatorsInfo(chain, substrateApi, decimals, chainStakin
|
|
|
615
638
|
for (const validator of validatorInfoList) {
|
|
616
639
|
const commission = extraInfoMap[validator.address].commission;
|
|
617
640
|
const bnValidatorStake = totalStakeMap[validator.address].div(bnDecimals);
|
|
618
|
-
if (
|
|
641
|
+
if (_constants2._STAKING_CHAIN_GROUP.aleph.includes(chain)) {
|
|
619
642
|
validator.expectedReturn = (0, _utils.calculateAlephZeroValidatorReturn)(chainStakingMetadata.expectedReturn, (0, _utils.getCommission)(commission));
|
|
620
|
-
} else if (
|
|
643
|
+
} else if (_constants2._STAKING_CHAIN_GROUP.ternoa.includes(chain)) {
|
|
621
644
|
const rewardPerValidator = new _util.BN(stakingRewards.sessionExtraRewardPayout).divn(allValidators.length).div(bnDecimals);
|
|
622
645
|
const validatorStake = totalStakeMap[validator.address].div(bnDecimals).toNumber();
|
|
623
646
|
validator.expectedReturn = (0, _utils.calculateTernoaValidatorReturn)(rewardPerValidator.toNumber(), validatorStake, (0, _utils.getCommission)(commission));
|
|
@@ -25,6 +25,6 @@ function getCurrencyId(tokenInfo) {
|
|
|
25
25
|
}
|
|
26
26
|
function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
27
27
|
const weightParam = ['pioneer'].includes(originChainInfo.slug) ? _utils.FOUR_INSTRUCTIONS_WEIGHT : (0, _utils.getDestWeight)();
|
|
28
|
-
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala', 'parallel', 'astar', 'shiden'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
28
|
+
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala', 'parallel', 'astar', 'shiden', 'centrifuge'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
29
29
|
return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, (0, _utils.getDestMultilocation)(destinationChainInfo, recipientAddress, destVersion), weightParam);
|
|
30
30
|
}
|
|
@@ -1043,21 +1043,24 @@ class KoniExtension {
|
|
|
1043
1043
|
});
|
|
1044
1044
|
return this.getPrice();
|
|
1045
1045
|
}
|
|
1046
|
-
getBalance(reset) {
|
|
1046
|
+
async getBalance(reset) {
|
|
1047
1047
|
return this.#koniState.getBalance(reset);
|
|
1048
1048
|
}
|
|
1049
|
-
subscribeBalance(id, port) {
|
|
1049
|
+
async subscribeBalance(id, port) {
|
|
1050
1050
|
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
1051
1051
|
const balanceSubscription = this.#koniState.subscribeBalance().subscribe({
|
|
1052
1052
|
next: rs => {
|
|
1053
|
-
|
|
1053
|
+
const data = {
|
|
1054
|
+
details: rs
|
|
1055
|
+
};
|
|
1056
|
+
cb(data);
|
|
1054
1057
|
}
|
|
1055
1058
|
});
|
|
1056
1059
|
this.createUnsubscriptionHandle(id, balanceSubscription.unsubscribe);
|
|
1057
1060
|
port.onDisconnect.addListener(() => {
|
|
1058
1061
|
this.cancelSubscription(id);
|
|
1059
1062
|
});
|
|
1060
|
-
return this.getBalance(true);
|
|
1063
|
+
return await this.getBalance(true);
|
|
1061
1064
|
}
|
|
1062
1065
|
getCrowdloan(reset) {
|
|
1063
1066
|
return this.#koniState.getCrowdloan(reset);
|
|
@@ -3832,9 +3835,9 @@ class KoniExtension {
|
|
|
3832
3835
|
case 'pri(price.getSubscription)':
|
|
3833
3836
|
return await this.subscribePrice(id, port);
|
|
3834
3837
|
case 'pri(balance.getBalance)':
|
|
3835
|
-
return this.getBalance();
|
|
3838
|
+
return await this.getBalance();
|
|
3836
3839
|
case 'pri(balance.getSubscription)':
|
|
3837
|
-
return this.subscribeBalance(id, port);
|
|
3840
|
+
return await this.subscribeBalance(id, port);
|
|
3838
3841
|
case 'pri(crowdloan.getCrowdloan)':
|
|
3839
3842
|
return this.getCrowdloan();
|
|
3840
3843
|
case 'pri(crowdloan.getSubscription)':
|
|
@@ -4170,8 +4173,8 @@ class KoniExtension {
|
|
|
4170
4173
|
return this.#koniState.dbService.exportDB();
|
|
4171
4174
|
case 'pri(database.import)':
|
|
4172
4175
|
return this.#koniState.dbService.importDB(request);
|
|
4173
|
-
case 'pri(database.
|
|
4174
|
-
return this.#koniState.dbService.
|
|
4176
|
+
case 'pri(database.exportJson)':
|
|
4177
|
+
return this.#koniState.dbService.getExportJson();
|
|
4175
4178
|
/* Database */
|
|
4176
4179
|
// Default
|
|
4177
4180
|
default:
|
|
@@ -4,10 +4,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
exports.isIndexedDBReset = isIndexedDBReset;
|
|
8
|
+
exports.isLocalStorageReset = isLocalStorageReset;
|
|
9
|
+
exports.isWebRunnerDataReset = isWebRunnerDataReset;
|
|
10
|
+
var _index = require("@subwallet/extension-base/koni/background/handlers/index");
|
|
11
|
+
var _storage = require("@subwallet/extension-base/storage");
|
|
12
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
7
13
|
var _promise = require("@subwallet/extension-base/utils/promise");
|
|
8
14
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
9
15
|
// SPDX-License-Identifier: Apache-2.0
|
|
10
16
|
|
|
17
|
+
function isLocalStorageReset() {
|
|
18
|
+
var _window;
|
|
19
|
+
if ((_window = window) !== null && _window !== void 0 && _window.localStorage) {
|
|
20
|
+
return !window.localStorage.getItem('keyring:subwallet');
|
|
21
|
+
} else {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function isIndexedDBReset() {
|
|
26
|
+
try {
|
|
27
|
+
return (await _index.state.dbService.stores.migration.table.count()) < 1;
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Detect problems on the web-runner
|
|
34
|
+
async function isWebRunnerDataReset() {
|
|
35
|
+
return isLocalStorageReset() || (await isIndexedDBReset());
|
|
36
|
+
}
|
|
37
|
+
const swStorage = _storage.SWStorage.instance;
|
|
11
38
|
const DEFAULT_SERVICE_MAP = {
|
|
12
39
|
subscription: {
|
|
13
40
|
chainRegistry: true,
|
|
@@ -28,8 +55,17 @@ class Mobile {
|
|
|
28
55
|
// @ts-ignore
|
|
29
56
|
|
|
30
57
|
restoreHandler = (0, _promise.createPromiseHandler)();
|
|
58
|
+
lastRestoreData = {};
|
|
31
59
|
constructor(state) {
|
|
32
60
|
this.state = state;
|
|
61
|
+
if (!isLocalStorageReset()) {
|
|
62
|
+
this.lastRestoreData.storage = swStorage.copy();
|
|
63
|
+
}
|
|
64
|
+
(async () => {
|
|
65
|
+
if (!(await isIndexedDBReset())) {
|
|
66
|
+
this.lastRestoreData.indexedDB = await state.dbService.getExportJson();
|
|
67
|
+
}
|
|
68
|
+
})().catch(console.error);
|
|
33
69
|
}
|
|
34
70
|
ping() {
|
|
35
71
|
return 'mobile:ping';
|
|
@@ -104,25 +140,65 @@ class Mobile {
|
|
|
104
140
|
restartSubscriptionServices(services) {
|
|
105
141
|
console.log('restartSubscriptionServices');
|
|
106
142
|
}
|
|
107
|
-
async
|
|
143
|
+
async _getLocalStorageExportData() {
|
|
144
|
+
return Promise.resolve(JSON.stringify(swStorage.copy()));
|
|
145
|
+
}
|
|
146
|
+
async _getDexieExportData() {
|
|
108
147
|
const indexedDB = await this.state.dbService.exportDB();
|
|
148
|
+
if ((await isIndexedDBReset()) && this.lastRestoreData.indexedDB) {
|
|
149
|
+
// Merge with latest restore DexieData
|
|
150
|
+
const exportData = await this.state.dbService.getExportJson();
|
|
151
|
+
const exportTables = exportData === null || exportData === void 0 ? void 0 : exportData.data.data;
|
|
152
|
+
const existedData = this.lastRestoreData.indexedDB;
|
|
153
|
+
const existedTableMap = Object.fromEntries(existedData.data.data.map(table => [table.tableName, table]));
|
|
154
|
+
if ((exportTables === null || exportTables === void 0 ? void 0 : exportTables.length) > 0) {
|
|
155
|
+
exportTables.forEach(_ref5 => {
|
|
156
|
+
let {
|
|
157
|
+
inbound,
|
|
158
|
+
rows,
|
|
159
|
+
tableName
|
|
160
|
+
} = _ref5;
|
|
161
|
+
const latestTable = existedTableMap[tableName];
|
|
162
|
+
|
|
163
|
+
// chain & asset & campaign
|
|
164
|
+
if (tableName === 'chain' || tableName === 'asset' || tableName === 'campaign') {
|
|
165
|
+
latestTable.rows = (0, _utils.listMerge)('slug', latestTable.rows, rows);
|
|
166
|
+
|
|
167
|
+
// Todo: Campaign still doesn't work
|
|
168
|
+
} else if (tableName === 'migrations') {
|
|
169
|
+
latestTable.rows = (0, _utils.listMerge)('key', latestTable.rows, rows);
|
|
170
|
+
} else if (tableName === 'transactions') {
|
|
171
|
+
latestTable.rows = (0, _utils.listMerge)(['chain', 'address', 'extrinsicHash'], latestTable.rows, rows);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return JSON.stringify(existedData);
|
|
176
|
+
}
|
|
177
|
+
return indexedDB;
|
|
178
|
+
}
|
|
179
|
+
async mobileBackup() {
|
|
180
|
+
const storage = await this._getLocalStorageExportData();
|
|
181
|
+
const indexedDB = await this._getDexieExportData();
|
|
109
182
|
return {
|
|
110
|
-
storage
|
|
183
|
+
storage,
|
|
111
184
|
indexedDB
|
|
112
185
|
};
|
|
113
186
|
}
|
|
114
|
-
async mobileRestore(
|
|
187
|
+
async mobileRestore(_ref6) {
|
|
115
188
|
let {
|
|
116
189
|
indexedDB,
|
|
117
190
|
storage
|
|
118
|
-
} =
|
|
191
|
+
} = _ref6;
|
|
119
192
|
if (storage) {
|
|
120
193
|
const storageData = JSON.parse(storage);
|
|
121
194
|
for (const key in storageData) {
|
|
122
|
-
|
|
195
|
+
swStorage.setItem(key, storageData[key]);
|
|
123
196
|
}
|
|
124
197
|
}
|
|
125
198
|
if (indexedDB) {
|
|
199
|
+
// Backup the last restore data to memory
|
|
200
|
+
this.lastRestoreData.indexedDB = JSON.parse(indexedDB);
|
|
201
|
+
// Backup the last restore data to memory
|
|
126
202
|
await this.state.dbService.importDB(indexedDB);
|
|
127
203
|
}
|
|
128
204
|
this.restoreHandler.resolve();
|