@subwallet/extension-base 1.0.13-1 → 1.1.1-dev.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/bundle-polkadot-extension-base.js +20 -0
- package/cjs/koni/api/staking/bonding/astar.js +2 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +12 -2
- package/cjs/koni/api/staking/bonding/utils.js +2 -2
- package/cjs/koni/background/cron.js +2 -37
- package/cjs/koni/background/handlers/State.js +2 -1
- package/cjs/koni/background/subscription.js +6 -86
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/helper/erc20_abi.json +224 -0
- package/cjs/services/chain-service/helper/erc721_abi.json +384 -0
- package/cjs/services/chain-service/helper/psp22_abi.json +1127 -0
- package/cjs/services/chain-service/helper/psp34_abi.json +3144 -0
- package/cjs/services/chain-service/helper/test_erc721_abi.json +393 -0
- package/koni/api/staking/bonding/astar.d.ts +1 -1
- package/koni/api/staking/bonding/astar.js +1 -1
- package/koni/api/staking/bonding/relayChain.js +12 -2
- package/koni/api/staking/bonding/utils.js +3 -3
- package/koni/background/cron.d.ts +0 -5
- package/koni/background/cron.js +4 -39
- package/koni/background/handlers/State.js +2 -1
- package/koni/background/subscription.d.ts +1 -4
- package/koni/background/subscription.js +8 -87
- package/package.json +6 -6
- package/packageInfo.js +1 -1
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [],
|
|
4
|
+
"stateMutability": "nonpayable",
|
|
5
|
+
"type": "constructor"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"anonymous": false,
|
|
9
|
+
"inputs": [
|
|
10
|
+
{
|
|
11
|
+
"indexed": true,
|
|
12
|
+
"internalType": "address",
|
|
13
|
+
"name": "_owner",
|
|
14
|
+
"type": "address"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"indexed": true,
|
|
18
|
+
"internalType": "address",
|
|
19
|
+
"name": "_approved",
|
|
20
|
+
"type": "address"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"indexed": true,
|
|
24
|
+
"internalType": "uint256",
|
|
25
|
+
"name": "_tokenId",
|
|
26
|
+
"type": "uint256"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"name": "Approval",
|
|
30
|
+
"type": "event"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"anonymous": false,
|
|
34
|
+
"inputs": [
|
|
35
|
+
{
|
|
36
|
+
"indexed": true,
|
|
37
|
+
"internalType": "address",
|
|
38
|
+
"name": "_owner",
|
|
39
|
+
"type": "address"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"indexed": true,
|
|
43
|
+
"internalType": "address",
|
|
44
|
+
"name": "_operator",
|
|
45
|
+
"type": "address"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"indexed": false,
|
|
49
|
+
"internalType": "bool",
|
|
50
|
+
"name": "_approved",
|
|
51
|
+
"type": "bool"
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"name": "ApprovalForAll",
|
|
55
|
+
"type": "event"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"anonymous": false,
|
|
59
|
+
"inputs": [
|
|
60
|
+
{
|
|
61
|
+
"indexed": true,
|
|
62
|
+
"internalType": "address",
|
|
63
|
+
"name": "_from",
|
|
64
|
+
"type": "address"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"indexed": true,
|
|
68
|
+
"internalType": "address",
|
|
69
|
+
"name": "_to",
|
|
70
|
+
"type": "address"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"indexed": true,
|
|
74
|
+
"internalType": "uint256",
|
|
75
|
+
"name": "_tokenId",
|
|
76
|
+
"type": "uint256"
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
"name": "Transfer",
|
|
80
|
+
"type": "event"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"inputs": [
|
|
84
|
+
{
|
|
85
|
+
"internalType": "address",
|
|
86
|
+
"name": "_approved",
|
|
87
|
+
"type": "address"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"internalType": "uint256",
|
|
91
|
+
"name": "_tokenId",
|
|
92
|
+
"type": "uint256"
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"name": "approve",
|
|
96
|
+
"outputs": [],
|
|
97
|
+
"stateMutability": "nonpayable",
|
|
98
|
+
"type": "function"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"inputs": [
|
|
102
|
+
{
|
|
103
|
+
"internalType": "address",
|
|
104
|
+
"name": "_owner",
|
|
105
|
+
"type": "address"
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"name": "balanceOf",
|
|
109
|
+
"outputs": [
|
|
110
|
+
{
|
|
111
|
+
"internalType": "uint256",
|
|
112
|
+
"name": "",
|
|
113
|
+
"type": "uint256"
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"stateMutability": "view",
|
|
117
|
+
"type": "function"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"inputs": [
|
|
121
|
+
{
|
|
122
|
+
"internalType": "uint256",
|
|
123
|
+
"name": "_tokenId",
|
|
124
|
+
"type": "uint256"
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
"name": "getApproved",
|
|
128
|
+
"outputs": [
|
|
129
|
+
{
|
|
130
|
+
"internalType": "address",
|
|
131
|
+
"name": "",
|
|
132
|
+
"type": "address"
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
"stateMutability": "view",
|
|
136
|
+
"type": "function"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"inputs": [
|
|
140
|
+
{
|
|
141
|
+
"internalType": "address",
|
|
142
|
+
"name": "_owner",
|
|
143
|
+
"type": "address"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"internalType": "address",
|
|
147
|
+
"name": "_operator",
|
|
148
|
+
"type": "address"
|
|
149
|
+
}
|
|
150
|
+
],
|
|
151
|
+
"name": "isApprovedForAll",
|
|
152
|
+
"outputs": [
|
|
153
|
+
{
|
|
154
|
+
"internalType": "bool",
|
|
155
|
+
"name": "",
|
|
156
|
+
"type": "bool"
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
"stateMutability": "view",
|
|
160
|
+
"type": "function"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"inputs": [],
|
|
164
|
+
"name": "name",
|
|
165
|
+
"outputs": [
|
|
166
|
+
{
|
|
167
|
+
"internalType": "string",
|
|
168
|
+
"name": "_name",
|
|
169
|
+
"type": "string"
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
"stateMutability": "view",
|
|
173
|
+
"type": "function"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"inputs": [
|
|
177
|
+
{
|
|
178
|
+
"internalType": "uint256",
|
|
179
|
+
"name": "_tokenId",
|
|
180
|
+
"type": "uint256"
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
"name": "ownerOf",
|
|
184
|
+
"outputs": [
|
|
185
|
+
{
|
|
186
|
+
"internalType": "address",
|
|
187
|
+
"name": "_owner",
|
|
188
|
+
"type": "address"
|
|
189
|
+
}
|
|
190
|
+
],
|
|
191
|
+
"stateMutability": "view",
|
|
192
|
+
"type": "function"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"inputs": [
|
|
196
|
+
{
|
|
197
|
+
"internalType": "address",
|
|
198
|
+
"name": "_from",
|
|
199
|
+
"type": "address"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"internalType": "address",
|
|
203
|
+
"name": "_to",
|
|
204
|
+
"type": "address"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"internalType": "uint256",
|
|
208
|
+
"name": "_tokenId",
|
|
209
|
+
"type": "uint256"
|
|
210
|
+
}
|
|
211
|
+
],
|
|
212
|
+
"name": "safeTransferFrom",
|
|
213
|
+
"outputs": [],
|
|
214
|
+
"stateMutability": "nonpayable",
|
|
215
|
+
"type": "function"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"inputs": [
|
|
219
|
+
{
|
|
220
|
+
"internalType": "address",
|
|
221
|
+
"name": "_from",
|
|
222
|
+
"type": "address"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"internalType": "address",
|
|
226
|
+
"name": "_to",
|
|
227
|
+
"type": "address"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"internalType": "uint256",
|
|
231
|
+
"name": "_tokenId",
|
|
232
|
+
"type": "uint256"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"internalType": "bytes",
|
|
236
|
+
"name": "_data",
|
|
237
|
+
"type": "bytes"
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
"name": "safeTransferFrom",
|
|
241
|
+
"outputs": [],
|
|
242
|
+
"stateMutability": "nonpayable",
|
|
243
|
+
"type": "function"
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"inputs": [
|
|
247
|
+
{
|
|
248
|
+
"internalType": "address",
|
|
249
|
+
"name": "_operator",
|
|
250
|
+
"type": "address"
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
"internalType": "bool",
|
|
254
|
+
"name": "_approved",
|
|
255
|
+
"type": "bool"
|
|
256
|
+
}
|
|
257
|
+
],
|
|
258
|
+
"name": "setApprovalForAll",
|
|
259
|
+
"outputs": [],
|
|
260
|
+
"stateMutability": "nonpayable",
|
|
261
|
+
"type": "function"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
"inputs": [
|
|
265
|
+
{
|
|
266
|
+
"internalType": "bytes4",
|
|
267
|
+
"name": "_interfaceID",
|
|
268
|
+
"type": "bytes4"
|
|
269
|
+
}
|
|
270
|
+
],
|
|
271
|
+
"name": "supportsInterface",
|
|
272
|
+
"outputs": [
|
|
273
|
+
{
|
|
274
|
+
"internalType": "bool",
|
|
275
|
+
"name": "",
|
|
276
|
+
"type": "bool"
|
|
277
|
+
}
|
|
278
|
+
],
|
|
279
|
+
"stateMutability": "view",
|
|
280
|
+
"type": "function"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"inputs": [],
|
|
284
|
+
"name": "symbol",
|
|
285
|
+
"outputs": [
|
|
286
|
+
{
|
|
287
|
+
"internalType": "string",
|
|
288
|
+
"name": "_symbol",
|
|
289
|
+
"type": "string"
|
|
290
|
+
}
|
|
291
|
+
],
|
|
292
|
+
"stateMutability": "view",
|
|
293
|
+
"type": "function"
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
"inputs": [
|
|
297
|
+
{
|
|
298
|
+
"internalType": "uint256",
|
|
299
|
+
"name": "_index",
|
|
300
|
+
"type": "uint256"
|
|
301
|
+
}
|
|
302
|
+
],
|
|
303
|
+
"name": "tokenByIndex",
|
|
304
|
+
"outputs": [
|
|
305
|
+
{
|
|
306
|
+
"internalType": "uint256",
|
|
307
|
+
"name": "",
|
|
308
|
+
"type": "uint256"
|
|
309
|
+
}
|
|
310
|
+
],
|
|
311
|
+
"stateMutability": "view",
|
|
312
|
+
"type": "function"
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
"inputs": [
|
|
316
|
+
{
|
|
317
|
+
"internalType": "address",
|
|
318
|
+
"name": "_owner",
|
|
319
|
+
"type": "address"
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
"internalType": "uint256",
|
|
323
|
+
"name": "_index",
|
|
324
|
+
"type": "uint256"
|
|
325
|
+
}
|
|
326
|
+
],
|
|
327
|
+
"name": "tokenOfOwnerByIndex",
|
|
328
|
+
"outputs": [
|
|
329
|
+
{
|
|
330
|
+
"internalType": "uint256",
|
|
331
|
+
"name": "",
|
|
332
|
+
"type": "uint256"
|
|
333
|
+
}
|
|
334
|
+
],
|
|
335
|
+
"stateMutability": "view",
|
|
336
|
+
"type": "function"
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
"inputs": [
|
|
340
|
+
{
|
|
341
|
+
"internalType": "uint256",
|
|
342
|
+
"name": "_tokenId",
|
|
343
|
+
"type": "uint256"
|
|
344
|
+
}
|
|
345
|
+
],
|
|
346
|
+
"name": "tokenURI",
|
|
347
|
+
"outputs": [
|
|
348
|
+
{
|
|
349
|
+
"internalType": "string",
|
|
350
|
+
"name": "",
|
|
351
|
+
"type": "string"
|
|
352
|
+
}
|
|
353
|
+
],
|
|
354
|
+
"stateMutability": "view",
|
|
355
|
+
"type": "function"
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
"inputs": [],
|
|
359
|
+
"name": "totalSupply",
|
|
360
|
+
"outputs": [
|
|
361
|
+
{
|
|
362
|
+
"internalType": "uint256",
|
|
363
|
+
"name": "",
|
|
364
|
+
"type": "uint256"
|
|
365
|
+
}
|
|
366
|
+
],
|
|
367
|
+
"stateMutability": "view",
|
|
368
|
+
"type": "function"
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
"inputs": [
|
|
372
|
+
{
|
|
373
|
+
"internalType": "address",
|
|
374
|
+
"name": "_from",
|
|
375
|
+
"type": "address"
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
"internalType": "address",
|
|
379
|
+
"name": "_to",
|
|
380
|
+
"type": "address"
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
"internalType": "uint256",
|
|
384
|
+
"name": "_tokenId",
|
|
385
|
+
"type": "uint256"
|
|
386
|
+
}
|
|
387
|
+
],
|
|
388
|
+
"name": "transferFrom",
|
|
389
|
+
"outputs": [],
|
|
390
|
+
"stateMutability": "nonpayable",
|
|
391
|
+
"type": "function"
|
|
392
|
+
}
|
|
393
|
+
]
|
|
@@ -12,4 +12,4 @@ export declare function getAstarBondingExtrinsic(substrateApi: _SubstrateApi, am
|
|
|
12
12
|
export declare function getAstarUnbondingExtrinsic(substrateApi: _SubstrateApi, amount: string, dappAddress: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
13
13
|
export declare function getAstarWithdrawalExtrinsic(substrateApi: _SubstrateApi): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
14
14
|
export declare function getAstarClaimRewardExtrinsic(substrateApi: _SubstrateApi, address: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function getCompoundWithdrawable(nominatorMetadata: NominatorMetadata): UnstakingInfo;
|
|
@@ -351,7 +351,7 @@ export async function getAstarClaimRewardExtrinsic(substrateApi, address) {
|
|
|
351
351
|
}
|
|
352
352
|
return apiPromise.api.tx.utility.batch(transactions);
|
|
353
353
|
}
|
|
354
|
-
export function
|
|
354
|
+
export function getCompoundWithdrawable(nominatorMetadata) {
|
|
355
355
|
const unstakingInfo = {
|
|
356
356
|
chain: nominatorMetadata.chain,
|
|
357
357
|
status: UnstakingStatus.CLAIMABLE,
|
|
@@ -588,17 +588,27 @@ export async function getRelayBondingExtrinsic(substrateApi, amount, targetValid
|
|
|
588
588
|
const binaryAmount = new BN(amount);
|
|
589
589
|
let bondTx;
|
|
590
590
|
let nominateTx;
|
|
591
|
+
const _params = chainApi.api.tx.staking.bond.toJSON();
|
|
592
|
+
const paramsCount = _params.args.length;
|
|
591
593
|
const validatorParamList = targetValidators.map(validator => {
|
|
592
594
|
return validator.address;
|
|
593
595
|
});
|
|
594
596
|
if (!nominatorMetadata) {
|
|
595
|
-
|
|
597
|
+
if (paramsCount === 2) {
|
|
598
|
+
bondTx = chainApi.api.tx.staking.bond(binaryAmount, bondDest);
|
|
599
|
+
} else {
|
|
600
|
+
bondTx = chainApi.api.tx.staking.bond(address, binaryAmount, bondDest);
|
|
601
|
+
}
|
|
596
602
|
nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
|
|
597
603
|
return chainApi.api.tx.utility.batchAll([bondTx, nominateTx]);
|
|
598
604
|
}
|
|
599
605
|
if (!nominatorMetadata.isBondedBefore) {
|
|
600
606
|
// first time
|
|
601
|
-
|
|
607
|
+
if (paramsCount === 2) {
|
|
608
|
+
bondTx = chainApi.api.tx.staking.bond(binaryAmount, bondDest);
|
|
609
|
+
} else {
|
|
610
|
+
bondTx = chainApi.api.tx.staking.bond(nominatorMetadata.address, binaryAmount, bondDest);
|
|
611
|
+
}
|
|
602
612
|
nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
|
|
603
613
|
return chainApi.api.tx.utility.batchAll([bondTx, nominateTx]);
|
|
604
614
|
} else {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { StakingStatus, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
-
import {
|
|
5
|
+
import { getCompoundWithdrawable } from '@subwallet/extension-base/koni/api/staking/bonding/astar';
|
|
6
6
|
import { _KNOWN_CHAIN_INFLATION_PARAMS, _STAKING_CHAIN_GROUP, _SUBSTRATE_DEFAULT_INFLATION_PARAMS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
7
|
import { parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
8
8
|
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO, bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
|
|
@@ -218,8 +218,8 @@ export function isActionFromValidator(stakingType, chain) {
|
|
|
218
218
|
export function getWithdrawalInfo(nominatorMetadata) {
|
|
219
219
|
const unstakings = nominatorMetadata.unstakings;
|
|
220
220
|
let result;
|
|
221
|
-
if (_STAKING_CHAIN_GROUP.astar.includes(nominatorMetadata.chain)) {
|
|
222
|
-
return
|
|
221
|
+
if (_STAKING_CHAIN_GROUP.astar.includes(nominatorMetadata.chain) || _STAKING_CHAIN_GROUP.relay.includes(nominatorMetadata.chain)) {
|
|
222
|
+
return getCompoundWithdrawable(nominatorMetadata);
|
|
223
223
|
}
|
|
224
224
|
for (const unstaking of unstakings) {
|
|
225
225
|
if (unstaking.status === UnstakingStatus.CLAIMABLE) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { ApiMap, ServiceInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { KoniSubscription } from '@subwallet/extension-base/koni/background/subscription';
|
|
4
|
-
import { _ChainState, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
4
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
6
5
|
import { Subject } from 'rxjs';
|
|
7
6
|
import KoniState from './handlers/State';
|
|
@@ -27,15 +26,11 @@ export declare class KoniCron {
|
|
|
27
26
|
syncMantaPay: () => void;
|
|
28
27
|
refreshNft: (address: string, apiMap: ApiMap, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>) => () => void;
|
|
29
28
|
resetNft: (newAddress: string) => void;
|
|
30
|
-
resetStakingReward: () => void;
|
|
31
29
|
refreshStakingReward: (address: string) => () => void;
|
|
32
30
|
refreshStakingRewardFastInterval: (address: string) => () => void;
|
|
33
31
|
setStakingRewardReady: () => void;
|
|
34
32
|
checkNetworkAvailable: (serviceInfo: ServiceInfo) => boolean;
|
|
35
|
-
updateChainStakingMetadata: (chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>) => () => void;
|
|
36
|
-
updateNominatorMetadata: (address: string, chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>) => () => void;
|
|
37
33
|
reloadNft(): Promise<boolean>;
|
|
38
34
|
reloadStaking(): Promise<boolean>;
|
|
39
35
|
private needUpdateNft;
|
|
40
|
-
private needUpdateStaking;
|
|
41
36
|
}
|
package/koni/background/cron.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import { _isChainSupportEvmNft, _isChainSupportNativeNft,
|
|
4
|
+
import { CRON_REFRESH_NFT_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL, CRON_REFRESH_STAKING_REWARD_INTERVAL, CRON_SYNC_MANTA_PAY } from '@subwallet/extension-base/constants';
|
|
5
|
+
import { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportWasmNft } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
6
|
import { waitTimeout } from '@subwallet/extension-base/utils';
|
|
7
7
|
import { Subject } from 'rxjs';
|
|
8
8
|
import { logger as createLogger } from '@polkadot/util';
|
|
@@ -61,7 +61,6 @@ export class KoniCron {
|
|
|
61
61
|
const serviceInfo = this.state.getServiceInfo();
|
|
62
62
|
const commonReload = eventTypes.some(eventType => commonReloadEvents.includes(eventType));
|
|
63
63
|
const chainUpdated = eventTypes.includes('chain.updateState');
|
|
64
|
-
const stakingSubmitted = eventTypes.includes('transaction.submitStaking');
|
|
65
64
|
const reloadMantaPay = eventTypes.includes('mantaPay.submitTransaction') || eventTypes.includes('mantaPay.enable');
|
|
66
65
|
const updatedChains = [];
|
|
67
66
|
if (chainUpdated) {
|
|
@@ -72,7 +71,7 @@ export class KoniCron {
|
|
|
72
71
|
}
|
|
73
72
|
});
|
|
74
73
|
}
|
|
75
|
-
if (!commonReload && !chainUpdated && !
|
|
74
|
+
if (!commonReload && !chainUpdated && !reloadMantaPay) {
|
|
76
75
|
return;
|
|
77
76
|
}
|
|
78
77
|
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
@@ -81,7 +80,6 @@ export class KoniCron {
|
|
|
81
80
|
}
|
|
82
81
|
const chainInfoMap = serviceInfo.chainInfoMap;
|
|
83
82
|
const needUpdateNft = this.needUpdateNft(chainInfoMap, updatedChains);
|
|
84
|
-
const needUpdateStaking = this.needUpdateStaking(chainInfoMap, updatedChains);
|
|
85
83
|
|
|
86
84
|
// MantaPay
|
|
87
85
|
reloadMantaPay && this.removeCron('syncMantaPay');
|
|
@@ -90,19 +88,10 @@ export class KoniCron {
|
|
|
90
88
|
(commonReload || needUpdateNft) && this.resetNft(address);
|
|
91
89
|
(commonReload || needUpdateNft) && this.removeCron('refreshNft');
|
|
92
90
|
|
|
93
|
-
// Staking
|
|
94
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.resetStakingReward();
|
|
95
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshStakingReward');
|
|
96
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshPoolingStakingReward');
|
|
97
|
-
needUpdateStaking && this.removeCron('updateChainStakingMetadata');
|
|
98
|
-
|
|
99
91
|
// Chains
|
|
100
92
|
if (this.checkNetworkAvailable(serviceInfo)) {
|
|
101
93
|
// only add cron job if there's at least 1 active network
|
|
102
94
|
(commonReload || needUpdateNft) && this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
103
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
104
|
-
(commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
105
|
-
needUpdateStaking && this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
106
95
|
reloadMantaPay && this.addCron('syncMantaPay', this.syncMantaPay, CRON_SYNC_MANTA_PAY);
|
|
107
96
|
} else {
|
|
108
97
|
this.setStakingRewardReady();
|
|
@@ -117,7 +106,6 @@ export class KoniCron {
|
|
|
117
106
|
this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
118
107
|
this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
119
108
|
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
120
|
-
this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
121
109
|
this.addCron('syncMantaPay', this.syncMantaPay, CRON_SYNC_MANTA_PAY);
|
|
122
110
|
} else {
|
|
123
111
|
this.setStakingRewardReady();
|
|
@@ -155,9 +143,6 @@ export class KoniCron {
|
|
|
155
143
|
resetNft = newAddress => {
|
|
156
144
|
this.state.resetNft(newAddress);
|
|
157
145
|
};
|
|
158
|
-
resetStakingReward = () => {
|
|
159
|
-
this.state.resetStakingReward();
|
|
160
|
-
};
|
|
161
146
|
refreshStakingReward = address => {
|
|
162
147
|
return () => {
|
|
163
148
|
this.subscriptions.subscribeStakingReward(address).catch(this.logger.error);
|
|
@@ -174,16 +159,6 @@ export class KoniCron {
|
|
|
174
159
|
checkNetworkAvailable = serviceInfo => {
|
|
175
160
|
return Object.keys(serviceInfo.chainApiMap.substrate).length > 0 || Object.keys(serviceInfo.chainApiMap.evm).length > 0;
|
|
176
161
|
};
|
|
177
|
-
updateChainStakingMetadata = (chainInfoMap, chainStateMap, substrateApiMap) => {
|
|
178
|
-
return () => {
|
|
179
|
-
this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
|
-
updateNominatorMetadata = (address, chainInfoMap, chainStateMap, substrateApiMap) => {
|
|
183
|
-
return () => {
|
|
184
|
-
this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
162
|
async reloadNft() {
|
|
188
163
|
const address = this.state.keyringService.currentAccount.address;
|
|
189
164
|
const serviceInfo = this.state.getServiceInfo();
|
|
@@ -195,11 +170,7 @@ export class KoniCron {
|
|
|
195
170
|
}
|
|
196
171
|
async reloadStaking() {
|
|
197
172
|
const address = this.state.keyringService.currentAccount.address;
|
|
198
|
-
|
|
199
|
-
this.removeCron('refreshStakingReward');
|
|
200
|
-
this.removeCron('refreshPoolingStakingReward');
|
|
201
|
-
this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
202
|
-
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
173
|
+
console.log('reload staking', address);
|
|
203
174
|
await waitTimeout(1800);
|
|
204
175
|
return true;
|
|
205
176
|
}
|
|
@@ -212,10 +183,4 @@ export class KoniCron {
|
|
|
212
183
|
}
|
|
213
184
|
return false;
|
|
214
185
|
}
|
|
215
|
-
needUpdateStaking(chainInfoMap, updatedChains) {
|
|
216
|
-
if (updatedChains && updatedChains.length > 0) {
|
|
217
|
-
return updatedChains.some(updatedChain => _isChainSupportSubstrateStaking(chainInfoMap[updatedChain]));
|
|
218
|
-
}
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
186
|
}
|
|
@@ -1538,7 +1538,8 @@ export default class KoniState {
|
|
|
1538
1538
|
return await this.cron.reloadNft();
|
|
1539
1539
|
}
|
|
1540
1540
|
async reloadStaking() {
|
|
1541
|
-
|
|
1541
|
+
await this.subscription.reloadStaking();
|
|
1542
|
+
return true;
|
|
1542
1543
|
}
|
|
1543
1544
|
async approvePassPhishingPage(_url) {
|
|
1544
1545
|
return new Promise(resolve => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { ChainStakingMetadata } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
2
|
import { _ChainState, _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
3
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
5
4
|
import KoniState from './handlers/State';
|
|
@@ -27,8 +26,6 @@ export declare class KoniSubscription {
|
|
|
27
26
|
initNftSubscription(addresses: string[], substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>): void;
|
|
28
27
|
subscribeStakingReward(address: string): Promise<void>;
|
|
29
28
|
subscribeStakingRewardFastInterval(address: string): Promise<void>;
|
|
30
|
-
|
|
31
|
-
fetchChainStakingMetadata(chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>): Promise<void>;
|
|
32
|
-
fetchNominatorMetadata(currentAddress: string, chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>): Promise<void>;
|
|
29
|
+
reloadStaking(): Promise<void>;
|
|
33
30
|
}
|
|
34
31
|
export {};
|