@subwallet/extension-base 1.3.22-0 → 1.3.24-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 +77 -4
- package/background/KoniTypes.js +2 -0
- package/cjs/background/KoniTypes.js +2 -0
- package/cjs/constants/environment.js +4 -2
- package/cjs/constants/index.js +21 -4
- package/cjs/constants/signing.js +6 -2
- package/cjs/core/logic-validation/recipientAddress.js +9 -1
- package/cjs/core/logic-validation/transfer.js +57 -36
- package/cjs/core/types.js +1 -0
- package/cjs/core/utils.js +12 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/api/dotsama/crowdloan.js +1 -1
- package/cjs/koni/api/nft/index.js +9 -16
- package/cjs/koni/api/staking/index.js +3 -4
- package/cjs/koni/background/handlers/Extension.js +343 -185
- package/cjs/koni/background/handlers/State.js +17 -2
- package/cjs/koni/background/handlers/Tabs.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/cardano/consts.js +11 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/index.js +63 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/utils.js +74 -0
- package/cjs/services/balance-service/helpers/subscribe/index.js +21 -7
- package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +2 -2
- package/cjs/services/balance-service/index.js +4 -2
- package/cjs/services/balance-service/transfer/cardano-transfer.js +122 -0
- package/cjs/services/balance-service/transfer/smart-contract.js +24 -3
- package/cjs/services/balance-service/transfer/token.js +4 -4
- package/cjs/services/chain-service/handler/CardanoApi.js +176 -0
- package/cjs/services/chain-service/handler/CardanoChainHandler.js +83 -0
- package/cjs/services/chain-service/handler/TonApi.js +2 -5
- package/cjs/services/chain-service/index.js +40 -7
- package/cjs/services/chain-service/utils/index.js +40 -11
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/cjs/services/earning-service/service.js +6 -12
- package/cjs/services/fee-service/service.js +19 -8
- package/cjs/services/fee-service/utils/tokenPayFee.js +151 -0
- package/cjs/services/history-service/index.js +4 -6
- package/cjs/services/inapp-notification-service/index.js +12 -4
- package/cjs/services/keyring-service/context/account-context.js +17 -2
- package/cjs/services/keyring-service/context/handlers/Derive.js +10 -7
- package/cjs/services/keyring-service/context/handlers/Migration.js +268 -0
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/cjs/services/keyring-service/context/handlers/Secret.js +1 -1
- package/cjs/services/keyring-service/utils.js +18 -0
- package/cjs/services/request-service/handler/CardanoRequestHandler.js +172 -0
- package/cjs/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/cjs/services/request-service/handler/MetadataRequestHandler.js +5 -13
- package/cjs/services/request-service/index.js +22 -4
- package/cjs/services/setting-service/constants.js +10 -1
- package/cjs/services/storage-service/DatabaseService.js +3 -0
- package/cjs/services/storage-service/db-stores/InappNotification.js +6 -0
- package/cjs/services/swap-service/handler/asset-hub/handler.js +0 -59
- package/cjs/services/swap-service/handler/chainflip-handler.js +33 -281
- package/cjs/services/swap-service/handler/hydradx-handler.js +23 -190
- package/cjs/services/swap-service/handler/simpleswap-handler.js +1 -222
- package/cjs/services/swap-service/handler/uniswap-handler.js +331 -0
- package/cjs/services/swap-service/index.js +31 -22
- package/cjs/services/swap-service/utils.js +21 -38
- package/cjs/services/transaction-service/helpers/index.js +6 -1
- package/cjs/services/transaction-service/index.js +286 -26
- package/cjs/services/transaction-service/utils.js +5 -1
- package/cjs/types/account/info/keyring.js +12 -1
- package/cjs/types/fee/cardano.js +1 -0
- package/cjs/types/swap/index.js +7 -2
- package/cjs/utils/account/analyze.js +2 -1
- package/cjs/utils/account/common.js +29 -20
- package/cjs/utils/account/derive/info/solo.js +9 -4
- package/cjs/utils/account/derive/validate.js +36 -2
- package/cjs/utils/account/transform.js +38 -13
- package/cjs/utils/fee/transfer.js +87 -21
- package/cjs/utils/index.js +2 -2
- package/cjs/utils/staticData/index.js +7 -2
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- package/constants/index.d.ts +6 -1
- package/constants/index.js +14 -1
- package/constants/signing.js +6 -2
- package/core/logic-validation/recipientAddress.js +11 -3
- package/core/logic-validation/transfer.d.ts +1 -1
- package/core/logic-validation/transfer.js +33 -12
- package/core/substrate/xcm-parser.d.ts +1 -1
- package/core/types.d.ts +1 -0
- package/core/types.js +1 -0
- package/core/utils.d.ts +1 -0
- package/core/utils.js +13 -3
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/api/dotsama/crowdloan.js +3 -3
- package/koni/api/nft/index.js +10 -16
- package/koni/api/nft/story_odyssey_nft/index.d.ts +1 -1
- package/koni/api/staking/index.js +4 -5
- package/koni/background/handlers/Extension.d.ts +9 -0
- package/koni/background/handlers/Extension.js +225 -69
- package/koni/background/handlers/State.d.ts +6 -2
- package/koni/background/handlers/State.js +18 -3
- package/koni/background/handlers/Tabs.js +1 -1
- package/package.json +76 -9
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/cardano/consts.d.ts +1 -0
- package/services/balance-service/helpers/subscribe/cardano/consts.js +4 -0
- package/services/balance-service/helpers/subscribe/cardano/index.d.ts +2 -0
- package/services/balance-service/helpers/subscribe/cardano/index.js +57 -0
- package/services/balance-service/helpers/subscribe/cardano/types.d.ts +34 -0
- package/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.d.ts +15 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.js +62 -0
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/index.js +23 -9
- package/services/balance-service/helpers/subscribe/ton/utils.d.ts +1 -1
- package/services/balance-service/helpers/subscribe/ton/utils.js +1 -1
- package/services/balance-service/index.js +4 -2
- package/services/balance-service/transfer/cardano-transfer.d.ts +24 -0
- package/services/balance-service/transfer/cardano-transfer.js +114 -0
- package/services/balance-service/transfer/smart-contract.d.ts +4 -2
- package/services/balance-service/transfer/smart-contract.js +24 -3
- package/services/balance-service/transfer/token.d.ts +1 -1
- package/services/balance-service/transfer/token.js +2 -2
- package/services/chain-service/handler/CardanoApi.d.ts +38 -0
- package/services/chain-service/handler/CardanoApi.js +167 -0
- package/services/chain-service/handler/CardanoChainHandler.d.ts +17 -0
- package/services/chain-service/handler/CardanoChainHandler.js +75 -0
- package/services/chain-service/handler/TonApi.js +3 -6
- package/services/chain-service/handler/types.d.ts +1 -0
- package/services/chain-service/index.d.ts +4 -1
- package/services/chain-service/index.js +41 -8
- package/services/chain-service/types.d.ts +9 -1
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +32 -11
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/services/earning-service/service.js +8 -14
- package/services/fee-service/interfaces.d.ts +25 -0
- package/services/fee-service/service.js +19 -8
- package/services/fee-service/utils/tokenPayFee.d.ts +8 -0
- package/services/fee-service/utils/tokenPayFee.js +141 -0
- package/services/history-service/index.js +6 -8
- package/services/inapp-notification-service/index.d.ts +3 -4
- package/services/inapp-notification-service/index.js +14 -6
- package/services/keyring-service/context/account-context.d.ts +6 -2
- package/services/keyring-service/context/account-context.js +17 -2
- package/services/keyring-service/context/handlers/Derive.d.ts +1 -1
- package/services/keyring-service/context/handlers/Derive.js +10 -8
- package/services/keyring-service/context/handlers/Migration.d.ts +17 -0
- package/services/keyring-service/context/handlers/Migration.js +258 -0
- package/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/services/keyring-service/context/handlers/Secret.js +2 -2
- package/services/keyring-service/utils.d.ts +2 -0
- package/services/keyring-service/utils.js +11 -0
- package/services/request-service/handler/CardanoRequestHandler.d.ts +16 -0
- package/services/request-service/handler/CardanoRequestHandler.js +163 -0
- package/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -1
- package/services/request-service/handler/MetadataRequestHandler.js +5 -13
- package/services/request-service/index.d.ts +7 -4
- package/services/request-service/index.js +21 -7
- package/services/setting-service/constants.d.ts +3 -0
- package/services/setting-service/constants.js +6 -0
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +3 -0
- package/services/storage-service/db-stores/InappNotification.d.ts +1 -0
- package/services/storage-service/db-stores/InappNotification.js +6 -0
- package/services/swap-service/handler/asset-hub/handler.d.ts +1 -4
- package/services/swap-service/handler/asset-hub/handler.js +2 -61
- package/services/swap-service/handler/base-handler.d.ts +1 -4
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -9
- package/services/swap-service/handler/chainflip-handler.js +31 -280
- package/services/swap-service/handler/hydradx-handler.d.ts +1 -6
- package/services/swap-service/handler/hydradx-handler.js +13 -180
- package/services/swap-service/handler/simpleswap-handler.d.ts +1 -4
- package/services/swap-service/handler/simpleswap-handler.js +5 -226
- package/services/swap-service/handler/uniswap-handler.d.ts +41 -0
- package/services/swap-service/handler/uniswap-handler.js +323 -0
- package/services/swap-service/index.js +30 -22
- package/services/swap-service/utils.d.ts +1 -5
- package/services/swap-service/utils.js +7 -21
- package/services/transaction-service/helpers/index.d.ts +2 -0
- package/services/transaction-service/helpers/index.js +4 -0
- package/services/transaction-service/index.d.ts +8 -2
- package/services/transaction-service/index.js +273 -17
- package/services/transaction-service/types.d.ts +7 -0
- package/services/transaction-service/utils.js +7 -2
- package/types/account/info/keyring.d.ts +4 -1
- package/types/account/info/keyring.js +9 -0
- package/types/account/info/proxy.d.ts +2 -0
- package/types/balance/index.d.ts +4 -1
- package/types/fee/base.d.ts +1 -1
- package/types/fee/cardano.d.ts +18 -0
- package/types/fee/cardano.js +1 -0
- package/types/fee/option.d.ts +1 -1
- package/types/fee/subscription.d.ts +4 -3
- package/types/swap/index.d.ts +11 -3
- package/types/swap/index.js +7 -2
- package/utils/account/analyze.js +2 -1
- package/utils/account/common.d.ts +11 -6
- package/utils/account/common.js +28 -19
- package/utils/account/derive/info/solo.js +10 -5
- package/utils/account/derive/validate.d.ts +1 -0
- package/utils/account/derive/validate.js +34 -1
- package/utils/account/transform.d.ts +2 -1
- package/utils/account/transform.js +37 -13
- package/utils/fee/transfer.d.ts +3 -2
- package/utils/fee/transfer.js +90 -24
- package/utils/index.js +4 -4
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/oldChainPrefix.json +1 -0
|
@@ -12,8 +12,10 @@ import { BasicTxErrorType } from '@subwallet/extension-base/types';
|
|
|
12
12
|
import { DEFAULT_FIRST_STEP, MOCK_STEP_FEE } from '@subwallet/extension-base/types/service-base';
|
|
13
13
|
import { _SUPPORTED_SWAP_PROVIDERS, SwapErrorType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types/swap';
|
|
14
14
|
import { createPromiseHandler } from '@subwallet/extension-base/utils';
|
|
15
|
+
import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
|
|
15
16
|
import { BehaviorSubject } from 'rxjs';
|
|
16
17
|
import { SimpleSwapHandler } from "./handler/simpleswap-handler.js";
|
|
18
|
+
import { UniswapHandler } from "./handler/uniswap-handler.js";
|
|
17
19
|
export const _isChainSupportedByProvider = (providerSlug, chain) => {
|
|
18
20
|
const supportedChains = _PROVIDER_TO_SUPPORTED_PAIR_MAP[providerSlug];
|
|
19
21
|
return supportedChains ? supportedChains.includes(chain) : false;
|
|
@@ -30,31 +32,34 @@ export class SwapService {
|
|
|
30
32
|
this.chainService = state.chainService;
|
|
31
33
|
}
|
|
32
34
|
async askProvidersForQuote(request) {
|
|
35
|
+
var _subwalletApiSdk$swap;
|
|
33
36
|
const availableQuotes = [];
|
|
34
|
-
const swappingSrcChain = this.chainService.getAssetBySlug(request.pair.from).originChain;
|
|
35
37
|
await Promise.all(Object.values(this.handlers).map(async handler => {
|
|
36
38
|
// temporary solution to reduce number of requests to providers, will work as long as there's only 1 provider for 1 chain
|
|
37
|
-
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
39
|
+
|
|
40
40
|
if (handler.init && handler.isReady === false) {
|
|
41
41
|
await handler.init();
|
|
42
42
|
}
|
|
43
|
-
const quote = await handler.getSwapQuote(request);
|
|
44
|
-
if (!(quote instanceof SwapError)) {
|
|
45
|
-
// todo: can do better
|
|
46
|
-
availableQuotes.push({
|
|
47
|
-
quote
|
|
48
|
-
});
|
|
49
|
-
} else {
|
|
50
|
-
availableQuotes.push({
|
|
51
|
-
error: quote
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
43
|
}));
|
|
55
|
-
|
|
44
|
+
const quotes = await ((_subwalletApiSdk$swap = subwalletApiSdk.swapApi) === null || _subwalletApiSdk$swap === void 0 ? void 0 : _subwalletApiSdk$swap.fetchSwapQuoteData(request));
|
|
45
|
+
if (Array.isArray(quotes)) {
|
|
46
|
+
quotes.forEach(quoteData => {
|
|
47
|
+
if (!quoteData.quote || Object.keys(quoteData.quote).length === 0) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!('errorClass' in quoteData.quote)) {
|
|
51
|
+
availableQuotes.push({
|
|
52
|
+
quote: quoteData.quote
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
availableQuotes.push({
|
|
56
|
+
error: new SwapError(quoteData.quote.errorType, quoteData.quote.message)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return availableQuotes;
|
|
56
62
|
}
|
|
57
|
-
|
|
58
63
|
getDefaultProcess(params) {
|
|
59
64
|
const result = {
|
|
60
65
|
totalFee: [MOCK_STEP_FEE],
|
|
@@ -76,7 +81,8 @@ export class SwapService {
|
|
|
76
81
|
if (!params.selectedQuote) {
|
|
77
82
|
return this.getDefaultProcess(params);
|
|
78
83
|
} else {
|
|
79
|
-
|
|
84
|
+
var _params$request$curre;
|
|
85
|
+
const providerId = ((_params$request$curre = params.request.currentQuote) === null || _params$request$curre === void 0 ? void 0 : _params$request$curre.id) || params.selectedQuote.provider.id;
|
|
80
86
|
const handler = this.handlers[providerId];
|
|
81
87
|
if (handler) {
|
|
82
88
|
return handler.generateOptimalProcess(params);
|
|
@@ -91,7 +97,6 @@ export class SwapService {
|
|
|
91
97
|
* 2. Select the best quote
|
|
92
98
|
* 3. Generate optimal process for that quote
|
|
93
99
|
* */
|
|
94
|
-
|
|
95
100
|
const swapQuoteResponse = await this.getLatestQuotes(request);
|
|
96
101
|
const optimalProcess = await this.generateOptimalProcess({
|
|
97
102
|
request,
|
|
@@ -155,15 +160,18 @@ export class SwapService {
|
|
|
155
160
|
case SwapProviderId.KUSAMA_ASSET_HUB:
|
|
156
161
|
this.handlers[providerId] = new AssetHubSwapHandler(this.chainService, this.state.balanceService, this.state.feeService, 'statemine');
|
|
157
162
|
break;
|
|
158
|
-
case SwapProviderId.ROCOCO_ASSET_HUB:
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
// case SwapProviderId.ROCOCO_ASSET_HUB:
|
|
164
|
+
// this.handlers[providerId] = new AssetHubSwapHandler(this.chainService, this.state.balanceService, this.state.feeService, 'rococo_assethub');
|
|
165
|
+
// break;
|
|
161
166
|
case SwapProviderId.WESTEND_ASSET_HUB:
|
|
162
167
|
this.handlers[providerId] = new AssetHubSwapHandler(this.chainService, this.state.balanceService, this.state.feeService, 'westend_assethub');
|
|
163
168
|
break;
|
|
164
169
|
case SwapProviderId.SIMPLE_SWAP:
|
|
165
170
|
this.handlers[providerId] = new SimpleSwapHandler(this.chainService, this.state.balanceService, this.state.feeService);
|
|
166
171
|
break;
|
|
172
|
+
case SwapProviderId.UNISWAP:
|
|
173
|
+
this.handlers[providerId] = new UniswapHandler(this.chainService, this.state.balanceService, this.state.transactionService, this.state.feeService);
|
|
174
|
+
break;
|
|
167
175
|
default:
|
|
168
176
|
throw new Error('Unsupported provider');
|
|
169
177
|
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { Asset, Chain } from '@chainflip/sdk/swap';
|
|
2
1
|
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
3
2
|
import { SwapPair } from '@subwallet/extension-base/types/swap';
|
|
4
3
|
export declare const CHAIN_FLIP_TESTNET_EXPLORER = "https://blocks-perseverance.chainflip.io";
|
|
5
4
|
export declare const CHAIN_FLIP_MAINNET_EXPLORER = "https://scan.chainflip.io";
|
|
6
5
|
export declare const SIMPLE_SWAP_EXPLORER = "https://simpleswap.io";
|
|
7
|
-
export declare const CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING: Record<string, Chain>;
|
|
8
|
-
export declare const CHAIN_FLIP_SUPPORTED_TESTNET_MAPPING: Record<string, Chain>;
|
|
9
|
-
export declare const CHAIN_FLIP_SUPPORTED_MAINNET_ASSET_MAPPING: Record<string, Asset>;
|
|
10
|
-
export declare const CHAIN_FLIP_SUPPORTED_TESTNET_ASSET_MAPPING: Record<string, Asset>;
|
|
11
6
|
export declare const SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING: Record<string, string>;
|
|
12
7
|
export declare const SWAP_QUOTE_TIMEOUT_MAP: Record<string, number>;
|
|
13
8
|
export declare const _PROVIDER_TO_SUPPORTED_PAIR_MAP: Record<string, string[]>;
|
|
@@ -27,3 +22,4 @@ export declare function getChainflipOptions(isTestnet: boolean): {
|
|
|
27
22
|
export declare function getChainflipBroker(isTestnet: boolean): {
|
|
28
23
|
url: string;
|
|
29
24
|
};
|
|
25
|
+
export declare function getChainflipSwap(isTestnet: boolean): string;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { Assets, Chains } from '@chainflip/sdk/swap';
|
|
5
4
|
import { COMMON_ASSETS, COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
6
5
|
import { _getAssetDecimals } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
6
|
import { CHAINFLIP_BROKER_API } from '@subwallet/extension-base/services/swap-service/handler/chainflip-handler';
|
|
@@ -10,26 +9,6 @@ import BigN from 'bignumber.js';
|
|
|
10
9
|
export const CHAIN_FLIP_TESTNET_EXPLORER = 'https://blocks-perseverance.chainflip.io';
|
|
11
10
|
export const CHAIN_FLIP_MAINNET_EXPLORER = 'https://scan.chainflip.io';
|
|
12
11
|
export const SIMPLE_SWAP_EXPLORER = 'https://simpleswap.io';
|
|
13
|
-
export const CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING = {
|
|
14
|
-
[COMMON_CHAIN_SLUGS.POLKADOT]: Chains.Polkadot,
|
|
15
|
-
[COMMON_CHAIN_SLUGS.ETHEREUM]: Chains.Ethereum,
|
|
16
|
-
[COMMON_CHAIN_SLUGS.ARBITRUM]: Chains.Arbitrum
|
|
17
|
-
};
|
|
18
|
-
export const CHAIN_FLIP_SUPPORTED_TESTNET_MAPPING = {
|
|
19
|
-
[COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA]: Chains.Ethereum,
|
|
20
|
-
[COMMON_CHAIN_SLUGS.CHAINFLIP_POLKADOT]: Chains.Polkadot
|
|
21
|
-
};
|
|
22
|
-
export const CHAIN_FLIP_SUPPORTED_MAINNET_ASSET_MAPPING = {
|
|
23
|
-
[COMMON_ASSETS.DOT]: Assets.DOT,
|
|
24
|
-
[COMMON_ASSETS.ETH]: Assets.ETH,
|
|
25
|
-
[COMMON_ASSETS.USDC_ETHEREUM]: Assets.USDC,
|
|
26
|
-
[COMMON_ASSETS.USDT_ETHEREUM]: Assets.USDT
|
|
27
|
-
};
|
|
28
|
-
export const CHAIN_FLIP_SUPPORTED_TESTNET_ASSET_MAPPING = {
|
|
29
|
-
[COMMON_ASSETS.PDOT]: Assets.DOT,
|
|
30
|
-
[COMMON_ASSETS.ETH_SEPOLIA]: Assets.ETH,
|
|
31
|
-
[COMMON_ASSETS.USDC_SEPOLIA]: Assets.USDC
|
|
32
|
-
};
|
|
33
12
|
export const SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING = {
|
|
34
13
|
'bittensor-NATIVE-TAO': 'tao',
|
|
35
14
|
[COMMON_ASSETS.ETH]: 'eth',
|
|
@@ -99,4 +78,11 @@ export function getChainflipBroker(isTestnet) {
|
|
|
99
78
|
url: `https://chainflip-broker.io/rpc/${CHAINFLIP_BROKER_API}`
|
|
100
79
|
};
|
|
101
80
|
}
|
|
81
|
+
}
|
|
82
|
+
export function getChainflipSwap(isTestnet) {
|
|
83
|
+
if (isTestnet) {
|
|
84
|
+
return `https://perseverance.chainflip-broker.io/swap?apikey=${CHAINFLIP_BROKER_API}`;
|
|
85
|
+
} else {
|
|
86
|
+
return `https://chainflip-broker.io/swap?apikey=${CHAINFLIP_BROKER_API}`;
|
|
87
|
+
}
|
|
102
88
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { CardanoTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/cardano-transfer';
|
|
2
3
|
import { TonTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
3
4
|
import { SWTransaction } from '@subwallet/extension-base/services/transaction-service/types';
|
|
4
5
|
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
|
|
@@ -6,4 +7,5 @@ export declare const getTransactionId: (chainType: string, chain: string, isInte
|
|
|
6
7
|
export declare const getValidationId: (chainType: string, chain: string) => string;
|
|
7
8
|
export declare const isSubstrateTransaction: (tx: SWTransaction['transaction']) => tx is SubmittableExtrinsic;
|
|
8
9
|
export declare const isTonTransaction: (tx: SWTransaction['transaction']) => tx is TonTransactionConfig;
|
|
10
|
+
export declare const isCardanoTransaction: (tx: SWTransaction['transaction']) => tx is CardanoTransactionConfig;
|
|
9
11
|
export declare const getBaseTransactionInfo: (transaction: SWTransaction, chainInfoMap: Record<string, _ChainInfo>) => string;
|
|
@@ -17,6 +17,10 @@ export const isTonTransaction = tx => {
|
|
|
17
17
|
const tonTransactionConfig = tx;
|
|
18
18
|
return Boolean(tonTransactionConfig.messagePayload) && tonTransactionConfig.seqno >= 0;
|
|
19
19
|
};
|
|
20
|
+
export const isCardanoTransaction = tx => {
|
|
21
|
+
const cardanoTransactionConfig = tx;
|
|
22
|
+
return cardanoTransactionConfig.cardanoPayload !== null && cardanoTransactionConfig.cardanoPayload !== undefined;
|
|
23
|
+
};
|
|
20
24
|
const typeName = type => {
|
|
21
25
|
switch (type) {
|
|
22
26
|
case ExtrinsicType.TRANSFER_BALANCE:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
2
2
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
3
|
-
import { SWTransaction, SWTransactionInput, SWTransactionResponse, TransactionEmitter } from '@subwallet/extension-base/services/transaction-service/types';
|
|
4
|
-
import { BriefProcessStep, ProcessStep, ProcessTransactionData } from '@subwallet/extension-base/types';
|
|
3
|
+
import { SWPermitTransactionInput, SWTransaction, SWTransactionInput, SWTransactionResponse, TransactionEmitter } from '@subwallet/extension-base/services/transaction-service/types';
|
|
4
|
+
import { BaseStepType, BriefProcessStep, ProcessStep, ProcessTransactionData } from '@subwallet/extension-base/types';
|
|
5
5
|
import { BehaviorSubject } from 'rxjs';
|
|
6
6
|
import { TransactionConfig } from 'web3-core';
|
|
7
7
|
import { HexString } from '@polkadot/util/types';
|
|
@@ -15,6 +15,7 @@ export default class TransactionService {
|
|
|
15
15
|
private aliveProcessMap;
|
|
16
16
|
private readonly transactionSubject;
|
|
17
17
|
private readonly aliveProcessSubject;
|
|
18
|
+
private cacheProcessInfo;
|
|
18
19
|
private get transactions();
|
|
19
20
|
constructor(state: KoniState);
|
|
20
21
|
private get allTransactions();
|
|
@@ -31,12 +32,15 @@ export default class TransactionService {
|
|
|
31
32
|
readonly transaction: Record<string, SWTransaction>;
|
|
32
33
|
readonly aliveProcess: Record<string, ProcessTransactionData>;
|
|
33
34
|
};
|
|
35
|
+
getCacheInfo(processId: string, step: BaseStepType): string;
|
|
34
36
|
private updateAliveProcess;
|
|
35
37
|
private fillTransactionDefaultInfo;
|
|
36
38
|
addTransaction(inputTransaction: SWTransactionInput): Promise<TransactionEmitter>;
|
|
37
39
|
generateBeforeHandleResponseErrors(errors: TransactionError[]): SWTransactionResponse;
|
|
38
40
|
handleTransaction(transaction: SWTransactionInput): Promise<SWTransactionResponse>;
|
|
41
|
+
handlePermitTransaction(transaction: SWPermitTransactionInput): Promise<SWTransactionResponse>;
|
|
39
42
|
private sendTransaction;
|
|
43
|
+
private sendPermitTransaction;
|
|
40
44
|
private removeTransaction;
|
|
41
45
|
private updateTransaction;
|
|
42
46
|
private getTransactionLink;
|
|
@@ -50,8 +54,10 @@ export default class TransactionService {
|
|
|
50
54
|
private onTimeOut;
|
|
51
55
|
generateHashPayload(chain: string, transaction: TransactionConfig): HexString;
|
|
52
56
|
private signAndSendEvmTransaction;
|
|
57
|
+
private signAndSendEvmPermitTransaction;
|
|
53
58
|
private signAndSendSubstrateTransaction;
|
|
54
59
|
private signAndSendTonTransaction;
|
|
60
|
+
private signAndSendCardanoTransaction;
|
|
55
61
|
private handleTransactionTimeout;
|
|
56
62
|
private handlePostEarningTransaction;
|
|
57
63
|
createProcessIfNeed(process: ProcessTransactionData): Promise<void>;
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
import { EvmProviderError } from '@subwallet/extension-base/background/errors/EvmProviderError';
|
|
5
5
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
6
6
|
import { ChainType, EvmProviderErrorType, ExtrinsicStatus, ExtrinsicType, NotificationType, TransactionDirection } from '@subwallet/extension-base/background/KoniTypes';
|
|
7
|
-
import { ALL_ACCOUNT_KEY, fetchBlockedConfigObjects, fetchLastestBlockedActionsAndFeatures, getPassConfigId } from '@subwallet/extension-base/constants';
|
|
7
|
+
import { _SUPPORT_TOKEN_PAY_FEE_GROUP, ALL_ACCOUNT_KEY, fetchBlockedConfigObjects, fetchLastestBlockedActionsAndFeatures, getPassConfigId } from '@subwallet/extension-base/constants';
|
|
8
8
|
import { checkBalanceWithTransactionFee, checkSigningAccountForTransaction, checkSupportForAction, checkSupportForFeature, checkSupportForTransaction, estimateFeeForTransaction } from '@subwallet/extension-base/core/logic-validation/transfer';
|
|
9
9
|
import { cellToBase64Str, externalMessage, getTransferCellPromise } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils';
|
|
10
|
-
import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getEvmChainId, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
|
+
import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getEvmChainId, _isChainEvmCompatible, _isNativeTokenBySlug } from '@subwallet/extension-base/services/chain-service/utils';
|
|
11
11
|
import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
|
|
12
12
|
import { TRANSACTION_TIMEOUT } from '@subwallet/extension-base/services/transaction-service/constants';
|
|
13
13
|
import { parseLiquidStakingEvents, parseLiquidStakingFastUnstakeEvents, parseTransferEventLogs, parseXcmEventLogs } from '@subwallet/extension-base/services/transaction-service/event-parser';
|
|
14
|
-
import { getBaseTransactionInfo, getTransactionId, isSubstrateTransaction, isTonTransaction } from '@subwallet/extension-base/services/transaction-service/helpers';
|
|
14
|
+
import { getBaseTransactionInfo, getTransactionId, isCardanoTransaction, isSubstrateTransaction, isTonTransaction } from '@subwallet/extension-base/services/transaction-service/helpers';
|
|
15
15
|
import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
|
|
16
16
|
import { isWalletConnectRequest } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
17
17
|
import { BasicTxErrorType, StepStatus, YieldPoolType } from '@subwallet/extension-base/types';
|
|
@@ -33,6 +33,7 @@ export default class TransactionService {
|
|
|
33
33
|
aliveProcessMap = new Map();
|
|
34
34
|
transactionSubject = new BehaviorSubject({});
|
|
35
35
|
aliveProcessSubject = new BehaviorSubject(this.aliveProcessMap);
|
|
36
|
+
cacheProcessInfo = {};
|
|
36
37
|
get transactions() {
|
|
37
38
|
return this.transactionSubject.getValue();
|
|
38
39
|
}
|
|
@@ -89,8 +90,6 @@ export default class TransactionService {
|
|
|
89
90
|
checkSupportForAction(validationResponse, blockedActionsMap);
|
|
90
91
|
}
|
|
91
92
|
const transaction = transactionInput.transaction;
|
|
92
|
-
const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(chain);
|
|
93
|
-
const tokenPayFeeInfo = transactionInput.nonNativeTokenPayFeeSlug ? this.chainService.getAssetBySlug(transactionInput.nonNativeTokenPayFeeSlug) : undefined;
|
|
94
93
|
|
|
95
94
|
// Check duplicated transaction
|
|
96
95
|
validationResponse.errors.push(...this.checkDuplicate(transactionInput));
|
|
@@ -103,16 +102,25 @@ export default class TransactionService {
|
|
|
103
102
|
const substrateApi = this.state.chainService.getSubstrateApi(chainInfo.slug);
|
|
104
103
|
const evmApi = this.state.chainService.getEvmApi(chainInfo.slug);
|
|
105
104
|
const tonApi = this.state.chainService.getTonApi(chainInfo.slug);
|
|
106
|
-
const
|
|
105
|
+
const cardanoApi = this.state.chainService.getCardanoApi(chainInfo.slug);
|
|
106
|
+
// todo: should split into isEvmTx && isNoEvmApi. Because other chains type also has no Evm Api. Same to all blockchain.
|
|
107
|
+
// todo: refactor check evmTransaction.
|
|
108
|
+
const isNoEvmApi = transaction && !isSubstrateTransaction(transaction) && !isTonTransaction(transaction) && !isCardanoTransaction(transaction) && !evmApi;
|
|
107
109
|
const isNoTonApi = transaction && isTonTransaction(transaction) && !tonApi;
|
|
108
|
-
|
|
110
|
+
const isNoCardanoApi = transaction && isCardanoTransaction(transaction) && !cardanoApi;
|
|
111
|
+
if (isNoEvmApi || isNoTonApi || isNoCardanoApi) {
|
|
109
112
|
validationResponse.errors.push(new TransactionError(BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
// Estimate fee for transaction
|
|
113
116
|
const id = getId();
|
|
114
117
|
const feeInfo = await this.state.feeService.subscribeChainFee(id, chain, 'evm');
|
|
115
|
-
|
|
118
|
+
const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(chain);
|
|
119
|
+
const tokenPayFeeSlug = transactionInput.tokenPayFeeSlug;
|
|
120
|
+
const isNonNativeTokenPayFee = tokenPayFeeSlug && !_isNativeTokenBySlug(tokenPayFeeSlug);
|
|
121
|
+
const nonNativeTokenPayFeeInfo = isNonNativeTokenPayFee ? this.chainService.getAssetBySlug(tokenPayFeeSlug) : undefined;
|
|
122
|
+
const priceMap = (await this.state.priceService.getPrice()).priceMap;
|
|
123
|
+
validationResponse.estimateFee = await estimateFeeForTransaction(validationResponse, transaction, chainInfo, evmApi, substrateApi, priceMap, feeInfo, nativeTokenInfo, nonNativeTokenPayFeeInfo, transactionInput.isTransferLocalTokenAndPayThatTokenAsFee);
|
|
116
124
|
const chainInfoMap = this.state.chainService.getChainInfoMap();
|
|
117
125
|
|
|
118
126
|
// Check account signing transaction
|
|
@@ -169,6 +177,10 @@ export default class TransactionService {
|
|
|
169
177
|
}
|
|
170
178
|
};
|
|
171
179
|
}
|
|
180
|
+
getCacheInfo(processId, step) {
|
|
181
|
+
var _this$cacheProcessInf;
|
|
182
|
+
return ((_this$cacheProcessInf = this.cacheProcessInfo[processId]) === null || _this$cacheProcessInf === void 0 ? void 0 : _this$cacheProcessInf[step]) || '';
|
|
183
|
+
}
|
|
172
184
|
updateAliveProcess() {
|
|
173
185
|
this.aliveProcessSubject.next(this.aliveProcessMap);
|
|
174
186
|
}
|
|
@@ -263,9 +275,61 @@ export default class TransactionService {
|
|
|
263
275
|
'eventsHandler' in validatedTransaction && delete validatedTransaction.eventsHandler;
|
|
264
276
|
return validatedTransaction;
|
|
265
277
|
}
|
|
278
|
+
async handlePermitTransaction(transaction) {
|
|
279
|
+
var _transaction$step;
|
|
280
|
+
const transactionId = getTransactionId(transaction.chainType, transaction.chain, true);
|
|
281
|
+
const validatedTransaction = {
|
|
282
|
+
...transaction,
|
|
283
|
+
id: transactionId,
|
|
284
|
+
extrinsicHash: '',
|
|
285
|
+
status: undefined,
|
|
286
|
+
errors: transaction.errors || [],
|
|
287
|
+
warnings: transaction.warnings || [],
|
|
288
|
+
processId: (_transaction$step = transaction.step) === null || _transaction$step === void 0 ? void 0 : _transaction$step.processId
|
|
289
|
+
};
|
|
290
|
+
const txInput = {
|
|
291
|
+
...transaction,
|
|
292
|
+
isInternal: true,
|
|
293
|
+
status: ExtrinsicStatus.QUEUED,
|
|
294
|
+
id: transactionId,
|
|
295
|
+
extrinsicHash: transactionId,
|
|
296
|
+
createdAt: new Date().getTime(),
|
|
297
|
+
updatedAt: new Date().getTime()
|
|
298
|
+
};
|
|
299
|
+
const _data = transaction.data;
|
|
300
|
+
const emitter = this.sendPermitTransaction(txInput);
|
|
301
|
+
await new Promise((resolve, reject) => {
|
|
302
|
+
emitter.on('success', data => {
|
|
303
|
+
validatedTransaction.id = data.id;
|
|
304
|
+
validatedTransaction.extrinsicHash = data.extrinsicHash;
|
|
305
|
+
this.cacheProcessInfo[_data.processId] = {
|
|
306
|
+
[_data.step]: data.extrinsicHash
|
|
307
|
+
};
|
|
308
|
+
resolve();
|
|
309
|
+
});
|
|
310
|
+
emitter.on('error', data => {
|
|
311
|
+
if (data.errors.length > 0) {
|
|
312
|
+
validatedTransaction.errors.push(...data.errors);
|
|
313
|
+
resolve();
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
emitter.on('timeout', data => {
|
|
317
|
+
if (transaction.errorOnTimeOut && data.errors.length > 0) {
|
|
318
|
+
validatedTransaction.errors.push(...data.errors);
|
|
319
|
+
resolve();
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// @ts-ignore
|
|
325
|
+
'transaction' in validatedTransaction && delete validatedTransaction.transaction;
|
|
326
|
+
'additionalValidator' in validatedTransaction && delete validatedTransaction.additionalValidator;
|
|
327
|
+
'eventsHandler' in validatedTransaction && delete validatedTransaction.eventsHandler;
|
|
328
|
+
return validatedTransaction;
|
|
329
|
+
}
|
|
266
330
|
async sendTransaction(transaction) {
|
|
267
331
|
// Send Transaction
|
|
268
|
-
const emitter = await (transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : transaction.chainType === 'evm' ? this.signAndSendEvmTransaction(transaction) : this.signAndSendTonTransaction(transaction));
|
|
332
|
+
const emitter = await (transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : transaction.chainType === 'evm' ? this.signAndSendEvmTransaction(transaction) : transaction.chainType === 'cardano' ? this.signAndSendCardanoTransaction(transaction) : this.signAndSendTonTransaction(transaction));
|
|
269
333
|
const {
|
|
270
334
|
eventsHandler,
|
|
271
335
|
step
|
|
@@ -315,7 +379,12 @@ export default class TransactionService {
|
|
|
315
379
|
}
|
|
316
380
|
return false;
|
|
317
381
|
});
|
|
318
|
-
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Now simple check, first step have step id = 1.
|
|
385
|
+
* Improve to fetch the process from db
|
|
386
|
+
* */
|
|
387
|
+
if (rejectError && step.stepId === 1) {
|
|
319
388
|
this.deleteProcess(step);
|
|
320
389
|
} else {
|
|
321
390
|
this.updateProcessStepStatus(step, {
|
|
@@ -341,6 +410,71 @@ export default class TransactionService {
|
|
|
341
410
|
eventsHandler === null || eventsHandler === void 0 ? void 0 : eventsHandler(emitter);
|
|
342
411
|
return emitter;
|
|
343
412
|
}
|
|
413
|
+
sendPermitTransaction(transaction) {
|
|
414
|
+
// Send Transaction
|
|
415
|
+
const emitter = this.signAndSendEvmPermitTransaction(transaction);
|
|
416
|
+
const {
|
|
417
|
+
eventsHandler,
|
|
418
|
+
step
|
|
419
|
+
} = transaction;
|
|
420
|
+
emitter.on('send', data => {
|
|
421
|
+
if (step) {
|
|
422
|
+
this.updateProcessStepStatus(step, {
|
|
423
|
+
transactionId: transaction.id,
|
|
424
|
+
status: StepStatus.SUBMITTING,
|
|
425
|
+
chain: transaction.chain
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
emitter.on('extrinsicHash', data => {
|
|
430
|
+
if (step) {
|
|
431
|
+
this.updateProcessStepStatus(step, {
|
|
432
|
+
extrinsicHash: data.extrinsicHash,
|
|
433
|
+
status: StepStatus.PROCESSING
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
emitter.on('success', data => {
|
|
438
|
+
if (step) {
|
|
439
|
+
this.updateProcessStepStatus(step, {
|
|
440
|
+
status: StepStatus.COMPLETE
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
emitter.on('error', data => {
|
|
445
|
+
// this.handlePostProcessing(data.id); // might enable this later
|
|
446
|
+
this.onFailed({
|
|
447
|
+
...data,
|
|
448
|
+
errors: [...data.errors, new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]
|
|
449
|
+
});
|
|
450
|
+
if (step) {
|
|
451
|
+
const rejectError = data.errors.find(error => {
|
|
452
|
+
// TODO: REFACTOR ERROR CODE
|
|
453
|
+
if ([BasicTxErrorType.UNABLE_TO_SIGN, BasicTxErrorType.USER_REJECT_REQUEST].includes(error.errorType)) {
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
return false;
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Now simple check, first step have step id = 1.
|
|
461
|
+
* Improve to fetch the process from db
|
|
462
|
+
* */
|
|
463
|
+
if (rejectError && step.stepId === 1) {
|
|
464
|
+
this.deleteProcess(step);
|
|
465
|
+
} else {
|
|
466
|
+
this.updateProcessStepStatus(step, {
|
|
467
|
+
status: StepStatus.FAILED
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
// Todo: handle any event with transaction.eventsHandler
|
|
474
|
+
|
|
475
|
+
eventsHandler === null || eventsHandler === void 0 ? void 0 : eventsHandler(emitter);
|
|
476
|
+
return emitter;
|
|
477
|
+
}
|
|
344
478
|
removeTransaction(id) {
|
|
345
479
|
if (this.transactions[id]) {
|
|
346
480
|
delete this.transactions[id];
|
|
@@ -364,7 +498,7 @@ export default class TransactionService {
|
|
|
364
498
|
return getExplorerLink(chainInfo, transaction.extrinsicHash, 'tx');
|
|
365
499
|
}
|
|
366
500
|
transactionToHistories(id, startBlock, nonce, eventLogs) {
|
|
367
|
-
var _transaction$
|
|
501
|
+
var _transaction$step2;
|
|
368
502
|
const transaction = this.getTransaction(id);
|
|
369
503
|
const extrinsicType = transaction.extrinsicType;
|
|
370
504
|
const chainInfo = this.state.chainService.getChainInfoByKey(transaction.chain);
|
|
@@ -389,7 +523,7 @@ export default class TransactionService {
|
|
|
389
523
|
// Will be added in next step
|
|
390
524
|
nonce: nonce !== null && nonce !== void 0 ? nonce : 0,
|
|
391
525
|
startBlock: startBlock || 0,
|
|
392
|
-
processId: (_transaction$
|
|
526
|
+
processId: (_transaction$step2 = transaction.step) === null || _transaction$step2 === void 0 ? void 0 : _transaction$step2.processId
|
|
393
527
|
};
|
|
394
528
|
const nativeAsset = _getChainNativeTokenBasicInfo(chainInfo);
|
|
395
529
|
const baseNativeAmount = {
|
|
@@ -1156,20 +1290,75 @@ export default class TransactionService {
|
|
|
1156
1290
|
}
|
|
1157
1291
|
return emitter;
|
|
1158
1292
|
}
|
|
1293
|
+
signAndSendEvmPermitTransaction({
|
|
1294
|
+
address,
|
|
1295
|
+
id,
|
|
1296
|
+
isPassConfirmation,
|
|
1297
|
+
step,
|
|
1298
|
+
transaction,
|
|
1299
|
+
url
|
|
1300
|
+
}) {
|
|
1301
|
+
// Allow sign transaction
|
|
1302
|
+
const canSign = true;
|
|
1303
|
+
const emitter = new EventEmitter();
|
|
1304
|
+
const eventData = {
|
|
1305
|
+
id,
|
|
1306
|
+
errors: [],
|
|
1307
|
+
warnings: [],
|
|
1308
|
+
extrinsicHash: id,
|
|
1309
|
+
processId: step === null || step === void 0 ? void 0 : step.processId
|
|
1310
|
+
};
|
|
1311
|
+
const evmSignaturePayload = {
|
|
1312
|
+
id: id,
|
|
1313
|
+
type: 'eth_signTypedData_v4',
|
|
1314
|
+
payload: transaction,
|
|
1315
|
+
address: address,
|
|
1316
|
+
hashPayload: '',
|
|
1317
|
+
canSign: canSign,
|
|
1318
|
+
processId: step === null || step === void 0 ? void 0 : step.processId
|
|
1319
|
+
};
|
|
1320
|
+
this.state.requestService.addConfirmation(id, url || EXTENSION_REQUEST_URL, 'evmSignatureRequest', evmSignaturePayload, {
|
|
1321
|
+
isPassConfirmation
|
|
1322
|
+
}).then(({
|
|
1323
|
+
isApproved,
|
|
1324
|
+
payload: signature
|
|
1325
|
+
}) => {
|
|
1326
|
+
if (isApproved) {
|
|
1327
|
+
// Emit signed event
|
|
1328
|
+
emitter.emit('signed', eventData);
|
|
1329
|
+
emitter.emit('send', eventData); // This event is needed after sending transaction with queue
|
|
1330
|
+
|
|
1331
|
+
if (!signature) {
|
|
1332
|
+
throw new EvmProviderError(EvmProviderErrorType.UNAUTHORIZED, t('Failed to sign'));
|
|
1333
|
+
}
|
|
1334
|
+
eventData.extrinsicHash = signature;
|
|
1335
|
+
emitter.emit('extrinsicHash', eventData);
|
|
1336
|
+
emitter.emit('success', eventData);
|
|
1337
|
+
} else {
|
|
1338
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.USER_REJECT_REQUEST));
|
|
1339
|
+
emitter.emit('error', eventData);
|
|
1340
|
+
}
|
|
1341
|
+
}).catch(e => {
|
|
1342
|
+
this.removeTransaction(id);
|
|
1343
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SIGN, t(e.message)));
|
|
1344
|
+
emitter.emit('error', eventData);
|
|
1345
|
+
});
|
|
1346
|
+
return emitter;
|
|
1347
|
+
}
|
|
1159
1348
|
signAndSendSubstrateTransaction({
|
|
1160
1349
|
address,
|
|
1161
1350
|
chain,
|
|
1162
1351
|
feeCustom,
|
|
1163
1352
|
id,
|
|
1164
|
-
nonNativeTokenPayFeeSlug,
|
|
1165
1353
|
signAfterCreate,
|
|
1166
1354
|
step,
|
|
1355
|
+
tokenPayFeeSlug,
|
|
1167
1356
|
transaction,
|
|
1168
1357
|
url
|
|
1169
1358
|
}) {
|
|
1170
1359
|
var _this$state$chainServ;
|
|
1171
1360
|
const tip = (feeCustom === null || feeCustom === void 0 ? void 0 : feeCustom.tip) || '0';
|
|
1172
|
-
const feeAssetId =
|
|
1361
|
+
const feeAssetId = tokenPayFeeSlug && !_isNativeTokenBySlug(tokenPayFeeSlug) && _SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(chain) ? (_this$state$chainServ = this.state.chainService.getAssetBySlug(tokenPayFeeSlug).metadata) === null || _this$state$chainServ === void 0 ? void 0 : _this$state$chainServ.multilocation : undefined;
|
|
1173
1362
|
const emitter = new EventEmitter();
|
|
1174
1363
|
const eventData = {
|
|
1175
1364
|
id,
|
|
@@ -1313,7 +1502,7 @@ export default class TransactionService {
|
|
|
1313
1502
|
});
|
|
1314
1503
|
});
|
|
1315
1504
|
};
|
|
1316
|
-
const tonTransactionConfig = transaction;
|
|
1505
|
+
const tonTransactionConfig = transaction; // todo: is this same as payload?
|
|
1317
1506
|
const seqno = tonTransactionConfig.seqno;
|
|
1318
1507
|
const messages = tonTransactionConfig.messages;
|
|
1319
1508
|
const transferObjectPromise = getTransferCellPromise(walletContract, signer, payload, seqno, messages);
|
|
@@ -1359,6 +1548,73 @@ export default class TransactionService {
|
|
|
1359
1548
|
});
|
|
1360
1549
|
return emitter;
|
|
1361
1550
|
}
|
|
1551
|
+
signAndSendCardanoTransaction({
|
|
1552
|
+
chain,
|
|
1553
|
+
id,
|
|
1554
|
+
transaction,
|
|
1555
|
+
url
|
|
1556
|
+
}) {
|
|
1557
|
+
const emitter = new EventEmitter();
|
|
1558
|
+
const eventData = {
|
|
1559
|
+
id,
|
|
1560
|
+
errors: [],
|
|
1561
|
+
warnings: [],
|
|
1562
|
+
extrinsicHash: id
|
|
1563
|
+
};
|
|
1564
|
+
const transactionConfig = transaction;
|
|
1565
|
+
const cardanoApi = this.state.chainService.getCardanoApi(chain);
|
|
1566
|
+
this.state.requestService.addConfirmationCardano(id, url || EXTENSION_REQUEST_URL, 'cardanoSendTransactionRequest', transactionConfig, {}).then(({
|
|
1567
|
+
isApproved,
|
|
1568
|
+
payload
|
|
1569
|
+
}) => {
|
|
1570
|
+
if (!isApproved) {
|
|
1571
|
+
this.removeTransaction(id);
|
|
1572
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.USER_REJECT_REQUEST));
|
|
1573
|
+
emitter.emit('error', eventData);
|
|
1574
|
+
} else {
|
|
1575
|
+
if (!payload) {
|
|
1576
|
+
throw new Error('Failed to sign');
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
// Emit signed event
|
|
1580
|
+
emitter.emit('signed', eventData);
|
|
1581
|
+
|
|
1582
|
+
// Send transaction
|
|
1583
|
+
this.handleTransactionTimeout(emitter, eventData);
|
|
1584
|
+
emitter.emit('send', eventData);
|
|
1585
|
+
|
|
1586
|
+
// send qua api
|
|
1587
|
+
cardanoApi.sendCardanoTxReturnHash(payload).then(txHash => {
|
|
1588
|
+
if (!txHash) {
|
|
1589
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.SEND_TRANSACTION_FAILED));
|
|
1590
|
+
emitter.emit('error', eventData);
|
|
1591
|
+
}
|
|
1592
|
+
eventData.extrinsicHash = txHash;
|
|
1593
|
+
emitter.emit('extrinsicHash', eventData);
|
|
1594
|
+
|
|
1595
|
+
// todo: wait transaction by fetch txHash by API
|
|
1596
|
+
cardanoApi.getStatusByTxHash(txHash, transactionConfig.cardanoTtlOffset).then(status => {
|
|
1597
|
+
if (!status) {
|
|
1598
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.SEND_TRANSACTION_FAILED));
|
|
1599
|
+
emitter.emit('error', eventData);
|
|
1600
|
+
}
|
|
1601
|
+
emitter.emit('success', eventData);
|
|
1602
|
+
}).catch(e => {
|
|
1603
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.SEND_TRANSACTION_FAILED, e.message));
|
|
1604
|
+
emitter.emit('error', eventData);
|
|
1605
|
+
});
|
|
1606
|
+
}).catch(e => {
|
|
1607
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.SEND_TRANSACTION_FAILED, e.message));
|
|
1608
|
+
emitter.emit('error', eventData);
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
}).catch(e => {
|
|
1612
|
+
this.removeTransaction(id);
|
|
1613
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SIGN, t(e.message)));
|
|
1614
|
+
emitter.emit('error', eventData);
|
|
1615
|
+
});
|
|
1616
|
+
return emitter;
|
|
1617
|
+
}
|
|
1362
1618
|
handleTransactionTimeout(emitter, eventData) {
|
|
1363
1619
|
const timeout = setTimeout(() => {
|
|
1364
1620
|
const transaction = this.getTransaction(eventData.id);
|
|
@@ -1501,9 +1757,9 @@ export default class TransactionService {
|
|
|
1501
1757
|
}
|
|
1502
1758
|
}
|
|
1503
1759
|
async createProcessNotification(transactionId) {
|
|
1504
|
-
var _transaction$
|
|
1760
|
+
var _transaction$step3;
|
|
1505
1761
|
const transaction = this.getTransaction(transactionId);
|
|
1506
|
-
if (transaction && (_transaction$
|
|
1762
|
+
if (transaction && (_transaction$step3 = transaction.step) !== null && _transaction$step3 !== void 0 && _transaction$step3.processId) {
|
|
1507
1763
|
const process = this.aliveProcessMap.get(transaction.step.processId);
|
|
1508
1764
|
if (process) {
|
|
1509
1765
|
await this.state.inappNotificationService.createProcessNotification(process);
|