@subwallet/extension-base 1.3.19-0 → 1.3.21-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 +8 -1
- package/cjs/core/logic-validation/request.js +4 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/background/handlers/Extension.js +519 -90
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +1 -1
- package/cjs/services/chain-service/handler/EvmApi.js +1 -3
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +19 -8
- package/cjs/services/earning-service/handlers/special.js +16 -10
- package/cjs/services/history-service/helpers/recoverHistoryStatus.js +14 -5
- package/cjs/services/history-service/index.js +15 -3
- package/cjs/services/inapp-notification-service/index.js +78 -0
- package/cjs/services/inapp-notification-service/interfaces.js +2 -0
- package/cjs/services/keyring-service/context/state.js +2 -1
- package/cjs/services/request-service/handler/EvmRequestHandler.js +10 -0
- package/cjs/services/request-service/handler/SubstrateRequestHandler.js +4 -3
- package/cjs/services/request-service/index.js +2 -2
- package/cjs/services/setting-service/constants.js +5 -2
- package/cjs/services/storage-service/DatabaseService.js +98 -2
- package/cjs/services/storage-service/databases/index.js +3 -0
- package/cjs/services/storage-service/db-stores/ProcessTransaction.js +47 -0
- package/cjs/services/storage-service/db-stores/Transaction.js +2 -0
- package/cjs/services/storage-service/db-stores/index.js +8 -1
- package/cjs/services/swap-service/handler/asset-hub/handler.js +30 -11
- package/cjs/services/swap-service/handler/hydradx-handler.js +18 -10
- package/cjs/services/swap-service/index.js +3 -0
- package/cjs/services/swap-service/utils.js +1 -0
- package/cjs/services/transaction-service/index.js +218 -9
- package/cjs/types/index.js +11 -0
- package/cjs/types/setting.js +1 -0
- package/cjs/types/swap/index.js +4 -1
- package/cjs/types/transaction/index.js +11 -0
- package/cjs/types/transaction/process.js +28 -0
- package/cjs/types/yield/actions/join/submit.js +16 -1
- package/core/logic-validation/request.js +4 -1
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/background/handlers/Extension.d.ts +5 -0
- package/koni/background/handlers/Extension.js +437 -12
- package/package.json +21 -6
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.js +1 -1
- package/services/chain-service/handler/EvmApi.js +1 -3
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +19 -8
- package/services/earning-service/handlers/special.js +18 -12
- package/services/history-service/helpers/recoverHistoryStatus.js +14 -5
- package/services/history-service/index.d.ts +6 -5
- package/services/history-service/index.js +16 -5
- package/services/inapp-notification-service/index.d.ts +2 -0
- package/services/inapp-notification-service/index.js +79 -1
- package/services/inapp-notification-service/interfaces.d.ts +8 -1
- package/services/inapp-notification-service/interfaces.js +2 -0
- package/services/keyring-service/context/state.d.ts +1 -1
- package/services/keyring-service/context/state.js +3 -2
- package/services/request-service/handler/EvmRequestHandler.js +10 -0
- package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -1
- package/services/request-service/handler/SubstrateRequestHandler.js +4 -3
- package/services/request-service/index.d.ts +1 -1
- package/services/request-service/index.js +2 -2
- package/services/setting-service/constants.d.ts +1 -0
- package/services/setting-service/constants.js +3 -1
- package/services/storage-service/DatabaseService.d.ts +12 -3
- package/services/storage-service/DatabaseService.js +100 -4
- package/services/storage-service/databases/index.d.ts +2 -1
- package/services/storage-service/databases/index.js +3 -0
- package/services/storage-service/db-stores/ProcessTransaction.d.ts +14 -0
- package/services/storage-service/db-stores/ProcessTransaction.js +39 -0
- package/services/storage-service/db-stores/Transaction.js +2 -0
- package/services/storage-service/db-stores/index.d.ts +1 -0
- package/services/storage-service/db-stores/index.js +2 -1
- package/services/swap-service/handler/asset-hub/handler.js +30 -11
- package/services/swap-service/handler/hydradx-handler.js +18 -10
- package/services/swap-service/index.js +3 -0
- package/services/swap-service/utils.js +1 -0
- package/services/transaction-service/index.d.ts +19 -1
- package/services/transaction-service/index.js +220 -11
- package/services/transaction-service/types.d.ts +13 -4
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/setting.d.ts +3 -0
- package/types/setting.js +1 -0
- package/types/swap/index.d.ts +3 -2
- package/types/swap/index.js +4 -1
- package/types/transaction/index.d.ts +1 -0
- package/types/transaction/index.js +1 -0
- package/types/transaction/process.d.ts +84 -0
- package/types/transaction/process.js +20 -0
- package/types/transaction/request.d.ts +3 -1
- package/types/yield/actions/join/submit.d.ts +18 -3
- package/types/yield/actions/join/submit.js +11 -1
|
@@ -837,6 +837,13 @@ class KoniExtension {
|
|
|
837
837
|
this.#koniState.updateSetting('isShowBalance', enable);
|
|
838
838
|
return true;
|
|
839
839
|
}
|
|
840
|
+
setAllowOneSign(_ref25) {
|
|
841
|
+
let {
|
|
842
|
+
allowOneSign
|
|
843
|
+
} = _ref25;
|
|
844
|
+
this.#koniState.updateSetting('allowOneSign', allowOneSign);
|
|
845
|
+
return true;
|
|
846
|
+
}
|
|
840
847
|
async subscribeAuthUrls(id, port) {
|
|
841
848
|
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
842
849
|
const authorizeUrlSubscription = this.#koniState.subscribeAuthorizeUrlSubject().subscribe({
|
|
@@ -882,10 +889,10 @@ class KoniExtension {
|
|
|
882
889
|
async getPrice() {
|
|
883
890
|
return this.#koniState.priceService.getPrice();
|
|
884
891
|
}
|
|
885
|
-
async setPriceCurrency(
|
|
892
|
+
async setPriceCurrency(_ref26) {
|
|
886
893
|
let {
|
|
887
894
|
currency
|
|
888
|
-
} =
|
|
895
|
+
} = _ref26;
|
|
889
896
|
return await this.#koniState.priceService.setPriceCurrency(currency);
|
|
890
897
|
}
|
|
891
898
|
subscribePrice(id, port) {
|
|
@@ -1093,11 +1100,11 @@ class KoniExtension {
|
|
|
1093
1100
|
// Re-filter
|
|
1094
1101
|
return historySubject.getValue().filter(item => addresses.some(address => (0, _utils7.isSameAddress)(item.address, address)));
|
|
1095
1102
|
}
|
|
1096
|
-
subscribeHistoryByChainAndAddress(
|
|
1103
|
+
subscribeHistoryByChainAndAddress(_ref27, id, port) {
|
|
1097
1104
|
let {
|
|
1098
1105
|
address,
|
|
1099
1106
|
chain
|
|
1100
|
-
} =
|
|
1107
|
+
} = _ref27;
|
|
1101
1108
|
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
1102
1109
|
const subscribeHistoriesResponse = this.#koniState.historyService.subscribeHistories(chain, address, cb);
|
|
1103
1110
|
this.createUnsubscriptionHandle(id, subscribeHistoriesResponse.unsubscribe);
|
|
@@ -1330,6 +1337,7 @@ class KoniExtension {
|
|
|
1330
1337
|
feeCustom,
|
|
1331
1338
|
feeOption,
|
|
1332
1339
|
from,
|
|
1340
|
+
isPassConfirmation,
|
|
1333
1341
|
nonNativeTokenPayFeeSlug,
|
|
1334
1342
|
originNetworkKey,
|
|
1335
1343
|
to,
|
|
@@ -1453,6 +1461,7 @@ class KoniExtension {
|
|
|
1453
1461
|
nonNativeTokenPayFeeSlug,
|
|
1454
1462
|
isTransferAll: transferAll,
|
|
1455
1463
|
isTransferLocalTokenAndPayThatTokenAsFee,
|
|
1464
|
+
isPassConfirmation,
|
|
1456
1465
|
errors,
|
|
1457
1466
|
additionalValidator: additionalValidator,
|
|
1458
1467
|
eventsHandler: eventsHandler
|
|
@@ -1574,21 +1583,21 @@ class KoniExtension {
|
|
|
1574
1583
|
disableChain(networkKey) {
|
|
1575
1584
|
return this.#koniState.disableChain(networkKey);
|
|
1576
1585
|
}
|
|
1577
|
-
async enableChain(
|
|
1586
|
+
async enableChain(_ref28) {
|
|
1578
1587
|
let {
|
|
1579
1588
|
chainSlug,
|
|
1580
1589
|
enableTokens
|
|
1581
|
-
} =
|
|
1590
|
+
} = _ref28;
|
|
1582
1591
|
return await this.#koniState.enableChain(chainSlug, enableTokens);
|
|
1583
1592
|
}
|
|
1584
1593
|
async reconnectChain(chainSlug) {
|
|
1585
1594
|
return this.#koniState.chainService.reconnectChain(chainSlug);
|
|
1586
1595
|
}
|
|
1587
|
-
async validateNetwork(
|
|
1596
|
+
async validateNetwork(_ref29) {
|
|
1588
1597
|
let {
|
|
1589
1598
|
existedChainSlug,
|
|
1590
1599
|
provider
|
|
1591
|
-
} =
|
|
1600
|
+
} = _ref29;
|
|
1592
1601
|
return await this.#koniState.validateCustomChain(provider, existedChainSlug);
|
|
1593
1602
|
}
|
|
1594
1603
|
resetDefaultNetwork() {
|
|
@@ -1679,13 +1688,13 @@ class KoniExtension {
|
|
|
1679
1688
|
async validateCustomAsset(data) {
|
|
1680
1689
|
return await this.#koniState.validateCustomAsset(data);
|
|
1681
1690
|
}
|
|
1682
|
-
async getAddressTransferableBalance(
|
|
1691
|
+
async getAddressTransferableBalance(_ref30) {
|
|
1683
1692
|
let {
|
|
1684
1693
|
address,
|
|
1685
1694
|
extrinsicType,
|
|
1686
1695
|
networkKey,
|
|
1687
1696
|
token
|
|
1688
|
-
} =
|
|
1697
|
+
} = _ref30;
|
|
1689
1698
|
if (token && _constants2._MANTA_ZK_CHAIN_GROUP.includes(networkKey)) {
|
|
1690
1699
|
const tokenInfo = this.#koniState.chainService.getAssetBySlug(token);
|
|
1691
1700
|
if (tokenInfo.symbol.startsWith(_constants2._ZK_ASSET_PREFIX)) {
|
|
@@ -1694,13 +1703,13 @@ class KoniExtension {
|
|
|
1694
1703
|
}
|
|
1695
1704
|
return await this.#koniState.balanceService.getTransferableBalance(address, networkKey, token, extrinsicType);
|
|
1696
1705
|
}
|
|
1697
|
-
async getAddressTotalBalance(
|
|
1706
|
+
async getAddressTotalBalance(_ref31) {
|
|
1698
1707
|
let {
|
|
1699
1708
|
address,
|
|
1700
1709
|
extrinsicType,
|
|
1701
1710
|
networkKey,
|
|
1702
1711
|
token
|
|
1703
|
-
} =
|
|
1712
|
+
} = _ref31;
|
|
1704
1713
|
return await this.#koniState.balanceService.getTotalBalance(address, networkKey, token, extrinsicType);
|
|
1705
1714
|
}
|
|
1706
1715
|
async subscribeMaxTransferable(request, id, port) {
|
|
@@ -1748,11 +1757,11 @@ class KoniExtension {
|
|
|
1748
1757
|
freeBalance: freeBalanceSubject,
|
|
1749
1758
|
fee: feeSubject
|
|
1750
1759
|
}).subscribe({
|
|
1751
|
-
next:
|
|
1760
|
+
next: _ref32 => {
|
|
1752
1761
|
let {
|
|
1753
1762
|
fee,
|
|
1754
1763
|
freeBalance
|
|
1755
|
-
} =
|
|
1764
|
+
} = _ref32;
|
|
1756
1765
|
(0, _utils7.calculateMaxTransferable)(id, _request, freeBalance, fee).then(cb).catch(console.error);
|
|
1757
1766
|
}
|
|
1758
1767
|
});
|
|
@@ -1786,13 +1795,13 @@ class KoniExtension {
|
|
|
1786
1795
|
});
|
|
1787
1796
|
return (0, _utils7.calculateMaxTransferable)(id, _request, freeBalance, fee);
|
|
1788
1797
|
}
|
|
1789
|
-
async subscribeAddressTransferableBalance(
|
|
1798
|
+
async subscribeAddressTransferableBalance(_ref33, id, port) {
|
|
1790
1799
|
let {
|
|
1791
1800
|
address,
|
|
1792
1801
|
extrinsicType,
|
|
1793
1802
|
networkKey,
|
|
1794
1803
|
token
|
|
1795
|
-
} =
|
|
1804
|
+
} = _ref33;
|
|
1796
1805
|
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
1797
1806
|
const convertData = data => {
|
|
1798
1807
|
return {
|
|
@@ -1843,11 +1852,11 @@ class KoniExtension {
|
|
|
1843
1852
|
isSendingSelf
|
|
1844
1853
|
};
|
|
1845
1854
|
}
|
|
1846
|
-
async enableChains(
|
|
1855
|
+
async enableChains(_ref34) {
|
|
1847
1856
|
let {
|
|
1848
1857
|
chainSlugs,
|
|
1849
1858
|
enableTokens
|
|
1850
|
-
} =
|
|
1859
|
+
} = _ref34;
|
|
1851
1860
|
try {
|
|
1852
1861
|
await Promise.all(chainSlugs.map(chainSlug => this.enableChain({
|
|
1853
1862
|
chainSlug,
|
|
@@ -1968,30 +1977,30 @@ class KoniExtension {
|
|
|
1968
1977
|
|
|
1969
1978
|
// Parse transaction
|
|
1970
1979
|
|
|
1971
|
-
parseSubstrateTransaction(
|
|
1980
|
+
parseSubstrateTransaction(_ref35) {
|
|
1972
1981
|
let {
|
|
1973
1982
|
data,
|
|
1974
1983
|
networkKey
|
|
1975
|
-
} =
|
|
1984
|
+
} = _ref35;
|
|
1976
1985
|
const apiProps = this.#koniState.getSubstrateApi(networkKey);
|
|
1977
1986
|
const apiPromise = apiProps.api;
|
|
1978
1987
|
return (0, _parseTransaction.parseSubstrateTransaction)(data, apiPromise);
|
|
1979
1988
|
}
|
|
1980
|
-
async parseEVMRLP(
|
|
1989
|
+
async parseEVMRLP(_ref36) {
|
|
1981
1990
|
let {
|
|
1982
1991
|
data
|
|
1983
|
-
} =
|
|
1992
|
+
} = _ref36;
|
|
1984
1993
|
return await (0, _parseTransaction2.parseEvmRlp)(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
|
|
1985
1994
|
}
|
|
1986
1995
|
|
|
1987
1996
|
// Sign
|
|
1988
1997
|
|
|
1989
|
-
qrSignSubstrate(
|
|
1998
|
+
qrSignSubstrate(_ref37) {
|
|
1990
1999
|
let {
|
|
1991
2000
|
address,
|
|
1992
2001
|
data,
|
|
1993
2002
|
networkKey
|
|
1994
|
-
} =
|
|
2003
|
+
} = _ref37;
|
|
1995
2004
|
const pair = _uiKeyring.keyring.getPair(address);
|
|
1996
2005
|
(0, _util.assert)(pair, (0, _i18next.t)('Unable to find account'));
|
|
1997
2006
|
if (pair.isLocked) {
|
|
@@ -2008,13 +2017,13 @@ class KoniExtension {
|
|
|
2008
2017
|
signature: signed
|
|
2009
2018
|
};
|
|
2010
2019
|
}
|
|
2011
|
-
async qrSignEVM(
|
|
2020
|
+
async qrSignEVM(_ref38) {
|
|
2012
2021
|
let {
|
|
2013
2022
|
address,
|
|
2014
2023
|
chainId,
|
|
2015
2024
|
message,
|
|
2016
2025
|
type
|
|
2017
|
-
} =
|
|
2026
|
+
} = _ref38;
|
|
2018
2027
|
let signed;
|
|
2019
2028
|
const network = this.getNetworkJsonByChainId(chainId);
|
|
2020
2029
|
if (!network) {
|
|
@@ -2098,11 +2107,11 @@ class KoniExtension {
|
|
|
2098
2107
|
});
|
|
2099
2108
|
return this.#koniState.getNominatorMetadata();
|
|
2100
2109
|
}
|
|
2101
|
-
async getBondingOptions(
|
|
2110
|
+
async getBondingOptions(_ref39) {
|
|
2102
2111
|
let {
|
|
2103
2112
|
chain,
|
|
2104
2113
|
type
|
|
2105
|
-
} =
|
|
2114
|
+
} = _ref39;
|
|
2106
2115
|
const apiProps = this.#koniState.getSubstrateApi(chain);
|
|
2107
2116
|
const chainInfo = this.#koniState.getChainInfo(chain);
|
|
2108
2117
|
const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
|
|
@@ -2292,12 +2301,12 @@ class KoniExtension {
|
|
|
2292
2301
|
}
|
|
2293
2302
|
|
|
2294
2303
|
// EVM Transaction
|
|
2295
|
-
async parseContractInput(
|
|
2304
|
+
async parseContractInput(_ref40) {
|
|
2296
2305
|
let {
|
|
2297
2306
|
chainId,
|
|
2298
2307
|
contract,
|
|
2299
2308
|
data
|
|
2300
|
-
} =
|
|
2309
|
+
} = _ref40;
|
|
2301
2310
|
const network = this.getNetworkJsonByChainId(chainId);
|
|
2302
2311
|
return await (0, _parseTransaction2.parseContractInput)(data, contract, network);
|
|
2303
2312
|
}
|
|
@@ -2397,10 +2406,10 @@ class KoniExtension {
|
|
|
2397
2406
|
|
|
2398
2407
|
// Unlock wallet
|
|
2399
2408
|
|
|
2400
|
-
keyringUnlock(
|
|
2409
|
+
keyringUnlock(_ref41) {
|
|
2401
2410
|
let {
|
|
2402
2411
|
password
|
|
2403
|
-
} =
|
|
2412
|
+
} = _ref41;
|
|
2404
2413
|
try {
|
|
2405
2414
|
_uiKeyring.keyring.unlockKeyring(password);
|
|
2406
2415
|
// this.#koniState.initMantaPay(password)
|
|
@@ -2431,11 +2440,11 @@ class KoniExtension {
|
|
|
2431
2440
|
|
|
2432
2441
|
// Export mnemonic
|
|
2433
2442
|
|
|
2434
|
-
keyringExportMnemonic(
|
|
2443
|
+
keyringExportMnemonic(_ref42) {
|
|
2435
2444
|
let {
|
|
2436
2445
|
address,
|
|
2437
2446
|
password
|
|
2438
|
-
} =
|
|
2447
|
+
} = _ref42;
|
|
2439
2448
|
const pair = _uiKeyring.keyring.getPair(address);
|
|
2440
2449
|
const result = pair.exportMnemonic(password);
|
|
2441
2450
|
return {
|
|
@@ -2445,10 +2454,10 @@ class KoniExtension {
|
|
|
2445
2454
|
|
|
2446
2455
|
// Reset wallet
|
|
2447
2456
|
|
|
2448
|
-
async resetWallet(
|
|
2457
|
+
async resetWallet(_ref43) {
|
|
2449
2458
|
let {
|
|
2450
2459
|
resetAll
|
|
2451
|
-
} =
|
|
2460
|
+
} = _ref43;
|
|
2452
2461
|
try {
|
|
2453
2462
|
await this.#koniState.resetWallet(resetAll);
|
|
2454
2463
|
return {
|
|
@@ -2464,10 +2473,10 @@ class KoniExtension {
|
|
|
2464
2473
|
}
|
|
2465
2474
|
|
|
2466
2475
|
// Signing substrate request
|
|
2467
|
-
async signingApprovePasswordV2(
|
|
2476
|
+
async signingApprovePasswordV2(_ref44) {
|
|
2468
2477
|
let {
|
|
2469
2478
|
id
|
|
2470
|
-
} =
|
|
2479
|
+
} = _ref44;
|
|
2471
2480
|
const queued = this.#koniState.getSignRequest(id);
|
|
2472
2481
|
(0, _util.assert)(queued, (0, _i18next.t)('Unable to proceed. Please try again'));
|
|
2473
2482
|
const {
|
|
@@ -2625,39 +2634,56 @@ class KoniExtension {
|
|
|
2625
2634
|
getSupportedSmartContractTypes() {
|
|
2626
2635
|
return this.#koniState.getSupportedSmartContractTypes();
|
|
2627
2636
|
}
|
|
2628
|
-
getTransaction(
|
|
2637
|
+
getTransaction(_ref45) {
|
|
2629
2638
|
let {
|
|
2630
2639
|
id
|
|
2631
|
-
} =
|
|
2640
|
+
} = _ref45;
|
|
2632
2641
|
const {
|
|
2633
2642
|
transaction,
|
|
2634
2643
|
...transactionResult
|
|
2635
2644
|
} = this.#koniState.transactionService.getTransaction(id);
|
|
2636
2645
|
return transactionResult;
|
|
2637
2646
|
}
|
|
2638
|
-
subscribeTransactions(id, port) {
|
|
2647
|
+
async subscribeTransactions(id, port) {
|
|
2639
2648
|
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
2640
|
-
function convertRs(rs) {
|
|
2641
|
-
return Object.fromEntries(Object.entries(rs).map(
|
|
2642
|
-
let [key, value] =
|
|
2649
|
+
function convertRs(rs, processMap) {
|
|
2650
|
+
return Object.fromEntries(Object.entries(rs).map(_ref46 => {
|
|
2651
|
+
let [key, value] = _ref46;
|
|
2643
2652
|
const {
|
|
2644
2653
|
additionalValidator,
|
|
2645
2654
|
eventsHandler,
|
|
2655
|
+
step,
|
|
2646
2656
|
transaction,
|
|
2647
|
-
...
|
|
2657
|
+
..._transactionResult
|
|
2648
2658
|
} = value;
|
|
2659
|
+
const transactionResult = _transactionResult;
|
|
2660
|
+
if (step !== null && step !== void 0 && step.processId) {
|
|
2661
|
+
const process = processMap[step.processId];
|
|
2662
|
+
if (process) {
|
|
2663
|
+
transactionResult.process = process;
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2649
2666
|
return [key, transactionResult];
|
|
2650
2667
|
}));
|
|
2651
2668
|
}
|
|
2652
2669
|
const transactionsSubject = this.#koniState.transactionService.getTransactionSubject();
|
|
2653
|
-
const
|
|
2654
|
-
|
|
2670
|
+
const transactionsObservable = transactionsSubject.asObservable();
|
|
2671
|
+
const processTransactionObservable = this.#koniState.dbService.observableProcessTransactions();
|
|
2672
|
+
const subscription = (0, _rxjs.combineLatest)({
|
|
2673
|
+
transactions: transactionsObservable,
|
|
2674
|
+
processMap: processTransactionObservable
|
|
2675
|
+
}).subscribe(_ref47 => {
|
|
2676
|
+
let {
|
|
2677
|
+
processMap,
|
|
2678
|
+
transactions
|
|
2679
|
+
} = _ref47;
|
|
2680
|
+
cb(convertRs(transactions, processMap));
|
|
2655
2681
|
});
|
|
2656
2682
|
port.onDisconnect.addListener(() => {
|
|
2657
|
-
|
|
2683
|
+
subscription.unsubscribe();
|
|
2658
2684
|
this.cancelSubscription(id);
|
|
2659
2685
|
});
|
|
2660
|
-
return convertRs(transactionsSubject.getValue());
|
|
2686
|
+
return convertRs(transactionsSubject.getValue(), await this.#koniState.dbService.getProcessTransactions());
|
|
2661
2687
|
}
|
|
2662
2688
|
subscribeNotifications(id, port) {
|
|
2663
2689
|
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
@@ -2671,10 +2697,10 @@ class KoniExtension {
|
|
|
2671
2697
|
});
|
|
2672
2698
|
return notificationSubject.value;
|
|
2673
2699
|
}
|
|
2674
|
-
async reloadCron(
|
|
2700
|
+
async reloadCron(_ref48) {
|
|
2675
2701
|
let {
|
|
2676
2702
|
data
|
|
2677
|
-
} =
|
|
2703
|
+
} = _ref48;
|
|
2678
2704
|
if (data === 'nft') {
|
|
2679
2705
|
return await this.#koniState.reloadNft();
|
|
2680
2706
|
} else if (data === 'staking') {
|
|
@@ -2717,10 +2743,10 @@ class KoniExtension {
|
|
|
2717
2743
|
}
|
|
2718
2744
|
|
|
2719
2745
|
// Phishing detect
|
|
2720
|
-
async passPhishingPage(
|
|
2746
|
+
async passPhishingPage(_ref49) {
|
|
2721
2747
|
let {
|
|
2722
2748
|
url
|
|
2723
|
-
} =
|
|
2749
|
+
} = _ref49;
|
|
2724
2750
|
return await this.#koniState.approvePassPhishingPage(url);
|
|
2725
2751
|
}
|
|
2726
2752
|
|
|
@@ -2741,10 +2767,10 @@ class KoniExtension {
|
|
|
2741
2767
|
/// Wallet connect
|
|
2742
2768
|
|
|
2743
2769
|
// Connect
|
|
2744
|
-
async connectWalletConnect(
|
|
2770
|
+
async connectWalletConnect(_ref50) {
|
|
2745
2771
|
let {
|
|
2746
2772
|
uri
|
|
2747
|
-
} =
|
|
2773
|
+
} = _ref50;
|
|
2748
2774
|
await this.#koniState.walletConnectService.connect(uri);
|
|
2749
2775
|
return true;
|
|
2750
2776
|
}
|
|
@@ -2757,11 +2783,11 @@ class KoniExtension {
|
|
|
2757
2783
|
});
|
|
2758
2784
|
return this.#koniState.requestService.allConnectWCRequests;
|
|
2759
2785
|
}
|
|
2760
|
-
async approveWalletConnectSession(
|
|
2786
|
+
async approveWalletConnectSession(_ref51) {
|
|
2761
2787
|
let {
|
|
2762
2788
|
accounts: selectedAccounts,
|
|
2763
2789
|
id
|
|
2764
|
-
} =
|
|
2790
|
+
} = _ref51;
|
|
2765
2791
|
const request = this.#koniState.requestService.getConnectWCRequest(id);
|
|
2766
2792
|
if ((0, _helpers2.isProposalExpired)(request.request.params)) {
|
|
2767
2793
|
throw new Error('The proposal has been expired');
|
|
@@ -2773,8 +2799,8 @@ class KoniExtension {
|
|
|
2773
2799
|
const availableNamespaces = {};
|
|
2774
2800
|
const namespaces = {};
|
|
2775
2801
|
const chainInfoMap = this.#koniState.getChainInfoMap();
|
|
2776
|
-
Object.entries(requiredNamespaces).forEach(
|
|
2777
|
-
let [key, namespace] =
|
|
2802
|
+
Object.entries(requiredNamespaces).forEach(_ref52 => {
|
|
2803
|
+
let [key, namespace] = _ref52;
|
|
2778
2804
|
if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
|
|
2779
2805
|
if (namespace.chains) {
|
|
2780
2806
|
const unSupportChains = namespace.chains.filter(chain => !(0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap));
|
|
@@ -2787,8 +2813,8 @@ class KoniExtension {
|
|
|
2787
2813
|
throw new Error((0, _utils8.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
|
|
2788
2814
|
}
|
|
2789
2815
|
});
|
|
2790
|
-
Object.entries(optionalNamespaces).forEach(
|
|
2791
|
-
let [key, namespace] =
|
|
2816
|
+
Object.entries(optionalNamespaces).forEach(_ref53 => {
|
|
2817
|
+
let [key, namespace] = _ref53;
|
|
2792
2818
|
if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
|
|
2793
2819
|
if (namespace.chains) {
|
|
2794
2820
|
const supportChains = namespace.chains.filter(chain => (0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap)) || [];
|
|
@@ -2812,8 +2838,8 @@ class KoniExtension {
|
|
|
2812
2838
|
}
|
|
2813
2839
|
}
|
|
2814
2840
|
});
|
|
2815
|
-
Object.entries(availableNamespaces).forEach(
|
|
2816
|
-
let [key, namespace] =
|
|
2841
|
+
Object.entries(availableNamespaces).forEach(_ref54 => {
|
|
2842
|
+
let [key, namespace] = _ref54;
|
|
2817
2843
|
if (namespace.chains) {
|
|
2818
2844
|
const accounts = selectedAccounts.filter(address => {
|
|
2819
2845
|
const [_namespace] = address.split(':');
|
|
@@ -2837,10 +2863,10 @@ class KoniExtension {
|
|
|
2837
2863
|
request.resolve();
|
|
2838
2864
|
return true;
|
|
2839
2865
|
}
|
|
2840
|
-
async rejectWalletConnectSession(
|
|
2866
|
+
async rejectWalletConnectSession(_ref55) {
|
|
2841
2867
|
let {
|
|
2842
2868
|
id
|
|
2843
|
-
} =
|
|
2869
|
+
} = _ref55;
|
|
2844
2870
|
const request = this.#koniState.requestService.getConnectWCRequest(id);
|
|
2845
2871
|
const wcId = request.request.id;
|
|
2846
2872
|
if ((0, _helpers2.isProposalExpired)(request.request.params)) {
|
|
@@ -2862,10 +2888,10 @@ class KoniExtension {
|
|
|
2862
2888
|
});
|
|
2863
2889
|
return this.#koniState.walletConnectService.sessions;
|
|
2864
2890
|
}
|
|
2865
|
-
async disconnectWalletConnectSession(
|
|
2891
|
+
async disconnectWalletConnectSession(_ref56) {
|
|
2866
2892
|
let {
|
|
2867
2893
|
topic
|
|
2868
|
-
} =
|
|
2894
|
+
} = _ref56;
|
|
2869
2895
|
await this.#koniState.walletConnectService.disconnect(topic);
|
|
2870
2896
|
return true;
|
|
2871
2897
|
}
|
|
@@ -2878,18 +2904,18 @@ class KoniExtension {
|
|
|
2878
2904
|
});
|
|
2879
2905
|
return this.#koniState.requestService.allNotSupportWCRequests;
|
|
2880
2906
|
}
|
|
2881
|
-
approveWalletConnectNotSupport(
|
|
2907
|
+
approveWalletConnectNotSupport(_ref57) {
|
|
2882
2908
|
let {
|
|
2883
2909
|
id
|
|
2884
|
-
} =
|
|
2910
|
+
} = _ref57;
|
|
2885
2911
|
const request = this.#koniState.requestService.getNotSupportWCRequest(id);
|
|
2886
2912
|
request.resolve();
|
|
2887
2913
|
return true;
|
|
2888
2914
|
}
|
|
2889
|
-
rejectWalletConnectNotSupport(
|
|
2915
|
+
rejectWalletConnectNotSupport(_ref58) {
|
|
2890
2916
|
let {
|
|
2891
2917
|
id
|
|
2892
|
-
} =
|
|
2918
|
+
} = _ref58;
|
|
2893
2919
|
const request = this.#koniState.requestService.getNotSupportWCRequest(id);
|
|
2894
2920
|
request.reject(new Error('USER_REJECTED'));
|
|
2895
2921
|
return true;
|
|
@@ -2897,11 +2923,11 @@ class KoniExtension {
|
|
|
2897
2923
|
|
|
2898
2924
|
/// Manta
|
|
2899
2925
|
|
|
2900
|
-
async enableMantaPay(
|
|
2926
|
+
async enableMantaPay(_ref59) {
|
|
2901
2927
|
let {
|
|
2902
2928
|
address,
|
|
2903
2929
|
password
|
|
2904
|
-
} =
|
|
2930
|
+
} = _ref59;
|
|
2905
2931
|
// always takes the current account
|
|
2906
2932
|
function timeout() {
|
|
2907
2933
|
return new Promise(resolve => setTimeout(resolve, 1500));
|
|
@@ -2991,11 +3017,11 @@ class KoniExtension {
|
|
|
2991
3017
|
async disableMantaPay(address) {
|
|
2992
3018
|
return this.#koniState.disableMantaPay(address);
|
|
2993
3019
|
}
|
|
2994
|
-
async isTonBounceableAddress(
|
|
3020
|
+
async isTonBounceableAddress(_ref60) {
|
|
2995
3021
|
let {
|
|
2996
3022
|
address,
|
|
2997
3023
|
chain
|
|
2998
|
-
} =
|
|
3024
|
+
} = _ref60;
|
|
2999
3025
|
try {
|
|
3000
3026
|
const tonApi = this.#koniState.getTonApi(chain);
|
|
3001
3027
|
const state = await tonApi.getAccountState(address);
|
|
@@ -3041,10 +3067,10 @@ class KoniExtension {
|
|
|
3041
3067
|
|
|
3042
3068
|
/* Metadata */
|
|
3043
3069
|
|
|
3044
|
-
async findRawMetadata(
|
|
3070
|
+
async findRawMetadata(_ref61) {
|
|
3045
3071
|
let {
|
|
3046
3072
|
genesisHash
|
|
3047
|
-
} =
|
|
3073
|
+
} = _ref61;
|
|
3048
3074
|
const {
|
|
3049
3075
|
metadata,
|
|
3050
3076
|
specVersion,
|
|
@@ -3058,20 +3084,20 @@ class KoniExtension {
|
|
|
3058
3084
|
userExtensions
|
|
3059
3085
|
};
|
|
3060
3086
|
}
|
|
3061
|
-
async calculateMetadataHash(
|
|
3087
|
+
async calculateMetadataHash(_ref62) {
|
|
3062
3088
|
let {
|
|
3063
3089
|
chain
|
|
3064
|
-
} =
|
|
3090
|
+
} = _ref62;
|
|
3065
3091
|
const hash = await this.#koniState.calculateMetadataHash(chain);
|
|
3066
3092
|
return {
|
|
3067
3093
|
metadataHash: hash || ''
|
|
3068
3094
|
};
|
|
3069
3095
|
}
|
|
3070
|
-
async shortenMetadata(
|
|
3096
|
+
async shortenMetadata(_ref63) {
|
|
3071
3097
|
let {
|
|
3072
3098
|
chain,
|
|
3073
3099
|
txBlob
|
|
3074
|
-
} =
|
|
3100
|
+
} = _ref63;
|
|
3075
3101
|
const shorten = await this.#koniState.shortenMetadata(chain, txBlob);
|
|
3076
3102
|
return {
|
|
3077
3103
|
txMetadata: shorten || ''
|
|
@@ -3121,12 +3147,29 @@ class KoniExtension {
|
|
|
3121
3147
|
async handleYieldStep(inputData) {
|
|
3122
3148
|
const {
|
|
3123
3149
|
data,
|
|
3124
|
-
|
|
3150
|
+
errorOnTimeOut,
|
|
3151
|
+
isPassConfirmation,
|
|
3152
|
+
onSend,
|
|
3153
|
+
path,
|
|
3154
|
+
processId
|
|
3125
3155
|
} = inputData;
|
|
3126
3156
|
const {
|
|
3127
3157
|
address
|
|
3128
3158
|
} = data;
|
|
3159
|
+
let step;
|
|
3160
|
+
if (processId) {
|
|
3161
|
+
const _step = path.steps[inputData.currentStep];
|
|
3162
|
+
step = {
|
|
3163
|
+
processId,
|
|
3164
|
+
stepId: _step.id
|
|
3165
|
+
};
|
|
3166
|
+
}
|
|
3129
3167
|
if (!data) {
|
|
3168
|
+
if (step) {
|
|
3169
|
+
this.#koniState.transactionService.updateProcessStepStatus(step, {
|
|
3170
|
+
status: _types3.StepStatus.FAILED
|
|
3171
|
+
});
|
|
3172
|
+
}
|
|
3130
3173
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new _TransactionError.TransactionError(_types3.BasicTxErrorType.INTERNAL_ERROR)]);
|
|
3131
3174
|
}
|
|
3132
3175
|
const isLastStep = inputData.currentStep + 1 === path.steps.length;
|
|
@@ -3136,6 +3179,11 @@ class KoniExtension {
|
|
|
3136
3179
|
}); // TODO: validate, set to fail upon submission
|
|
3137
3180
|
|
|
3138
3181
|
if (yieldValidation.length > 0) {
|
|
3182
|
+
if (step) {
|
|
3183
|
+
this.#koniState.transactionService.updateProcessStepStatus(step, {
|
|
3184
|
+
status: _types3.StepStatus.FAILED
|
|
3185
|
+
});
|
|
3186
|
+
}
|
|
3139
3187
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors(yieldValidation);
|
|
3140
3188
|
}
|
|
3141
3189
|
|
|
@@ -3149,7 +3197,66 @@ class KoniExtension {
|
|
|
3149
3197
|
txData
|
|
3150
3198
|
} = await this.#koniState.earningService.handleYieldJoin(inputData);
|
|
3151
3199
|
const isPoolSupportAlternativeFee = this.#koniState.earningService.isPoolSupportAlternativeFee(inputData.data.slug);
|
|
3200
|
+
const poolHandler = this.#koniState.earningService.getPoolHandler(data.slug);
|
|
3152
3201
|
const isMintingStep = _utils2.YIELD_EXTRINSIC_TYPES.includes(extrinsicType);
|
|
3202
|
+
const eventsHandler = eventEmitter => {
|
|
3203
|
+
if (onSend) {
|
|
3204
|
+
eventEmitter.on('send', onSend);
|
|
3205
|
+
}
|
|
3206
|
+
};
|
|
3207
|
+
if (processId && poolHandler) {
|
|
3208
|
+
const convertFee = fee => {
|
|
3209
|
+
return {
|
|
3210
|
+
feeComponent: [{
|
|
3211
|
+
amount: fee.amount || '0',
|
|
3212
|
+
// TODO: Add fee type
|
|
3213
|
+
feeType: _types3.SwapFeeType.NETWORK_FEE,
|
|
3214
|
+
tokenSlug: fee.slug
|
|
3215
|
+
}],
|
|
3216
|
+
defaultFeeToken: fee.slug,
|
|
3217
|
+
feeOptions: [fee.slug]
|
|
3218
|
+
};
|
|
3219
|
+
};
|
|
3220
|
+
if (!this.#koniState.transactionService.checkProcessExist(processId) && step) {
|
|
3221
|
+
const lastStep = path.steps[path.steps.length - 1];
|
|
3222
|
+
const combineInfo = {
|
|
3223
|
+
// In real case, only `YIELD` have multiple steps
|
|
3224
|
+
type: lastStep.type === _types3.YieldStepType.JOIN_NOMINATION_POOL ? _types3.EarningProcessType.NOMINATION_POOL : lastStep.type === _types3.YieldStepType.NOMINATE ? _types3.EarningProcessType.NATIVE_STAKING : _types3.EarningProcessType.YIELD,
|
|
3225
|
+
data,
|
|
3226
|
+
brief: {
|
|
3227
|
+
amount: data.amount,
|
|
3228
|
+
chain: poolHandler.chain,
|
|
3229
|
+
token: poolHandler.metadataInfo.inputAsset,
|
|
3230
|
+
method: poolHandler.type
|
|
3231
|
+
}
|
|
3232
|
+
};
|
|
3233
|
+
await this.#koniState.transactionService.createProcessIfNeed({
|
|
3234
|
+
id: processId,
|
|
3235
|
+
address: (0, _utils7.reformatAddress)(address),
|
|
3236
|
+
type: _types3.ProcessType.EARNING,
|
|
3237
|
+
combineInfo,
|
|
3238
|
+
currentStepId: step.stepId,
|
|
3239
|
+
steps: path.steps.map((step, index) => {
|
|
3240
|
+
const fee = convertFee(path.totalFee[index]);
|
|
3241
|
+
if (![_types3.YieldStepType.XCM, _types3.YieldStepType.DEFAULT, _types3.YieldStepType.TOKEN_APPROVAL].includes(step.type)) {
|
|
3242
|
+
const metadata = data;
|
|
3243
|
+
return {
|
|
3244
|
+
...step,
|
|
3245
|
+
status: _types3.StepStatus.QUEUED,
|
|
3246
|
+
fee,
|
|
3247
|
+
metadata: metadata
|
|
3248
|
+
};
|
|
3249
|
+
}
|
|
3250
|
+
return {
|
|
3251
|
+
...step,
|
|
3252
|
+
fee,
|
|
3253
|
+
status: _types3.StepStatus.QUEUED
|
|
3254
|
+
};
|
|
3255
|
+
}).filter(step => step.type !== _types3.YieldStepType.DEFAULT),
|
|
3256
|
+
status: _types3.StepStatus.QUEUED
|
|
3257
|
+
});
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3153
3260
|
return await this.#koniState.transactionService.handleTransaction({
|
|
3154
3261
|
address,
|
|
3155
3262
|
chain: txChain,
|
|
@@ -3161,7 +3268,11 @@ class KoniExtension {
|
|
|
3161
3268
|
chainType,
|
|
3162
3269
|
resolveOnDone: !isLastStep,
|
|
3163
3270
|
transferNativeAmount,
|
|
3164
|
-
skipFeeValidation: isMintingStep && isPoolSupportAlternativeFee
|
|
3271
|
+
skipFeeValidation: isMintingStep && isPoolSupportAlternativeFee,
|
|
3272
|
+
errorOnTimeOut,
|
|
3273
|
+
...this.createPassConfirmationParams(isPassConfirmation),
|
|
3274
|
+
eventsHandler,
|
|
3275
|
+
step
|
|
3165
3276
|
});
|
|
3166
3277
|
}
|
|
3167
3278
|
async handleYieldLeave(params) {
|
|
@@ -3317,18 +3428,18 @@ class KoniExtension {
|
|
|
3317
3428
|
|
|
3318
3429
|
/* Campaign */
|
|
3319
3430
|
|
|
3320
|
-
unlockDotCheckCanMint(
|
|
3431
|
+
unlockDotCheckCanMint(_ref64) {
|
|
3321
3432
|
let {
|
|
3322
3433
|
address,
|
|
3323
3434
|
network,
|
|
3324
3435
|
slug
|
|
3325
|
-
} =
|
|
3436
|
+
} = _ref64;
|
|
3326
3437
|
return this.#koniState.mintCampaignService.unlockDotCampaign.canMint(address, slug, network);
|
|
3327
3438
|
}
|
|
3328
|
-
unlockDotSubscribeMintedData(id, port,
|
|
3439
|
+
unlockDotSubscribeMintedData(id, port, _ref65) {
|
|
3329
3440
|
let {
|
|
3330
3441
|
transactionId
|
|
3331
|
-
} =
|
|
3442
|
+
} = _ref65;
|
|
3332
3443
|
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
3333
3444
|
const subscription = this.#koniState.mintCampaignService.unlockDotCampaign.subscribeMintedNft(transactionId, cb);
|
|
3334
3445
|
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
@@ -3360,10 +3471,10 @@ class KoniExtension {
|
|
|
3360
3471
|
});
|
|
3361
3472
|
return filterBanner(await this.#koniState.campaignService.getProcessingCampaign());
|
|
3362
3473
|
}
|
|
3363
|
-
async completeCampaignBanner(
|
|
3474
|
+
async completeCampaignBanner(_ref66) {
|
|
3364
3475
|
let {
|
|
3365
3476
|
slug
|
|
3366
|
-
} =
|
|
3477
|
+
} = _ref66;
|
|
3367
3478
|
const campaign = await this.#koniState.dbService.getCampaign(slug);
|
|
3368
3479
|
if (campaign) {
|
|
3369
3480
|
await this.#koniState.dbService.upsertCampaign({
|
|
@@ -3508,11 +3619,28 @@ class KoniExtension {
|
|
|
3508
3619
|
async handleSwapStep(inputData) {
|
|
3509
3620
|
const {
|
|
3510
3621
|
address,
|
|
3622
|
+
errorOnTimeOut,
|
|
3623
|
+
isPassConfirmation,
|
|
3624
|
+
onSend,
|
|
3511
3625
|
process,
|
|
3626
|
+
processId,
|
|
3512
3627
|
quote,
|
|
3513
3628
|
recipient
|
|
3514
3629
|
} = inputData;
|
|
3630
|
+
let step;
|
|
3631
|
+
if (processId) {
|
|
3632
|
+
const _step = process.steps[inputData.currentStep];
|
|
3633
|
+
step = {
|
|
3634
|
+
processId,
|
|
3635
|
+
stepId: _step.id
|
|
3636
|
+
};
|
|
3637
|
+
}
|
|
3515
3638
|
if (!quote || !address || !process) {
|
|
3639
|
+
if (step) {
|
|
3640
|
+
this.#koniState.transactionService.updateProcessStepStatus(step, {
|
|
3641
|
+
status: _types3.StepStatus.FAILED
|
|
3642
|
+
});
|
|
3643
|
+
}
|
|
3516
3644
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new _TransactionError.TransactionError(_types3.BasicTxErrorType.INTERNAL_ERROR)]);
|
|
3517
3645
|
}
|
|
3518
3646
|
const isLastStep = inputData.currentStep + 1 === process.steps.length;
|
|
@@ -3523,6 +3651,11 @@ class KoniExtension {
|
|
|
3523
3651
|
recipient
|
|
3524
3652
|
});
|
|
3525
3653
|
if (swapValidations.length > 0) {
|
|
3654
|
+
if (step) {
|
|
3655
|
+
this.#koniState.transactionService.updateProcessStepStatus(step, {
|
|
3656
|
+
status: _types3.StepStatus.FAILED
|
|
3657
|
+
});
|
|
3658
|
+
}
|
|
3526
3659
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors(swapValidations);
|
|
3527
3660
|
}
|
|
3528
3661
|
|
|
@@ -3538,6 +3671,85 @@ class KoniExtension {
|
|
|
3538
3671
|
// const chosenFeeToken = process.steps.findIndex((step) => step.type === SwapStepType.SET_FEE_TOKEN) > -1;
|
|
3539
3672
|
// const allowSkipValidation = [ExtrinsicType.SET_FEE_TOKEN, ExtrinsicType.SWAP].includes(extrinsicType);
|
|
3540
3673
|
|
|
3674
|
+
const eventsHandler = eventEmitter => {
|
|
3675
|
+
if (onSend) {
|
|
3676
|
+
eventEmitter.on('send', onSend);
|
|
3677
|
+
}
|
|
3678
|
+
};
|
|
3679
|
+
if (processId) {
|
|
3680
|
+
const _step = process.steps[inputData.currentStep];
|
|
3681
|
+
if (!this.#koniState.transactionService.checkProcessExist(processId) && step) {
|
|
3682
|
+
const combineInfo = {
|
|
3683
|
+
provider: quote.provider,
|
|
3684
|
+
slippage: inputData.slippage,
|
|
3685
|
+
address,
|
|
3686
|
+
recipient,
|
|
3687
|
+
quote,
|
|
3688
|
+
process
|
|
3689
|
+
};
|
|
3690
|
+
await this.#koniState.transactionService.createProcessIfNeed({
|
|
3691
|
+
id: processId,
|
|
3692
|
+
address: (0, _utils7.reformatAddress)(address),
|
|
3693
|
+
type: _types3.ProcessType.SWAP,
|
|
3694
|
+
currentStepId: step.stepId,
|
|
3695
|
+
combineInfo,
|
|
3696
|
+
steps: inputData.process.steps.map((step, index) => {
|
|
3697
|
+
const fee = inputData.process.totalFee[index];
|
|
3698
|
+
if (step.type === _types3.SwapStepType.SWAP) {
|
|
3699
|
+
const metadata = {
|
|
3700
|
+
pair: quote.pair,
|
|
3701
|
+
aliveUntil: quote.aliveUntil,
|
|
3702
|
+
fromAmount: quote.fromAmount,
|
|
3703
|
+
rate: quote.rate,
|
|
3704
|
+
provider: quote.provider,
|
|
3705
|
+
route: quote.route,
|
|
3706
|
+
toAmount: quote.toAmount
|
|
3707
|
+
};
|
|
3708
|
+
return {
|
|
3709
|
+
...step,
|
|
3710
|
+
status: _types3.StepStatus.QUEUED,
|
|
3711
|
+
fee,
|
|
3712
|
+
metadata: metadata
|
|
3713
|
+
};
|
|
3714
|
+
}
|
|
3715
|
+
return {
|
|
3716
|
+
...step,
|
|
3717
|
+
fee,
|
|
3718
|
+
status: _types3.StepStatus.QUEUED
|
|
3719
|
+
};
|
|
3720
|
+
}).filter(step => step.type !== _types3.CommonStepType.DEFAULT),
|
|
3721
|
+
status: _types3.StepStatus.QUEUED
|
|
3722
|
+
});
|
|
3723
|
+
}
|
|
3724
|
+
const isLastStep = inputData.currentStep === process.steps.length - 1;
|
|
3725
|
+
if (isLastStep) {
|
|
3726
|
+
const metadata = {
|
|
3727
|
+
pair: quote.pair,
|
|
3728
|
+
aliveUntil: quote.aliveUntil,
|
|
3729
|
+
fromAmount: quote.fromAmount,
|
|
3730
|
+
rate: quote.rate,
|
|
3731
|
+
provider: quote.provider,
|
|
3732
|
+
route: quote.route,
|
|
3733
|
+
toAmount: quote.toAmount
|
|
3734
|
+
};
|
|
3735
|
+
const step = {
|
|
3736
|
+
..._step,
|
|
3737
|
+
// In case one sign, status already set to prepare before
|
|
3738
|
+
status: process.steps.length > 2 ? _types3.StepStatus.PREPARE : _types3.StepStatus.QUEUED,
|
|
3739
|
+
fee: process.totalFee[inputData.currentStep],
|
|
3740
|
+
metadata: metadata
|
|
3741
|
+
};
|
|
3742
|
+
const combineInfo = {
|
|
3743
|
+
provider: quote.provider,
|
|
3744
|
+
slippage: inputData.slippage,
|
|
3745
|
+
address,
|
|
3746
|
+
recipient,
|
|
3747
|
+
quote,
|
|
3748
|
+
process
|
|
3749
|
+
};
|
|
3750
|
+
await this.#koniState.transactionService.updateProcessInfo(processId, combineInfo, step);
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3541
3753
|
return await this.#koniState.transactionService.handleTransaction({
|
|
3542
3754
|
address,
|
|
3543
3755
|
chain: txChain,
|
|
@@ -3548,7 +3760,11 @@ class KoniExtension {
|
|
|
3548
3760
|
// change this depends on step
|
|
3549
3761
|
chainType,
|
|
3550
3762
|
resolveOnDone: !isLastStep,
|
|
3551
|
-
transferNativeAmount
|
|
3763
|
+
transferNativeAmount,
|
|
3764
|
+
...this.createPassConfirmationParams(isPassConfirmation),
|
|
3765
|
+
errorOnTimeOut,
|
|
3766
|
+
eventsHandler,
|
|
3767
|
+
step
|
|
3552
3768
|
// skipFeeValidation: chosenFeeToken && allowSkipValidation
|
|
3553
3769
|
});
|
|
3554
3770
|
}
|
|
@@ -3677,6 +3893,208 @@ class KoniExtension {
|
|
|
3677
3893
|
|
|
3678
3894
|
/* Popular tokens */
|
|
3679
3895
|
|
|
3896
|
+
/* Multi process */
|
|
3897
|
+
|
|
3898
|
+
async handleSubmitProcessTransaction(_request) {
|
|
3899
|
+
const {
|
|
3900
|
+
address,
|
|
3901
|
+
id: processId,
|
|
3902
|
+
request: requestData,
|
|
3903
|
+
type
|
|
3904
|
+
} = _request;
|
|
3905
|
+
const pair = _uiKeyring.keyring.getPair(address);
|
|
3906
|
+
if (!pair) {
|
|
3907
|
+
throw new Error('Pair not found');
|
|
3908
|
+
}
|
|
3909
|
+
const signMode = (0, _utils7.getAccountSignMode)(address, pair.meta);
|
|
3910
|
+
if (signMode !== _types3.AccountSignMode.PASSWORD) {
|
|
3911
|
+
throw new Error('Account can not use this feature');
|
|
3912
|
+
}
|
|
3913
|
+
const setting = await new Promise(resolve => this.#koniState.settingService.getSettings(resolve));
|
|
3914
|
+
if (!setting.allowOneSign) {
|
|
3915
|
+
throw new Error('Wallet not enable this feature');
|
|
3916
|
+
}
|
|
3917
|
+
switch (type) {
|
|
3918
|
+
case _types3.ProcessType.EARNING:
|
|
3919
|
+
|
|
3920
|
+
// eslint-disable-next-line no-fallthrough
|
|
3921
|
+
case _types3.ProcessType.SWAP:
|
|
3922
|
+
{
|
|
3923
|
+
const currentStep = requestData.currentStep;
|
|
3924
|
+
let stepNums;
|
|
3925
|
+
let submitData;
|
|
3926
|
+
let waitXcmData;
|
|
3927
|
+
if (type === _types3.ProcessType.EARNING) {
|
|
3928
|
+
const data = requestData;
|
|
3929
|
+
const poolHandler = this.#koniState.earningService.getPoolHandler(data.data.slug);
|
|
3930
|
+
if (poolHandler) {
|
|
3931
|
+
waitXcmData = {
|
|
3932
|
+
targetAmount: data.data.amount,
|
|
3933
|
+
chain: poolHandler.chain,
|
|
3934
|
+
token: poolHandler.metadataInfo.inputAsset,
|
|
3935
|
+
// TODO: Change this depends on pool
|
|
3936
|
+
nextTxType: _KoniTypes.ExtrinsicType.JOIN_YIELD_POOL
|
|
3937
|
+
};
|
|
3938
|
+
}
|
|
3939
|
+
submitData = async (step, callback) => {
|
|
3940
|
+
const isPassConfirmation = !callback;
|
|
3941
|
+
const onSend = callback
|
|
3942
|
+
// eslint-disable-next-line node/no-callback-literal
|
|
3943
|
+
? rs => callback(rs) : undefined;
|
|
3944
|
+
return this.handleYieldStep({
|
|
3945
|
+
...data,
|
|
3946
|
+
currentStep: step,
|
|
3947
|
+
isPassConfirmation,
|
|
3948
|
+
onSend,
|
|
3949
|
+
errorOnTimeOut: true,
|
|
3950
|
+
processId
|
|
3951
|
+
});
|
|
3952
|
+
};
|
|
3953
|
+
stepNums = data.path.steps.length;
|
|
3954
|
+
} else {
|
|
3955
|
+
const data = requestData;
|
|
3956
|
+
stepNums = data.process.steps.length;
|
|
3957
|
+
const inputAsset = this.#koniState.chainService.getAssetBySlug(data.quote.pair.from);
|
|
3958
|
+
waitXcmData = {
|
|
3959
|
+
targetAmount: data.quote.fromAmount,
|
|
3960
|
+
chain: inputAsset.originChain,
|
|
3961
|
+
token: inputAsset.slug,
|
|
3962
|
+
nextTxType: _KoniTypes.ExtrinsicType.SWAP
|
|
3963
|
+
};
|
|
3964
|
+
submitData = async (step, callback) => {
|
|
3965
|
+
const isLastStep = step === stepNums - 1;
|
|
3966
|
+
const isPassConfirmation = !callback;
|
|
3967
|
+
const onSend = callback
|
|
3968
|
+
// eslint-disable-next-line node/no-callback-literal
|
|
3969
|
+
? rs => callback(rs) : undefined;
|
|
3970
|
+
if (stepNums > 2 && isLastStep) {
|
|
3971
|
+
const quote = data.quote;
|
|
3972
|
+
const latestSwapQuote = await this.getLatestSwapQuote({
|
|
3973
|
+
address: data.address,
|
|
3974
|
+
currentQuote: quote.provider,
|
|
3975
|
+
feeToken: quote.feeInfo.selectedFeeToken,
|
|
3976
|
+
recipient: data.recipient,
|
|
3977
|
+
pair: quote.pair,
|
|
3978
|
+
fromAmount: quote.fromAmount,
|
|
3979
|
+
slippage: data.slippage
|
|
3980
|
+
});
|
|
3981
|
+
return this.handleSwapStep({
|
|
3982
|
+
...data,
|
|
3983
|
+
quote: latestSwapQuote.optimalQuote || data.quote,
|
|
3984
|
+
currentStep: step,
|
|
3985
|
+
isPassConfirmation,
|
|
3986
|
+
errorOnTimeOut: true,
|
|
3987
|
+
processId
|
|
3988
|
+
});
|
|
3989
|
+
}
|
|
3990
|
+
return this.handleSwapStep({
|
|
3991
|
+
...data,
|
|
3992
|
+
currentStep: step,
|
|
3993
|
+
isPassConfirmation,
|
|
3994
|
+
onSend,
|
|
3995
|
+
errorOnTimeOut: true,
|
|
3996
|
+
processId
|
|
3997
|
+
});
|
|
3998
|
+
};
|
|
3999
|
+
}
|
|
4000
|
+
if (stepNums < 3) {
|
|
4001
|
+
throw new Error('Not need to use this feature');
|
|
4002
|
+
}
|
|
4003
|
+
const loopSubmit = async (submitFunc, step, callback) => {
|
|
4004
|
+
const isLastStep = step === stepNums - 1;
|
|
4005
|
+
const rs = await submitFunc(step, callback);
|
|
4006
|
+
if (isLastStep) {
|
|
4007
|
+
return rs;
|
|
4008
|
+
} else {
|
|
4009
|
+
if (rs.errors.length || rs.warnings.length) {
|
|
4010
|
+
return rs;
|
|
4011
|
+
}
|
|
4012
|
+
if (rs.extrinsicType === _KoniTypes.ExtrinsicType.TRANSFER_XCM) {
|
|
4013
|
+
await new Promise(resolve => {
|
|
4014
|
+
setTimeout(resolve, 60 * 1000);
|
|
4015
|
+
if (waitXcmData) {
|
|
4016
|
+
let unsub = _util.noop;
|
|
4017
|
+
const onRs = rs => {
|
|
4018
|
+
var _waitXcmData;
|
|
4019
|
+
if ((0, _bignumber.default)(rs.value).gte((0, _bignumber.default)(((_waitXcmData = waitXcmData) === null || _waitXcmData === void 0 ? void 0 : _waitXcmData.targetAmount) || '0'))) {
|
|
4020
|
+
unsub();
|
|
4021
|
+
resolve();
|
|
4022
|
+
}
|
|
4023
|
+
};
|
|
4024
|
+
this.#koniState.balanceService.subscribeTransferableBalance(address, waitXcmData.chain, waitXcmData.token, waitXcmData.nextTxType, onRs).then(_ref67 => {
|
|
4025
|
+
let [_unsub, rs] = _ref67;
|
|
4026
|
+
unsub = _unsub;
|
|
4027
|
+
onRs(rs);
|
|
4028
|
+
}).catch(console.error);
|
|
4029
|
+
}
|
|
4030
|
+
});
|
|
4031
|
+
}
|
|
4032
|
+
return loopSubmit(submitFunc, step + 1);
|
|
4033
|
+
}
|
|
4034
|
+
};
|
|
4035
|
+
return new Promise((resolve, reject) => {
|
|
4036
|
+
loopSubmit(submitData, currentStep, resolve).then(resolve).catch(reject);
|
|
4037
|
+
});
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
}
|
|
4041
|
+
createPassConfirmationParams() {
|
|
4042
|
+
let pass = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
4043
|
+
if (pass) {
|
|
4044
|
+
return {
|
|
4045
|
+
isPassConfirmation: true,
|
|
4046
|
+
signAfterCreate: id => {
|
|
4047
|
+
this.signingApprovePasswordV2({
|
|
4048
|
+
id
|
|
4049
|
+
}).catch(console.log);
|
|
4050
|
+
}
|
|
4051
|
+
};
|
|
4052
|
+
} else {
|
|
4053
|
+
return {
|
|
4054
|
+
isPassConfirmation: false
|
|
4055
|
+
};
|
|
4056
|
+
}
|
|
4057
|
+
}
|
|
4058
|
+
async subscribeProcessById(request, id, port) {
|
|
4059
|
+
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
4060
|
+
const observable = this.#koniState.dbService.observableProcessTransactionById(request.processId);
|
|
4061
|
+
const subscription = observable.subscribe(rs => {
|
|
4062
|
+
// eslint-disable-next-line node/no-callback-literal
|
|
4063
|
+
cb({
|
|
4064
|
+
process: rs,
|
|
4065
|
+
id
|
|
4066
|
+
});
|
|
4067
|
+
});
|
|
4068
|
+
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
4069
|
+
port.onDisconnect.addListener(() => {
|
|
4070
|
+
this.cancelSubscription(id);
|
|
4071
|
+
});
|
|
4072
|
+
return {
|
|
4073
|
+
process: await this.#koniState.dbService.getProcessTransactionById(request.processId),
|
|
4074
|
+
id
|
|
4075
|
+
};
|
|
4076
|
+
}
|
|
4077
|
+
subscribeProcessAlive(id, port) {
|
|
4078
|
+
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
4079
|
+
const observable = this.#koniState.transactionService.observables.aliveProcess;
|
|
4080
|
+
const convertData = rs => {
|
|
4081
|
+
return {
|
|
4082
|
+
processes: rs
|
|
4083
|
+
};
|
|
4084
|
+
};
|
|
4085
|
+
const subscription = observable.subscribe(rs => {
|
|
4086
|
+
cb(convertData(rs));
|
|
4087
|
+
});
|
|
4088
|
+
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
4089
|
+
port.onDisconnect.addListener(() => {
|
|
4090
|
+
this.cancelSubscription(id);
|
|
4091
|
+
});
|
|
4092
|
+
const value = this.#koniState.transactionService.values.aliveProcess;
|
|
4093
|
+
return convertData(value);
|
|
4094
|
+
}
|
|
4095
|
+
|
|
4096
|
+
/* Multi process */
|
|
4097
|
+
|
|
3680
4098
|
// --------------------------------------------------------------
|
|
3681
4099
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3682
4100
|
async handle(id, type, request, port) {
|
|
@@ -3768,6 +4186,8 @@ class KoniExtension {
|
|
|
3768
4186
|
return this.setLanguage(request);
|
|
3769
4187
|
case 'pri(settings.saveShowBalance)':
|
|
3770
4188
|
return this.setShowBalance(request);
|
|
4189
|
+
case 'pri(settings.update.allowOneSign)':
|
|
4190
|
+
return this.setAllowOneSign(request);
|
|
3771
4191
|
case 'pri(price.getPrice)':
|
|
3772
4192
|
return await this.getPrice();
|
|
3773
4193
|
case 'pri(price.getSubscription)':
|
|
@@ -4276,6 +4696,15 @@ class KoniExtension {
|
|
|
4276
4696
|
return this.subscribePriorityTokens(id, port);
|
|
4277
4697
|
/* Priority tokens */
|
|
4278
4698
|
|
|
4699
|
+
/* Multi process */
|
|
4700
|
+
case 'pri(process.transaction.submit)':
|
|
4701
|
+
return this.handleSubmitProcessTransaction(request);
|
|
4702
|
+
case 'pri(process.subscribe.id)':
|
|
4703
|
+
return this.subscribeProcessById(request, id, port);
|
|
4704
|
+
case 'pri(process.subscribe.alive)':
|
|
4705
|
+
return this.subscribeProcessAlive(id, port);
|
|
4706
|
+
/* Multi process */
|
|
4707
|
+
|
|
4279
4708
|
// Default
|
|
4280
4709
|
default:
|
|
4281
4710
|
throw new Error(`Unable to handle message of type ${type}`);
|