@subwallet/extension-base 1.1.29-0 → 1.1.29-beta.1
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 +95 -68
- package/background/KoniTypes.js +16 -13
- package/background/errors/TransactionError.js +9 -0
- package/cjs/background/KoniTypes.js +17 -16
- package/cjs/background/errors/TransactionError.js +9 -0
- package/cjs/constants/index.js +19 -4
- package/cjs/koni/api/nft/config.js +33 -23
- package/cjs/koni/api/nft/index.js +14 -0
- package/cjs/koni/api/nft/nft.js +1 -22
- package/cjs/koni/api/nft/ordinal_nft/constants.js +21 -0
- package/cjs/koni/api/nft/ordinal_nft/index.js +121 -0
- package/cjs/koni/api/nft/ordinal_nft/utils.js +41 -0
- package/cjs/koni/api/staking/bonding/amplitude.js +17 -15
- package/cjs/koni/api/staking/bonding/astar.js +11 -10
- package/cjs/koni/api/staking/bonding/index.js +4 -1
- package/cjs/koni/api/staking/bonding/paraChain.js +25 -23
- package/cjs/koni/api/staking/bonding/relayChain.js +48 -45
- package/cjs/koni/api/staking/bonding/utils.js +104 -86
- package/cjs/koni/api/staking/index.js +6 -5
- package/cjs/koni/api/staking/paraChain.js +6 -5
- package/cjs/koni/api/staking/relayChain.js +3 -2
- package/cjs/koni/api/yield/helper/utils.js +46 -0
- package/cjs/koni/background/cron.js +11 -1
- package/cjs/koni/background/handlers/Extension.js +362 -69
- package/cjs/koni/background/handlers/State.js +51 -3
- package/cjs/koni/background/handlers/index.js +4 -2
- package/cjs/koni/background/subscription.js +95 -37
- package/cjs/services/campaign-service/index.js +9 -6
- package/cjs/services/chain-service/constants.js +2 -16
- package/cjs/services/chain-service/utils.js +7 -1
- package/cjs/services/earning-service/constants/chains.js +29 -0
- package/cjs/services/earning-service/constants/index.js +27 -0
- package/cjs/services/earning-service/constants/step.js +18 -0
- package/cjs/services/earning-service/handlers/base.js +232 -0
- package/cjs/services/earning-service/handlers/index.js +60 -0
- package/cjs/services/earning-service/handlers/lending/base.js +20 -0
- package/cjs/services/earning-service/handlers/lending/index.js +13 -0
- package/cjs/services/earning-service/handlers/lending/interlay.js +184 -0
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +217 -0
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +43 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +283 -0
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +196 -0
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +409 -0
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +382 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +459 -0
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +137 -0
- package/cjs/services/earning-service/handlers/native-staking/base.js +159 -0
- package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +383 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +542 -0
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +541 -0
- package/cjs/services/earning-service/handlers/special.js +411 -0
- package/cjs/services/earning-service/service.js +387 -0
- package/cjs/services/earning-service/utils/index.js +128 -0
- package/cjs/services/event-service/index.js +4 -0
- package/cjs/services/keyring-service/index.js +14 -2
- package/cjs/services/migration-service/scripts/DeleteEarningData.js +21 -0
- package/cjs/services/migration-service/scripts/EnableEarningChains.js +21 -0
- package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +21 -0
- package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +21 -0
- package/cjs/services/migration-service/scripts/index.js +7 -1
- package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +149 -0
- package/cjs/services/mint-campaign-service/campaigns/index.js +13 -0
- package/cjs/services/mint-campaign-service/constants.js +11 -0
- package/cjs/services/mint-campaign-service/index.js +18 -0
- package/cjs/services/notification-service/NotificationService.js +1 -1
- package/cjs/services/storage-service/DatabaseService.js +51 -0
- package/cjs/services/storage-service/databases/index.js +4 -0
- package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/cjs/services/storage-service/db-stores/YieldPoolStore.js +36 -0
- package/cjs/services/storage-service/db-stores/YieldPositionStore.js +65 -0
- package/cjs/services/subscan-service/index.js +16 -0
- package/cjs/services/transaction-service/event-parser/index.js +58 -0
- package/cjs/services/transaction-service/helpers/index.js +3 -1
- package/cjs/services/transaction-service/index.js +185 -74
- package/cjs/services/transaction-service/utils.js +1 -0
- package/cjs/types/campaigns/index.js +16 -0
- package/cjs/types/campaigns/unlock-dot.js +1 -0
- package/cjs/types/index.js +44 -0
- package/cjs/types/ordinal.js +1 -0
- package/cjs/types/transaction.js +1 -0
- package/cjs/types/yield/actions/index.js +27 -0
- package/cjs/types/yield/actions/join/index.js +38 -0
- package/cjs/types/yield/actions/join/step.js +47 -0
- package/cjs/types/yield/actions/join/submit.js +1 -0
- package/cjs/types/yield/actions/join/validate.js +16 -0
- package/cjs/types/yield/actions/others.js +1 -0
- package/cjs/types/yield/index.js +27 -0
- package/cjs/types/yield/info/account/index.js +49 -0
- package/cjs/types/yield/info/account/info.js +1 -0
- package/cjs/types/yield/info/account/reward.js +1 -0
- package/cjs/types/yield/info/account/target.js +32 -0
- package/cjs/types/yield/info/account/unstake.js +27 -0
- package/cjs/types/yield/info/base.js +41 -0
- package/cjs/types/yield/info/chain/index.js +27 -0
- package/cjs/types/yield/info/chain/info.js +1 -0
- package/cjs/types/yield/info/chain/target.js +1 -0
- package/cjs/types/yield/info/index.js +49 -0
- package/cjs/types/yield/info/pallet.js +15 -0
- package/cjs/utils/fetchStaticData.js +2 -1
- package/cjs/utils/index.js +89 -1
- package/cjs/utils/object.js +12 -0
- package/cjs/utils/yield/index.js +3 -0
- package/constants/index.d.ts +6 -1
- package/constants/index.js +6 -1
- package/koni/api/nft/config.js +33 -23
- package/koni/api/nft/index.js +15 -1
- package/koni/api/nft/nft.js +2 -23
- package/koni/api/nft/ordinal_nft/constants.d.ts +9 -0
- package/koni/api/nft/ordinal_nft/constants.js +12 -0
- package/koni/api/nft/ordinal_nft/index.d.ts +8 -0
- package/koni/api/nft/ordinal_nft/index.js +114 -0
- package/koni/api/nft/ordinal_nft/utils.d.ts +2 -0
- package/koni/api/nft/ordinal_nft/utils.js +33 -0
- package/koni/api/staking/bonding/amplitude.js +11 -9
- package/koni/api/staking/bonding/astar.js +9 -8
- package/koni/api/staking/bonding/index.d.ts +1 -1
- package/koni/api/staking/bonding/index.js +5 -1
- package/koni/api/staking/bonding/paraChain.js +12 -10
- package/koni/api/staking/bonding/relayChain.d.ts +2 -2
- package/koni/api/staking/bonding/relayChain.js +33 -30
- package/koni/api/staking/bonding/utils.d.ts +15 -38
- package/koni/api/staking/bonding/utils.js +85 -69
- package/koni/api/staking/index.js +2 -1
- package/koni/api/staking/paraChain.js +7 -6
- package/koni/api/staking/relayChain.js +4 -3
- package/koni/api/yield/helper/utils.d.ts +10 -0
- package/koni/api/yield/helper/utils.js +32 -0
- package/koni/background/cron.d.ts +1 -0
- package/koni/background/cron.js +12 -2
- package/koni/background/handlers/Extension.d.ts +17 -1
- package/koni/background/handlers/Extension.js +321 -30
- package/koni/background/handlers/State.d.ts +18 -2
- package/koni/background/handlers/State.js +50 -3
- package/koni/background/handlers/index.js +4 -2
- package/koni/background/subscription.d.ts +6 -1
- package/koni/background/subscription.js +97 -38
- package/package.json +316 -3
- package/services/campaign-service/index.js +9 -6
- package/services/chain-service/constants.d.ts +0 -11
- package/services/chain-service/constants.js +1 -14
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +5 -1
- package/services/earning-service/constants/abis/compound_finance_v2_abi.json +1235 -0
- package/services/earning-service/constants/abis/st_liquid_token_abi.json +1355 -0
- package/services/earning-service/constants/chains.d.ts +14 -0
- package/services/earning-service/constants/chains.js +21 -0
- package/services/earning-service/constants/index.d.ts +2 -0
- package/services/earning-service/constants/index.js +5 -0
- package/services/earning-service/constants/step.d.ts +3 -0
- package/services/earning-service/constants/step.js +10 -0
- package/services/earning-service/handlers/base.d.ts +112 -0
- package/services/earning-service/handlers/base.js +226 -0
- package/services/earning-service/handlers/index.d.ts +5 -0
- package/services/earning-service/handlers/index.js +8 -0
- package/services/earning-service/handlers/lending/base.d.ts +6 -0
- package/services/earning-service/handlers/lending/base.js +12 -0
- package/services/earning-service/handlers/lending/index.d.ts +1 -0
- package/services/earning-service/handlers/lending/index.js +4 -0
- package/services/earning-service/handlers/lending/interlay.d.ts +23 -0
- package/services/earning-service/handlers/lending/interlay.js +176 -0
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +26 -0
- package/services/earning-service/handlers/liquid-staking/acala.js +209 -0
- package/services/earning-service/handlers/liquid-staking/base.d.ts +9 -0
- package/services/earning-service/handlers/liquid-staking/base.js +35 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +45 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.js +272 -0
- package/services/earning-service/handlers/liquid-staking/index.d.ts +4 -0
- package/services/earning-service/handlers/liquid-staking/index.js +7 -0
- package/services/earning-service/handlers/liquid-staking/parallel.d.ts +25 -0
- package/services/earning-service/handlers/liquid-staking/parallel.js +188 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +34 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +399 -0
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +373 -0
- package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
- package/services/earning-service/handlers/native-staking/astar.js +449 -0
- package/services/earning-service/handlers/native-staking/base-para.d.ts +11 -0
- package/services/earning-service/handlers/native-staking/base-para.js +129 -0
- package/services/earning-service/handlers/native-staking/base.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/base.js +150 -0
- package/services/earning-service/handlers/native-staking/index.d.ts +4 -0
- package/services/earning-service/handlers/native-staking/index.js +7 -0
- package/services/earning-service/handlers/native-staking/para-chain.d.ts +15 -0
- package/services/earning-service/handlers/native-staking/para-chain.js +375 -0
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +533 -0
- package/services/earning-service/handlers/nomination-pool/index.d.ts +35 -0
- package/services/earning-service/handlers/nomination-pool/index.js +531 -0
- package/services/earning-service/handlers/special.d.ts +56 -0
- package/services/earning-service/handlers/special.js +403 -0
- package/services/earning-service/service.d.ts +45 -0
- package/services/earning-service/service.js +379 -0
- package/services/earning-service/utils/index.d.ts +18 -0
- package/services/earning-service/utils/index.js +112 -0
- package/services/event-service/index.d.ts +1 -0
- package/services/event-service/index.js +4 -0
- package/services/event-service/types.d.ts +8 -0
- package/services/keyring-service/index.d.ts +2 -1
- package/services/keyring-service/index.js +14 -2
- package/services/migration-service/scripts/DeleteEarningData.d.ts +4 -0
- package/services/migration-service/scripts/DeleteEarningData.js +13 -0
- package/services/migration-service/scripts/EnableEarningChains.d.ts +4 -0
- package/services/migration-service/scripts/EnableEarningChains.js +13 -0
- package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateEarningHistory.js +13 -0
- package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateEarningVersion.js +13 -0
- package/services/migration-service/scripts/index.js +7 -1
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +13 -0
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +139 -0
- package/services/mint-campaign-service/campaigns/index.d.ts +1 -0
- package/services/mint-campaign-service/campaigns/index.js +4 -0
- package/services/mint-campaign-service/constants.d.ts +1 -0
- package/services/mint-campaign-service/constants.js +4 -0
- package/services/mint-campaign-service/index.d.ts +7 -0
- package/services/mint-campaign-service/index.js +11 -0
- package/services/notification-service/NotificationService.js +1 -1
- package/services/storage-service/DatabaseService.d.ts +18 -1
- package/services/storage-service/DatabaseService.js +51 -0
- package/services/storage-service/databases/index.d.ts +3 -1
- package/services/storage-service/databases/index.js +4 -0
- package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/services/storage-service/db-stores/YieldPoolStore.d.ts +10 -0
- package/services/storage-service/db-stores/YieldPoolStore.js +28 -0
- package/services/storage-service/db-stores/YieldPositionStore.d.ts +9 -0
- package/services/storage-service/db-stores/YieldPositionStore.js +57 -0
- package/services/subscan-service/index.d.ts +3 -2
- package/services/subscan-service/index.js +15 -0
- package/services/subscan-service/types.d.ts +20 -0
- package/services/transaction-service/event-parser/index.d.ts +3 -1
- package/services/transaction-service/event-parser/index.js +57 -1
- package/services/transaction-service/helpers/index.js +3 -1
- package/services/transaction-service/index.d.ts +4 -15
- package/services/transaction-service/index.js +183 -72
- package/services/transaction-service/types.d.ts +2 -0
- package/services/transaction-service/utils.js +1 -0
- package/types/campaigns/index.d.ts +1 -0
- package/types/campaigns/index.js +4 -0
- package/types/campaigns/unlock-dot.d.ts +71 -0
- package/types/campaigns/unlock-dot.js +1 -0
- package/types/index.d.ts +5 -0
- package/types/index.js +5 -1
- package/types/ordinal.d.ts +69 -0
- package/types/ordinal.js +1 -0
- package/types/transaction.d.ts +3 -0
- package/types/transaction.js +1 -0
- package/types/yield/actions/index.d.ts +2 -0
- package/types/yield/actions/index.js +5 -0
- package/types/yield/actions/join/index.d.ts +3 -0
- package/types/yield/actions/join/index.js +6 -0
- package/types/yield/actions/join/step.d.ts +94 -0
- package/types/yield/actions/join/step.js +46 -0
- package/types/yield/actions/join/submit.d.ts +53 -0
- package/types/yield/actions/join/submit.js +1 -0
- package/types/yield/actions/join/validate.d.ts +18 -0
- package/types/yield/actions/join/validate.js +10 -0
- package/types/yield/actions/others.d.ts +63 -0
- package/types/yield/actions/others.js +1 -0
- package/types/yield/index.d.ts +2 -0
- package/types/yield/index.js +5 -0
- package/types/yield/info/account/index.d.ts +4 -0
- package/types/yield/info/account/index.js +7 -0
- package/types/yield/info/account/info.d.ts +92 -0
- package/types/yield/info/account/info.js +1 -0
- package/types/yield/info/account/reward.d.ts +45 -0
- package/types/yield/info/account/reward.js +1 -0
- package/types/yield/info/account/target.d.ts +43 -0
- package/types/yield/info/account/target.js +27 -0
- package/types/yield/info/account/unstake.d.ts +31 -0
- package/types/yield/info/account/unstake.js +22 -0
- package/types/yield/info/base.d.ts +45 -0
- package/types/yield/info/base.js +36 -0
- package/types/yield/info/chain/index.d.ts +2 -0
- package/types/yield/info/chain/index.js +5 -0
- package/types/yield/info/chain/info.d.ts +243 -0
- package/types/yield/info/chain/info.js +1 -0
- package/types/yield/info/chain/target.d.ts +37 -0
- package/types/yield/info/chain/target.js +1 -0
- package/types/yield/info/index.d.ts +4 -0
- package/types/yield/info/index.js +7 -0
- package/types/yield/info/pallet.d.ts +143 -0
- package/types/yield/info/pallet.js +9 -0
- package/utils/fetchStaticData.js +2 -1
- package/utils/index.d.ts +5 -0
- package/utils/index.js +53 -1
- package/utils/object.d.ts +1 -0
- package/utils/object.js +6 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
6
|
export function parseXcmEventLogs(historyItem, eventLogs, chain, sendingTokenInfo, chainInfo) {
|
|
6
7
|
for (let index = 0; index < eventLogs.length; index++) {
|
|
7
8
|
const record = eventLogs[index];
|
|
@@ -65,4 +66,59 @@ export function parseTransferEventLogs(historyItem, eventLogs, chain, sendingTok
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
}
|
|
69
|
+
}
|
|
70
|
+
export function parseLiquidStakingEvents(historyItem, eventLogs, inputTokenInfo, chainInfo, feePaidWithInputAsset, extrinsicType) {
|
|
71
|
+
if (feePaidWithInputAsset) {
|
|
72
|
+
historyItem.fee = {
|
|
73
|
+
value: '0',
|
|
74
|
+
// TODO
|
|
75
|
+
symbol: _getAssetSymbol(inputTokenInfo),
|
|
76
|
+
decimals: _getAssetDecimals(inputTokenInfo)
|
|
77
|
+
};
|
|
78
|
+
} else {
|
|
79
|
+
for (let index = 0; index < eventLogs.length; index++) {
|
|
80
|
+
const record = eventLogs[index];
|
|
81
|
+
const {
|
|
82
|
+
decimals: nativeDecimals,
|
|
83
|
+
symbol: nativeSymbol
|
|
84
|
+
} = _getChainNativeTokenBasicInfo(chainInfo);
|
|
85
|
+
const section = extrinsicType === ExtrinsicType.REDEEM_QDOT ? 'tokens' : 'balances';
|
|
86
|
+
const eventMethod = extrinsicType === ExtrinsicType.REDEEM_QDOT ? 'withdrawn' : 'withdraw';
|
|
87
|
+
if (record.event.section === section && record.event.method.toLowerCase() === eventMethod) {
|
|
88
|
+
var _record$event$data$9;
|
|
89
|
+
if ((_record$event$data$9 = record.event.data[2]) !== null && _record$event$data$9 !== void 0 && _record$event$data$9.toString()) {
|
|
90
|
+
var _record$event$data$10;
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
92
|
+
historyItem.fee = {
|
|
93
|
+
value: ((_record$event$data$10 = record.event.data[2]) === null || _record$event$data$10 === void 0 ? void 0 : _record$event$data$10.toString()) || '0',
|
|
94
|
+
symbol: nativeSymbol,
|
|
95
|
+
decimals: nativeDecimals
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export function parseLiquidStakingFastUnstakeEvents(historyItem, eventLogs, chainInfo, extrinsicType) {
|
|
103
|
+
for (let index = 0; index < eventLogs.length; index++) {
|
|
104
|
+
const record = eventLogs[index];
|
|
105
|
+
const {
|
|
106
|
+
decimals: nativeDecimals,
|
|
107
|
+
symbol: nativeSymbol
|
|
108
|
+
} = _getChainNativeTokenBasicInfo(chainInfo);
|
|
109
|
+
const section = extrinsicType === ExtrinsicType.REDEEM_QDOT ? 'tokens' : 'balances';
|
|
110
|
+
const eventMethod = extrinsicType === ExtrinsicType.REDEEM_QDOT ? 'withdrawn' : 'withdraw';
|
|
111
|
+
if (record.event.section === section && record.event.method.toLowerCase() === eventMethod) {
|
|
112
|
+
var _record$event$data$11;
|
|
113
|
+
if ((_record$event$data$11 = record.event.data[2]) !== null && _record$event$data$11 !== void 0 && _record$event$data$11.toString()) {
|
|
114
|
+
var _record$event$data$12;
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
116
|
+
historyItem.fee = {
|
|
117
|
+
value: ((_record$event$data$12 = record.event.data[2]) === null || _record$event$data$12 === void 0 ? void 0 : _record$event$data$12.toString()) || '0',
|
|
118
|
+
symbol: nativeSymbol,
|
|
119
|
+
decimals: nativeDecimals
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
68
124
|
}
|
|
@@ -30,7 +30,7 @@ const typeName = type => {
|
|
|
30
30
|
case ExtrinsicType.STAKING_BOND:
|
|
31
31
|
return 'Bond';
|
|
32
32
|
case ExtrinsicType.STAKING_UNBOND:
|
|
33
|
-
return '
|
|
33
|
+
return 'Unstake';
|
|
34
34
|
case ExtrinsicType.STAKING_CLAIM_REWARD:
|
|
35
35
|
return 'Claim reward';
|
|
36
36
|
case ExtrinsicType.STAKING_WITHDRAW:
|
|
@@ -45,6 +45,8 @@ const typeName = type => {
|
|
|
45
45
|
return 'Cancel compounding';
|
|
46
46
|
case ExtrinsicType.STAKING_POOL_WITHDRAW:
|
|
47
47
|
return 'Withdraw pool';
|
|
48
|
+
case ExtrinsicType.JOIN_YIELD_POOL:
|
|
49
|
+
return 'Start earning';
|
|
48
50
|
case ExtrinsicType.UNKNOWN:
|
|
49
51
|
default:
|
|
50
52
|
return 'unknown';
|
|
@@ -1,27 +1,15 @@
|
|
|
1
1
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
2
|
-
import
|
|
3
|
-
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
4
|
-
import { EventService } from '@subwallet/extension-base/services/event-service';
|
|
5
|
-
import { HistoryService } from '@subwallet/extension-base/services/history-service';
|
|
6
|
-
import NotificationService from '@subwallet/extension-base/services/notification-service/NotificationService';
|
|
7
|
-
import RequestService from '@subwallet/extension-base/services/request-service';
|
|
8
|
-
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
2
|
+
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
9
3
|
import { SWTransaction, SWTransactionInput, SWTransactionResponse, TransactionEmitter } from '@subwallet/extension-base/services/transaction-service/types';
|
|
10
4
|
import { BehaviorSubject } from 'rxjs';
|
|
11
5
|
import { TransactionConfig } from 'web3-core';
|
|
12
6
|
import { HexString } from '@polkadot/util/types';
|
|
13
7
|
export default class TransactionService {
|
|
14
|
-
private readonly
|
|
15
|
-
private readonly chainService;
|
|
16
|
-
private readonly databaseService;
|
|
17
|
-
private readonly eventService;
|
|
18
|
-
private readonly historyService;
|
|
19
|
-
private readonly notificationService;
|
|
20
|
-
private readonly requestService;
|
|
8
|
+
private readonly state;
|
|
21
9
|
private readonly transactionSubject;
|
|
22
10
|
private readonly watchTransactionSubscribes;
|
|
23
11
|
private get transactions();
|
|
24
|
-
constructor(
|
|
12
|
+
constructor(state: KoniState);
|
|
25
13
|
private get allTransactions();
|
|
26
14
|
private get processingTransactions();
|
|
27
15
|
getTransaction(id: string): SWTransaction;
|
|
@@ -47,5 +35,6 @@ export default class TransactionService {
|
|
|
47
35
|
private signAndSendEvmTransaction;
|
|
48
36
|
private signAndSendSubstrateTransaction;
|
|
49
37
|
private handleTransactionTimeout;
|
|
38
|
+
private handlePostEarningTransaction;
|
|
50
39
|
resetWallet(): void;
|
|
51
40
|
}
|
|
@@ -6,14 +6,14 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
|
|
|
6
6
|
import { BasicTxErrorType, BasicTxWarningCode, ChainType, EvmProviderErrorType, ExtrinsicStatus, ExtrinsicType, NotificationType, TransactionDirection } from '@subwallet/extension-base/background/KoniTypes';
|
|
7
7
|
import { TransactionWarning } from '@subwallet/extension-base/background/warnings/TransactionWarning';
|
|
8
8
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
9
|
-
import {
|
|
10
|
-
import { _getChainNativeTokenBasicInfo, _getEvmChainId } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
|
+
import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getEvmChainId, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
11
10
|
import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
|
|
12
11
|
import { TRANSACTION_TIMEOUT } from '@subwallet/extension-base/services/transaction-service/constants';
|
|
13
|
-
import { parseTransferEventLogs, parseXcmEventLogs } from '@subwallet/extension-base/services/transaction-service/event-parser';
|
|
12
|
+
import { parseLiquidStakingEvents, parseLiquidStakingFastUnstakeEvents, parseTransferEventLogs, parseXcmEventLogs } from '@subwallet/extension-base/services/transaction-service/event-parser';
|
|
14
13
|
import { getBaseTransactionInfo, getTransactionId, isSubstrateTransaction } from '@subwallet/extension-base/services/transaction-service/helpers';
|
|
15
14
|
import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
|
|
16
15
|
import { isWalletConnectRequest } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
16
|
+
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
17
17
|
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
18
18
|
import { anyNumberToBN, recalculateGasPrice } from '@subwallet/extension-base/utils/eth';
|
|
19
19
|
import { mergeTransactionAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature';
|
|
@@ -26,20 +26,15 @@ import EventEmitter from 'eventemitter3';
|
|
|
26
26
|
import { t } from 'i18next';
|
|
27
27
|
import { BehaviorSubject } from 'rxjs';
|
|
28
28
|
import { isHex } from '@polkadot/util';
|
|
29
|
+
import { _TRANSFER_CHAIN_GROUP } from "../chain-service/constants.js";
|
|
29
30
|
export default class TransactionService {
|
|
30
31
|
transactionSubject = new BehaviorSubject({});
|
|
31
32
|
watchTransactionSubscribes = {};
|
|
32
33
|
get transactions() {
|
|
33
34
|
return this.transactionSubject.getValue();
|
|
34
35
|
}
|
|
35
|
-
constructor(
|
|
36
|
-
this.
|
|
37
|
-
this.eventService = eventService;
|
|
38
|
-
this.requestService = requestService;
|
|
39
|
-
this.balanceService = balanceService;
|
|
40
|
-
this.historyService = historyService;
|
|
41
|
-
this.notificationService = notificationService;
|
|
42
|
-
this.databaseService = databaseService;
|
|
36
|
+
constructor(state) {
|
|
37
|
+
this.state = state;
|
|
43
38
|
}
|
|
44
39
|
get allTransactions() {
|
|
45
40
|
return Object.values(this.transactions);
|
|
@@ -96,7 +91,7 @@ export default class TransactionService {
|
|
|
96
91
|
decimals: 0,
|
|
97
92
|
value: ''
|
|
98
93
|
};
|
|
99
|
-
const chainInfo = this.chainService.getChainInfoByKey(chain);
|
|
94
|
+
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
100
95
|
if (!chainInfo) {
|
|
101
96
|
validationResponse.errors.push(new TransactionError(BasicTxErrorType.INTERNAL_ERROR, t('Cannot find network')));
|
|
102
97
|
} else {
|
|
@@ -111,7 +106,7 @@ export default class TransactionService {
|
|
|
111
106
|
if (isSubstrateTransaction(transaction)) {
|
|
112
107
|
estimateFee.value = (await transaction.paymentInfo(address)).partialFee.toString();
|
|
113
108
|
} else {
|
|
114
|
-
const web3 = this.chainService.getEvmApi(chain);
|
|
109
|
+
const web3 = this.state.chainService.getEvmApi(chain);
|
|
115
110
|
if (!web3) {
|
|
116
111
|
validationResponse.errors.push(new TransactionError(BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
|
|
117
112
|
} else {
|
|
@@ -145,32 +140,35 @@ export default class TransactionService {
|
|
|
145
140
|
|
|
146
141
|
// Balance
|
|
147
142
|
const transferNative = validationResponse.transferNativeAmount || '0';
|
|
148
|
-
const nativeTokenInfo = this.chainService.getNativeTokenInfo(chain);
|
|
149
|
-
const balance = await this.balanceService.getTokenFreeBalance(address, chain, nativeTokenInfo.slug);
|
|
143
|
+
const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(chain);
|
|
144
|
+
const balance = await this.state.balanceService.getTokenFreeBalance(address, chain, nativeTokenInfo.slug);
|
|
150
145
|
const existentialDeposit = nativeTokenInfo.minAmount || '0';
|
|
151
146
|
const feeNum = parseInt(estimateFee.value);
|
|
152
147
|
const balanceNum = parseInt(balance.value);
|
|
153
148
|
const edNum = parseInt(existentialDeposit);
|
|
154
149
|
const transferNativeNum = parseInt(transferNative);
|
|
155
|
-
if (!
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (transferNativeNum + feeNum > balanceNum) {
|
|
159
|
-
if (!isTransferAll) {
|
|
150
|
+
if (!validationInput.skipFeeValidation) {
|
|
151
|
+
// TODO
|
|
152
|
+
if (!new BigN(balance.value).gt(0)) {
|
|
160
153
|
validationResponse.errors.push(new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE));
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
154
|
+
}
|
|
155
|
+
if (transferNativeNum + feeNum > balanceNum) {
|
|
156
|
+
if (!isTransferAll) {
|
|
164
157
|
validationResponse.errors.push(new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE));
|
|
158
|
+
} else {
|
|
159
|
+
if ([..._TRANSFER_CHAIN_GROUP.acala, ..._TRANSFER_CHAIN_GROUP.genshiro, ..._TRANSFER_CHAIN_GROUP.bitcountry, ..._TRANSFER_CHAIN_GROUP.statemine].includes(chain)) {
|
|
160
|
+
// Chain not have transfer all function
|
|
161
|
+
validationResponse.errors.push(new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE));
|
|
162
|
+
}
|
|
165
163
|
}
|
|
166
164
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
165
|
+
if (!isTransferAll) {
|
|
166
|
+
if (balanceNum - (transferNativeNum + feeNum) < edNum) {
|
|
167
|
+
if (edAsWarning) {
|
|
168
|
+
validationResponse.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT));
|
|
169
|
+
} else {
|
|
170
|
+
validationResponse.errors.push(new TransactionError(BasicTxErrorType.NOT_ENOUGH_EXISTENTIAL_DEPOSIT));
|
|
171
|
+
}
|
|
174
172
|
}
|
|
175
173
|
}
|
|
176
174
|
}
|
|
@@ -237,12 +235,21 @@ export default class TransactionService {
|
|
|
237
235
|
}
|
|
238
236
|
validatedTransaction.warnings = [];
|
|
239
237
|
const emitter = await this.addTransaction(validatedTransaction);
|
|
240
|
-
await new Promise(resolve => {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
238
|
+
await new Promise((resolve, reject) => {
|
|
239
|
+
// TODO
|
|
240
|
+
if (transaction.resolveOnDone) {
|
|
241
|
+
emitter.on('success', data => {
|
|
242
|
+
validatedTransaction.id = data.id;
|
|
243
|
+
validatedTransaction.extrinsicHash = data.extrinsicHash;
|
|
244
|
+
resolve();
|
|
245
|
+
});
|
|
246
|
+
} else {
|
|
247
|
+
emitter.on('signed', data => {
|
|
248
|
+
validatedTransaction.id = data.id;
|
|
249
|
+
validatedTransaction.extrinsicHash = data.extrinsicHash;
|
|
250
|
+
resolve();
|
|
251
|
+
});
|
|
252
|
+
}
|
|
246
253
|
emitter.on('error', data => {
|
|
247
254
|
if (data.errors.length > 0) {
|
|
248
255
|
validatedTransaction.errors.push(...data.errors);
|
|
@@ -308,7 +315,7 @@ export default class TransactionService {
|
|
|
308
315
|
}
|
|
309
316
|
getTransactionLink(id) {
|
|
310
317
|
const transaction = this.getTransaction(id);
|
|
311
|
-
const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
|
|
318
|
+
const chainInfo = this.state.chainService.getChainInfoByKey(transaction.chain);
|
|
312
319
|
return getExplorerLink(chainInfo, transaction.extrinsicHash, 'tx');
|
|
313
320
|
}
|
|
314
321
|
transactionToHistories(id, startBlock, nonce, eventLogs) {
|
|
@@ -336,7 +343,7 @@ export default class TransactionService {
|
|
|
336
343
|
nonce: nonce !== null && nonce !== void 0 ? nonce : 0,
|
|
337
344
|
startBlock: startBlock || 0
|
|
338
345
|
};
|
|
339
|
-
const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
|
|
346
|
+
const chainInfo = this.state.chainService.getChainInfoByKey(transaction.chain);
|
|
340
347
|
const nativeAsset = _getChainNativeTokenBasicInfo(chainInfo);
|
|
341
348
|
const baseNativeAmount = {
|
|
342
349
|
value: '0',
|
|
@@ -350,7 +357,7 @@ export default class TransactionService {
|
|
|
350
357
|
{
|
|
351
358
|
const inputData = parseTransactionData(transaction.data);
|
|
352
359
|
historyItem.to = inputData.to;
|
|
353
|
-
const sendingTokenInfo = this.chainService.getAssetBySlug(inputData.tokenSlug);
|
|
360
|
+
const sendingTokenInfo = this.state.chainService.getAssetBySlug(inputData.tokenSlug);
|
|
354
361
|
historyItem.amount = {
|
|
355
362
|
value: inputData.value || '0',
|
|
356
363
|
decimals: sendingTokenInfo.decimals || 0,
|
|
@@ -363,7 +370,7 @@ export default class TransactionService {
|
|
|
363
370
|
{
|
|
364
371
|
const inputData = parseTransactionData(transaction.data);
|
|
365
372
|
historyItem.to = inputData.to;
|
|
366
|
-
const sendingTokenInfo = this.chainService.getAssetBySlug(inputData.tokenSlug);
|
|
373
|
+
const sendingTokenInfo = this.state.chainService.getAssetBySlug(inputData.tokenSlug);
|
|
367
374
|
historyItem.amount = {
|
|
368
375
|
value: inputData.value || '0',
|
|
369
376
|
decimals: sendingTokenInfo.decimals || 0,
|
|
@@ -376,7 +383,7 @@ export default class TransactionService {
|
|
|
376
383
|
{
|
|
377
384
|
const inputData = parseTransactionData(transaction.data);
|
|
378
385
|
historyItem.to = inputData.to;
|
|
379
|
-
const sendingTokenInfo = this.chainService.getAssetBySlug(inputData.tokenSlug);
|
|
386
|
+
const sendingTokenInfo = this.state.chainService.getAssetBySlug(inputData.tokenSlug);
|
|
380
387
|
historyItem.amount = {
|
|
381
388
|
value: inputData.value || '0',
|
|
382
389
|
decimals: sendingTokenInfo.decimals || 0,
|
|
@@ -425,17 +432,29 @@ export default class TransactionService {
|
|
|
425
432
|
case ExtrinsicType.STAKING_UNBOND:
|
|
426
433
|
{
|
|
427
434
|
const data = parseTransactionData(transaction.data);
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
435
|
+
if (data.isLiquidStaking && data.derivativeTokenInfo && data.exchangeRate && data.inputTokenInfo) {
|
|
436
|
+
historyItem.amount = {
|
|
437
|
+
decimals: _getAssetDecimals(data.derivativeTokenInfo),
|
|
438
|
+
symbol: _getAssetSymbol(data.derivativeTokenInfo),
|
|
439
|
+
value: data.amount
|
|
440
|
+
};
|
|
441
|
+
historyItem.additionalInfo = {
|
|
442
|
+
inputTokenSlug: data.inputTokenInfo.slug,
|
|
443
|
+
exchangeRate: data.exchangeRate
|
|
444
|
+
};
|
|
445
|
+
} else {
|
|
446
|
+
historyItem.to = data.validatorAddress || '';
|
|
447
|
+
historyItem.amount = {
|
|
448
|
+
...baseNativeAmount,
|
|
449
|
+
value: data.amount || '0'
|
|
450
|
+
};
|
|
451
|
+
}
|
|
433
452
|
}
|
|
434
453
|
break;
|
|
435
454
|
case ExtrinsicType.STAKING_LEAVE_POOL:
|
|
436
455
|
{
|
|
437
456
|
const data = parseTransactionData(transaction.data);
|
|
438
|
-
historyItem.to = data.
|
|
457
|
+
historyItem.to = data.address || '';
|
|
439
458
|
historyItem.amount = {
|
|
440
459
|
...baseNativeAmount,
|
|
441
460
|
value: data.amount || '0'
|
|
@@ -454,7 +473,7 @@ export default class TransactionService {
|
|
|
454
473
|
case ExtrinsicType.STAKING_WITHDRAW:
|
|
455
474
|
{
|
|
456
475
|
const data = parseTransactionData(transaction.data);
|
|
457
|
-
historyItem.to = data.validatorAddress || '';
|
|
476
|
+
historyItem.to = data.unstakingInfo.validatorAddress || '';
|
|
458
477
|
historyItem.amount = {
|
|
459
478
|
...baseNativeAmount,
|
|
460
479
|
value: data.unstakingInfo.claimable || '0'
|
|
@@ -479,6 +498,67 @@ export default class TransactionService {
|
|
|
479
498
|
historyItem.to = (data === null || data === void 0 ? void 0 : data.to) || '';
|
|
480
499
|
break;
|
|
481
500
|
}
|
|
501
|
+
case ExtrinsicType.MINT_STDOT:
|
|
502
|
+
case ExtrinsicType.MINT_QDOT:
|
|
503
|
+
case ExtrinsicType.MINT_LDOT:
|
|
504
|
+
case ExtrinsicType.MINT_SDOT:
|
|
505
|
+
|
|
506
|
+
// eslint-disable-next-line no-fallthrough
|
|
507
|
+
case ExtrinsicType.MINT_VDOT:
|
|
508
|
+
{
|
|
509
|
+
const params = parseTransactionData(transaction.data);
|
|
510
|
+
const inputTokenInfo = this.state.chainService.getAssetBySlug(params.inputTokenSlug);
|
|
511
|
+
const isFeePaidWithInputAsset = params.feeTokenSlug === params.inputTokenSlug;
|
|
512
|
+
historyItem.amount = {
|
|
513
|
+
value: params.amount,
|
|
514
|
+
symbol: _getAssetSymbol(inputTokenInfo),
|
|
515
|
+
decimals: _getAssetDecimals(inputTokenInfo)
|
|
516
|
+
};
|
|
517
|
+
historyItem.additionalInfo = {
|
|
518
|
+
derivativeTokenSlug: params.derivativeTokenSlug,
|
|
519
|
+
exchangeRate: params.exchangeRate
|
|
520
|
+
};
|
|
521
|
+
eventLogs && !_isChainEvmCompatible(chainInfo) && parseLiquidStakingEvents(historyItem, eventLogs, inputTokenInfo, chainInfo, isFeePaidWithInputAsset, extrinsicType);
|
|
522
|
+
break;
|
|
523
|
+
}
|
|
524
|
+
case ExtrinsicType.REDEEM_QDOT:
|
|
525
|
+
{
|
|
526
|
+
const data = parseTransactionData(transaction.data);
|
|
527
|
+
const yieldPoolInfo = data.poolInfo;
|
|
528
|
+
if (yieldPoolInfo.metadata.derivativeAssets) {
|
|
529
|
+
const inputTokenSlug = yieldPoolInfo.metadata.inputAsset;
|
|
530
|
+
const inputTokenInfo = this.state.chainService.getAssetBySlug(inputTokenSlug);
|
|
531
|
+
historyItem.amount = {
|
|
532
|
+
value: data.amount,
|
|
533
|
+
symbol: _getAssetSymbol(inputTokenInfo),
|
|
534
|
+
decimals: _getAssetDecimals(inputTokenInfo)
|
|
535
|
+
};
|
|
536
|
+
eventLogs && parseLiquidStakingFastUnstakeEvents(historyItem, eventLogs, chainInfo, extrinsicType);
|
|
537
|
+
}
|
|
538
|
+
break;
|
|
539
|
+
}
|
|
540
|
+
case ExtrinsicType.REDEEM_STDOT:
|
|
541
|
+
case ExtrinsicType.REDEEM_LDOT:
|
|
542
|
+
case ExtrinsicType.REDEEM_SDOT:
|
|
543
|
+
|
|
544
|
+
// eslint-disable-next-line no-fallthrough
|
|
545
|
+
case ExtrinsicType.REDEEM_VDOT:
|
|
546
|
+
{
|
|
547
|
+
const data = parseTransactionData(transaction.data);
|
|
548
|
+
const yieldPoolInfo = data.poolInfo;
|
|
549
|
+
if (yieldPoolInfo.metadata.derivativeAssets) {
|
|
550
|
+
const derivativeTokenSlug = yieldPoolInfo.metadata.derivativeAssets[0];
|
|
551
|
+
const derivativeTokenInfo = this.state.chainService.getAssetBySlug(derivativeTokenSlug);
|
|
552
|
+
const chainInfo = this.state.chainService.getChainInfoByKey(data.poolInfo.chain);
|
|
553
|
+
historyItem.amount = {
|
|
554
|
+
value: data.amount,
|
|
555
|
+
symbol: _getAssetSymbol(derivativeTokenInfo),
|
|
556
|
+
decimals: _getAssetDecimals(derivativeTokenInfo)
|
|
557
|
+
};
|
|
558
|
+
eventLogs && !_isChainEvmCompatible(chainInfo) && parseLiquidStakingFastUnstakeEvents(historyItem, eventLogs, chainInfo, extrinsicType);
|
|
559
|
+
}
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
482
562
|
case ExtrinsicType.UNKNOWN:
|
|
483
563
|
break;
|
|
484
564
|
}
|
|
@@ -524,7 +604,7 @@ export default class TransactionService {
|
|
|
524
604
|
});
|
|
525
605
|
|
|
526
606
|
// Create Input History Transaction History
|
|
527
|
-
this.historyService.insertHistories(this.transactionToHistories(id, startBlock, nonce)).catch(console.error);
|
|
607
|
+
this.state.historyService.insertHistories(this.transactionToHistories(id, startBlock, nonce)).catch(console.error);
|
|
528
608
|
console.debug(`Transaction "${id}" is sent`);
|
|
529
609
|
}
|
|
530
610
|
onHasTransactionHash({
|
|
@@ -541,8 +621,12 @@ export default class TransactionService {
|
|
|
541
621
|
this.updateTransaction(id, updateData);
|
|
542
622
|
|
|
543
623
|
// In this case transaction id is the same as extrinsic hash and will change after below update
|
|
544
|
-
this.historyService.updateHistoryByExtrinsicHash(id, updateData).catch(console.error);
|
|
624
|
+
this.state.historyService.updateHistoryByExtrinsicHash(id, updateData).catch(console.error);
|
|
545
625
|
console.debug(`Transaction "${id}" is submitted with hash ${extrinsicHash || ''}`);
|
|
626
|
+
const transaction = this.getTransaction(id);
|
|
627
|
+
if ([ExtrinsicType.STAKING_JOIN_POOL, ExtrinsicType.JOIN_YIELD_POOL, ExtrinsicType.MINT_LDOT, ExtrinsicType.MINT_QDOT, ExtrinsicType.MINT_SDOT, ExtrinsicType.MINT_VDOT].includes(transaction.extrinsicType)) {
|
|
628
|
+
this.handlePostEarningTransaction(id);
|
|
629
|
+
}
|
|
546
630
|
}
|
|
547
631
|
handlePostProcessing(id) {
|
|
548
632
|
// must be done after success/failure to make sure the transaction is finalized
|
|
@@ -551,15 +635,15 @@ export default class TransactionService {
|
|
|
551
635
|
const inputData = parseTransactionData(transaction.data);
|
|
552
636
|
try {
|
|
553
637
|
const sender = keyring.getPair(inputData.senderAddress);
|
|
554
|
-
sender && this.
|
|
555
|
-
this.eventService.emit('transaction.transferNft', undefined);
|
|
638
|
+
sender && this.state.dbService.handleNftTransfer(transaction.chain, [sender.address, ALL_ACCOUNT_KEY], inputData.nftItem).then(() => {
|
|
639
|
+
this.state.eventService.emit('transaction.transferNft', undefined);
|
|
556
640
|
}).catch(console.error);
|
|
557
641
|
} catch (e) {
|
|
558
642
|
console.error(e);
|
|
559
643
|
}
|
|
560
644
|
try {
|
|
561
645
|
const recipient = keyring.getPair(inputData.recipientAddress);
|
|
562
|
-
recipient && this.
|
|
646
|
+
recipient && this.state.dbService.addNft(recipient.address, {
|
|
563
647
|
...inputData.nftItem,
|
|
564
648
|
owner: recipient.address
|
|
565
649
|
}).catch(console.error);
|
|
@@ -567,7 +651,7 @@ export default class TransactionService {
|
|
|
567
651
|
console.error(e);
|
|
568
652
|
}
|
|
569
653
|
} else if ([ExtrinsicType.STAKING_BOND, ExtrinsicType.STAKING_UNBOND, ExtrinsicType.STAKING_WITHDRAW, ExtrinsicType.STAKING_CANCEL_UNSTAKE, ExtrinsicType.STAKING_CLAIM_REWARD, ExtrinsicType.STAKING_JOIN_POOL, ExtrinsicType.STAKING_POOL_WITHDRAW, ExtrinsicType.STAKING_LEAVE_POOL].includes(transaction.extrinsicType)) {
|
|
570
|
-
this.eventService.emit('transaction.submitStaking', transaction.chain);
|
|
654
|
+
this.state.eventService.emit('transaction.submitStaking', transaction.chain);
|
|
571
655
|
}
|
|
572
656
|
}
|
|
573
657
|
onSuccess({
|
|
@@ -583,14 +667,14 @@ export default class TransactionService {
|
|
|
583
667
|
});
|
|
584
668
|
|
|
585
669
|
// Write success transaction history
|
|
586
|
-
this.historyService.updateHistoryByExtrinsicHash(transaction.extrinsicHash, {
|
|
670
|
+
this.state.historyService.updateHistoryByExtrinsicHash(transaction.extrinsicHash, {
|
|
587
671
|
extrinsicHash,
|
|
588
672
|
status: ExtrinsicStatus.SUCCESS,
|
|
589
673
|
blockNumber: blockNumber || 0,
|
|
590
674
|
blockHash: blockHash || ''
|
|
591
675
|
}).catch(console.error);
|
|
592
|
-
const info = isHex(extrinsicHash) ? extrinsicHash : getBaseTransactionInfo(transaction, this.chainService.getChainInfoMap());
|
|
593
|
-
this.notificationService.notify({
|
|
676
|
+
const info = isHex(extrinsicHash) ? extrinsicHash : getBaseTransactionInfo(transaction, this.state.chainService.getChainInfoMap());
|
|
677
|
+
this.state.notificationService.notify({
|
|
594
678
|
type: NotificationType.SUCCESS,
|
|
595
679
|
title: t('Transaction completed'),
|
|
596
680
|
message: t('Transaction {{info}} completed', {
|
|
@@ -603,7 +687,7 @@ export default class TransactionService {
|
|
|
603
687
|
},
|
|
604
688
|
notifyViaBrowser: true
|
|
605
689
|
});
|
|
606
|
-
this.eventService.emit('transaction.done', transaction);
|
|
690
|
+
this.state.eventService.emit('transaction.done', transaction);
|
|
607
691
|
}
|
|
608
692
|
onFailed({
|
|
609
693
|
blockHash,
|
|
@@ -622,14 +706,14 @@ export default class TransactionService {
|
|
|
622
706
|
});
|
|
623
707
|
|
|
624
708
|
// Write failed transaction history
|
|
625
|
-
this.historyService.updateHistoryByExtrinsicHash(transaction.extrinsicHash, {
|
|
709
|
+
this.state.historyService.updateHistoryByExtrinsicHash(transaction.extrinsicHash, {
|
|
626
710
|
extrinsicHash: extrinsicHash || transaction.extrinsicHash,
|
|
627
711
|
status: nextStatus,
|
|
628
712
|
blockNumber: blockNumber || 0,
|
|
629
713
|
blockHash: blockHash || ''
|
|
630
714
|
}).catch(console.error);
|
|
631
|
-
const info = isHex(transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash) ? transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash : getBaseTransactionInfo(transaction, this.chainService.getChainInfoMap());
|
|
632
|
-
this.notificationService.notify({
|
|
715
|
+
const info = isHex(transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash) ? transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash : getBaseTransactionInfo(transaction, this.state.chainService.getChainInfoMap());
|
|
716
|
+
this.state.notificationService.notify({
|
|
633
717
|
type: NotificationType.ERROR,
|
|
634
718
|
title: t('Transaction failed'),
|
|
635
719
|
message: t('Transaction {{info}} failed', {
|
|
@@ -643,11 +727,11 @@ export default class TransactionService {
|
|
|
643
727
|
notifyViaBrowser: true
|
|
644
728
|
});
|
|
645
729
|
}
|
|
646
|
-
this.eventService.emit('transaction.failed', transaction);
|
|
730
|
+
this.state.eventService.emit('transaction.failed', transaction);
|
|
647
731
|
}
|
|
648
732
|
generateHashPayload(chain, transaction) {
|
|
649
733
|
var _transaction$nonce;
|
|
650
|
-
const chainInfo = this.chainService.getChainInfoByKey(chain);
|
|
734
|
+
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
651
735
|
const txObject = {
|
|
652
736
|
nonce: (_transaction$nonce = transaction.nonce) !== null && _transaction$nonce !== void 0 ? _transaction$nonce : 0,
|
|
653
737
|
gasPrice: addHexPrefix(anyNumberToBN(transaction.gasPrice).toString(16)),
|
|
@@ -668,8 +752,8 @@ export default class TransactionService {
|
|
|
668
752
|
}) {
|
|
669
753
|
var _payload$nonce;
|
|
670
754
|
const payload = transaction;
|
|
671
|
-
const evmApi = this.chainService.getEvmApi(chain);
|
|
672
|
-
const chainInfo = this.chainService.getChainInfoByKey(chain);
|
|
755
|
+
const evmApi = this.state.chainService.getEvmApi(chain);
|
|
756
|
+
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
673
757
|
const accountPair = keyring.getPair(address);
|
|
674
758
|
const account = {
|
|
675
759
|
address,
|
|
@@ -699,7 +783,7 @@ export default class TransactionService {
|
|
|
699
783
|
|
|
700
784
|
// Set unique nonce to avoid transaction errors
|
|
701
785
|
if (!payload.nonce) {
|
|
702
|
-
const evmApi = this.chainService.getEvmApi(chain);
|
|
786
|
+
const evmApi = this.state.chainService.getEvmApi(chain);
|
|
703
787
|
payload.nonce = await evmApi.api.eth.getTransactionCount(address);
|
|
704
788
|
}
|
|
705
789
|
if (!payload.chainId) {
|
|
@@ -734,7 +818,7 @@ export default class TransactionService {
|
|
|
734
818
|
extrinsicHash: id
|
|
735
819
|
};
|
|
736
820
|
if (isInjected) {
|
|
737
|
-
this.requestService.addConfirmation(id, url || EXTENSION_REQUEST_URL, 'evmWatchTransactionRequest', payload, {}).then(async ({
|
|
821
|
+
this.state.requestService.addConfirmation(id, url || EXTENSION_REQUEST_URL, 'evmWatchTransactionRequest', payload, {}).then(async ({
|
|
738
822
|
isApproved,
|
|
739
823
|
payload
|
|
740
824
|
}) => {
|
|
@@ -742,7 +826,7 @@ export default class TransactionService {
|
|
|
742
826
|
if (!payload) {
|
|
743
827
|
throw new EvmProviderError(EvmProviderErrorType.UNAUTHORIZED, 'Bad signature');
|
|
744
828
|
}
|
|
745
|
-
const web3Api = this.chainService.getEvmApi(chain).api;
|
|
829
|
+
const web3Api = this.state.chainService.getEvmApi(chain).api;
|
|
746
830
|
|
|
747
831
|
// Emit signed event
|
|
748
832
|
emitter.emit('signed', eventData);
|
|
@@ -798,7 +882,7 @@ export default class TransactionService {
|
|
|
798
882
|
emitter.emit('error', eventData);
|
|
799
883
|
});
|
|
800
884
|
} else {
|
|
801
|
-
this.requestService.addConfirmation(id, url || EXTENSION_REQUEST_URL, 'evmSendTransactionRequest', payload, {}).then(async ({
|
|
885
|
+
this.state.requestService.addConfirmation(id, url || EXTENSION_REQUEST_URL, 'evmSendTransactionRequest', payload, {}).then(async ({
|
|
802
886
|
isApproved,
|
|
803
887
|
payload
|
|
804
888
|
}) => {
|
|
@@ -807,7 +891,7 @@ export default class TransactionService {
|
|
|
807
891
|
if (!payload) {
|
|
808
892
|
throw new EvmProviderError(EvmProviderErrorType.UNAUTHORIZED, t('Failed to sign'));
|
|
809
893
|
}
|
|
810
|
-
const web3Api = this.chainService.getEvmApi(chain).api;
|
|
894
|
+
const web3Api = this.state.chainService.getEvmApi(chain).api;
|
|
811
895
|
if (!isExternal) {
|
|
812
896
|
signedTransaction = payload;
|
|
813
897
|
} else {
|
|
@@ -874,7 +958,7 @@ export default class TransactionService {
|
|
|
874
958
|
transaction.signAsync(address, {
|
|
875
959
|
signer: {
|
|
876
960
|
signPayload: async payload => {
|
|
877
|
-
const signing = await this.requestService.signInternalTransaction(id, address, url || EXTENSION_REQUEST_URL, payload);
|
|
961
|
+
const signing = await this.state.requestService.signInternalTransaction(id, address, url || EXTENSION_REQUEST_URL, payload);
|
|
878
962
|
return {
|
|
879
963
|
id: new Date().getTime(),
|
|
880
964
|
signature: signing.signature
|
|
@@ -886,7 +970,7 @@ export default class TransactionService {
|
|
|
886
970
|
emitter.emit('signed', eventData);
|
|
887
971
|
|
|
888
972
|
// Send transaction
|
|
889
|
-
const api = this.chainService.getSubstrateApi(chain);
|
|
973
|
+
const api = this.state.chainService.getSubstrateApi(chain);
|
|
890
974
|
eventData.nonce = rs.nonce.toNumber();
|
|
891
975
|
eventData.startBlock = (await api.api.query.system.number()).toPrimitive();
|
|
892
976
|
this.handleTransactionTimeout(emitter, eventData);
|
|
@@ -954,6 +1038,33 @@ export default class TransactionService {
|
|
|
954
1038
|
clearTimeout(timeout);
|
|
955
1039
|
});
|
|
956
1040
|
}
|
|
1041
|
+
handlePostEarningTransaction(id) {
|
|
1042
|
+
const transaction = this.getTransaction(id);
|
|
1043
|
+
let slug;
|
|
1044
|
+
|
|
1045
|
+
// TODO
|
|
1046
|
+
if ('data' in transaction.data) {
|
|
1047
|
+
slug = transaction.data.data.slug;
|
|
1048
|
+
} else {
|
|
1049
|
+
slug = transaction.data.slug;
|
|
1050
|
+
}
|
|
1051
|
+
const poolHandler = this.state.earningService.getPoolHandler(slug);
|
|
1052
|
+
if (poolHandler) {
|
|
1053
|
+
const type = poolHandler.type;
|
|
1054
|
+
if (type === YieldPoolType.NATIVE_STAKING) {
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
} else {
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
this.state.mintCampaignService.unlockDotCampaign.mintNft({
|
|
1061
|
+
transactionId: id,
|
|
1062
|
+
address: transaction.address,
|
|
1063
|
+
slug: slug,
|
|
1064
|
+
network: transaction.chain,
|
|
1065
|
+
extrinsicHash: transaction.extrinsicHash
|
|
1066
|
+
}).catch(console.error);
|
|
1067
|
+
}
|
|
957
1068
|
resetWallet() {
|
|
958
1069
|
this.transactionSubject.next({});
|
|
959
1070
|
}
|
|
@@ -30,6 +30,8 @@ export interface SWTransactionInput extends SwInputBase, Partial<Pick<SWTransact
|
|
|
30
30
|
errors?: SWTransaction['errors'];
|
|
31
31
|
edAsWarning?: boolean;
|
|
32
32
|
isTransferAll?: boolean;
|
|
33
|
+
resolveOnDone?: boolean;
|
|
34
|
+
skipFeeValidation?: boolean;
|
|
33
35
|
}
|
|
34
36
|
export declare type SWTransactionResponse = SwInputBase & Pick<SWTransaction, 'warnings' | 'errors'> & Partial<Pick<SWTransaction, 'id' | 'extrinsicHash' | 'status' | 'estimateFee'>>;
|
|
35
37
|
export declare type ValidateTransactionResponseInput = SWTransactionInput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './unlock-dot';
|