@subwallet/extension-base 1.1.51-2 → 1.1.53-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/koni/api/tokens/evm/balance.js +1 -2
- package/cjs/koni/api/tokens/evm/transfer.js +3 -5
- package/cjs/koni/api/tokens/evm/web3.js +3 -3
- package/cjs/koni/background/handlers/Extension.js +5 -4
- package/cjs/koni/background/handlers/State.js +8 -71
- package/cjs/koni/background/subscription.js +3 -63
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/BalanceMapImpl.js +2 -2
- package/cjs/services/balance-service/helpers/index.js +27 -0
- package/cjs/services/balance-service/helpers/subscribe/evm.js +33 -15
- package/cjs/services/balance-service/helpers/subscribe/{balance.js → index.js} +46 -29
- package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +34 -15
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +157 -72
- package/cjs/services/balance-service/index.js +277 -75
- package/cjs/services/chain-service/constants.js +2 -1
- package/cjs/services/chain-service/health-check/utils/asset-info.js +1 -3
- package/cjs/services/chain-service/index.js +1 -9
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
- package/cjs/services/request-service/handler/ConnectWCRequestHandler.js +0 -1
- package/cjs/services/storage-service/DatabaseService.js +10 -1
- package/cjs/services/wallet-connect-service/helpers.js +1 -1
- package/cjs/services/wallet-connect-service/index.js +19 -0
- package/cjs/utils/asset.js +19 -0
- package/cjs/utils/eth/parseTransaction/index.js +1 -1
- package/cjs/utils/index.js +12 -0
- package/koni/api/tokens/evm/balance.d.ts +1 -1
- package/koni/api/tokens/evm/balance.js +1 -2
- package/koni/api/tokens/evm/transfer.d.ts +2 -2
- package/koni/api/tokens/evm/transfer.js +3 -5
- package/koni/api/tokens/evm/web3.d.ts +1 -1
- package/koni/api/tokens/evm/web3.js +2 -2
- package/koni/background/handlers/Extension.js +5 -4
- package/koni/background/handlers/State.d.ts +1 -12
- package/koni/background/handlers/State.js +9 -72
- package/koni/background/subscription.d.ts +1 -5
- package/koni/background/subscription.js +1 -60
- package/package.json +23 -13
- package/packageInfo.js +1 -1
- package/services/balance-service/BalanceMapImpl.js +1 -1
- package/services/balance-service/helpers/index.d.ts +2 -0
- package/services/balance-service/helpers/index.js +5 -0
- package/services/balance-service/helpers/subscribe/evm.d.ts +3 -5
- package/services/balance-service/helpers/subscribe/evm.js +31 -14
- package/services/balance-service/helpers/subscribe/{balance.d.ts → index.d.ts} +2 -2
- package/services/balance-service/helpers/subscribe/{balance.js → index.js} +41 -28
- package/services/balance-service/helpers/subscribe/substrate/equilibrium.d.ts +3 -4
- package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +29 -13
- package/services/balance-service/helpers/subscribe/substrate/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/substrate/index.js +144 -67
- package/services/balance-service/index.d.ts +64 -6
- package/services/balance-service/index.js +279 -77
- package/services/chain-service/constants.js +2 -1
- package/services/chain-service/health-check/utils/asset-info.js +1 -3
- package/services/chain-service/index.js +2 -10
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
- package/services/request-service/handler/ConnectWCRequestHandler.js +0 -1
- package/services/storage-service/DatabaseService.js +7 -1
- package/services/wallet-connect-service/helpers.js +1 -1
- package/services/wallet-connect-service/index.d.ts +1 -0
- package/services/wallet-connect-service/index.js +19 -1
- package/types/{balance.d.ts → balance/index.d.ts} +16 -0
- package/types/index.js +1 -1
- package/utils/asset.d.ts +2 -0
- package/utils/asset.js +12 -0
- package/utils/eth/parseTransaction/index.js +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- /package/cjs/types/{balance.js → balance/index.js} +0 -0
- /package/types/{balance.js → balance/index.js} +0 -0
|
@@ -34,10 +34,9 @@ export const handleTransferBalanceResult = ({
|
|
|
34
34
|
});
|
|
35
35
|
callback(response);
|
|
36
36
|
};
|
|
37
|
-
export async function getEVMTransactionObject(chainInfo, from, to, value, transferAll,
|
|
37
|
+
export async function getEVMTransactionObject(chainInfo, from, to, value, transferAll, web3Api) {
|
|
38
38
|
var _priority$maxFeePerGa, _priority$maxPriority;
|
|
39
39
|
const networkKey = chainInfo.slug;
|
|
40
|
-
const web3Api = evmApiMap[networkKey];
|
|
41
40
|
const priority = await calculateGasFeeParams(web3Api, networkKey);
|
|
42
41
|
const transactionObject = {
|
|
43
42
|
to: to,
|
|
@@ -63,11 +62,10 @@ export async function getEVMTransactionObject(chainInfo, from, to, value, transf
|
|
|
63
62
|
}
|
|
64
63
|
return [transactionObject, transactionObject.value.toString()];
|
|
65
64
|
}
|
|
66
|
-
export async function getERC20TransactionObject(assetAddress, chainInfo, from, to, value, transferAll,
|
|
65
|
+
export async function getERC20TransactionObject(assetAddress, chainInfo, from, to, value, transferAll, evmApi) {
|
|
67
66
|
var _priority$maxFeePerGa2, _priority$maxPriority2;
|
|
68
67
|
const networkKey = chainInfo.slug;
|
|
69
|
-
const
|
|
70
|
-
const erc20Contract = getERC20Contract(networkKey, assetAddress, evmApiMap);
|
|
68
|
+
const erc20Contract = getERC20Contract(assetAddress, evmApi);
|
|
71
69
|
let freeAmount = new BigN(0);
|
|
72
70
|
let transferValue = value;
|
|
73
71
|
if (transferAll) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
2
2
|
import { Contract } from 'web3-eth-contract';
|
|
3
|
-
export declare const getERC20Contract: (
|
|
3
|
+
export declare const getERC20Contract: (assetAddress: string, evmApi: _EvmApi, options?: {}) => Contract;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { _ERC20_ABI } from '@subwallet/extension-base/services/chain-service/helper';
|
|
5
|
-
export const getERC20Contract = (
|
|
5
|
+
export const getERC20Contract = (assetAddress, evmApi, options = {}) => {
|
|
6
6
|
// @ts-ignore
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
8
|
-
return new
|
|
8
|
+
return new evmApi.api.eth.Contract(_ERC20_ABI, assetAddress, options);
|
|
9
9
|
};
|
|
@@ -1036,11 +1036,11 @@ export default class KoniExtension {
|
|
|
1036
1036
|
return this.getPrice();
|
|
1037
1037
|
}
|
|
1038
1038
|
async getBalance(reset) {
|
|
1039
|
-
return this.#koniState.getBalance(reset);
|
|
1039
|
+
return this.#koniState.balanceService.getBalance(reset);
|
|
1040
1040
|
}
|
|
1041
1041
|
async subscribeBalance(id, port) {
|
|
1042
1042
|
const cb = createSubscription(id, port);
|
|
1043
|
-
const balanceSubscription = this.#koniState.
|
|
1043
|
+
const balanceSubscription = this.#koniState.balanceService.subscribeBalanceMap().subscribe({
|
|
1044
1044
|
next: rs => {
|
|
1045
1045
|
const data = {
|
|
1046
1046
|
details: rs
|
|
@@ -1565,12 +1565,13 @@ export default class KoniExtension {
|
|
|
1565
1565
|
// TODO: review this
|
|
1566
1566
|
chainType = ChainType.EVM;
|
|
1567
1567
|
const txVal = transferAll ? freeBalance.value : value || '0';
|
|
1568
|
+
const evmApi = evmApiMap[networkKey];
|
|
1568
1569
|
|
|
1569
1570
|
// Estimate with EVM API
|
|
1570
1571
|
if (_isTokenEvmSmartContract(tokenInfo) || _isLocalToken(tokenInfo)) {
|
|
1571
|
-
[transaction, transferAmount.value] = await getERC20TransactionObject(_getContractAddressOfToken(tokenInfo), chainInfo, from, to, txVal, !!transferAll,
|
|
1572
|
+
[transaction, transferAmount.value] = await getERC20TransactionObject(_getContractAddressOfToken(tokenInfo), chainInfo, from, to, txVal, !!transferAll, evmApi);
|
|
1572
1573
|
} else {
|
|
1573
|
-
[transaction, transferAmount.value] = await getEVMTransactionObject(chainInfo, from, to, txVal, !!transferAll,
|
|
1574
|
+
[transaction, transferAmount.value] = await getEVMTransactionObject(chainInfo, from, to, txVal, !!transferAll, evmApi);
|
|
1574
1575
|
}
|
|
1575
1576
|
} else if (_isMantaZkAsset(tokenInfo)) {
|
|
1576
1577
|
// TODO
|
|
@@ -23,7 +23,7 @@ import DatabaseService from '@subwallet/extension-base/services/storage-service/
|
|
|
23
23
|
import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
|
|
24
24
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
25
25
|
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
26
|
-
import {
|
|
26
|
+
import { BalanceMap, EvmFeeInfo } from '@subwallet/extension-base/types';
|
|
27
27
|
import { MetadataDef, ProviderMeta } from '@subwallet/extension-inject/types';
|
|
28
28
|
import SimpleKeyring from 'eth-simple-keyring';
|
|
29
29
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
@@ -38,7 +38,6 @@ export default class KoniState {
|
|
|
38
38
|
private readonly unsubscriptionMap;
|
|
39
39
|
private readonly accountRefStore;
|
|
40
40
|
private externalRequest;
|
|
41
|
-
private balanceMap;
|
|
42
41
|
private crowdloanMap;
|
|
43
42
|
private crowdloanSubject;
|
|
44
43
|
private nftSubject;
|
|
@@ -155,18 +154,8 @@ export default class KoniState {
|
|
|
155
154
|
getAccountAddress(): string | null;
|
|
156
155
|
getDecodedAddresses(address?: string): string[];
|
|
157
156
|
getAllAddresses(): string[];
|
|
158
|
-
removeInactiveChainBalances(): Promise<void>;
|
|
159
|
-
getBalance(reset?: boolean): Promise<BalanceJson>;
|
|
160
|
-
getStoredBalance(address: string): Promise<BalanceItem[]>;
|
|
161
|
-
private isFirstLoad;
|
|
162
|
-
handleResetBalance(newAddress: string, forceRefresh?: boolean): Promise<void>;
|
|
163
157
|
resetCrowdloanMap(newAddress: string): Promise<void>;
|
|
164
158
|
resetStaking(newAddress: string): void;
|
|
165
|
-
private balanceUpdateCache;
|
|
166
|
-
/** Note: items must be same tokenSlug */
|
|
167
|
-
setBalanceItem(items: BalanceItem[]): void;
|
|
168
|
-
private updateBalanceStore;
|
|
169
|
-
subscribeBalance(): BehaviorSubject<BalanceMap>;
|
|
170
159
|
getCrowdloan(reset?: boolean): CrowdloanJson;
|
|
171
160
|
getStoredCrowdloan(address: string): Promise<Record<string, import("../../../services/storage-service/databases").ICrowdloanItem>>;
|
|
172
161
|
setCrowdloanItem(networkKey: string, item: CrowdloanItem): void;
|
|
@@ -7,7 +7,6 @@ import { isSubscriptionRunning, unsubscribe } from '@subwallet/extension-base/ba
|
|
|
7
7
|
import { APIItemState, BasicTxErrorType, ChainType, EvmProviderErrorType, ExternalRequestPromiseStatus, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
8
8
|
import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, MANTA_PAY_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
9
9
|
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
10
|
-
import { BalanceMapImpl } from '@subwallet/extension-base/services/balance-service/BalanceMapImpl';
|
|
11
10
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
12
11
|
import BuyService from '@subwallet/extension-base/services/buy-service';
|
|
13
12
|
import CampaignService from '@subwallet/extension-base/services/campaign-service';
|
|
@@ -32,7 +31,7 @@ import { SUBSCAN_API_CHAIN_MAP } from '@subwallet/extension-base/services/subsca
|
|
|
32
31
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
33
32
|
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
34
33
|
import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
|
|
35
|
-
import {
|
|
34
|
+
import { isAccountAll, stripUrl, TARGET_ENV } from '@subwallet/extension-base/utils';
|
|
36
35
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
37
36
|
import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
38
37
|
import { decodePair } from '@subwallet/keyring/pair/decode';
|
|
@@ -66,7 +65,6 @@ export default class KoniState {
|
|
|
66
65
|
unsubscriptionMap = {};
|
|
67
66
|
accountRefStore = new AccountRefStore();
|
|
68
67
|
externalRequest = {};
|
|
69
|
-
balanceMap = new BalanceMapImpl();
|
|
70
68
|
crowdloanMap = generateDefaultCrowdloanMap();
|
|
71
69
|
crowdloanSubject = new Subject();
|
|
72
70
|
nftSubject = new Subject();
|
|
@@ -226,6 +224,7 @@ export default class KoniState {
|
|
|
226
224
|
await this.migrationService.run();
|
|
227
225
|
this.campaignService.init();
|
|
228
226
|
this.eventService.emit('chain.ready', true);
|
|
227
|
+
await this.balanceService.init();
|
|
229
228
|
await this.earningService.init();
|
|
230
229
|
this.onReady();
|
|
231
230
|
this.onAccountAdd();
|
|
@@ -675,35 +674,6 @@ export default class KoniState {
|
|
|
675
674
|
getAllAddresses() {
|
|
676
675
|
return keyring.getAccounts().map(account => account.address);
|
|
677
676
|
}
|
|
678
|
-
async removeInactiveChainBalances() {
|
|
679
|
-
const assetSettings = await this.chainService.getAssetSettings();
|
|
680
|
-
this.balanceMap.removeBalanceItemByFilter(item => {
|
|
681
|
-
return !assetSettings[item.tokenSlug];
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
async getBalance(reset) {
|
|
685
|
-
await this.removeInactiveChainBalances();
|
|
686
|
-
return {
|
|
687
|
-
details: this.balanceMap.map,
|
|
688
|
-
reset
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
|
-
async getStoredBalance(address) {
|
|
692
|
-
return await this.dbService.stores.balance.getBalanceMapByAddresses(address);
|
|
693
|
-
}
|
|
694
|
-
isFirstLoad = true;
|
|
695
|
-
async handleResetBalance(newAddress, forceRefresh) {
|
|
696
|
-
if (this.isFirstLoad) {
|
|
697
|
-
const backupBalanceData = await this.dbService.getStoredBalance();
|
|
698
|
-
this.balanceMap.updateBalanceItems(backupBalanceData, isAccountAll(newAddress));
|
|
699
|
-
this.isFirstLoad = false;
|
|
700
|
-
}
|
|
701
|
-
if (forceRefresh) {
|
|
702
|
-
this.balanceMap.setData({});
|
|
703
|
-
await this.dbService.stores.balance.clear();
|
|
704
|
-
}
|
|
705
|
-
await Promise.all([this.removeInactiveChainBalances()]);
|
|
706
|
-
}
|
|
707
677
|
async resetCrowdloanMap(newAddress) {
|
|
708
678
|
const defaultData = generateDefaultCrowdloanMap();
|
|
709
679
|
const storedData = await this.getStoredCrowdloan(newAddress);
|
|
@@ -725,36 +695,6 @@ export default class KoniState {
|
|
|
725
695
|
});
|
|
726
696
|
});
|
|
727
697
|
}
|
|
728
|
-
balanceUpdateCache = [];
|
|
729
|
-
|
|
730
|
-
/** Note: items must be same tokenSlug */
|
|
731
|
-
setBalanceItem(items) {
|
|
732
|
-
if (items.length) {
|
|
733
|
-
const nowTime = new Date().getTime();
|
|
734
|
-
for (const item of items) {
|
|
735
|
-
const balance = {
|
|
736
|
-
timestamp: nowTime,
|
|
737
|
-
...item
|
|
738
|
-
};
|
|
739
|
-
this.balanceUpdateCache.push(balance);
|
|
740
|
-
}
|
|
741
|
-
addLazy('updateBalanceStore', () => {
|
|
742
|
-
const isAllAccount = isAccountAll(this.keyringService.currentAccount.address);
|
|
743
|
-
this.balanceMap.updateBalanceItems(this.balanceUpdateCache, isAllAccount);
|
|
744
|
-
if (isAllAccount) {
|
|
745
|
-
this.balanceUpdateCache = [...this.balanceUpdateCache, ...Object.values(this.balanceMap.map[ALL_ACCOUNT_KEY])];
|
|
746
|
-
}
|
|
747
|
-
this.updateBalanceStore(this.balanceUpdateCache);
|
|
748
|
-
this.balanceUpdateCache = [];
|
|
749
|
-
}, 300, 1800);
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
updateBalanceStore(items) {
|
|
753
|
-
this.dbService.updateBulkBalanceStore(items).catch(e => this.logger.warn(e));
|
|
754
|
-
}
|
|
755
|
-
subscribeBalance() {
|
|
756
|
-
return this.balanceMap.mapSubject;
|
|
757
|
-
}
|
|
758
698
|
getCrowdloan(reset) {
|
|
759
699
|
return {
|
|
760
700
|
details: this.crowdloanMap,
|
|
@@ -1456,7 +1396,7 @@ export default class KoniState {
|
|
|
1456
1396
|
// Stopping services
|
|
1457
1397
|
await Promise.all([this.cron.stop(), this.subscription.stop()]);
|
|
1458
1398
|
await this.pauseAllNetworks(undefined, 'IDLE mode');
|
|
1459
|
-
await Promise.all([this.historyService.stop(), this.priceService.stop(), this.earningService.stop()]);
|
|
1399
|
+
await Promise.all([this.historyService.stop(), this.priceService.stop(), this.balanceService.stop(), this.earningService.stop()]);
|
|
1460
1400
|
|
|
1461
1401
|
// Complete sleeping
|
|
1462
1402
|
sleeping.resolve();
|
|
@@ -1488,7 +1428,7 @@ export default class KoniState {
|
|
|
1488
1428
|
}
|
|
1489
1429
|
|
|
1490
1430
|
// Start services
|
|
1491
|
-
await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.earningService.start()]);
|
|
1431
|
+
await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.balanceService.start(), this.earningService.start()]);
|
|
1492
1432
|
|
|
1493
1433
|
// Complete starting
|
|
1494
1434
|
starting.resolve();
|
|
@@ -1534,11 +1474,6 @@ export default class KoniState {
|
|
|
1534
1474
|
|
|
1535
1475
|
const stores = this.dbService.stores;
|
|
1536
1476
|
|
|
1537
|
-
// Remove Balance
|
|
1538
|
-
stores.balance.removeAllByAddress(address).catch(console.error);
|
|
1539
|
-
stores.balance.removeAllByAddress(ALL_ACCOUNT_KEY).catch(console.error);
|
|
1540
|
-
this.balanceMap.removeBalanceItems([address, ALL_ACCOUNT_KEY]);
|
|
1541
|
-
|
|
1542
1477
|
// Remove NFT
|
|
1543
1478
|
stores.nft.deleteNftByAddress([address]).catch(console.error);
|
|
1544
1479
|
|
|
@@ -1556,7 +1491,7 @@ export default class KoniState {
|
|
|
1556
1491
|
return true;
|
|
1557
1492
|
}
|
|
1558
1493
|
async reloadBalance() {
|
|
1559
|
-
await this.
|
|
1494
|
+
await this.balanceService.reloadBalance();
|
|
1560
1495
|
return true;
|
|
1561
1496
|
}
|
|
1562
1497
|
async reloadCrowdloan() {
|
|
@@ -1581,9 +1516,11 @@ export default class KoniState {
|
|
|
1581
1516
|
}
|
|
1582
1517
|
async resetWallet(resetAll) {
|
|
1583
1518
|
await this.keyringService.resetWallet(resetAll);
|
|
1519
|
+
await this.earningService.resetYieldPosition();
|
|
1520
|
+
await this.balanceService.handleResetBalance(true);
|
|
1584
1521
|
this.requestService.resetWallet();
|
|
1585
1522
|
this.transactionService.resetWallet();
|
|
1586
|
-
await this.handleResetBalance(ALL_ACCOUNT_KEY, true);
|
|
1523
|
+
// await this.handleResetBalance(ALL_ACCOUNT_KEY, true);
|
|
1587
1524
|
await this.earningService.resetWallet();
|
|
1588
1525
|
await this.dbService.resetWallet(resetAll);
|
|
1589
1526
|
this.accountRefStore.set('refList', []);
|
|
@@ -1696,7 +1633,7 @@ export default class KoniState {
|
|
|
1696
1633
|
};
|
|
1697
1634
|
balanceItem.free = ((_zkBalances$i = zkBalances[i]) === null || _zkBalances$i === void 0 ? void 0 : _zkBalances$i.toString()) || '0';
|
|
1698
1635
|
balanceItem.state = APIItemState.READY;
|
|
1699
|
-
this.setBalanceItem([balanceItem]);
|
|
1636
|
+
this.balanceService.setBalanceItem([balanceItem]);
|
|
1700
1637
|
}
|
|
1701
1638
|
}).catch(console.warn);
|
|
1702
1639
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import {
|
|
2
|
+
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
3
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
4
4
|
import KoniState from './handlers/State';
|
|
5
5
|
declare type SubscriptionName = 'balance' | 'crowdloan' | 'yieldPoolStats' | 'yieldPosition';
|
|
@@ -16,14 +16,10 @@ export declare class KoniSubscription {
|
|
|
16
16
|
stopAllSubscription(): void;
|
|
17
17
|
start(): Promise<void>;
|
|
18
18
|
stop(): Promise<void>;
|
|
19
|
-
subscribeBalances(address: string, chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>, web3ApiMap: Record<string, _EvmApi>, onlyRunOnFirstTime?: boolean): void;
|
|
20
19
|
subscribeCrowdloans(address: string, substrateApiMap: Record<string, _SubstrateApi>, onlyRunOnFirstTime?: boolean): void;
|
|
21
|
-
initBalanceSubscription(addresses: string[], chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, onlyRunOnFirstTime?: boolean): (() => void) | undefined;
|
|
22
20
|
initCrowdloanSubscription(addresses: string[], substrateApiMap: Record<string, _SubstrateApi>, onlyRunOnFirstTime?: boolean): (() => void) | undefined;
|
|
23
21
|
subscribeNft(address: string, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>): void;
|
|
24
22
|
initNftSubscription(addresses: string[], substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>): void;
|
|
25
|
-
subscribeStakingReward(address: string): Promise<void>;
|
|
26
|
-
reloadBalance(): Promise<void>;
|
|
27
23
|
reloadCrowdloan(): Promise<void>;
|
|
28
24
|
}
|
|
29
25
|
export {};
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { subscribeCrowdloan } from '@subwallet/extension-base/koni/api/dotsama/crowdloan';
|
|
5
|
-
import { getNominationStakingRewardData } from '@subwallet/extension-base/koni/api/staking';
|
|
6
5
|
import { nftHandler } from '@subwallet/extension-base/koni/background/handlers';
|
|
7
|
-
import { subscribeBalance } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/balance';
|
|
8
|
-
import { _isChainEnabled, _isChainSupportSubstrateStaking } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
6
|
import { COMMON_RELOAD_EVENTS } from '@subwallet/extension-base/services/event-service/types';
|
|
10
7
|
import { waitTimeout } from '@subwallet/extension-base/utils';
|
|
11
8
|
import { logger as createLogger } from '@polkadot/util';
|
|
@@ -47,7 +44,6 @@ export class KoniSubscription {
|
|
|
47
44
|
await Promise.all([this.state.eventService.waitCryptoReady, this.state.eventService.waitKeyringReady, this.state.eventService.waitAssetReady]);
|
|
48
45
|
const currentAddress = (_this$state$keyringSe = this.state.keyringService.currentAccount) === null || _this$state$keyringSe === void 0 ? void 0 : _this$state$keyringSe.address;
|
|
49
46
|
if (currentAddress) {
|
|
50
|
-
this.subscribeBalances(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
|
|
51
47
|
this.subscribeCrowdloans(currentAddress, this.state.getSubstrateApiMap());
|
|
52
48
|
}
|
|
53
49
|
this.eventHandler = (events, eventTypes) => {
|
|
@@ -61,7 +57,6 @@ export class KoniSubscription {
|
|
|
61
57
|
if (!address) {
|
|
62
58
|
return;
|
|
63
59
|
}
|
|
64
|
-
this.subscribeBalances(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate, serviceInfo.chainApiMap.evm);
|
|
65
60
|
this.subscribeCrowdloans(address, serviceInfo.chainApiMap.substrate);
|
|
66
61
|
};
|
|
67
62
|
this.state.eventService.onLazy(this.eventHandler.bind(this));
|
|
@@ -74,15 +69,6 @@ export class KoniSubscription {
|
|
|
74
69
|
this.stopAllSubscription();
|
|
75
70
|
return Promise.resolve();
|
|
76
71
|
}
|
|
77
|
-
subscribeBalances(address, chainInfoMap, chainStateMap, substrateApiMap, web3ApiMap, onlyRunOnFirstTime) {
|
|
78
|
-
const addresses = this.state.getDecodedAddresses(address);
|
|
79
|
-
if (!addresses.length) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
this.state.handleResetBalance(address).then(() => {
|
|
83
|
-
this.updateSubscription('balance', this.initBalanceSubscription(addresses, chainInfoMap, chainStateMap, substrateApiMap, web3ApiMap, onlyRunOnFirstTime));
|
|
84
|
-
}).catch(err => this.logger.warn(err));
|
|
85
|
-
}
|
|
86
72
|
subscribeCrowdloans(address, substrateApiMap, onlyRunOnFirstTime) {
|
|
87
73
|
const addresses = this.state.getDecodedAddresses(address);
|
|
88
74
|
if (!addresses.length) {
|
|
@@ -92,27 +78,6 @@ export class KoniSubscription {
|
|
|
92
78
|
this.updateSubscription('crowdloan', this.initCrowdloanSubscription(addresses, substrateApiMap, onlyRunOnFirstTime));
|
|
93
79
|
}).catch(console.error);
|
|
94
80
|
}
|
|
95
|
-
initBalanceSubscription(addresses, chainInfoMap, chainStateMap, substrateApiMap, evmApiMap, onlyRunOnFirstTime) {
|
|
96
|
-
const filteredChainInfoMap = {};
|
|
97
|
-
Object.values(chainStateMap).forEach(chainState => {
|
|
98
|
-
if (chainState.active) {
|
|
99
|
-
filteredChainInfoMap[chainState.slug] = chainInfoMap[chainState.slug];
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
const unsub = subscribeBalance(addresses, filteredChainInfoMap, substrateApiMap, evmApiMap, result => {
|
|
103
|
-
this.state.setBalanceItem(result);
|
|
104
|
-
});
|
|
105
|
-
const unsub2 = this.state.subscribeMantaPayBalance();
|
|
106
|
-
if (onlyRunOnFirstTime) {
|
|
107
|
-
unsub && unsub();
|
|
108
|
-
unsub2 && unsub2();
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
return () => {
|
|
112
|
-
unsub && unsub();
|
|
113
|
-
unsub2 && unsub2();
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
81
|
initCrowdloanSubscription(addresses, substrateApiMap, onlyRunOnFirstTime) {
|
|
117
82
|
const subscriptionPromise = subscribeCrowdloan(addresses, substrateApiMap, (networkKey, rs) => {
|
|
118
83
|
this.state.setCrowdloanItem(networkKey, rs);
|
|
@@ -139,33 +104,9 @@ export class KoniSubscription {
|
|
|
139
104
|
nftHandler.setAddresses(addresses);
|
|
140
105
|
nftHandler.handleNfts(smartContractNfts, (...args) => this.state.updateNftData(...args), (...args) => this.state.setNftCollection(...args)).catch(this.logger.log);
|
|
141
106
|
}
|
|
142
|
-
async
|
|
143
|
-
const addresses = this.state.getDecodedAddresses(address);
|
|
144
|
-
if (!addresses.length) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
const chainInfoMap = this.state.getChainInfoMap();
|
|
148
|
-
const targetNetworkMap = {};
|
|
149
|
-
Object.entries(chainInfoMap).forEach(([key, network]) => {
|
|
150
|
-
const chainState = this.state.getChainStateByKey(key);
|
|
151
|
-
if (_isChainEnabled(chainState) && _isChainSupportSubstrateStaking(network)) {
|
|
152
|
-
targetNetworkMap[key] = network;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
await getNominationStakingRewardData(addresses, targetNetworkMap, rewardItem => {
|
|
156
|
-
this.state.updateStakingReward(rewardItem);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
async reloadBalance() {
|
|
107
|
+
async reloadCrowdloan() {
|
|
160
108
|
var _this$state$keyringSe2;
|
|
161
109
|
const currentAddress = (_this$state$keyringSe2 = this.state.keyringService.currentAccount) === null || _this$state$keyringSe2 === void 0 ? void 0 : _this$state$keyringSe2.address;
|
|
162
|
-
await this.state.handleResetBalance(currentAddress, true);
|
|
163
|
-
this.subscribeBalances(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
|
|
164
|
-
await waitTimeout(1800);
|
|
165
|
-
}
|
|
166
|
-
async reloadCrowdloan() {
|
|
167
|
-
var _this$state$keyringSe3;
|
|
168
|
-
const currentAddress = (_this$state$keyringSe3 = this.state.keyringService.currentAccount) === null || _this$state$keyringSe3 === void 0 ? void 0 : _this$state$keyringSe3.address;
|
|
169
110
|
this.subscribeCrowdloans(currentAddress, this.state.getSubstrateApiMap());
|
|
170
111
|
await waitTimeout(1800);
|
|
171
112
|
}
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.1.
|
|
20
|
+
"version": "1.1.53-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -535,15 +535,20 @@
|
|
|
535
535
|
"require": "./cjs/services/balance-service/BalanceMapImpl.js",
|
|
536
536
|
"default": "./services/balance-service/BalanceMapImpl.js"
|
|
537
537
|
},
|
|
538
|
+
"./services/balance-service/helpers": {
|
|
539
|
+
"types": "./services/balance-service/helpers/index.d.ts",
|
|
540
|
+
"require": "./cjs/services/balance-service/helpers/index.js",
|
|
541
|
+
"default": "./services/balance-service/helpers/index.js"
|
|
542
|
+
},
|
|
538
543
|
"./services/balance-service/helpers/group": {
|
|
539
544
|
"types": "./services/balance-service/helpers/group.d.ts",
|
|
540
545
|
"require": "./cjs/services/balance-service/helpers/group.js",
|
|
541
546
|
"default": "./services/balance-service/helpers/group.js"
|
|
542
547
|
},
|
|
543
|
-
"./services/balance-service/helpers/subscribe
|
|
544
|
-
"types": "./services/balance-service/helpers/subscribe/
|
|
545
|
-
"require": "./cjs/services/balance-service/helpers/subscribe/
|
|
546
|
-
"default": "./services/balance-service/helpers/subscribe/
|
|
548
|
+
"./services/balance-service/helpers/subscribe": {
|
|
549
|
+
"types": "./services/balance-service/helpers/subscribe/index.d.ts",
|
|
550
|
+
"require": "./cjs/services/balance-service/helpers/subscribe/index.js",
|
|
551
|
+
"default": "./services/balance-service/helpers/subscribe/index.js"
|
|
547
552
|
},
|
|
548
553
|
"./services/balance-service/helpers/subscribe/evm": {
|
|
549
554
|
"types": "./services/balance-service/helpers/subscribe/evm.d.ts",
|
|
@@ -1531,9 +1536,9 @@
|
|
|
1531
1536
|
"default": "./types/index.js"
|
|
1532
1537
|
},
|
|
1533
1538
|
"./types/balance": {
|
|
1534
|
-
"types": "./types/balance.d.ts",
|
|
1535
|
-
"require": "./cjs/types/balance.js",
|
|
1536
|
-
"default": "./types/balance.js"
|
|
1539
|
+
"types": "./types/balance/index.d.ts",
|
|
1540
|
+
"require": "./cjs/types/balance/index.js",
|
|
1541
|
+
"default": "./types/balance/index.js"
|
|
1537
1542
|
},
|
|
1538
1543
|
"./types/buy": {
|
|
1539
1544
|
"types": "./types/buy.d.ts",
|
|
@@ -1670,6 +1675,11 @@
|
|
|
1670
1675
|
"require": "./cjs/utils/array.js",
|
|
1671
1676
|
"default": "./utils/array.js"
|
|
1672
1677
|
},
|
|
1678
|
+
"./utils/asset": {
|
|
1679
|
+
"types": "./utils/asset.d.ts",
|
|
1680
|
+
"require": "./cjs/utils/asset.js",
|
|
1681
|
+
"default": "./utils/asset.js"
|
|
1682
|
+
},
|
|
1673
1683
|
"./utils/canDerive": {
|
|
1674
1684
|
"types": "./utils/canDerive.d.ts",
|
|
1675
1685
|
"require": "./cjs/utils/canDerive.js",
|
|
@@ -1806,11 +1816,11 @@
|
|
|
1806
1816
|
"@reduxjs/toolkit": "^1.9.1",
|
|
1807
1817
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
1808
1818
|
"@substrate/connect": "^0.7.26",
|
|
1809
|
-
"@subwallet/chain-list": "0.2.
|
|
1810
|
-
"@subwallet/extension-base": "^1.1.
|
|
1811
|
-
"@subwallet/extension-chains": "^1.1.
|
|
1812
|
-
"@subwallet/extension-dapp": "^1.1.
|
|
1813
|
-
"@subwallet/extension-inject": "^1.1.
|
|
1819
|
+
"@subwallet/chain-list": "0.2.54",
|
|
1820
|
+
"@subwallet/extension-base": "^1.1.53-0",
|
|
1821
|
+
"@subwallet/extension-chains": "^1.1.53-0",
|
|
1822
|
+
"@subwallet/extension-dapp": "^1.1.53-0",
|
|
1823
|
+
"@subwallet/extension-inject": "^1.1.53-0",
|
|
1814
1824
|
"@subwallet/keyring": "^0.1.3",
|
|
1815
1825
|
"@subwallet/ui-keyring": "^0.1.3",
|
|
1816
1826
|
"@walletconnect/sign-client": "^2.8.4",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.1.
|
|
10
|
+
version: '1.1.53-0'
|
|
11
11
|
};
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
5
|
-
import { groupBalance } from '@subwallet/extension-base/services/balance-service/helpers/group';
|
|
6
5
|
import { isAccountAll } from '@subwallet/extension-base/utils';
|
|
7
6
|
import { BehaviorSubject } from 'rxjs';
|
|
7
|
+
import { groupBalance } from "./helpers/index.js";
|
|
8
8
|
export class BalanceMapImpl {
|
|
9
9
|
constructor(_map = {}) {
|
|
10
10
|
this._map = _map;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare function subscribeERC20Interval(addresses: string[], chain: string, evmApiMap: Record<string, _EvmApi>, callBack: (result: BalanceItem[]) => void): () => void;
|
|
5
|
-
export declare function subscribeEVMBalance(chain: string, addresses: string[], evmApiMap: Record<string, _EvmApi>, callback: (rs: BalanceItem[]) => void, tokenInfo: _ChainAsset): () => void;
|
|
1
|
+
import { SubscribeEvmPalletBalance } from '@subwallet/extension-base/types';
|
|
2
|
+
export declare function subscribeERC20Interval({ addresses, assetMap, callback, chainInfo, evmApi }: SubscribeEvmPalletBalance): () => void;
|
|
3
|
+
export declare function subscribeEVMBalance(params: SubscribeEvmPalletBalance): () => void;
|
|
@@ -6,12 +6,22 @@ import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
|
|
|
6
6
|
import { ASTAR_REFRESH_BALANCE_INTERVAL, SUB_TOKEN_REFRESH_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
7
7
|
import { getEVMBalance } from '@subwallet/extension-base/koni/api/tokens/evm/balance';
|
|
8
8
|
import { getERC20Contract } from '@subwallet/extension-base/koni/api/tokens/evm/web3';
|
|
9
|
-
import { state } from '@subwallet/extension-base/koni/background/handlers';
|
|
10
9
|
import { _getContractAddressOfToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
|
+
import { filterAssetsByChainAndType } from '@subwallet/extension-base/utils';
|
|
11
11
|
import { BN } from '@polkadot/util';
|
|
12
|
-
export function subscribeERC20Interval(
|
|
13
|
-
|
|
12
|
+
export function subscribeERC20Interval({
|
|
13
|
+
addresses,
|
|
14
|
+
assetMap,
|
|
15
|
+
callback,
|
|
16
|
+
chainInfo,
|
|
17
|
+
evmApi
|
|
18
|
+
}) {
|
|
19
|
+
const chain = chainInfo.slug;
|
|
20
|
+
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.ERC20]);
|
|
14
21
|
const erc20ContractMap = {};
|
|
22
|
+
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
23
|
+
erc20ContractMap[slug] = getERC20Contract(_getContractAddressOfToken(tokenInfo), evmApi);
|
|
24
|
+
});
|
|
15
25
|
const getTokenBalances = () => {
|
|
16
26
|
Object.values(tokenList).map(async tokenInfo => {
|
|
17
27
|
try {
|
|
@@ -34,40 +44,47 @@ export function subscribeERC20Interval(addresses, chain, evmApiMap, callBack) {
|
|
|
34
44
|
state: APIItemState.READY
|
|
35
45
|
};
|
|
36
46
|
});
|
|
37
|
-
|
|
47
|
+
callback(items);
|
|
38
48
|
} catch (err) {
|
|
39
49
|
console.log(tokenInfo.slug, err);
|
|
40
50
|
}
|
|
41
51
|
});
|
|
42
52
|
};
|
|
43
|
-
tokenList = state.getAssetByChainAndAsset(chain, [_AssetType.ERC20]);
|
|
44
|
-
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
45
|
-
erc20ContractMap[slug] = getERC20Contract(chain, _getContractAddressOfToken(tokenInfo), evmApiMap);
|
|
46
|
-
});
|
|
47
53
|
getTokenBalances();
|
|
48
54
|
const interval = setInterval(getTokenBalances, SUB_TOKEN_REFRESH_BALANCE_INTERVAL);
|
|
49
55
|
return () => {
|
|
50
56
|
clearInterval(interval);
|
|
51
57
|
};
|
|
52
58
|
}
|
|
53
|
-
export function subscribeEVMBalance(
|
|
59
|
+
export function subscribeEVMBalance(params) {
|
|
60
|
+
var _Object$values$;
|
|
61
|
+
const {
|
|
62
|
+
addresses,
|
|
63
|
+
assetMap,
|
|
64
|
+
callback,
|
|
65
|
+
chainInfo,
|
|
66
|
+
evmApi
|
|
67
|
+
} = params;
|
|
68
|
+
const chain = chainInfo.slug;
|
|
69
|
+
const nativeTokenInfo = filterAssetsByChainAndType(assetMap, chain, [_AssetType.NATIVE]);
|
|
70
|
+
const nativeTokenSlug = ((_Object$values$ = Object.values(nativeTokenInfo)[0]) === null || _Object$values$ === void 0 ? void 0 : _Object$values$.slug) || '';
|
|
54
71
|
function getBalance() {
|
|
55
|
-
getEVMBalance(chain, addresses,
|
|
72
|
+
getEVMBalance(chain, addresses, evmApi).then(balances => {
|
|
56
73
|
return balances.map((balance, index) => {
|
|
57
74
|
return {
|
|
58
75
|
address: addresses[index],
|
|
59
|
-
tokenSlug:
|
|
76
|
+
tokenSlug: nativeTokenSlug,
|
|
60
77
|
state: APIItemState.READY,
|
|
61
78
|
free: new BN(balance || '0').toString(),
|
|
62
79
|
locked: '0'
|
|
63
80
|
};
|
|
64
81
|
});
|
|
65
82
|
}).catch(e => {
|
|
66
|
-
console.error(`Error on get native balance with token ${
|
|
83
|
+
console.error(`Error on get native balance with token ${nativeTokenSlug}`, e);
|
|
67
84
|
return addresses.map(address => {
|
|
68
85
|
return {
|
|
69
86
|
address: address,
|
|
70
|
-
tokenSlug:
|
|
87
|
+
tokenSlug: nativeTokenSlug,
|
|
71
88
|
state: APIItemState.READY,
|
|
72
89
|
free: '0',
|
|
73
90
|
locked: '0'
|
|
@@ -79,7 +96,7 @@ export function subscribeEVMBalance(chain, addresses, evmApiMap, callback, token
|
|
|
79
96
|
}
|
|
80
97
|
getBalance();
|
|
81
98
|
const interval = setInterval(getBalance, ASTAR_REFRESH_BALANCE_INTERVAL);
|
|
82
|
-
const unsub2 = subscribeERC20Interval(
|
|
99
|
+
const unsub2 = subscribeERC20Interval(params);
|
|
83
100
|
return () => {
|
|
84
101
|
clearInterval(interval);
|
|
85
102
|
unsub2 && unsub2();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
1
|
+
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { AccountJson } from '@subwallet/extension-base/background/types';
|
|
3
3
|
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
4
|
import { BalanceItem } from '@subwallet/extension-base/types';
|
|
@@ -12,4 +12,4 @@ import { BalanceItem } from '@subwallet/extension-base/types';
|
|
|
12
12
|
* @returns {AccountJson|null} - Account info or null if not found
|
|
13
13
|
*/
|
|
14
14
|
export declare const getAccountJsonByAddress: (address: string) => AccountJson | null;
|
|
15
|
-
export declare function subscribeBalance(addresses: string[],
|
|
15
|
+
export declare function subscribeBalance(addresses: string[], chains: string[], tokens: string[], _chainAssetMap: Record<string, _ChainAsset>, _chainInfoMap: Record<string, _ChainInfo>, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, callback: (rs: BalanceItem[]) => void): () => void;
|