@subwallet/extension-base 1.3.34-0 → 1.3.36-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 -0
- package/cjs/core/logic-validation/request.js +1 -1
- package/cjs/koni/background/handlers/Extension.js +32 -4
- package/cjs/koni/background/utils.js +64 -29
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/process.js +1 -5
- package/cjs/services/balance-service/index.js +20 -1
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +91 -175
- package/cjs/services/balance-service/transfer/xcm/index.js +7 -6
- package/cjs/services/price-service/coingecko.js +22 -15
- package/cjs/services/price-service/index.js +12 -0
- package/cjs/services/request-service/handler/EvmRequestHandler.js +4 -1
- package/cjs/services/swap-service/handler/kyber-handler.js +355 -0
- package/cjs/services/swap-service/handler/uniswap-handler.js +223 -41
- package/cjs/services/swap-service/index.js +34 -2
- package/cjs/services/swap-service/utils.js +4 -1
- package/cjs/services/transaction-service/index.js +297 -52
- package/cjs/types/swap/index.js +2 -1
- package/core/logic-validation/request.js +1 -1
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +32 -4
- package/koni/background/utils.d.ts +3 -5
- package/koni/background/utils.js +64 -29
- package/package.json +11 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/process.d.ts +2 -2
- package/services/balance-service/helpers/process.js +1 -5
- package/services/balance-service/index.js +21 -2
- package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +9 -8
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +91 -174
- package/services/balance-service/transfer/xcm/index.js +7 -6
- package/services/event-service/types.d.ts +6 -6
- package/services/price-service/coingecko.d.ts +1 -1
- package/services/price-service/coingecko.js +22 -16
- package/services/price-service/index.d.ts +1 -0
- package/services/price-service/index.js +12 -0
- package/services/request-service/handler/EvmRequestHandler.js +4 -1
- package/services/swap-service/handler/kyber-handler.d.ts +28 -0
- package/services/swap-service/handler/kyber-handler.js +346 -0
- package/services/swap-service/handler/uniswap-handler.d.ts +48 -0
- package/services/swap-service/handler/uniswap-handler.js +224 -42
- package/services/swap-service/index.js +34 -2
- package/services/swap-service/utils.js +4 -1
- package/services/transaction-service/helpers/index.d.ts +5 -5
- package/services/transaction-service/index.d.ts +10 -5
- package/services/transaction-service/index.js +279 -36
- package/services/transaction-service/types.d.ts +23 -10
- package/types/swap/index.d.ts +4 -1
- package/types/swap/index.js +2 -1
|
@@ -207,6 +207,22 @@ class TransactionService {
|
|
|
207
207
|
extrinsicHash: transactionId
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
|
+
fillDutchTransactionDefaultInfo(transaction) {
|
|
211
|
+
const isInternal = !transaction.url;
|
|
212
|
+
const transactionId = (0, _helpers.getTransactionId)(transaction.chainType, transaction.chain, isInternal, (0, _helpers2.isWalletConnectRequest)(transaction.id));
|
|
213
|
+
return {
|
|
214
|
+
...transaction,
|
|
215
|
+
createdAt: new Date().getTime(),
|
|
216
|
+
updatedAt: new Date().getTime(),
|
|
217
|
+
errors: transaction.errors || [],
|
|
218
|
+
warnings: transaction.warnings || [],
|
|
219
|
+
url: transaction.url || _constants2.EXTENSION_REQUEST_URL,
|
|
220
|
+
status: _KoniTypes.ExtrinsicStatus.QUEUED,
|
|
221
|
+
isInternal,
|
|
222
|
+
id: transactionId,
|
|
223
|
+
extrinsicHash: transactionId
|
|
224
|
+
};
|
|
225
|
+
}
|
|
210
226
|
async addTransaction(inputTransaction) {
|
|
211
227
|
const transactions = this.transactions;
|
|
212
228
|
// Fill transaction default info
|
|
@@ -219,6 +235,15 @@ class TransactionService {
|
|
|
219
235
|
});
|
|
220
236
|
return await this.sendTransaction(transaction);
|
|
221
237
|
}
|
|
238
|
+
addDutchTransaction(inputTransaction) {
|
|
239
|
+
const transactions = this.transactions;
|
|
240
|
+
const transaction = this.fillDutchTransactionDefaultInfo(inputTransaction);
|
|
241
|
+
transactions[transaction.id] = transaction;
|
|
242
|
+
this.transactionSubject.next({
|
|
243
|
+
...transactions
|
|
244
|
+
});
|
|
245
|
+
return this.sendDutchTransaction(transaction);
|
|
246
|
+
}
|
|
222
247
|
generateBeforeHandleResponseErrors(errors) {
|
|
223
248
|
return {
|
|
224
249
|
errors,
|
|
@@ -334,6 +359,62 @@ class TransactionService {
|
|
|
334
359
|
'eventsHandler' in validatedTransaction && delete validatedTransaction.eventsHandler;
|
|
335
360
|
return validatedTransaction;
|
|
336
361
|
}
|
|
362
|
+
async handleDutchTransaction(transaction) {
|
|
363
|
+
var _transaction$step2;
|
|
364
|
+
const transactionId = (0, _helpers.getTransactionId)(transaction.chainType, transaction.chain, true);
|
|
365
|
+
const validatedTransaction = {
|
|
366
|
+
...transaction,
|
|
367
|
+
id: transactionId,
|
|
368
|
+
extrinsicHash: '',
|
|
369
|
+
status: undefined,
|
|
370
|
+
errors: transaction.errors || [],
|
|
371
|
+
warnings: transaction.warnings || [],
|
|
372
|
+
processId: (_transaction$step2 = transaction.step) === null || _transaction$step2 === void 0 ? void 0 : _transaction$step2.processId
|
|
373
|
+
};
|
|
374
|
+
const txInput = {
|
|
375
|
+
...transaction,
|
|
376
|
+
isInternal: true,
|
|
377
|
+
status: _KoniTypes.ExtrinsicStatus.QUEUED,
|
|
378
|
+
id: transactionId,
|
|
379
|
+
extrinsicHash: transactionId,
|
|
380
|
+
createdAt: new Date().getTime(),
|
|
381
|
+
updatedAt: new Date().getTime()
|
|
382
|
+
};
|
|
383
|
+
const emitter = this.addDutchTransaction(txInput);
|
|
384
|
+
await new Promise(resolve => {
|
|
385
|
+
if (transaction.resolveOnDone) {
|
|
386
|
+
emitter.on('success', data => {
|
|
387
|
+
validatedTransaction.id = data.id;
|
|
388
|
+
validatedTransaction.extrinsicHash = data.extrinsicHash;
|
|
389
|
+
resolve();
|
|
390
|
+
});
|
|
391
|
+
} else {
|
|
392
|
+
emitter.on('signed', data => {
|
|
393
|
+
validatedTransaction.id = data.id;
|
|
394
|
+
validatedTransaction.extrinsicHash = data.extrinsicHash;
|
|
395
|
+
resolve();
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
emitter.on('error', data => {
|
|
399
|
+
if (data.errors.length > 0) {
|
|
400
|
+
validatedTransaction.errors.push(...data.errors);
|
|
401
|
+
resolve();
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
emitter.on('timeout', data => {
|
|
405
|
+
if (transaction.errorOnTimeOut && data.errors.length > 0) {
|
|
406
|
+
validatedTransaction.errors.push(...data.errors);
|
|
407
|
+
resolve();
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
// @ts-ignore
|
|
413
|
+
'transaction' in validatedTransaction && delete validatedTransaction.transaction;
|
|
414
|
+
'additionalValidator' in validatedTransaction && delete validatedTransaction.additionalValidator;
|
|
415
|
+
'eventsHandler' in validatedTransaction && delete validatedTransaction.eventsHandler;
|
|
416
|
+
return validatedTransaction;
|
|
417
|
+
}
|
|
337
418
|
async sendTransaction(transaction) {
|
|
338
419
|
// Send Transaction
|
|
339
420
|
const emitter = await (transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : transaction.chainType === 'evm' ? this.signAndSendEvmTransaction(transaction) : transaction.chainType === 'cardano' ? this.signAndSendCardanoTransaction(transaction) : this.signAndSendTonTransaction(transaction));
|
|
@@ -381,10 +462,7 @@ class TransactionService {
|
|
|
381
462
|
if (step) {
|
|
382
463
|
const rejectError = data.errors.find(error => {
|
|
383
464
|
// TODO: REFACTOR ERROR CODE
|
|
384
|
-
|
|
385
|
-
return true;
|
|
386
|
-
}
|
|
387
|
-
return false;
|
|
465
|
+
return [_types.BasicTxErrorType.UNABLE_TO_SIGN, _types.BasicTxErrorType.USER_REJECT_REQUEST].includes(error.errorType);
|
|
388
466
|
});
|
|
389
467
|
|
|
390
468
|
/**
|
|
@@ -457,10 +535,7 @@ class TransactionService {
|
|
|
457
535
|
if (step) {
|
|
458
536
|
const rejectError = data.errors.find(error => {
|
|
459
537
|
// TODO: REFACTOR ERROR CODE
|
|
460
|
-
|
|
461
|
-
return true;
|
|
462
|
-
}
|
|
463
|
-
return false;
|
|
538
|
+
return [_types.BasicTxErrorType.UNABLE_TO_SIGN, _types.BasicTxErrorType.USER_REJECT_REQUEST].includes(error.errorType);
|
|
464
539
|
});
|
|
465
540
|
|
|
466
541
|
/**
|
|
@@ -482,6 +557,83 @@ class TransactionService {
|
|
|
482
557
|
eventsHandler === null || eventsHandler === void 0 ? void 0 : eventsHandler(emitter);
|
|
483
558
|
return emitter;
|
|
484
559
|
}
|
|
560
|
+
sendDutchTransaction(transaction) {
|
|
561
|
+
// Send Transaction
|
|
562
|
+
const emitter = this.signAndSendEvmDutchTransaction(transaction);
|
|
563
|
+
const {
|
|
564
|
+
eventsHandler,
|
|
565
|
+
step
|
|
566
|
+
} = transaction;
|
|
567
|
+
emitter.on('send', data => {
|
|
568
|
+
this.onSend(data);
|
|
569
|
+
if (step) {
|
|
570
|
+
this.updateProcessStepStatus(step, {
|
|
571
|
+
transactionId: transaction.id,
|
|
572
|
+
status: _types.StepStatus.SUBMITTING,
|
|
573
|
+
chain: transaction.chain
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
emitter.on('extrinsicHash', data => {
|
|
578
|
+
this.onHasTransactionHash(data);
|
|
579
|
+
if (step) {
|
|
580
|
+
this.updateProcessStepStatus(step, {
|
|
581
|
+
extrinsicHash: data.extrinsicHash,
|
|
582
|
+
status: _types.StepStatus.PROCESSING
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
emitter.on('success', data => {
|
|
587
|
+
this.handlePostProcessing(data.id);
|
|
588
|
+
this.onSuccess(data);
|
|
589
|
+
if (step) {
|
|
590
|
+
this.updateProcessStepStatus(step, {
|
|
591
|
+
status: _types.StepStatus.COMPLETE
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
emitter.on('error', data => {
|
|
596
|
+
// this.handlePostProcessing(data.id); // might enable this later
|
|
597
|
+
this.onFailed({
|
|
598
|
+
...data,
|
|
599
|
+
errors: [...data.errors, new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR)]
|
|
600
|
+
});
|
|
601
|
+
if (step) {
|
|
602
|
+
const rejectError = data.errors.find(error => {
|
|
603
|
+
// TODO: REFACTOR ERROR CODE
|
|
604
|
+
return [_types.BasicTxErrorType.UNABLE_TO_SIGN, _types.BasicTxErrorType.USER_REJECT_REQUEST].includes(error.errorType);
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Now simple check, first step have step id = 1.
|
|
609
|
+
* Improve to fetch the process from db
|
|
610
|
+
* */
|
|
611
|
+
if (rejectError && step.stepId === 1) {
|
|
612
|
+
this.deleteProcess(step);
|
|
613
|
+
} else {
|
|
614
|
+
this.updateProcessStepStatus(step, {
|
|
615
|
+
status: _types.StepStatus.FAILED
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
emitter.on('timeout', data => {
|
|
621
|
+
this.onTimeOut({
|
|
622
|
+
...data,
|
|
623
|
+
errors: [...data.errors, new _TransactionError.TransactionError(_types.BasicTxErrorType.TIMEOUT)]
|
|
624
|
+
});
|
|
625
|
+
if (step) {
|
|
626
|
+
this.updateProcessStepStatus(step, {
|
|
627
|
+
status: _types.StepStatus.TIMEOUT
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
// Todo: handle any event with transaction.eventsHandler
|
|
633
|
+
|
|
634
|
+
eventsHandler === null || eventsHandler === void 0 ? void 0 : eventsHandler(emitter);
|
|
635
|
+
return emitter;
|
|
636
|
+
}
|
|
485
637
|
removeTransaction(id) {
|
|
486
638
|
if (this.transactions[id]) {
|
|
487
639
|
delete this.transactions[id];
|
|
@@ -505,7 +657,7 @@ class TransactionService {
|
|
|
505
657
|
return (0, _utils3.getExplorerLink)(chainInfo, transaction.extrinsicHash, 'tx');
|
|
506
658
|
}
|
|
507
659
|
transactionToHistories(id, startBlock, nonce, eventLogs) {
|
|
508
|
-
var _transaction$
|
|
660
|
+
var _transaction$step3;
|
|
509
661
|
const transaction = this.getTransaction(id);
|
|
510
662
|
const extrinsicType = transaction.extrinsicType;
|
|
511
663
|
const chainInfo = this.state.chainService.getChainInfoByKey(transaction.chain);
|
|
@@ -530,7 +682,7 @@ class TransactionService {
|
|
|
530
682
|
// Will be added in next step
|
|
531
683
|
nonce: nonce !== null && nonce !== void 0 ? nonce : 0,
|
|
532
684
|
startBlock: startBlock || 0,
|
|
533
|
-
processId: (_transaction$
|
|
685
|
+
processId: (_transaction$step3 = transaction.step) === null || _transaction$step3 === void 0 ? void 0 : _transaction$step3.processId
|
|
534
686
|
};
|
|
535
687
|
const nativeAsset = (0, _utils2._getChainNativeTokenBasicInfo)(chainInfo);
|
|
536
688
|
const baseNativeAmount = {
|
|
@@ -1369,7 +1521,79 @@ class TransactionService {
|
|
|
1369
1521
|
});
|
|
1370
1522
|
return emitter;
|
|
1371
1523
|
}
|
|
1372
|
-
|
|
1524
|
+
signAndSendEvmDutchTransaction(_ref12) {
|
|
1525
|
+
let {
|
|
1526
|
+
address,
|
|
1527
|
+
id,
|
|
1528
|
+
isPassConfirmation,
|
|
1529
|
+
step,
|
|
1530
|
+
transaction,
|
|
1531
|
+
url
|
|
1532
|
+
} = _ref12;
|
|
1533
|
+
const emitter = new _eventemitter.default();
|
|
1534
|
+
const eventData = {
|
|
1535
|
+
id,
|
|
1536
|
+
errors: [],
|
|
1537
|
+
warnings: [],
|
|
1538
|
+
extrinsicHash: id,
|
|
1539
|
+
processId: step === null || step === void 0 ? void 0 : step.processId
|
|
1540
|
+
};
|
|
1541
|
+
|
|
1542
|
+
// todo: review this object
|
|
1543
|
+
const evmSignaturePayload = {
|
|
1544
|
+
id: id,
|
|
1545
|
+
type: 'eth_signTypedData_v4',
|
|
1546
|
+
payload: transaction,
|
|
1547
|
+
address: address,
|
|
1548
|
+
hashPayload: '',
|
|
1549
|
+
canSign: true,
|
|
1550
|
+
processId: step === null || step === void 0 ? void 0 : step.processId
|
|
1551
|
+
};
|
|
1552
|
+
this.state.requestService.addConfirmation(id, url || _constants2.EXTENSION_REQUEST_URL, 'submitApiRequest', evmSignaturePayload, {
|
|
1553
|
+
isPassConfirmation
|
|
1554
|
+
}).then(_ref13 => {
|
|
1555
|
+
let {
|
|
1556
|
+
isApproved,
|
|
1557
|
+
payload: signature
|
|
1558
|
+
} = _ref13;
|
|
1559
|
+
if (isApproved) {
|
|
1560
|
+
emitter.emit('signed', eventData);
|
|
1561
|
+
emitter.emit('send', eventData);
|
|
1562
|
+
transaction.submitSwapOrder().then(isSendSuccess => {
|
|
1563
|
+
if (!isSendSuccess) {
|
|
1564
|
+
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.UNAUTHORIZED, (0, _i18next.t)('Failed to sign'));
|
|
1565
|
+
}
|
|
1566
|
+
this.handleTransactionTimeout(emitter, eventData);
|
|
1567
|
+
transaction.cronCheckTxSuccess().then(order => {
|
|
1568
|
+
if (!order) {
|
|
1569
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED));
|
|
1570
|
+
emitter.emit('error', eventData);
|
|
1571
|
+
} else {
|
|
1572
|
+
eventData.extrinsicHash = order.txHash;
|
|
1573
|
+
emitter.emit('extrinsicHash', eventData);
|
|
1574
|
+
emitter.emit('success', eventData);
|
|
1575
|
+
}
|
|
1576
|
+
}).catch(e => {
|
|
1577
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED, (0, _i18next.t)(e.message)));
|
|
1578
|
+
emitter.emit('error', eventData);
|
|
1579
|
+
});
|
|
1580
|
+
}).catch(e => {
|
|
1581
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNABLE_TO_SEND, (0, _i18next.t)(e.message)));
|
|
1582
|
+
emitter.emit('error', eventData);
|
|
1583
|
+
});
|
|
1584
|
+
} else {
|
|
1585
|
+
this.removeTransaction(id);
|
|
1586
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.USER_REJECT_REQUEST));
|
|
1587
|
+
emitter.emit('error', eventData);
|
|
1588
|
+
}
|
|
1589
|
+
}).catch(e => {
|
|
1590
|
+
this.removeTransaction(id);
|
|
1591
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNABLE_TO_SIGN, (0, _i18next.t)(e.message)));
|
|
1592
|
+
emitter.emit('error', eventData);
|
|
1593
|
+
});
|
|
1594
|
+
return emitter;
|
|
1595
|
+
}
|
|
1596
|
+
signAndSendSubstrateTransaction(_ref14) {
|
|
1373
1597
|
var _this$state$chainServ;
|
|
1374
1598
|
let {
|
|
1375
1599
|
address,
|
|
@@ -1381,7 +1605,7 @@ class TransactionService {
|
|
|
1381
1605
|
tokenPayFeeSlug,
|
|
1382
1606
|
transaction,
|
|
1383
1607
|
url
|
|
1384
|
-
} =
|
|
1608
|
+
} = _ref14;
|
|
1385
1609
|
const tip = (feeCustom === null || feeCustom === void 0 ? void 0 : feeCustom.tip) || '0';
|
|
1386
1610
|
const feeAssetId = tokenPayFeeSlug && !(0, _utils2._isNativeTokenBySlug)(tokenPayFeeSlug) && _constants._SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(chain) ? (_this$state$chainServ = this.state.chainService.getAssetBySlug(tokenPayFeeSlug).metadata) === null || _this$state$chainServ === void 0 ? void 0 : _this$state$chainServ.multilocation : undefined;
|
|
1387
1611
|
const emitter = new _eventemitter.default();
|
|
@@ -1435,44 +1659,65 @@ class TransactionService {
|
|
|
1435
1659
|
this.handleTransactionTimeout(emitter, eventData);
|
|
1436
1660
|
emitter.emit('send', eventData); // This event is needed after sending transaction with queue
|
|
1437
1661
|
|
|
1662
|
+
let isBroadcast = false;
|
|
1663
|
+
let isInBlock = false;
|
|
1664
|
+
let isFinish = false;
|
|
1438
1665
|
rs.send(txState => {
|
|
1439
1666
|
// handle events, logs, history
|
|
1440
1667
|
if (!txState || !txState.status) {
|
|
1441
1668
|
return;
|
|
1442
1669
|
}
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1670
|
+
|
|
1671
|
+
// Broadcast transaction
|
|
1672
|
+
if (!isBroadcast) {
|
|
1673
|
+
if (txState.status.isBroadcast || txState.status.isInBlock || txState.status.isFinalized) {
|
|
1446
1674
|
eventData.extrinsicHash = txState.txHash.toHex();
|
|
1675
|
+
isBroadcast = true;
|
|
1676
|
+
if (!isFinish) {
|
|
1677
|
+
emitter.emit('extrinsicHash', eventData);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
// Transaction in block
|
|
1683
|
+
if (!isInBlock) {
|
|
1684
|
+
if (txState.status.isInBlock || txState.status.isFinalized) {
|
|
1447
1685
|
eventData.blockHash = txState.status.asInBlock.toHex();
|
|
1448
|
-
|
|
1686
|
+
eventData.eventLogs = txState.events;
|
|
1687
|
+
isInBlock = true;
|
|
1449
1688
|
}
|
|
1450
1689
|
}
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
event: {
|
|
1458
|
-
section
|
|
1459
|
-
}
|
|
1460
|
-
} = _ref13;
|
|
1461
|
-
return section === 'system';
|
|
1462
|
-
}).forEach(_ref14 => {
|
|
1463
|
-
let {
|
|
1464
|
-
event: {
|
|
1465
|
-
data: [error],
|
|
1466
|
-
method
|
|
1467
|
-
}
|
|
1468
|
-
} = _ref14;
|
|
1469
|
-
if (method === 'ExtrinsicFailed') {
|
|
1470
|
-
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED, error.toString()));
|
|
1471
|
-
emitter.emit('error', eventData);
|
|
1472
|
-
} else if (method === 'ExtrinsicSuccess') {
|
|
1473
|
-
emitter.emit('success', eventData);
|
|
1690
|
+
|
|
1691
|
+
// Transaction finished
|
|
1692
|
+
if (!isFinish) {
|
|
1693
|
+
if (txState.status.isInBlock || txState.status.isFinalized) {
|
|
1694
|
+
if (!eventData.extrinsicHash) {
|
|
1695
|
+
eventData.extrinsicHash = txState.txHash.toHex();
|
|
1474
1696
|
}
|
|
1475
|
-
|
|
1697
|
+
txState.events.filter(_ref15 => {
|
|
1698
|
+
let {
|
|
1699
|
+
event: {
|
|
1700
|
+
section
|
|
1701
|
+
}
|
|
1702
|
+
} = _ref15;
|
|
1703
|
+
return section === 'system';
|
|
1704
|
+
}).forEach(_ref16 => {
|
|
1705
|
+
let {
|
|
1706
|
+
event: {
|
|
1707
|
+
data: [error],
|
|
1708
|
+
method
|
|
1709
|
+
}
|
|
1710
|
+
} = _ref16;
|
|
1711
|
+
if (method === 'ExtrinsicFailed') {
|
|
1712
|
+
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED, error.toString()));
|
|
1713
|
+
emitter.emit('error', eventData);
|
|
1714
|
+
isFinish = true;
|
|
1715
|
+
} else if (method === 'ExtrinsicSuccess') {
|
|
1716
|
+
emitter.emit('success', eventData);
|
|
1717
|
+
isFinish = true;
|
|
1718
|
+
}
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1476
1721
|
}
|
|
1477
1722
|
}).catch(e => {
|
|
1478
1723
|
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.SEND_TRANSACTION_FAILED, e.message));
|
|
@@ -1485,7 +1730,7 @@ class TransactionService {
|
|
|
1485
1730
|
});
|
|
1486
1731
|
return emitter;
|
|
1487
1732
|
}
|
|
1488
|
-
signAndSendTonTransaction(
|
|
1733
|
+
signAndSendTonTransaction(_ref17) {
|
|
1489
1734
|
let {
|
|
1490
1735
|
address,
|
|
1491
1736
|
chain,
|
|
@@ -1494,7 +1739,7 @@ class TransactionService {
|
|
|
1494
1739
|
step,
|
|
1495
1740
|
transaction,
|
|
1496
1741
|
url
|
|
1497
|
-
} =
|
|
1742
|
+
} = _ref17;
|
|
1498
1743
|
const walletContract = _uiKeyring.default.getPair(address).ton.currentContract;
|
|
1499
1744
|
const emitter = new _eventemitter.default();
|
|
1500
1745
|
const eventData = {
|
|
@@ -1511,11 +1756,11 @@ class TransactionService {
|
|
|
1511
1756
|
...payload,
|
|
1512
1757
|
messagePayload: (0, _utils.cellToBase64Str)(message),
|
|
1513
1758
|
messages: []
|
|
1514
|
-
}, {}).then(
|
|
1759
|
+
}, {}).then(_ref18 => {
|
|
1515
1760
|
let {
|
|
1516
1761
|
isApproved,
|
|
1517
1762
|
payload
|
|
1518
|
-
} =
|
|
1763
|
+
} = _ref18;
|
|
1519
1764
|
if (!isApproved) {
|
|
1520
1765
|
this.removeTransaction(id);
|
|
1521
1766
|
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.USER_REJECT_REQUEST));
|
|
@@ -1550,8 +1795,8 @@ class TransactionService {
|
|
|
1550
1795
|
if (!externalMsgHash) {
|
|
1551
1796
|
return;
|
|
1552
1797
|
}
|
|
1553
|
-
tonApi.getStatusByExtMsgHash(externalMsgHash, extrinsicType).then(
|
|
1554
|
-
let [status, hex] =
|
|
1798
|
+
tonApi.getStatusByExtMsgHash(externalMsgHash, extrinsicType).then(_ref19 => {
|
|
1799
|
+
let [status, hex] = _ref19;
|
|
1555
1800
|
if (status && hex) {
|
|
1556
1801
|
eventData.extrinsicHash = hex;
|
|
1557
1802
|
emitter.emit('extrinsicHash', eventData);
|
|
@@ -1580,13 +1825,13 @@ class TransactionService {
|
|
|
1580
1825
|
});
|
|
1581
1826
|
return emitter;
|
|
1582
1827
|
}
|
|
1583
|
-
signAndSendCardanoTransaction(
|
|
1828
|
+
signAndSendCardanoTransaction(_ref20) {
|
|
1584
1829
|
let {
|
|
1585
1830
|
chain,
|
|
1586
1831
|
id,
|
|
1587
1832
|
transaction,
|
|
1588
1833
|
url
|
|
1589
|
-
} =
|
|
1834
|
+
} = _ref20;
|
|
1590
1835
|
const emitter = new _eventemitter.default();
|
|
1591
1836
|
const eventData = {
|
|
1592
1837
|
id,
|
|
@@ -1596,11 +1841,11 @@ class TransactionService {
|
|
|
1596
1841
|
};
|
|
1597
1842
|
const transactionConfig = transaction;
|
|
1598
1843
|
const cardanoApi = this.state.chainService.getCardanoApi(chain);
|
|
1599
|
-
this.state.requestService.addConfirmationCardano(id, url || _constants2.EXTENSION_REQUEST_URL, 'cardanoSendTransactionRequest', transactionConfig, {}).then(
|
|
1844
|
+
this.state.requestService.addConfirmationCardano(id, url || _constants2.EXTENSION_REQUEST_URL, 'cardanoSendTransactionRequest', transactionConfig, {}).then(_ref21 => {
|
|
1600
1845
|
let {
|
|
1601
1846
|
isApproved,
|
|
1602
1847
|
payload
|
|
1603
|
-
} =
|
|
1848
|
+
} = _ref21;
|
|
1604
1849
|
if (!isApproved) {
|
|
1605
1850
|
this.removeTransaction(id);
|
|
1606
1851
|
eventData.errors.push(new _TransactionError.TransactionError(_types.BasicTxErrorType.USER_REJECT_REQUEST));
|
|
@@ -1791,9 +2036,9 @@ class TransactionService {
|
|
|
1791
2036
|
}
|
|
1792
2037
|
}
|
|
1793
2038
|
async createProcessNotification(transactionId) {
|
|
1794
|
-
var _transaction$
|
|
2039
|
+
var _transaction$step4;
|
|
1795
2040
|
const transaction = this.getTransaction(transactionId);
|
|
1796
|
-
if (transaction && (_transaction$
|
|
2041
|
+
if (transaction && (_transaction$step4 = transaction.step) !== null && _transaction$step4 !== void 0 && _transaction$step4.processId) {
|
|
1797
2042
|
const process = this.aliveProcessMap.get(transaction.step.processId);
|
|
1798
2043
|
if (process) {
|
|
1799
2044
|
await this.state.inappNotificationService.createProcessNotification(process);
|
package/cjs/types/swap/index.js
CHANGED
|
@@ -42,13 +42,14 @@ exports.SwapProviderId = SwapProviderId;
|
|
|
42
42
|
SwapProviderId["WESTEND_ASSET_HUB"] = "WESTEND_ASSET_HUB";
|
|
43
43
|
SwapProviderId["SIMPLE_SWAP"] = "SIMPLE_SWAP";
|
|
44
44
|
SwapProviderId["UNISWAP"] = "UNISWAP";
|
|
45
|
+
SwapProviderId["KYBER"] = "KYBER";
|
|
45
46
|
})(SwapProviderId || (exports.SwapProviderId = SwapProviderId = {}));
|
|
46
47
|
const _SUPPORTED_SWAP_PROVIDERS = [SwapProviderId.CHAIN_FLIP_TESTNET, SwapProviderId.CHAIN_FLIP_MAINNET, SwapProviderId.HYDRADX_MAINNET,
|
|
47
48
|
// SwapProviderId.HYDRADX_TESTNET,
|
|
48
49
|
SwapProviderId.POLKADOT_ASSET_HUB, SwapProviderId.KUSAMA_ASSET_HUB,
|
|
49
50
|
// SwapProviderId.ROCOCO_ASSET_HUB,
|
|
50
51
|
// SwapProviderId.WESTEND_ASSET_HUB,
|
|
51
|
-
SwapProviderId.SIMPLE_SWAP, SwapProviderId.UNISWAP];
|
|
52
|
+
SwapProviderId.SIMPLE_SWAP, SwapProviderId.UNISWAP, SwapProviderId.KYBER];
|
|
52
53
|
exports._SUPPORTED_SWAP_PROVIDERS = _SUPPORTED_SWAP_PROVIDERS;
|
|
53
54
|
// process handling
|
|
54
55
|
let SwapFeeType;
|
|
@@ -351,7 +351,7 @@ export async function validationEvmDataTransactionMiddleware(koni, url, payload)
|
|
|
351
351
|
transaction.maxPriorityFeePerGas = feeCombine.maxPriorityFeePerGas;
|
|
352
352
|
} else if (feeCombine.gasPrice) {
|
|
353
353
|
estimateGas = new BigN(feeCombine.gasPrice || 0).multipliedBy(gasLimit).toFixed(0);
|
|
354
|
-
transaction.
|
|
354
|
+
transaction.gasPrice = feeCombine.gasPrice;
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
} catch (e) {
|
|
@@ -880,6 +880,9 @@ export default class KoniExtension {
|
|
|
880
880
|
}) {
|
|
881
881
|
return this.#koniState.priceService.getHistoryTokenPriceData(priceId, timeframe);
|
|
882
882
|
}
|
|
883
|
+
checkCoinGeckoPriceSupport(priceId) {
|
|
884
|
+
return this.#koniState.priceService.checkCoinGeckoPriceSupport(priceId);
|
|
885
|
+
}
|
|
883
886
|
subscribeCurrentTokenPrice(priceId, id, port) {
|
|
884
887
|
const cb = createSubscription(id, port);
|
|
885
888
|
const {
|
|
@@ -1443,7 +1446,8 @@ export default class KoniExtension {
|
|
|
1443
1446
|
xcmFeeDryRun = dryRunInfo.fee;
|
|
1444
1447
|
}
|
|
1445
1448
|
if (isAcrossBridgeTransfer) {
|
|
1446
|
-
const
|
|
1449
|
+
const data = await getAcrossQuote(params);
|
|
1450
|
+
const metadata = data.metadata;
|
|
1447
1451
|
inputData.metadata = {
|
|
1448
1452
|
amountOut: metadata.outputAmount,
|
|
1449
1453
|
rate: metadata.rate,
|
|
@@ -2583,11 +2587,12 @@ export default class KoniExtension {
|
|
|
2583
2587
|
let registry = new TypeRegistry();
|
|
2584
2588
|
if (isJsonPayload(payload)) {
|
|
2585
2589
|
const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
|
|
2586
|
-
const
|
|
2587
|
-
|
|
2590
|
+
const registries = await Promise.all([setupApiRegistry(chainInfo, this.#koniState), setupDatabaseRegistry(chainInfo, payload, this.#koniState), setupDappRegistry(payload, this.#koniState)]);
|
|
2591
|
+
const validRegistries = registries.filter(item => !!(item !== null && item !== void 0 && item.registry));
|
|
2592
|
+
if (validRegistries.length === 0) {
|
|
2588
2593
|
registry.setSignedExtensions(payload.signedExtensions);
|
|
2589
2594
|
} else {
|
|
2590
|
-
registry = getSuitableRegistry(
|
|
2595
|
+
registry = getSuitableRegistry(validRegistries, payload);
|
|
2591
2596
|
}
|
|
2592
2597
|
}
|
|
2593
2598
|
const result = request.sign(registry, pair);
|
|
@@ -2715,6 +2720,7 @@ export default class KoniExtension {
|
|
|
2715
2720
|
getTransaction({
|
|
2716
2721
|
id
|
|
2717
2722
|
}) {
|
|
2723
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
2718
2724
|
const {
|
|
2719
2725
|
transaction,
|
|
2720
2726
|
...transactionResult
|
|
@@ -2725,6 +2731,7 @@ export default class KoniExtension {
|
|
|
2725
2731
|
const cb = createSubscription(id, port);
|
|
2726
2732
|
function convertRs(rs, processMap) {
|
|
2727
2733
|
return Object.fromEntries(Object.entries(rs).map(([key, value]) => {
|
|
2734
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
2728
2735
|
const {
|
|
2729
2736
|
additionalValidator,
|
|
2730
2737
|
eventsHandler,
|
|
@@ -3762,6 +3769,7 @@ export default class KoniExtension {
|
|
|
3762
3769
|
chainType,
|
|
3763
3770
|
extrinsic,
|
|
3764
3771
|
extrinsicType,
|
|
3772
|
+
isDutch,
|
|
3765
3773
|
isPermit,
|
|
3766
3774
|
transferNativeAmount,
|
|
3767
3775
|
txChain,
|
|
@@ -3818,6 +3826,24 @@ export default class KoniExtension {
|
|
|
3818
3826
|
step
|
|
3819
3827
|
});
|
|
3820
3828
|
}
|
|
3829
|
+
if (isDutch) {
|
|
3830
|
+
return await this.#koniState.transactionService.handleDutchTransaction({
|
|
3831
|
+
address,
|
|
3832
|
+
chain: txChain,
|
|
3833
|
+
transaction: extrinsic,
|
|
3834
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
3835
|
+
data: txData,
|
|
3836
|
+
extrinsicType,
|
|
3837
|
+
// change this depends on step
|
|
3838
|
+
chainType,
|
|
3839
|
+
resolveOnDone: !isLastStep,
|
|
3840
|
+
transferNativeAmount,
|
|
3841
|
+
...this.createPassConfirmationParams(isPassConfirmation),
|
|
3842
|
+
errorOnTimeOut,
|
|
3843
|
+
eventsHandler,
|
|
3844
|
+
step
|
|
3845
|
+
});
|
|
3846
|
+
}
|
|
3821
3847
|
return await this.#koniState.transactionService.handleTransaction({
|
|
3822
3848
|
address,
|
|
3823
3849
|
chain: txChain,
|
|
@@ -4271,6 +4297,8 @@ export default class KoniExtension {
|
|
|
4271
4297
|
return await this.subscribePrice(id, port);
|
|
4272
4298
|
case 'pri(price.getHistory)':
|
|
4273
4299
|
return await this.getHistoryTokenPrice(request);
|
|
4300
|
+
case 'pri(price.checkCoinGeckoPriceSupport)':
|
|
4301
|
+
return this.checkCoinGeckoPriceSupport(request);
|
|
4274
4302
|
case 'pri(price.subscribeCurrentTokenPrice)':
|
|
4275
4303
|
return this.subscribeCurrentTokenPrice(request, id, port);
|
|
4276
4304
|
case 'pri(settings.savePriceCurrency)':
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { MetadataItem } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
-
import { MetadataDef } from '@subwallet/extension-inject/types';
|
|
4
2
|
import { Registry, SignerPayloadJSON } from '@polkadot/types/types';
|
|
5
3
|
import KoniState from './handlers/State';
|
|
6
4
|
export interface RegistrySource {
|
|
@@ -8,6 +6,6 @@ export interface RegistrySource {
|
|
|
8
6
|
specVersion: string | number;
|
|
9
7
|
}
|
|
10
8
|
export declare function getSuitableRegistry(registries: RegistrySource[], payload: SignerPayloadJSON): Registry;
|
|
11
|
-
export declare function setupApiRegistry(chainInfo: _ChainInfo | undefined, koniState: KoniState): RegistrySource | null
|
|
12
|
-
export declare function setupDatabaseRegistry(
|
|
13
|
-
export declare function setupDappRegistry(
|
|
9
|
+
export declare function setupApiRegistry(chainInfo: _ChainInfo | undefined, koniState: KoniState): Promise<RegistrySource | null>;
|
|
10
|
+
export declare function setupDatabaseRegistry(chainInfo: _ChainInfo | undefined, payload: SignerPayloadJSON, koniState: KoniState): Promise<RegistrySource | null>;
|
|
11
|
+
export declare function setupDappRegistry(payload: SignerPayloadJSON, koniState: KoniState): Promise<RegistrySource | null>;
|