@subwallet/extension-base 1.0.2-3 → 1.0.3-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 +10 -2
- package/background/KoniTypes.js +3 -1
- package/cjs/background/KoniTypes.js +3 -1
- package/cjs/koni/background/handlers/Extension.js +9 -0
- package/cjs/koni/background/handlers/State.js +8 -1
- package/cjs/koni/background/subscription.js +24 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/base/types.js +20 -0
- package/cjs/services/chain-service/index.js +14 -4
- package/cjs/services/history-service/index.js +84 -39
- package/cjs/services/migration-service/scripts/MigrateImportedToken.js +2 -1
- package/cjs/services/price-service/index.js +71 -23
- package/cjs/services/storage-service/DatabaseService.js +10 -0
- package/cjs/services/storage-service/db-stores/Transaction.js +6 -10
- package/cjs/services/transaction-service/index.js +78 -33
- package/cjs/services/transaction-service/utils.js +10 -8
- package/cjs/utils/promise.js +26 -0
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +9 -0
- package/koni/background/handlers/State.js +8 -1
- package/koni/background/subscription.d.ts +2 -0
- package/koni/background/subscription.js +23 -2
- package/package.json +17 -7
- package/packageInfo.js +1 -1
- package/services/base/types.d.ts +34 -0
- package/services/base/types.js +15 -0
- package/services/chain-service/index.d.ts +2 -0
- package/services/chain-service/index.js +15 -5
- package/services/history-service/index.d.ts +24 -5
- package/services/history-service/index.js +84 -39
- package/services/migration-service/scripts/MigrateImportedToken.js +2 -1
- package/services/price-service/index.d.ts +22 -1
- package/services/price-service/index.js +71 -23
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +10 -0
- package/services/storage-service/db-stores/Transaction.d.ts +2 -0
- package/services/storage-service/db-stores/Transaction.js +6 -10
- package/services/transaction-service/index.d.ts +2 -0
- package/services/transaction-service/index.js +60 -17
- package/services/transaction-service/types.d.ts +2 -0
- package/services/transaction-service/utils.js +10 -8
- package/utils/promise.d.ts +6 -0
- package/utils/promise.js +20 -0
|
@@ -44,7 +44,7 @@ class TransactionService {
|
|
|
44
44
|
return Object.values(this.transactions);
|
|
45
45
|
}
|
|
46
46
|
get processingTransactions() {
|
|
47
|
-
return this.allTransactions.filter(t => t.status === _KoniTypes.ExtrinsicStatus.
|
|
47
|
+
return this.allTransactions.filter(t => t.status === _KoniTypes.ExtrinsicStatus.QUEUED || t.status === _KoniTypes.ExtrinsicStatus.PROCESSING);
|
|
48
48
|
}
|
|
49
49
|
getTransaction(id) {
|
|
50
50
|
return this.transactions[id];
|
|
@@ -164,6 +164,7 @@ class TransactionService {
|
|
|
164
164
|
}
|
|
165
165
|
fillTransactionDefaultInfo(transaction) {
|
|
166
166
|
const isInternal = !transaction.url;
|
|
167
|
+
const transactionId = (0, _helpers.getTransactionId)(transaction.chainType, transaction.chain, isInternal);
|
|
167
168
|
return {
|
|
168
169
|
...transaction,
|
|
169
170
|
createdAt: new Date(),
|
|
@@ -171,10 +172,10 @@ class TransactionService {
|
|
|
171
172
|
errors: transaction.errors || [],
|
|
172
173
|
warnings: transaction.warnings || [],
|
|
173
174
|
url: transaction.url || _constants2.EXTENSION_REQUEST_URL,
|
|
174
|
-
status: _KoniTypes.ExtrinsicStatus.
|
|
175
|
+
status: _KoniTypes.ExtrinsicStatus.QUEUED,
|
|
175
176
|
isInternal,
|
|
176
|
-
id:
|
|
177
|
-
extrinsicHash:
|
|
177
|
+
id: transactionId,
|
|
178
|
+
extrinsicHash: transactionId
|
|
178
179
|
};
|
|
179
180
|
}
|
|
180
181
|
async addTransaction(inputTransaction) {
|
|
@@ -187,8 +188,6 @@ class TransactionService {
|
|
|
187
188
|
this.transactionSubject.next({
|
|
188
189
|
...transactions
|
|
189
190
|
});
|
|
190
|
-
|
|
191
|
-
// Send transaction
|
|
192
191
|
return await this.sendTransaction(transaction);
|
|
193
192
|
}
|
|
194
193
|
generateBeforeHandleResponseErrors(errors) {
|
|
@@ -215,7 +214,8 @@ class TransactionService {
|
|
|
215
214
|
validatedTransaction.warnings = [];
|
|
216
215
|
const emitter = await this.addTransaction(validatedTransaction);
|
|
217
216
|
await new Promise(resolve => {
|
|
218
|
-
emitter.on('
|
|
217
|
+
emitter.on('signed', data => {
|
|
218
|
+
validatedTransaction.id = data.id;
|
|
219
219
|
validatedTransaction.extrinsicHash = data.extrinsicHash;
|
|
220
220
|
resolve();
|
|
221
221
|
});
|
|
@@ -231,6 +231,12 @@ class TransactionService {
|
|
|
231
231
|
async sendTransaction(transaction) {
|
|
232
232
|
// Send Transaction
|
|
233
233
|
const emitter = transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : await this.signAndSendEvmTransaction(transaction);
|
|
234
|
+
emitter.on('signed', data => {
|
|
235
|
+
this.onSigned(data);
|
|
236
|
+
});
|
|
237
|
+
emitter.on('send', data => {
|
|
238
|
+
this.onSend(data);
|
|
239
|
+
});
|
|
234
240
|
emitter.on('extrinsicHash', data => {
|
|
235
241
|
this.onHasTransactionHash(data);
|
|
236
242
|
});
|
|
@@ -283,7 +289,8 @@ class TransactionService {
|
|
|
283
289
|
to: '',
|
|
284
290
|
chainType: transaction.chainType,
|
|
285
291
|
address: transaction.address,
|
|
286
|
-
status:
|
|
292
|
+
status: transaction.status,
|
|
293
|
+
transactionId: transaction.id,
|
|
287
294
|
extrinsicHash: transaction.extrinsicHash,
|
|
288
295
|
time: transaction.createdAt.getTime(),
|
|
289
296
|
fee: transaction.estimateFee,
|
|
@@ -426,8 +433,14 @@ class TransactionService {
|
|
|
426
433
|
break;
|
|
427
434
|
}
|
|
428
435
|
case _KoniTypes.ExtrinsicType.EVM_EXECUTE:
|
|
429
|
-
|
|
430
|
-
|
|
436
|
+
{
|
|
437
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
438
|
+
const data = (0, _utils2.parseTransactionData)(transaction.data);
|
|
439
|
+
|
|
440
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
|
|
441
|
+
historyItem.to = (data === null || data === void 0 ? void 0 : data.to) || '';
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
431
444
|
case _KoniTypes.ExtrinsicType.UNKNOWN:
|
|
432
445
|
break;
|
|
433
446
|
}
|
|
@@ -446,18 +459,39 @@ class TransactionService {
|
|
|
446
459
|
}
|
|
447
460
|
return [historyItem];
|
|
448
461
|
}
|
|
449
|
-
|
|
462
|
+
onSigned(_ref) {
|
|
450
463
|
let {
|
|
451
|
-
eventLogs,
|
|
452
|
-
extrinsicHash,
|
|
453
464
|
id
|
|
454
465
|
} = _ref;
|
|
455
|
-
|
|
466
|
+
console.log(`Transaction "${id}" is signed`);
|
|
467
|
+
}
|
|
468
|
+
onSend(_ref2) {
|
|
469
|
+
let {
|
|
470
|
+
id
|
|
471
|
+
} = _ref2;
|
|
472
|
+
// Update transaction status
|
|
456
473
|
this.updateTransaction(id, {
|
|
474
|
+
status: _KoniTypes.ExtrinsicStatus.SUBMITTING
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
// Create Input History Transaction History
|
|
478
|
+
this.historyService.insertHistories(this.transactionToHistories(id)).catch(console.error);
|
|
479
|
+
console.log(`Transaction "${id}" is sent`);
|
|
480
|
+
}
|
|
481
|
+
onHasTransactionHash(_ref3) {
|
|
482
|
+
let {
|
|
483
|
+
extrinsicHash,
|
|
484
|
+
id
|
|
485
|
+
} = _ref3;
|
|
486
|
+
// Write processing transaction history
|
|
487
|
+
const updateData = {
|
|
457
488
|
extrinsicHash,
|
|
458
489
|
status: _KoniTypes.ExtrinsicStatus.PROCESSING
|
|
459
|
-
}
|
|
460
|
-
this.
|
|
490
|
+
};
|
|
491
|
+
this.updateTransaction(id, updateData);
|
|
492
|
+
|
|
493
|
+
// In this case transaction id is the same as extrinsic hash and will change after below update
|
|
494
|
+
this.historyService.updateHistoryByExtrinsicHash(id, updateData).catch(console.error);
|
|
461
495
|
console.log(`Transaction "${id}" is submitted with hash ${extrinsicHash || ''}`);
|
|
462
496
|
}
|
|
463
497
|
handlePostProcessing(id) {
|
|
@@ -486,12 +520,12 @@ class TransactionService {
|
|
|
486
520
|
this.eventService.emit('transaction.submitStaking', transaction.chain);
|
|
487
521
|
}
|
|
488
522
|
}
|
|
489
|
-
onSuccess(
|
|
523
|
+
onSuccess(_ref4) {
|
|
490
524
|
let {
|
|
491
525
|
blockHash,
|
|
492
526
|
blockNumber,
|
|
493
527
|
id
|
|
494
|
-
} =
|
|
528
|
+
} = _ref4;
|
|
495
529
|
const transaction = this.getTransaction(id);
|
|
496
530
|
this.updateTransaction(id, {
|
|
497
531
|
status: _KoniTypes.ExtrinsicStatus.SUCCESS
|
|
@@ -515,24 +549,25 @@ class TransactionService {
|
|
|
515
549
|
});
|
|
516
550
|
this.eventService.emit('transaction.done', transaction);
|
|
517
551
|
}
|
|
518
|
-
onFailed(
|
|
552
|
+
onFailed(_ref5) {
|
|
519
553
|
let {
|
|
520
554
|
blockHash,
|
|
521
555
|
blockNumber,
|
|
522
556
|
errors,
|
|
523
557
|
id
|
|
524
|
-
} =
|
|
558
|
+
} = _ref5;
|
|
525
559
|
const transaction = this.getTransaction(id);
|
|
560
|
+
const nextStatus = _KoniTypes.ExtrinsicStatus.FAIL;
|
|
526
561
|
if (transaction) {
|
|
527
562
|
this.updateTransaction(id, {
|
|
528
|
-
status:
|
|
563
|
+
status: nextStatus,
|
|
529
564
|
errors
|
|
530
565
|
});
|
|
531
566
|
console.log('Transaction failed', id, transaction.extrinsicHash);
|
|
532
567
|
|
|
533
568
|
// Write failed transaction history
|
|
534
569
|
this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
|
|
535
|
-
status:
|
|
570
|
+
status: nextStatus,
|
|
536
571
|
blockNumber: blockNumber || 0,
|
|
537
572
|
blockHash: blockHash || ''
|
|
538
573
|
}).catch(console.error);
|
|
@@ -566,14 +601,14 @@ class TransactionService {
|
|
|
566
601
|
const encoded = _rlp.default.encode(data);
|
|
567
602
|
return (0, _util.u8aToHex)(encoded);
|
|
568
603
|
}
|
|
569
|
-
async signAndSendEvmTransaction(
|
|
604
|
+
async signAndSendEvmTransaction(_ref6) {
|
|
570
605
|
let {
|
|
571
606
|
address,
|
|
572
607
|
chain,
|
|
573
608
|
id,
|
|
574
609
|
transaction,
|
|
575
610
|
url
|
|
576
|
-
} =
|
|
611
|
+
} = _ref6;
|
|
577
612
|
const payload = transaction;
|
|
578
613
|
const evmApi = this.chainService.getEvmApi(chain);
|
|
579
614
|
const chainInfo = this.chainService.getChainInfoByKey(chain);
|
|
@@ -633,11 +668,11 @@ class TransactionService {
|
|
|
633
668
|
errors: [],
|
|
634
669
|
warnings: []
|
|
635
670
|
};
|
|
636
|
-
this.requestService.addConfirmation(id, url || _constants2.EXTENSION_REQUEST_URL, 'evmSendTransactionRequest', payload, {}).then(
|
|
671
|
+
this.requestService.addConfirmation(id, url || _constants2.EXTENSION_REQUEST_URL, 'evmSendTransactionRequest', payload, {}).then(_ref7 => {
|
|
637
672
|
let {
|
|
638
673
|
isApproved,
|
|
639
674
|
payload
|
|
640
|
-
} =
|
|
675
|
+
} = _ref7;
|
|
641
676
|
if (isApproved) {
|
|
642
677
|
let signedTransaction;
|
|
643
678
|
if (!payload) {
|
|
@@ -654,6 +689,12 @@ class TransactionService {
|
|
|
654
689
|
}
|
|
655
690
|
signedTransaction = signed;
|
|
656
691
|
}
|
|
692
|
+
|
|
693
|
+
// Emit signed event
|
|
694
|
+
emitter.emit('signed', eventData);
|
|
695
|
+
|
|
696
|
+
// Send transaction
|
|
697
|
+
emitter.emit('send', eventData); // This event is needed after sending transaction with queue
|
|
657
698
|
signedTransaction && web3Api.eth.sendSignedTransaction(signedTransaction).once('transactionHash', hash => {
|
|
658
699
|
eventData.extrinsicHash = hash;
|
|
659
700
|
emitter.emit('extrinsicHash', eventData);
|
|
@@ -680,20 +721,19 @@ class TransactionService {
|
|
|
680
721
|
});
|
|
681
722
|
return emitter;
|
|
682
723
|
}
|
|
683
|
-
signAndSendSubstrateTransaction(
|
|
724
|
+
signAndSendSubstrateTransaction(_ref8) {
|
|
684
725
|
let {
|
|
685
726
|
address,
|
|
686
727
|
id,
|
|
687
728
|
transaction,
|
|
688
729
|
url
|
|
689
|
-
} =
|
|
730
|
+
} = _ref8;
|
|
690
731
|
const emitter = new _eventemitter.default();
|
|
691
732
|
const eventData = {
|
|
692
733
|
id,
|
|
693
734
|
errors: [],
|
|
694
735
|
warnings: []
|
|
695
736
|
};
|
|
696
|
-
console.debug(address, transaction);
|
|
697
737
|
transaction.signAsync(address, {
|
|
698
738
|
signer: {
|
|
699
739
|
signPayload: async payload => {
|
|
@@ -705,6 +745,11 @@ class TransactionService {
|
|
|
705
745
|
}
|
|
706
746
|
}
|
|
707
747
|
}).then(rs => {
|
|
748
|
+
// Emit signed event
|
|
749
|
+
emitter.emit('signed', eventData);
|
|
750
|
+
|
|
751
|
+
// Send transaction
|
|
752
|
+
emitter.emit('send', eventData); // This event is needed after sending transaction with queue
|
|
708
753
|
rs.send(txState => {
|
|
709
754
|
// handle events, logs, history
|
|
710
755
|
if (!txState || !txState.status) {
|
|
@@ -720,20 +765,20 @@ class TransactionService {
|
|
|
720
765
|
if (txState.status.isFinalized) {
|
|
721
766
|
eventData.eventLogs = txState.events;
|
|
722
767
|
// TODO: push block hash and block number into eventData
|
|
723
|
-
txState.events.filter(
|
|
768
|
+
txState.events.filter(_ref9 => {
|
|
724
769
|
let {
|
|
725
770
|
event: {
|
|
726
771
|
section
|
|
727
772
|
}
|
|
728
|
-
} =
|
|
773
|
+
} = _ref9;
|
|
729
774
|
return section === 'system';
|
|
730
|
-
}).forEach(
|
|
775
|
+
}).forEach(_ref10 => {
|
|
731
776
|
let {
|
|
732
777
|
event: {
|
|
733
778
|
method,
|
|
734
779
|
data: [error]
|
|
735
780
|
}
|
|
736
|
-
} =
|
|
781
|
+
} = _ref10;
|
|
737
782
|
if (method === 'ExtrinsicFailed') {
|
|
738
783
|
eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.SEND_TRANSACTION_FAILED, error.toString()));
|
|
739
784
|
emitter.emit('error', eventData);
|
|
@@ -15,15 +15,17 @@ function parseTransactionData(data) {
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
17
|
function getTransactionLink(chainInfo, extrinsicHash) {
|
|
18
|
-
|
|
19
|
-
if ((0, _utils._isPureEvmChain)(chainInfo)) {
|
|
20
|
-
if (explorerLink) {
|
|
21
|
-
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}tx/${extrinsicHash}`;
|
|
22
|
-
}
|
|
23
|
-
} else {
|
|
18
|
+
if (extrinsicHash.startsWith('0x')) {
|
|
24
19
|
const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
|
|
25
|
-
if (
|
|
26
|
-
|
|
20
|
+
if ((0, _utils._isPureEvmChain)(chainInfo)) {
|
|
21
|
+
if (explorerLink) {
|
|
22
|
+
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}tx/${extrinsicHash}`;
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
|
|
26
|
+
if (explorerLink) {
|
|
27
|
+
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${extrinsicHash}`;
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
return undefined;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createPromiseHandler = createPromiseHandler;
|
|
7
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
10
|
+
function createPromiseHandler() {
|
|
11
|
+
let _resolve = () => {
|
|
12
|
+
console.warn('This promise handler is not implemented');
|
|
13
|
+
};
|
|
14
|
+
let _reject = () => {
|
|
15
|
+
console.warn('This promise handler is not implemented');
|
|
16
|
+
};
|
|
17
|
+
const promise = new Promise((resolve, reject) => {
|
|
18
|
+
_resolve = resolve;
|
|
19
|
+
_reject = reject;
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
resolve: _resolve,
|
|
23
|
+
reject: _reject,
|
|
24
|
+
promise
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -184,5 +184,6 @@ export default class KoniExtension {
|
|
|
184
184
|
private subscribeTransactions;
|
|
185
185
|
private subscribeNotifications;
|
|
186
186
|
private reloadCron;
|
|
187
|
+
private getLogoMap;
|
|
187
188
|
handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
|
|
188
189
|
}
|
|
@@ -2814,6 +2814,13 @@ export default class KoniExtension {
|
|
|
2814
2814
|
}
|
|
2815
2815
|
return Promise.resolve(false);
|
|
2816
2816
|
}
|
|
2817
|
+
async getLogoMap() {
|
|
2818
|
+
const [chainLogoMap, assetLogoMap] = await Promise.all([this.#koniState.chainService.getChainLogoMap(), this.#koniState.chainService.getAssetLogoMap()]);
|
|
2819
|
+
return {
|
|
2820
|
+
chainLogoMap,
|
|
2821
|
+
assetLogoMap
|
|
2822
|
+
};
|
|
2823
|
+
}
|
|
2817
2824
|
|
|
2818
2825
|
// --------------------------------------------------------------
|
|
2819
2826
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
@@ -3173,6 +3180,8 @@ export default class KoniExtension {
|
|
|
3173
3180
|
return this.subscribeNotifications(id, port);
|
|
3174
3181
|
case 'pri(cron.reload)':
|
|
3175
3182
|
return await this.reloadCron(request);
|
|
3183
|
+
case 'pri(settings.getLogoMaps)':
|
|
3184
|
+
return await this.getLogoMap();
|
|
3176
3185
|
|
|
3177
3186
|
// Default
|
|
3178
3187
|
default:
|
|
@@ -211,6 +211,8 @@ export default class KoniState {
|
|
|
211
211
|
onReady() {
|
|
212
212
|
this.subscription.start();
|
|
213
213
|
this.cron.start();
|
|
214
|
+
this.historyService.start().catch(console.error);
|
|
215
|
+
this.priceService.start().catch(console.error);
|
|
214
216
|
this.ready = true;
|
|
215
217
|
this.logger.log('State is ready');
|
|
216
218
|
}
|
|
@@ -556,7 +558,8 @@ export default class KoniState {
|
|
|
556
558
|
assetType: tokenInfo.type,
|
|
557
559
|
metadata: _parseMetadataForSmartContractAsset(tokenInfo.contractAddress),
|
|
558
560
|
multiChainAsset: null,
|
|
559
|
-
hasValue: _isChainTestNet(this.chainService.getChainInfoByKey(tokenInfo.originChain))
|
|
561
|
+
hasValue: _isChainTestNet(this.chainService.getChainInfoByKey(tokenInfo.originChain)),
|
|
562
|
+
icon: ''
|
|
560
563
|
});
|
|
561
564
|
return isApproved;
|
|
562
565
|
} else {
|
|
@@ -1321,11 +1324,15 @@ export default class KoniState {
|
|
|
1321
1324
|
this.cron.stop();
|
|
1322
1325
|
this.subscription.stop();
|
|
1323
1326
|
await this.pauseAllNetworks(undefined, 'IDLE mode');
|
|
1327
|
+
await this.historyService.stop();
|
|
1328
|
+
await this.priceService.stop();
|
|
1324
1329
|
}
|
|
1325
1330
|
async wakeup() {
|
|
1326
1331
|
await this.resumeAllNetworks();
|
|
1327
1332
|
this.cron.start();
|
|
1328
1333
|
this.subscription.start();
|
|
1334
|
+
await this.historyService.start();
|
|
1335
|
+
await this.priceService.start();
|
|
1329
1336
|
}
|
|
1330
1337
|
cancelSubscription(id) {
|
|
1331
1338
|
if (isSubscriptionRunning(id)) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { ChainStakingMetadata } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
3
|
import { _ChainState, _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
4
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
4
5
|
import KoniState from './handlers/State';
|
|
@@ -26,6 +27,7 @@ export declare class KoniSubscription {
|
|
|
26
27
|
initNftSubscription(addresses: string[], substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>): void;
|
|
27
28
|
subscribeStakingReward(address: string): Promise<void>;
|
|
28
29
|
subscribeStakingRewardFastInterval(address: string): Promise<void>;
|
|
30
|
+
fetchingStakingFromApi(): Promise<Record<string, ChainStakingMetadata>>;
|
|
29
31
|
fetchChainStakingMetadata(chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>): Promise<void>;
|
|
30
32
|
fetchNominatorMetadata(currentAddress: string, chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>): Promise<void>;
|
|
31
33
|
}
|
|
@@ -12,6 +12,7 @@ import { nftHandler } from '@subwallet/extension-base/koni/background/handlers';
|
|
|
12
12
|
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
13
13
|
import { _isChainEnabled, _isChainEvmCompatible, _isChainSupportSubstrateStaking, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
14
14
|
import { COMMON_RELOAD_EVENTS } from '@subwallet/extension-base/services/event-service/types';
|
|
15
|
+
import axios from 'axios';
|
|
15
16
|
import { logger as createLogger } from '@polkadot/util';
|
|
16
17
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
17
18
|
export class KoniSubscription {
|
|
@@ -223,6 +224,17 @@ export class KoniSubscription {
|
|
|
223
224
|
const result = [...poolingStakingRewards, ...amplitudeUnclaimedStakingRewards];
|
|
224
225
|
this.state.updateStakingReward(result, 'fastInterval');
|
|
225
226
|
}
|
|
227
|
+
async fetchingStakingFromApi() {
|
|
228
|
+
try {
|
|
229
|
+
const response = await axios.get('https://staking-data.subwallet.app/api/staking/get');
|
|
230
|
+
if (response.status === 200) {
|
|
231
|
+
return response.data;
|
|
232
|
+
}
|
|
233
|
+
} catch (e) {
|
|
234
|
+
this.logger.error(e);
|
|
235
|
+
}
|
|
236
|
+
return {};
|
|
237
|
+
}
|
|
226
238
|
async fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap) {
|
|
227
239
|
const filteredChainInfoMap = {};
|
|
228
240
|
Object.values(chainInfoMap).forEach(chainInfo => {
|
|
@@ -234,9 +246,18 @@ export class KoniSubscription {
|
|
|
234
246
|
if (Object.values(filteredChainInfoMap).length === 0) {
|
|
235
247
|
return;
|
|
236
248
|
}
|
|
249
|
+
|
|
250
|
+
// Fetch data from helper API
|
|
251
|
+
const dataFromApi = await this.fetchingStakingFromApi();
|
|
237
252
|
await Promise.all(Object.values(filteredChainInfoMap).map(async chainInfo => {
|
|
238
|
-
|
|
239
|
-
|
|
253
|
+
// Use fetch API data if available
|
|
254
|
+
if (dataFromApi[chainInfo.slug]) {
|
|
255
|
+
this.state.updateChainStakingMetadata(dataFromApi[chainInfo.slug]);
|
|
256
|
+
} else {
|
|
257
|
+
console.warn('Not found staking data from api', chainInfo.slug);
|
|
258
|
+
const chainStakingMetadata = await getChainStakingMetadata(chainInfo, substrateApiMap[chainInfo.slug]);
|
|
259
|
+
this.state.updateChainStakingMetadata(chainStakingMetadata);
|
|
260
|
+
}
|
|
240
261
|
}));
|
|
241
262
|
}
|
|
242
263
|
async fetchNominatorMetadata(currentAddress, chainInfoMap, chainStateMap, substrateApiMap) {
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.0.
|
|
20
|
+
"version": "1.0.3-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -495,6 +495,11 @@
|
|
|
495
495
|
"require": "./cjs/services/balance-service/index.js",
|
|
496
496
|
"default": "./services/balance-service/index.js"
|
|
497
497
|
},
|
|
498
|
+
"./services/base/types": {
|
|
499
|
+
"types": "./services/base/types.d.ts",
|
|
500
|
+
"require": "./cjs/services/base/types.js",
|
|
501
|
+
"default": "./services/base/types.js"
|
|
502
|
+
},
|
|
498
503
|
"./services/chain-service": {
|
|
499
504
|
"types": "./services/chain-service/index.d.ts",
|
|
500
505
|
"require": "./cjs/services/chain-service/index.js",
|
|
@@ -1595,6 +1600,11 @@
|
|
|
1595
1600
|
"require": "./cjs/utils/keyring.js",
|
|
1596
1601
|
"default": "./utils/keyring.js"
|
|
1597
1602
|
},
|
|
1603
|
+
"./utils/promise": {
|
|
1604
|
+
"types": "./utils/promise.d.ts",
|
|
1605
|
+
"require": "./cjs/utils/promise.js",
|
|
1606
|
+
"default": "./utils/promise.js"
|
|
1607
|
+
},
|
|
1598
1608
|
"./utils/request": {
|
|
1599
1609
|
"types": "./utils/request.d.ts",
|
|
1600
1610
|
"require": "./cjs/utils/request.js",
|
|
@@ -1604,7 +1614,7 @@
|
|
|
1604
1614
|
"dependencies": {
|
|
1605
1615
|
"@acala-network/api": "^4.1.8-2.3",
|
|
1606
1616
|
"@acala-network/type-definitions": "^4.1.5",
|
|
1607
|
-
"@apollo/client": "^3.7.
|
|
1617
|
+
"@apollo/client": "^3.7.14",
|
|
1608
1618
|
"@babel/runtime": "^7.20.6",
|
|
1609
1619
|
"@bifrost-finance/type-definitions": "^1.7.2",
|
|
1610
1620
|
"@crustio/type-definitions": "^1.3.0",
|
|
@@ -1656,11 +1666,11 @@
|
|
|
1656
1666
|
"@sora-substrate/type-definitions": "^1.12.4",
|
|
1657
1667
|
"@subsocial/types": "^0.6.8",
|
|
1658
1668
|
"@substrate/connect": "^0.7.18",
|
|
1659
|
-
"@subwallet/chain-list": "^0.
|
|
1660
|
-
"@subwallet/extension-base": "^1.0.
|
|
1661
|
-
"@subwallet/extension-chains": "^1.0.
|
|
1662
|
-
"@subwallet/extension-dapp": "^1.0.
|
|
1663
|
-
"@subwallet/extension-inject": "^1.0.
|
|
1669
|
+
"@subwallet/chain-list": "^0.1.2",
|
|
1670
|
+
"@subwallet/extension-base": "^1.0.3-0",
|
|
1671
|
+
"@subwallet/extension-chains": "^1.0.3-0",
|
|
1672
|
+
"@subwallet/extension-dapp": "^1.0.3-0",
|
|
1673
|
+
"@subwallet/extension-inject": "^1.0.3-0",
|
|
1664
1674
|
"@subwallet/keyring": "^0.0.5",
|
|
1665
1675
|
"@subwallet/ui-keyring": "^0.0.3",
|
|
1666
1676
|
"@unique-nft/types": "^0.6.0-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.0.
|
|
10
|
+
version: '1.0.3-0'
|
|
11
11
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
2
|
+
export declare enum ServiceStatus {
|
|
3
|
+
NOT_INITIALIZED = "not_initialized",
|
|
4
|
+
INITIALIZING = "initializing",
|
|
5
|
+
INITIALIZED = "initialized",
|
|
6
|
+
STARTED = "started",
|
|
7
|
+
STARTING = "starting",
|
|
8
|
+
STOPPED = "stopped",
|
|
9
|
+
STOPPING = "stopping"
|
|
10
|
+
}
|
|
11
|
+
export interface CoreServiceInterface {
|
|
12
|
+
status: ServiceStatus;
|
|
13
|
+
init: () => Promise<void>;
|
|
14
|
+
startPromiseHandler: PromiseHandler<void>;
|
|
15
|
+
start: () => Promise<void>;
|
|
16
|
+
waitForStarted: () => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface StoppableServiceInterface extends CoreServiceInterface {
|
|
19
|
+
stopPromiseHandler: PromiseHandler<void>;
|
|
20
|
+
stop: () => Promise<void>;
|
|
21
|
+
waitForStopped: () => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export interface PersistDataServiceInterface {
|
|
24
|
+
loadData: () => Promise<void>;
|
|
25
|
+
persistData: () => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export interface SubscribeServiceInterface {
|
|
28
|
+
subscribe: () => Promise<void>;
|
|
29
|
+
unsubscribe: () => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export interface CronServiceInterface {
|
|
32
|
+
startCron: () => Promise<void>;
|
|
33
|
+
stopCron: () => Promise<void>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// 'init' | 'started' | 'starting' | 'stopped' | 'stopping'
|
|
5
|
+
|
|
6
|
+
export let ServiceStatus;
|
|
7
|
+
(function (ServiceStatus) {
|
|
8
|
+
ServiceStatus["NOT_INITIALIZED"] = "not_initialized";
|
|
9
|
+
ServiceStatus["INITIALIZING"] = "initializing";
|
|
10
|
+
ServiceStatus["INITIALIZED"] = "initialized";
|
|
11
|
+
ServiceStatus["STARTED"] = "started";
|
|
12
|
+
ServiceStatus["STARTING"] = "starting";
|
|
13
|
+
ServiceStatus["STOPPED"] = "stopped";
|
|
14
|
+
ServiceStatus["STOPPING"] = "stopping";
|
|
15
|
+
})(ServiceStatus || (ServiceStatus = {}));
|
|
@@ -102,4 +102,6 @@ export declare class ChainService {
|
|
|
102
102
|
updateAssetSetting(assetSlug: string, assetSetting: AssetSetting): Promise<boolean | undefined>;
|
|
103
103
|
updateAssetSettingByChain(chainSlug: string, visible: boolean): Promise<void>;
|
|
104
104
|
subscribeAssetSettings(): BehaviorSubject<Record<string, AssetSetting>>;
|
|
105
|
+
getChainLogoMap(): Promise<Record<string, string>>;
|
|
106
|
+
getAssetLogoMap(): Promise<Record<string, string>>;
|
|
105
107
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { AssetRefMap, ChainAssetMap, ChainInfoMap, MultiChainAssetMap } from '@subwallet/chain-list';
|
|
4
|
+
import { AssetLogoMap, AssetRefMap, ChainAssetMap, ChainInfoMap, ChainLogoMap, MultiChainAssetMap } from '@subwallet/chain-list';
|
|
5
5
|
import { _AssetRefPath, _AssetType, _ChainStatus, _SubstrateChainType } from '@subwallet/chain-list/types';
|
|
6
6
|
import { _DEFAULT_ACTIVE_CHAINS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
7
|
import { EvmChainHandler } from '@subwallet/extension-base/services/chain-service/handler/EvmChainHandler';
|
|
@@ -149,7 +149,8 @@ export class ChainService {
|
|
|
149
149
|
priceId: '',
|
|
150
150
|
slug: '',
|
|
151
151
|
symbol: '',
|
|
152
|
-
hasValue: true
|
|
152
|
+
hasValue: true,
|
|
153
|
+
icon: ''
|
|
153
154
|
};
|
|
154
155
|
for (const assetInfo of Object.values(this.getAssetRegistry())) {
|
|
155
156
|
if (assetInfo.assetType === _AssetType.NATIVE && assetInfo.originChain === chainSlug) {
|
|
@@ -546,7 +547,8 @@ export class ChainService {
|
|
|
546
547
|
evmInfo: storedChainInfo.evmInfo,
|
|
547
548
|
substrateInfo: storedChainInfo.substrateInfo,
|
|
548
549
|
isTestnet: storedChainInfo.isTestnet,
|
|
549
|
-
chainStatus: storedChainInfo.chainStatus
|
|
550
|
+
chainStatus: storedChainInfo.chainStatus,
|
|
551
|
+
icon: storedChainInfo.icon
|
|
550
552
|
};
|
|
551
553
|
this.dataMap.chainStateMap[storedSlug] = {
|
|
552
554
|
currentProvider: storedChainInfo.currentProvider,
|
|
@@ -717,7 +719,8 @@ export class ChainService {
|
|
|
717
719
|
substrateInfo,
|
|
718
720
|
evmInfo,
|
|
719
721
|
isTestnet: false,
|
|
720
|
-
chainStatus: _ChainStatus.ACTIVE
|
|
722
|
+
chainStatus: _ChainStatus.ACTIVE,
|
|
723
|
+
icon: '' // Todo: Allow update with custom chain
|
|
721
724
|
};
|
|
722
725
|
|
|
723
726
|
// insert new chainInfo
|
|
@@ -745,7 +748,8 @@ export class ChainService {
|
|
|
745
748
|
priceId: params.chainEditInfo.priceId || null,
|
|
746
749
|
slug: '',
|
|
747
750
|
symbol: params.chainEditInfo.symbol,
|
|
748
|
-
hasValue: true
|
|
751
|
+
hasValue: true,
|
|
752
|
+
icon: ''
|
|
749
753
|
});
|
|
750
754
|
|
|
751
755
|
// update subscription
|
|
@@ -1181,4 +1185,10 @@ export class ChainService {
|
|
|
1181
1185
|
subscribeAssetSettings() {
|
|
1182
1186
|
return this.assetSettingSubject;
|
|
1183
1187
|
}
|
|
1188
|
+
async getChainLogoMap() {
|
|
1189
|
+
return Promise.resolve(ChainLogoMap);
|
|
1190
|
+
}
|
|
1191
|
+
async getAssetLogoMap() {
|
|
1192
|
+
return Promise.resolve(AssetLogoMap);
|
|
1193
|
+
}
|
|
1184
1194
|
}
|