@subwallet/extension-base 1.3.21-0 → 1.3.23-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 +75 -2
- package/background/KoniTypes.js +2 -0
- package/cjs/background/KoniTypes.js +2 -0
- package/cjs/constants/environment.js +4 -2
- package/cjs/constants/signing.js +6 -2
- package/cjs/core/logic-validation/recipientAddress.js +9 -1
- package/cjs/core/logic-validation/transfer.js +35 -29
- 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 +234 -96
- package/cjs/koni/background/handlers/State.js +15 -0
- 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/token.js +4 -4
- package/cjs/services/chain-service/constants.js +8 -3
- 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/SubstrateChainHandler.js +3 -2
- package/cjs/services/chain-service/handler/TonApi.js +2 -5
- package/cjs/services/chain-service/index.js +38 -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/constants/chains.js +2 -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/handlers/native-staking/mythos.js +337 -0
- package/cjs/services/earning-service/service.js +10 -12
- package/cjs/services/earning-service/utils/index.js +2 -0
- package/cjs/services/fee-service/service.js +19 -8
- 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/migration-service/scripts/databases/ClearMetadataDatabase.js +3 -23
- package/cjs/services/migration-service/scripts/databases/ClearMetadataForChains.js +40 -0
- package/cjs/services/migration-service/scripts/databases/ClearMetadataForMythos.js +15 -0
- package/cjs/services/migration-service/scripts/index.js +6 -2
- 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/index.js +20 -2
- package/cjs/services/setting-service/constants.js +10 -1
- package/cjs/services/storage-service/DatabaseService.js +6 -0
- package/cjs/services/storage-service/db-stores/InappNotification.js +6 -0
- package/cjs/services/storage-service/db-stores/Metadata.js +3 -0
- package/cjs/services/storage-service/db-stores/Migration.js +6 -1
- 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 +278 -21
- 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 +40 -7
- 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/signing.js +6 -2
- package/core/logic-validation/recipientAddress.js +11 -3
- package/core/logic-validation/transfer.js +9 -3
- 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 +144 -8
- package/koni/background/handlers/State.d.ts +5 -1
- package/koni/background/handlers/State.js +16 -1
- package/package.json +102 -25
- 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/token.d.ts +1 -1
- package/services/balance-service/transfer/token.js +2 -2
- package/services/chain-service/constants.js +8 -3
- 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/SubstrateChainHandler.js +3 -2
- 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 +38 -7
- 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/constants/chains.d.ts +1 -0
- package/services/earning-service/constants/chains.js +2 -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/handlers/native-staking/mythos.d.ts +35 -0
- package/services/earning-service/handlers/native-staking/mythos.js +329 -0
- package/services/earning-service/service.js +12 -14
- package/services/earning-service/utils/index.js +2 -0
- package/services/fee-service/service.js +19 -8
- 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/migration-service/scripts/databases/ClearMetadataDatabase.d.ts +3 -3
- package/services/migration-service/scripts/databases/ClearMetadataDatabase.js +3 -23
- package/services/migration-service/scripts/databases/ClearMetadataForChains.d.ts +5 -0
- package/services/migration-service/scripts/databases/ClearMetadataForChains.js +32 -0
- package/services/migration-service/scripts/databases/ClearMetadataForMythos.d.ts +4 -0
- package/services/migration-service/scripts/databases/ClearMetadataForMythos.js +7 -0
- package/services/migration-service/scripts/index.d.ts +1 -0
- package/services/migration-service/scripts/index.js +4 -1
- 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/index.d.ts +6 -3
- package/services/request-service/index.js +19 -5
- package/services/setting-service/constants.d.ts +3 -0
- package/services/setting-service/constants.js +6 -0
- package/services/storage-service/DatabaseService.d.ts +2 -0
- package/services/storage-service/DatabaseService.js +6 -0
- package/services/storage-service/db-stores/InappNotification.d.ts +1 -0
- package/services/storage-service/db-stores/InappNotification.js +6 -0
- package/services/storage-service/db-stores/Metadata.d.ts +1 -0
- package/services/storage-service/db-stores/Metadata.js +3 -0
- package/services/storage-service/db-stores/Migration.d.ts +1 -0
- package/services/storage-service/db-stores/Migration.js +6 -1
- 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 +263 -10
- 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/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 +2 -1
- package/utils/fee/transfer.js +44 -11
- 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>;
|
|
@@ -11,7 +11,7 @@ import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _get
|
|
|
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
|
}
|
|
@@ -103,9 +104,13 @@ export default class TransactionService {
|
|
|
103
104
|
const substrateApi = this.state.chainService.getSubstrateApi(chainInfo.slug);
|
|
104
105
|
const evmApi = this.state.chainService.getEvmApi(chainInfo.slug);
|
|
105
106
|
const tonApi = this.state.chainService.getTonApi(chainInfo.slug);
|
|
106
|
-
const
|
|
107
|
+
const cardanoApi = this.state.chainService.getCardanoApi(chainInfo.slug);
|
|
108
|
+
// todo: should split into isEvmTx && isNoEvmApi. Because other chains type also has no Evm Api. Same to all blockchain.
|
|
109
|
+
// todo: refactor check evmTransaction.
|
|
110
|
+
const isNoEvmApi = transaction && !isSubstrateTransaction(transaction) && !isTonTransaction(transaction) && !isCardanoTransaction(transaction) && !evmApi;
|
|
107
111
|
const isNoTonApi = transaction && isTonTransaction(transaction) && !tonApi;
|
|
108
|
-
|
|
112
|
+
const isNoCardanoApi = transaction && isCardanoTransaction(transaction) && !cardanoApi;
|
|
113
|
+
if (isNoEvmApi || isNoTonApi || isNoCardanoApi) {
|
|
109
114
|
validationResponse.errors.push(new TransactionError(BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
|
|
110
115
|
}
|
|
111
116
|
|
|
@@ -169,6 +174,10 @@ export default class TransactionService {
|
|
|
169
174
|
}
|
|
170
175
|
};
|
|
171
176
|
}
|
|
177
|
+
getCacheInfo(processId, step) {
|
|
178
|
+
var _this$cacheProcessInf;
|
|
179
|
+
return ((_this$cacheProcessInf = this.cacheProcessInfo[processId]) === null || _this$cacheProcessInf === void 0 ? void 0 : _this$cacheProcessInf[step]) || '';
|
|
180
|
+
}
|
|
172
181
|
updateAliveProcess() {
|
|
173
182
|
this.aliveProcessSubject.next(this.aliveProcessMap);
|
|
174
183
|
}
|
|
@@ -263,9 +272,61 @@ export default class TransactionService {
|
|
|
263
272
|
'eventsHandler' in validatedTransaction && delete validatedTransaction.eventsHandler;
|
|
264
273
|
return validatedTransaction;
|
|
265
274
|
}
|
|
275
|
+
async handlePermitTransaction(transaction) {
|
|
276
|
+
var _transaction$step;
|
|
277
|
+
const transactionId = getTransactionId(transaction.chainType, transaction.chain, true);
|
|
278
|
+
const validatedTransaction = {
|
|
279
|
+
...transaction,
|
|
280
|
+
id: transactionId,
|
|
281
|
+
extrinsicHash: '',
|
|
282
|
+
status: undefined,
|
|
283
|
+
errors: transaction.errors || [],
|
|
284
|
+
warnings: transaction.warnings || [],
|
|
285
|
+
processId: (_transaction$step = transaction.step) === null || _transaction$step === void 0 ? void 0 : _transaction$step.processId
|
|
286
|
+
};
|
|
287
|
+
const txInput = {
|
|
288
|
+
...transaction,
|
|
289
|
+
isInternal: true,
|
|
290
|
+
status: ExtrinsicStatus.QUEUED,
|
|
291
|
+
id: transactionId,
|
|
292
|
+
extrinsicHash: transactionId,
|
|
293
|
+
createdAt: new Date().getTime(),
|
|
294
|
+
updatedAt: new Date().getTime()
|
|
295
|
+
};
|
|
296
|
+
const _data = transaction.data;
|
|
297
|
+
const emitter = this.sendPermitTransaction(txInput);
|
|
298
|
+
await new Promise((resolve, reject) => {
|
|
299
|
+
emitter.on('success', data => {
|
|
300
|
+
validatedTransaction.id = data.id;
|
|
301
|
+
validatedTransaction.extrinsicHash = data.extrinsicHash;
|
|
302
|
+
this.cacheProcessInfo[_data.processId] = {
|
|
303
|
+
[_data.step]: data.extrinsicHash
|
|
304
|
+
};
|
|
305
|
+
resolve();
|
|
306
|
+
});
|
|
307
|
+
emitter.on('error', data => {
|
|
308
|
+
if (data.errors.length > 0) {
|
|
309
|
+
validatedTransaction.errors.push(...data.errors);
|
|
310
|
+
resolve();
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
emitter.on('timeout', data => {
|
|
314
|
+
if (transaction.errorOnTimeOut && data.errors.length > 0) {
|
|
315
|
+
validatedTransaction.errors.push(...data.errors);
|
|
316
|
+
resolve();
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// @ts-ignore
|
|
322
|
+
'transaction' in validatedTransaction && delete validatedTransaction.transaction;
|
|
323
|
+
'additionalValidator' in validatedTransaction && delete validatedTransaction.additionalValidator;
|
|
324
|
+
'eventsHandler' in validatedTransaction && delete validatedTransaction.eventsHandler;
|
|
325
|
+
return validatedTransaction;
|
|
326
|
+
}
|
|
266
327
|
async sendTransaction(transaction) {
|
|
267
328
|
// Send Transaction
|
|
268
|
-
const emitter = await (transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : transaction.chainType === 'evm' ? this.signAndSendEvmTransaction(transaction) : this.signAndSendTonTransaction(transaction));
|
|
329
|
+
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
330
|
const {
|
|
270
331
|
eventsHandler,
|
|
271
332
|
step
|
|
@@ -315,7 +376,12 @@ export default class TransactionService {
|
|
|
315
376
|
}
|
|
316
377
|
return false;
|
|
317
378
|
});
|
|
318
|
-
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Now simple check, first step have step id = 1.
|
|
382
|
+
* Improve to fetch the process from db
|
|
383
|
+
* */
|
|
384
|
+
if (rejectError && step.stepId === 1) {
|
|
319
385
|
this.deleteProcess(step);
|
|
320
386
|
} else {
|
|
321
387
|
this.updateProcessStepStatus(step, {
|
|
@@ -341,6 +407,71 @@ export default class TransactionService {
|
|
|
341
407
|
eventsHandler === null || eventsHandler === void 0 ? void 0 : eventsHandler(emitter);
|
|
342
408
|
return emitter;
|
|
343
409
|
}
|
|
410
|
+
sendPermitTransaction(transaction) {
|
|
411
|
+
// Send Transaction
|
|
412
|
+
const emitter = this.signAndSendEvmPermitTransaction(transaction);
|
|
413
|
+
const {
|
|
414
|
+
eventsHandler,
|
|
415
|
+
step
|
|
416
|
+
} = transaction;
|
|
417
|
+
emitter.on('send', data => {
|
|
418
|
+
if (step) {
|
|
419
|
+
this.updateProcessStepStatus(step, {
|
|
420
|
+
transactionId: transaction.id,
|
|
421
|
+
status: StepStatus.SUBMITTING,
|
|
422
|
+
chain: transaction.chain
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
emitter.on('extrinsicHash', data => {
|
|
427
|
+
if (step) {
|
|
428
|
+
this.updateProcessStepStatus(step, {
|
|
429
|
+
extrinsicHash: data.extrinsicHash,
|
|
430
|
+
status: StepStatus.PROCESSING
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
emitter.on('success', data => {
|
|
435
|
+
if (step) {
|
|
436
|
+
this.updateProcessStepStatus(step, {
|
|
437
|
+
status: StepStatus.COMPLETE
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
emitter.on('error', data => {
|
|
442
|
+
// this.handlePostProcessing(data.id); // might enable this later
|
|
443
|
+
this.onFailed({
|
|
444
|
+
...data,
|
|
445
|
+
errors: [...data.errors, new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]
|
|
446
|
+
});
|
|
447
|
+
if (step) {
|
|
448
|
+
const rejectError = data.errors.find(error => {
|
|
449
|
+
// TODO: REFACTOR ERROR CODE
|
|
450
|
+
if ([BasicTxErrorType.UNABLE_TO_SIGN, BasicTxErrorType.USER_REJECT_REQUEST].includes(error.errorType)) {
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
return false;
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Now simple check, first step have step id = 1.
|
|
458
|
+
* Improve to fetch the process from db
|
|
459
|
+
* */
|
|
460
|
+
if (rejectError && step.stepId === 1) {
|
|
461
|
+
this.deleteProcess(step);
|
|
462
|
+
} else {
|
|
463
|
+
this.updateProcessStepStatus(step, {
|
|
464
|
+
status: StepStatus.FAILED
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// Todo: handle any event with transaction.eventsHandler
|
|
471
|
+
|
|
472
|
+
eventsHandler === null || eventsHandler === void 0 ? void 0 : eventsHandler(emitter);
|
|
473
|
+
return emitter;
|
|
474
|
+
}
|
|
344
475
|
removeTransaction(id) {
|
|
345
476
|
if (this.transactions[id]) {
|
|
346
477
|
delete this.transactions[id];
|
|
@@ -364,7 +495,7 @@ export default class TransactionService {
|
|
|
364
495
|
return getExplorerLink(chainInfo, transaction.extrinsicHash, 'tx');
|
|
365
496
|
}
|
|
366
497
|
transactionToHistories(id, startBlock, nonce, eventLogs) {
|
|
367
|
-
var _transaction$
|
|
498
|
+
var _transaction$step2;
|
|
368
499
|
const transaction = this.getTransaction(id);
|
|
369
500
|
const extrinsicType = transaction.extrinsicType;
|
|
370
501
|
const chainInfo = this.state.chainService.getChainInfoByKey(transaction.chain);
|
|
@@ -389,7 +520,7 @@ export default class TransactionService {
|
|
|
389
520
|
// Will be added in next step
|
|
390
521
|
nonce: nonce !== null && nonce !== void 0 ? nonce : 0,
|
|
391
522
|
startBlock: startBlock || 0,
|
|
392
|
-
processId: (_transaction$
|
|
523
|
+
processId: (_transaction$step2 = transaction.step) === null || _transaction$step2 === void 0 ? void 0 : _transaction$step2.processId
|
|
393
524
|
};
|
|
394
525
|
const nativeAsset = _getChainNativeTokenBasicInfo(chainInfo);
|
|
395
526
|
const baseNativeAmount = {
|
|
@@ -1156,6 +1287,61 @@ export default class TransactionService {
|
|
|
1156
1287
|
}
|
|
1157
1288
|
return emitter;
|
|
1158
1289
|
}
|
|
1290
|
+
signAndSendEvmPermitTransaction({
|
|
1291
|
+
address,
|
|
1292
|
+
id,
|
|
1293
|
+
isPassConfirmation,
|
|
1294
|
+
step,
|
|
1295
|
+
transaction,
|
|
1296
|
+
url
|
|
1297
|
+
}) {
|
|
1298
|
+
// Allow sign transaction
|
|
1299
|
+
const canSign = true;
|
|
1300
|
+
const emitter = new EventEmitter();
|
|
1301
|
+
const eventData = {
|
|
1302
|
+
id,
|
|
1303
|
+
errors: [],
|
|
1304
|
+
warnings: [],
|
|
1305
|
+
extrinsicHash: id,
|
|
1306
|
+
processId: step === null || step === void 0 ? void 0 : step.processId
|
|
1307
|
+
};
|
|
1308
|
+
const evmSignaturePayload = {
|
|
1309
|
+
id: id,
|
|
1310
|
+
type: 'eth_signTypedData_v4',
|
|
1311
|
+
payload: transaction,
|
|
1312
|
+
address: address,
|
|
1313
|
+
hashPayload: '',
|
|
1314
|
+
canSign: canSign,
|
|
1315
|
+
processId: step === null || step === void 0 ? void 0 : step.processId
|
|
1316
|
+
};
|
|
1317
|
+
this.state.requestService.addConfirmation(id, url || EXTENSION_REQUEST_URL, 'evmSignatureRequest', evmSignaturePayload, {
|
|
1318
|
+
isPassConfirmation
|
|
1319
|
+
}).then(({
|
|
1320
|
+
isApproved,
|
|
1321
|
+
payload: signature
|
|
1322
|
+
}) => {
|
|
1323
|
+
if (isApproved) {
|
|
1324
|
+
// Emit signed event
|
|
1325
|
+
emitter.emit('signed', eventData);
|
|
1326
|
+
emitter.emit('send', eventData); // This event is needed after sending transaction with queue
|
|
1327
|
+
|
|
1328
|
+
if (!signature) {
|
|
1329
|
+
throw new EvmProviderError(EvmProviderErrorType.UNAUTHORIZED, t('Failed to sign'));
|
|
1330
|
+
}
|
|
1331
|
+
eventData.extrinsicHash = signature;
|
|
1332
|
+
emitter.emit('extrinsicHash', eventData);
|
|
1333
|
+
emitter.emit('success', eventData);
|
|
1334
|
+
} else {
|
|
1335
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.USER_REJECT_REQUEST));
|
|
1336
|
+
emitter.emit('error', eventData);
|
|
1337
|
+
}
|
|
1338
|
+
}).catch(e => {
|
|
1339
|
+
this.removeTransaction(id);
|
|
1340
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SIGN, t(e.message)));
|
|
1341
|
+
emitter.emit('error', eventData);
|
|
1342
|
+
});
|
|
1343
|
+
return emitter;
|
|
1344
|
+
}
|
|
1159
1345
|
signAndSendSubstrateTransaction({
|
|
1160
1346
|
address,
|
|
1161
1347
|
chain,
|
|
@@ -1313,7 +1499,7 @@ export default class TransactionService {
|
|
|
1313
1499
|
});
|
|
1314
1500
|
});
|
|
1315
1501
|
};
|
|
1316
|
-
const tonTransactionConfig = transaction;
|
|
1502
|
+
const tonTransactionConfig = transaction; // todo: is this same as payload?
|
|
1317
1503
|
const seqno = tonTransactionConfig.seqno;
|
|
1318
1504
|
const messages = tonTransactionConfig.messages;
|
|
1319
1505
|
const transferObjectPromise = getTransferCellPromise(walletContract, signer, payload, seqno, messages);
|
|
@@ -1359,6 +1545,73 @@ export default class TransactionService {
|
|
|
1359
1545
|
});
|
|
1360
1546
|
return emitter;
|
|
1361
1547
|
}
|
|
1548
|
+
signAndSendCardanoTransaction({
|
|
1549
|
+
chain,
|
|
1550
|
+
id,
|
|
1551
|
+
transaction,
|
|
1552
|
+
url
|
|
1553
|
+
}) {
|
|
1554
|
+
const emitter = new EventEmitter();
|
|
1555
|
+
const eventData = {
|
|
1556
|
+
id,
|
|
1557
|
+
errors: [],
|
|
1558
|
+
warnings: [],
|
|
1559
|
+
extrinsicHash: id
|
|
1560
|
+
};
|
|
1561
|
+
const transactionConfig = transaction;
|
|
1562
|
+
const cardanoApi = this.state.chainService.getCardanoApi(chain);
|
|
1563
|
+
this.state.requestService.addConfirmationCardano(id, url || EXTENSION_REQUEST_URL, 'cardanoSendTransactionRequest', transactionConfig, {}).then(({
|
|
1564
|
+
isApproved,
|
|
1565
|
+
payload
|
|
1566
|
+
}) => {
|
|
1567
|
+
if (!isApproved) {
|
|
1568
|
+
this.removeTransaction(id);
|
|
1569
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.USER_REJECT_REQUEST));
|
|
1570
|
+
emitter.emit('error', eventData);
|
|
1571
|
+
} else {
|
|
1572
|
+
if (!payload) {
|
|
1573
|
+
throw new Error('Failed to sign');
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
// Emit signed event
|
|
1577
|
+
emitter.emit('signed', eventData);
|
|
1578
|
+
|
|
1579
|
+
// Send transaction
|
|
1580
|
+
this.handleTransactionTimeout(emitter, eventData);
|
|
1581
|
+
emitter.emit('send', eventData);
|
|
1582
|
+
|
|
1583
|
+
// send qua api
|
|
1584
|
+
cardanoApi.sendCardanoTxReturnHash(payload).then(txHash => {
|
|
1585
|
+
if (!txHash) {
|
|
1586
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.SEND_TRANSACTION_FAILED));
|
|
1587
|
+
emitter.emit('error', eventData);
|
|
1588
|
+
}
|
|
1589
|
+
eventData.extrinsicHash = txHash;
|
|
1590
|
+
emitter.emit('extrinsicHash', eventData);
|
|
1591
|
+
|
|
1592
|
+
// todo: wait transaction by fetch txHash by API
|
|
1593
|
+
cardanoApi.getStatusByTxHash(txHash, transactionConfig.cardanoTtlOffset).then(status => {
|
|
1594
|
+
if (!status) {
|
|
1595
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.SEND_TRANSACTION_FAILED));
|
|
1596
|
+
emitter.emit('error', eventData);
|
|
1597
|
+
}
|
|
1598
|
+
emitter.emit('success', eventData);
|
|
1599
|
+
}).catch(e => {
|
|
1600
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.SEND_TRANSACTION_FAILED, e.message));
|
|
1601
|
+
emitter.emit('error', eventData);
|
|
1602
|
+
});
|
|
1603
|
+
}).catch(e => {
|
|
1604
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.SEND_TRANSACTION_FAILED, e.message));
|
|
1605
|
+
emitter.emit('error', eventData);
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
}).catch(e => {
|
|
1609
|
+
this.removeTransaction(id);
|
|
1610
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SIGN, t(e.message)));
|
|
1611
|
+
emitter.emit('error', eventData);
|
|
1612
|
+
});
|
|
1613
|
+
return emitter;
|
|
1614
|
+
}
|
|
1362
1615
|
handleTransactionTimeout(emitter, eventData) {
|
|
1363
1616
|
const timeout = setTimeout(() => {
|
|
1364
1617
|
const transaction = this.getTransaction(eventData.id);
|
|
@@ -1501,9 +1754,9 @@ export default class TransactionService {
|
|
|
1501
1754
|
}
|
|
1502
1755
|
}
|
|
1503
1756
|
async createProcessNotification(transactionId) {
|
|
1504
|
-
var _transaction$
|
|
1757
|
+
var _transaction$step3;
|
|
1505
1758
|
const transaction = this.getTransaction(transactionId);
|
|
1506
|
-
if (transaction && (_transaction$
|
|
1759
|
+
if (transaction && (_transaction$step3 = transaction.step) !== null && _transaction$step3 !== void 0 && _transaction$step3.processId) {
|
|
1507
1760
|
const process = this.aliveProcessMap.get(transaction.step.processId);
|
|
1508
1761
|
if (process) {
|
|
1509
1762
|
await this.state.inappNotificationService.createProcessNotification(process);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ChainType, ExtrinsicDataTypeMap, ExtrinsicStatus, ExtrinsicType, FeeData, ValidateTransactionResponse } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { SignTypedDataMessageV3V4 } from '@subwallet/extension-base/core/logic-validation';
|
|
2
3
|
import { TonTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
3
4
|
import { BaseRequestSign, BriefProcessStep, ProcessTransactionData, TransactionFee } from '@subwallet/extension-base/types';
|
|
4
5
|
import EventEmitter from 'eventemitter3';
|
|
@@ -27,6 +28,9 @@ export interface SWTransaction extends ValidateTransactionResponse, Partial<Pick
|
|
|
27
28
|
signAfterCreate?: (id: string) => void;
|
|
28
29
|
step?: BriefProcessStep;
|
|
29
30
|
}
|
|
31
|
+
export interface SWPermitTransaction extends Omit<SWTransaction, 'transaction'> {
|
|
32
|
+
transaction: SignTypedDataMessageV3V4;
|
|
33
|
+
}
|
|
30
34
|
export interface SWTransactionResult extends Omit<SWTransaction, 'transaction' | 'additionalValidator' | 'eventsHandler' | 'process'> {
|
|
31
35
|
process?: ProcessTransactionData;
|
|
32
36
|
}
|
|
@@ -42,6 +46,9 @@ export interface SWTransactionInput extends SwInputBase, Partial<Pick<SWTransact
|
|
|
42
46
|
resolveOnDone?: boolean;
|
|
43
47
|
skipFeeValidation?: boolean;
|
|
44
48
|
}
|
|
49
|
+
export interface SWPermitTransactionInput extends Omit<SWTransactionInput, 'transaction'> {
|
|
50
|
+
transaction?: SWPermitTransaction['transaction'] | null;
|
|
51
|
+
}
|
|
45
52
|
export declare type SWTransactionResponse = SwInputBase & Pick<SWTransaction, 'warnings' | 'errors'> & Partial<Pick<SWTransaction, 'id' | 'extrinsicHash' | 'status' | 'estimateFee'>> & TransactionFee & {
|
|
46
53
|
processId?: string;
|
|
47
54
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { _getBlockExplorerFromChain, _isChainTestNet, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
4
|
+
import { _getBlockExplorerFromChain, _isChainTestNet, _isPureCardanoChain, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
5
|
import { CHAIN_FLIP_MAINNET_EXPLORER, CHAIN_FLIP_TESTNET_EXPLORER, SIMPLE_SWAP_EXPLORER } from '@subwallet/extension-base/services/swap-service/utils';
|
|
6
|
+
import { hexAddPrefix, isHex } from '@polkadot/util';
|
|
7
|
+
|
|
6
8
|
// @ts-ignore
|
|
7
9
|
export function parseTransactionData(data) {
|
|
8
10
|
// @ts-ignore
|
|
@@ -46,6 +48,9 @@ function getBlockExplorerTxRoute(chainInfo) {
|
|
|
46
48
|
if (_isPureEvmChain(chainInfo)) {
|
|
47
49
|
return 'tx';
|
|
48
50
|
}
|
|
51
|
+
if (_isPureCardanoChain(chainInfo)) {
|
|
52
|
+
return 'transaction';
|
|
53
|
+
}
|
|
49
54
|
if (['aventus', 'deeper_network'].includes(chainInfo.slug)) {
|
|
50
55
|
return 'transaction';
|
|
51
56
|
}
|
|
@@ -60,7 +65,7 @@ export function getExplorerLink(chainInfo, value, type) {
|
|
|
60
65
|
const route = getBlockExplorerAccountRoute(explorerLink);
|
|
61
66
|
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
|
|
62
67
|
}
|
|
63
|
-
if (explorerLink && value
|
|
68
|
+
if (explorerLink && isHex(hexAddPrefix(value))) {
|
|
64
69
|
if (chainInfo.slug === 'bittensor') {
|
|
65
70
|
return undefined;
|
|
66
71
|
}
|
|
@@ -112,8 +112,11 @@ export declare enum AccountChainType {
|
|
|
112
112
|
SUBSTRATE = "substrate",
|
|
113
113
|
ETHEREUM = "ethereum",
|
|
114
114
|
BITCOIN = "bitcoin",
|
|
115
|
-
TON = "ton"
|
|
115
|
+
TON = "ton",
|
|
116
|
+
CARDANO = "cardano"
|
|
116
117
|
}
|
|
118
|
+
export declare const ACCOUNT_CHAIN_TYPE_ORDINAL_MAP: Record<string, number>;
|
|
119
|
+
export declare const SUPPORTED_ACCOUNT_CHAIN_TYPES: string[];
|
|
117
120
|
export declare enum AccountActions {
|
|
118
121
|
DERIVE = "DERIVE",
|
|
119
122
|
EXPORT_MNEMONIC = "EXPORT_MNEMONIC",
|