Skip to content

Commit c17a72a

Browse files
authored
Merge pull request Koniverse#3082 from Koniverse/koni/dev/issue-3081
[Issue-3081] [Extension] Fix earning data for update chain online
2 parents e8b40e3 + b41d181 commit c17a72a

File tree

10 files changed

+46
-21
lines changed

10 files changed

+46
-21
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"@polkadot/types-codec": "^11.0.3",
9292
"@polkadot/util": "^12.6.2",
9393
"@polkadot/util-crypto": "^12.6.2",
94-
"@subwallet/chain-list": "0.2.62",
94+
"@subwallet/chain-list": "0.2.63",
9595
"@subwallet/keyring": "^0.1.5",
9696
"@subwallet/react-ui": "5.1.2-b77",
9797
"@subwallet/ui-keyring": "^0.1.5",

packages/extension-base/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@reduxjs/toolkit": "^1.9.1",
5252
"@sora-substrate/type-definitions": "^1.17.7",
5353
"@substrate/connect": "^0.8.9",
54-
"@subwallet/chain-list": "0.2.62",
54+
"@subwallet/chain-list": "0.2.63",
5555
"@subwallet/extension-base": "^1.1.66-0",
5656
"@subwallet/extension-chains": "^1.1.66-0",
5757
"@subwallet/extension-dapp": "^1.1.66-0",

packages/extension-base/src/koni/background/cron.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
55
import { ApiMap, ServiceInfo } from '@subwallet/extension-base/background/KoniTypes';
6-
import { CRON_REFRESH_NFT_INTERVAL, CRON_SYNC_MANTA_PAY } from '@subwallet/extension-base/constants';
6+
import { CRON_REFRESH_CHAIN_STAKING_METADATA, CRON_REFRESH_NFT_INTERVAL, CRON_SYNC_MANTA_PAY } from '@subwallet/extension-base/constants';
77
import { KoniSubscription } from '@subwallet/extension-base/koni/background/subscription';
88
import { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportWasmNft } from '@subwallet/extension-base/services/chain-service/utils';
99
import { EventItem, EventType } from '@subwallet/extension-base/services/event-service/types';
@@ -129,6 +129,12 @@ export class KoniCron {
129129
(commonReload || needUpdateNft) && this.removeCron('refreshNft');
130130
commonReload && this.removeCron('refreshPoolingStakingReward');
131131

132+
if (chainUpdated) {
133+
this.stopPoolInfo();
134+
this.removeCron('fetchPoolInfo');
135+
this.addCron('fetchPoolInfo', this.fetchPoolInfo, CRON_REFRESH_CHAIN_STAKING_METADATA);
136+
}
137+
132138
// Chains
133139
if (this.checkNetworkAvailable(serviceInfo)) { // only add cron jobs if there's at least 1 active network
134140
(commonReload || needUpdateNft) && this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
@@ -138,6 +144,8 @@ export class KoniCron {
138144

139145
this.state.eventService.onLazy(this.eventHandler);
140146

147+
this.addCron('fetchPoolInfo', this.fetchPoolInfo, CRON_REFRESH_CHAIN_STAKING_METADATA);
148+
141149
if (!currentAccountInfo?.address) {
142150
return;
143151
}
@@ -169,6 +177,7 @@ export class KoniCron {
169177
}
170178

171179
this.removeAllCrons();
180+
this.stopPoolInfo();
172181

173182
this.status = 'stopped';
174183

@@ -181,6 +190,14 @@ export class KoniCron {
181190
}
182191
};
183192

193+
fetchPoolInfo = () => {
194+
this.state.earningService.runSubscribePoolsInfo().catch(console.error);
195+
};
196+
197+
stopPoolInfo = () => {
198+
this.state.earningService.runUnsubscribePoolsInfo();
199+
};
200+
184201
refreshNft = (address: string, apiMap: ApiMap, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>) => {
185202
return () => {
186203
this.subscriptions.subscribeNft(address, apiMap.substrate, apiMap.evm, smartContractNfts, chainInfoMap);

packages/extension-base/src/services/earning-service/service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export default class EarningService implements StoppableServiceInterface, Persis
244244
this.status = ServiceStatus.STARTING;
245245

246246
// Start subscribe pools' info
247-
await this.runSubscribePoolsInfo();
247+
// await this.runSubscribePoolsInfo();
248248

249249
// Start subscribe pools' position
250250
await this.runSubscribePoolsPosition();
@@ -276,7 +276,7 @@ export default class EarningService implements StoppableServiceInterface, Persis
276276
await this.persistData();
277277

278278
// Stop subscribe pools' info
279-
this.runUnsubscribePoolsInfo();
279+
// this.runUnsubscribePoolsInfo();
280280

281281
// Stop subscribe pools' position
282282
this.runUnsubscribePoolsPosition();

packages/extension-koni-ui/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@polkadot/util-crypto": "^12.6.2",
3535
"@ramonak/react-progress-bar": "^5.0.3",
3636
"@reduxjs/toolkit": "^1.9.1",
37-
"@subwallet/chain-list": "0.2.62",
37+
"@subwallet/chain-list": "0.2.63",
3838
"@subwallet/extension-base": "^1.1.66-0",
3939
"@subwallet/extension-chains": "^1.1.66-0",
4040
"@subwallet/extension-dapp": "^1.1.66-0",

packages/extension-koni-ui/src/hooks/common/useGetChainSlugsByCurrentAccount.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import type { KeypairType } from '@polkadot/util-crypto/types';
55

6-
import { _ChainInfo } from '@subwallet/chain-list/types';
6+
import { _ChainInfo, _ChainStatus } from '@subwallet/chain-list/types';
77
import { AccountJson } from '@subwallet/extension-base/background/types';
88
import { _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
99
import { RootState } from '@subwallet/extension-koni-ui/stores';
@@ -18,7 +18,11 @@ import { isEthereumAddress } from '@polkadot/util-crypto';
1818
function getChainsAccountType (accountType: AccountType, chainInfoMap: Record<string, _ChainInfo>, accountNetworks?: string[]): string[] {
1919
const result: string[] = [];
2020

21-
Object.keys(chainInfoMap).forEach((chain) => {
21+
for (const [chain, { chainStatus }] of Object.entries(chainInfoMap)) {
22+
if (chainStatus !== _ChainStatus.ACTIVE) {
23+
continue;
24+
}
25+
2226
if (accountNetworks) {
2327
if (accountNetworks.includes(chain)) {
2428
result.push(chain);
@@ -36,7 +40,7 @@ function getChainsAccountType (accountType: AccountType, chainInfoMap: Record<st
3640
}
3741
}
3842
}
39-
});
43+
}
4044

4145
return result;
4246
}

packages/extension-web-ui/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@polkadot/util-crypto": "^12.6.2",
3636
"@ramonak/react-progress-bar": "^5.0.3",
3737
"@reduxjs/toolkit": "^1.9.1",
38-
"@subwallet/chain-list": "0.2.62",
38+
"@subwallet/chain-list": "0.2.63",
3939
"@subwallet/extension-base": "^1.1.66-0",
4040
"@subwallet/extension-chains": "^1.1.66-0",
4141
"@subwallet/extension-dapp": "^1.1.66-0",

packages/extension-web-ui/src/hooks/common/useGetChainSlugsByCurrentAccount.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import type { KeypairType } from '@polkadot/util-crypto/types';
55

6-
import { _ChainInfo } from '@subwallet/chain-list/types';
6+
import { _ChainInfo, _ChainStatus } from '@subwallet/chain-list/types';
77
import { AccountJson } from '@subwallet/extension-base/background/types';
88
import { _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
99
import { RootState } from '@subwallet/extension-web-ui/stores';
@@ -18,7 +18,11 @@ import { isEthereumAddress } from '@polkadot/util-crypto';
1818
function getChainsAccountType (accountType: AccountType, chainInfoMap: Record<string, _ChainInfo>, accountNetworks?: string[]): string[] {
1919
const result: string[] = [];
2020

21-
Object.keys(chainInfoMap).forEach((chain) => {
21+
for (const [chain, { chainStatus }] of Object.entries(chainInfoMap)) {
22+
if (chainStatus !== _ChainStatus.ACTIVE) {
23+
continue;
24+
}
25+
2226
if (accountNetworks) {
2327
if (accountNetworks.includes(chain)) {
2428
result.push(chain);
@@ -36,7 +40,7 @@ function getChainsAccountType (accountType: AccountType, chainInfoMap: Record<st
3640
}
3741
}
3842
}
39-
});
43+
}
4044

4145
return result;
4246
}

packages/webapp/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@
4949
"webpack-cli": "^5.1.4",
5050
"webpack-dev-server": "^5.0.4"
5151
}
52-
}
52+
}

yarn.lock

+7-7
Original file line numberDiff line numberDiff line change
@@ -6130,14 +6130,14 @@ __metadata:
61306130
languageName: node
61316131
linkType: hard
61326132

6133-
"@subwallet/chain-list@npm:0.2.62":
6134-
version: 0.2.62
6135-
resolution: "@subwallet/chain-list@npm:0.2.62"
6133+
"@subwallet/chain-list@npm:0.2.63":
6134+
version: 0.2.63
6135+
resolution: "@subwallet/chain-list@npm:0.2.63"
61366136
dependencies:
61376137
"@polkadot/dev": 0.67.167
61386138
"@polkadot/util": ^12.5.1
61396139
eventemitter3: ^5.0.1
6140-
checksum: e3291cef981e99fdb43068c246dd0b0fc0a6e13dc49577e9353ba644b84835d96252b4fde5f0609f66cdff1698c21d893c1115ab929cc16a62e67ac44639fc58
6140+
checksum: 2329276f361d12f44ae457b626d790bb995533cbb0af4dc89e06e36bb22fa30fca994d2f7100df9bbea605a535b4a7f4ecedd1a3ff985693189f546a1fe2bc4a
61416141
languageName: node
61426142
linkType: hard
61436143

@@ -6176,7 +6176,7 @@ __metadata:
61766176
"@reduxjs/toolkit": ^1.9.1
61776177
"@sora-substrate/type-definitions": ^1.17.7
61786178
"@substrate/connect": ^0.8.9
6179-
"@subwallet/chain-list": 0.2.62
6179+
"@subwallet/chain-list": 0.2.63
61806180
"@subwallet/extension-base": ^1.1.66-0
61816181
"@subwallet/extension-chains": ^1.1.66-0
61826182
"@subwallet/extension-dapp": ^1.1.66-0
@@ -6307,7 +6307,7 @@ __metadata:
63076307
"@polkadot/util-crypto": ^12.6.2
63086308
"@ramonak/react-progress-bar": ^5.0.3
63096309
"@reduxjs/toolkit": ^1.9.1
6310-
"@subwallet/chain-list": 0.2.62
6310+
"@subwallet/chain-list": 0.2.63
63116311
"@subwallet/extension-base": ^1.1.66-0
63126312
"@subwallet/extension-chains": ^1.1.66-0
63136313
"@subwallet/extension-dapp": ^1.1.66-0
@@ -6440,7 +6440,7 @@ __metadata:
64406440
"@polkadot/util-crypto": ^12.6.2
64416441
"@ramonak/react-progress-bar": ^5.0.3
64426442
"@reduxjs/toolkit": ^1.9.1
6443-
"@subwallet/chain-list": 0.2.62
6443+
"@subwallet/chain-list": 0.2.63
64446444
"@subwallet/extension-base": ^1.1.66-0
64456445
"@subwallet/extension-chains": ^1.1.66-0
64466446
"@subwallet/extension-dapp": ^1.1.66-0

0 commit comments

Comments
 (0)