@subwallet/extension-base 1.3.40-0 → 1.3.42-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 +121 -4
- package/background/KoniTypes.js +18 -0
- package/background/errors/BitcoinProviderError.d.ts +6 -0
- package/background/errors/BitcoinProviderError.js +47 -0
- package/cjs/background/KoniTypes.js +20 -1
- package/cjs/background/errors/BitcoinProviderError.js +54 -0
- package/cjs/constants/bitcoin.js +22 -0
- package/cjs/constants/environment.js +4 -2
- package/cjs/constants/index.js +16 -1
- package/cjs/core/logic-validation/recipientAddress.js +9 -0
- package/cjs/core/logic-validation/transfer.js +25 -5
- package/cjs/core/types.js +1 -0
- package/cjs/core/utils.js +15 -1
- package/cjs/koni/background/handlers/Extension.js +96 -41
- package/cjs/koni/background/handlers/State.js +52 -11
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/bitcoin.js +94 -0
- package/cjs/services/balance-service/helpers/subscribe/evm.js +6 -1
- package/cjs/services/balance-service/helpers/subscribe/index.js +19 -7
- package/cjs/services/balance-service/index.js +32 -4
- package/cjs/services/balance-service/transfer/bitcoin-transfer.js +119 -0
- package/cjs/services/balance-service/transfer/token.js +2 -0
- package/cjs/services/balance-service/transfer/xcm/index.js +15 -9
- package/cjs/services/balance-service/transfer/xcm/utils.js +12 -14
- package/cjs/services/base/types.js +2 -0
- package/cjs/services/chain-service/constants.js +18 -6
- package/cjs/services/chain-service/handler/CardanoApi.js +25 -35
- package/cjs/services/chain-service/handler/bitcoin/BitcoinApi.js +105 -0
- package/cjs/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +78 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +371 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +19 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +368 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +302 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
- package/cjs/services/chain-service/index.js +27 -3
- package/cjs/services/chain-service/utils/index.js +57 -4
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/native-staking/tao.js +4 -38
- package/cjs/services/event-service/index.js +4 -0
- package/cjs/services/fee-service/service.js +8 -3
- package/cjs/services/hiro-service/index.js +96 -0
- package/cjs/services/hiro-service/utils/index.js +85 -0
- package/cjs/services/history-service/bitcoin-history.js +58 -0
- package/cjs/services/history-service/helpers/recoverHistoryStatus.js +96 -4
- package/cjs/services/history-service/index.js +41 -3
- package/cjs/services/keyring-service/context/handlers/Derive.js +1 -1
- package/cjs/services/keyring-service/context/handlers/Migration.js +2 -2
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +4 -3
- package/cjs/services/migration-service/scripts/MigrateNewUnifiedAccount.js +29 -0
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/request-service/handler/BitcoinRequestHandler.js +440 -0
- package/cjs/services/request-service/index.js +29 -3
- package/cjs/services/rune-service/index.js +105 -0
- package/cjs/services/swap-service/handler/chainflip-handler.js +29 -18
- package/cjs/services/swap-service/handler/kyber-handler.js +5 -9
- package/cjs/services/swap-service/handler/simpleswap-handler.js +4 -7
- package/cjs/services/swap-service/handler/uniswap-handler.js +5 -12
- package/cjs/services/swap-service/utils.js +46 -37
- package/cjs/services/transaction-service/helpers/index.js +7 -1
- package/cjs/services/transaction-service/index.js +136 -15
- package/cjs/services/transaction-service/utils.js +6 -3
- package/cjs/strategy/api-request-strategy/context/base.js +31 -0
- package/cjs/strategy/api-request-strategy/index.js +90 -0
- package/cjs/strategy/api-request-strategy/types.js +1 -0
- package/cjs/strategy/api-request-strategy/utils/index.js +33 -0
- package/cjs/types/account/info/keyring.js +1 -1
- package/cjs/types/bitcoin.js +24 -0
- package/cjs/types/environment.js +19 -0
- package/cjs/types/fee/bitcoin.js +1 -0
- package/cjs/types/fee/index.js +11 -0
- package/cjs/types/index.js +11 -0
- package/cjs/utils/account/analyze.js +3 -3
- package/cjs/utils/account/common.js +16 -6
- package/cjs/utils/account/derive/info/solo.js +68 -19
- package/cjs/utils/account/derive/info/unified.js +2 -0
- package/cjs/utils/account/derive/validate.js +70 -2
- package/cjs/utils/account/transform.js +11 -5
- package/cjs/utils/bitcoin/common.js +98 -0
- package/cjs/utils/bitcoin/fee.js +21 -0
- package/cjs/utils/bitcoin/index.js +38 -0
- package/cjs/utils/bitcoin/utxo-management.js +281 -0
- package/cjs/utils/environment.js +30 -2
- package/cjs/utils/fee/transfer.js +48 -0
- package/cjs/utils/index.js +15 -1
- package/constants/bitcoin.d.ts +3 -0
- package/constants/bitcoin.js +13 -0
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- package/constants/index.d.ts +2 -0
- package/constants/index.js +3 -1
- package/core/logic-validation/recipientAddress.js +10 -1
- package/core/logic-validation/transfer.d.ts +2 -2
- package/core/logic-validation/transfer.js +27 -7
- package/core/types.d.ts +1 -0
- package/core/types.js +1 -0
- package/core/utils.d.ts +1 -0
- package/core/utils.js +15 -2
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +95 -42
- package/koni/background/handlers/State.d.ts +7 -3
- package/koni/background/handlers/State.js +52 -12
- package/package.json +149 -8
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/bitcoin.d.ts +2 -0
- package/services/balance-service/helpers/subscribe/bitcoin.js +87 -0
- package/services/balance-service/helpers/subscribe/evm.js +6 -1
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/index.js +20 -8
- package/services/balance-service/index.d.ts +2 -0
- package/services/balance-service/index.js +32 -4
- package/services/balance-service/transfer/bitcoin-transfer.d.ts +14 -0
- package/services/balance-service/transfer/bitcoin-transfer.js +112 -0
- package/services/balance-service/transfer/token.js +2 -0
- package/services/balance-service/transfer/xcm/index.js +15 -9
- package/services/balance-service/transfer/xcm/utils.d.ts +2 -0
- package/services/balance-service/transfer/xcm/utils.js +12 -14
- package/services/base/types.d.ts +2 -0
- package/services/base/types.js +2 -0
- package/services/chain-service/constants.d.ts +7 -0
- package/services/chain-service/constants.js +12 -5
- package/services/chain-service/handler/CardanoApi.d.ts +1 -5
- package/services/chain-service/handler/CardanoApi.js +26 -34
- package/services/chain-service/handler/bitcoin/BitcoinApi.d.ts +31 -0
- package/services/chain-service/handler/bitcoin/BitcoinApi.js +98 -0
- package/services/chain-service/handler/bitcoin/BitcoinChainHandler.d.ts +16 -0
- package/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +70 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.d.ts +28 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +362 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.d.ts +2 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +5 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.d.ts +28 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +359 -0
- package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.d.ts +28 -0
- package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +293 -0
- package/services/chain-service/handler/bitcoin/strategy/types.d.ts +291 -0
- package/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
- package/services/chain-service/index.d.ts +3 -0
- package/services/chain-service/index.js +31 -5
- package/services/chain-service/types.d.ts +20 -0
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +50 -4
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/native-staking/tao.d.ts +0 -11
- package/services/earning-service/handlers/native-staking/tao.js +4 -24
- package/services/event-service/index.d.ts +3 -0
- package/services/event-service/index.js +4 -0
- package/services/event-service/types.d.ts +3 -0
- package/services/fee-service/service.js +8 -3
- package/services/hiro-service/index.d.ts +17 -0
- package/services/hiro-service/index.js +88 -0
- package/services/hiro-service/utils/index.d.ts +6 -0
- package/services/hiro-service/utils/index.js +72 -0
- package/services/history-service/bitcoin-history.d.ts +4 -0
- package/services/history-service/bitcoin-history.js +52 -0
- package/services/history-service/helpers/recoverHistoryStatus.d.ts +3 -1
- package/services/history-service/helpers/recoverHistoryStatus.js +96 -4
- package/services/history-service/index.d.ts +1 -0
- package/services/history-service/index.js +42 -4
- package/services/keyring-service/context/handlers/Derive.js +2 -2
- package/services/keyring-service/context/handlers/Migration.js +2 -2
- package/services/keyring-service/context/handlers/Mnemonic.js +4 -3
- package/services/migration-service/scripts/MigrateNewUnifiedAccount.d.ts +4 -0
- package/services/migration-service/scripts/MigrateNewUnifiedAccount.js +21 -0
- package/services/migration-service/scripts/index.js +3 -1
- package/services/request-service/handler/BitcoinRequestHandler.d.ts +23 -0
- package/services/request-service/handler/BitcoinRequestHandler.js +427 -0
- package/services/request-service/index.d.ts +9 -2
- package/services/request-service/index.js +25 -3
- package/services/rune-service/index.d.ts +17 -0
- package/services/rune-service/index.js +97 -0
- package/services/swap-service/handler/chainflip-handler.d.ts +0 -2
- package/services/swap-service/handler/chainflip-handler.js +25 -13
- package/services/swap-service/handler/kyber-handler.d.ts +0 -1
- package/services/swap-service/handler/kyber-handler.js +5 -8
- package/services/swap-service/handler/simpleswap-handler.d.ts +0 -1
- package/services/swap-service/handler/simpleswap-handler.js +4 -6
- package/services/swap-service/handler/uniswap-handler.js +6 -13
- package/services/swap-service/utils.d.ts +0 -13
- package/services/swap-service/utils.js +46 -34
- package/services/transaction-service/helpers/index.d.ts +3 -1
- package/services/transaction-service/helpers/index.js +5 -0
- package/services/transaction-service/index.d.ts +3 -5
- package/services/transaction-service/index.js +135 -16
- package/services/transaction-service/types.d.ts +12 -2
- package/services/transaction-service/utils.js +7 -4
- package/strategy/api-request-strategy/context/base.d.ts +15 -0
- package/strategy/api-request-strategy/context/base.js +24 -0
- package/strategy/api-request-strategy/index.d.ts +15 -0
- package/strategy/api-request-strategy/index.js +83 -0
- package/strategy/api-request-strategy/types.d.ts +22 -0
- package/strategy/api-request-strategy/types.js +1 -0
- package/strategy/api-request-strategy/utils/index.d.ts +2 -0
- package/strategy/api-request-strategy/utils/index.js +23 -0
- package/types/account/info/keyring.d.ts +1 -1
- package/types/account/info/keyring.js +1 -1
- package/types/balance/index.d.ts +4 -1
- package/types/balance/transfer.d.ts +17 -0
- package/types/bitcoin.d.ts +93 -0
- package/types/bitcoin.js +17 -0
- package/types/environment.d.ts +9 -0
- package/types/environment.js +13 -0
- package/types/fee/base.d.ts +4 -1
- package/types/fee/bitcoin.d.ts +18 -0
- package/types/fee/bitcoin.js +1 -0
- package/types/fee/index.d.ts +1 -0
- package/types/fee/index.js +2 -1
- package/types/fee/subscription.d.ts +4 -3
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/utils/account/analyze.js +4 -4
- package/utils/account/common.d.ts +7 -8
- package/utils/account/common.js +16 -6
- package/utils/account/derive/info/solo.js +70 -21
- package/utils/account/derive/info/unified.js +2 -0
- package/utils/account/derive/validate.d.ts +1 -0
- package/utils/account/derive/validate.js +68 -1
- package/utils/account/transform.d.ts +1 -1
- package/utils/account/transform.js +11 -5
- package/utils/bitcoin/common.d.ts +22 -0
- package/utils/bitcoin/common.js +88 -0
- package/utils/bitcoin/fee.d.ts +2 -0
- package/utils/bitcoin/fee.js +14 -0
- package/utils/bitcoin/index.d.ts +3 -0
- package/utils/bitcoin/index.js +6 -0
- package/utils/bitcoin/utxo-management.d.ts +33 -0
- package/utils/bitcoin/utxo-management.js +266 -0
- package/utils/environment.d.ts +2 -0
- package/utils/environment.js +27 -1
- package/utils/fee/transfer.d.ts +3 -1
- package/utils/fee/transfer.js +47 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +6 -3
|
@@ -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, isCardanoTransaction, isSubstrateTransaction, isTonTransaction } from '@subwallet/extension-base/services/transaction-service/helpers';
|
|
14
|
+
import { getBaseTransactionInfo, getTransactionId, isBitcoinTransaction, 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';
|
|
@@ -39,10 +39,6 @@ export default class TransactionService {
|
|
|
39
39
|
}
|
|
40
40
|
constructor(state) {
|
|
41
41
|
this.state = state;
|
|
42
|
-
this.eventService = state.eventService;
|
|
43
|
-
this.historyService = state.historyService;
|
|
44
|
-
this.notificationService = state.notificationService;
|
|
45
|
-
this.chainService = state.chainService;
|
|
46
42
|
}
|
|
47
43
|
get allTransactions() {
|
|
48
44
|
return Object.values(this.transactions);
|
|
@@ -74,6 +70,7 @@ export default class TransactionService {
|
|
|
74
70
|
additionalValidator,
|
|
75
71
|
address,
|
|
76
72
|
chain,
|
|
73
|
+
chainType,
|
|
77
74
|
extrinsicType
|
|
78
75
|
} = validationResponse;
|
|
79
76
|
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
@@ -103,27 +100,30 @@ export default class TransactionService {
|
|
|
103
100
|
const evmApi = this.state.chainService.getEvmApi(chainInfo.slug);
|
|
104
101
|
const tonApi = this.state.chainService.getTonApi(chainInfo.slug);
|
|
105
102
|
const cardanoApi = this.state.chainService.getCardanoApi(chainInfo.slug);
|
|
103
|
+
const bitcoinApi = this.state.chainService.getBitcoinApi(chainInfo.slug);
|
|
106
104
|
// todo: should split into isEvmTx && isNoEvmApi. Because other chains type also has no Evm Api. Same to all blockchain.
|
|
107
105
|
// todo: refactor check evmTransaction.
|
|
108
|
-
const isNoEvmApi = transaction && !isSubstrateTransaction(transaction) && !isTonTransaction(transaction) && !isCardanoTransaction(transaction) && !evmApi;
|
|
106
|
+
const isNoEvmApi = transaction && !isSubstrateTransaction(transaction) && !isTonTransaction(transaction) && !isCardanoTransaction(transaction) && !isBitcoinTransaction(transaction) && !evmApi;
|
|
109
107
|
const isNoTonApi = transaction && isTonTransaction(transaction) && !tonApi;
|
|
110
108
|
const isNoCardanoApi = transaction && isCardanoTransaction(transaction) && !cardanoApi;
|
|
111
|
-
|
|
109
|
+
const isNoBitcoinApi = transaction && isBitcoinTransaction(transaction) && !bitcoinApi;
|
|
110
|
+
if (isNoEvmApi || isNoTonApi || isNoCardanoApi || isNoBitcoinApi) {
|
|
112
111
|
validationResponse.errors.push(new TransactionError(BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
|
|
113
112
|
}
|
|
114
113
|
|
|
115
114
|
// Estimate fee for transaction
|
|
116
115
|
const id = getId();
|
|
117
|
-
const feeInfo = await this.state.feeService.subscribeChainFee(id, chain,
|
|
116
|
+
const feeInfo = await this.state.feeService.subscribeChainFee(id, chain, chainType);
|
|
118
117
|
const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(chain);
|
|
119
118
|
const tokenPayFeeSlug = transactionInput.tokenPayFeeSlug;
|
|
120
119
|
const isNonNativeTokenPayFee = tokenPayFeeSlug && !_isNativeTokenBySlug(tokenPayFeeSlug);
|
|
121
|
-
const nonNativeTokenPayFeeInfo = isNonNativeTokenPayFee ? this.chainService.getAssetBySlug(tokenPayFeeSlug) : undefined;
|
|
120
|
+
const nonNativeTokenPayFeeInfo = isNonNativeTokenPayFee ? this.state.chainService.getAssetBySlug(tokenPayFeeSlug) : undefined;
|
|
122
121
|
const priceMap = (await this.state.priceService.getPrice()).priceMap;
|
|
123
122
|
validationResponse.estimateFee = await estimateFeeForTransaction(validationResponse, transaction, chainInfo, evmApi, substrateApi, priceMap, feeInfo, nativeTokenInfo, nonNativeTokenPayFeeInfo, transactionInput.isTransferLocalTokenAndPayThatTokenAsFee);
|
|
124
123
|
const chainInfoMap = this.state.chainService.getChainInfoMap();
|
|
125
124
|
|
|
126
125
|
// Check account signing transaction
|
|
126
|
+
|
|
127
127
|
checkSigningAccountForTransaction(validationResponse, chainInfoMap);
|
|
128
128
|
const nativeTokenAvailable = await this.state.balanceService.getTransferableBalance(address, chain, nativeTokenInfo.slug, extrinsicType);
|
|
129
129
|
|
|
@@ -186,7 +186,7 @@ export default class TransactionService {
|
|
|
186
186
|
}
|
|
187
187
|
fillTransactionDefaultInfo(transaction) {
|
|
188
188
|
const isInternal = !transaction.url;
|
|
189
|
-
const transactionId = getTransactionId(transaction.chainType, transaction.chain, isInternal, isWalletConnectRequest(transaction.id));
|
|
189
|
+
const transactionId = transaction.id || getTransactionId(transaction.chainType, transaction.chain, isInternal, isWalletConnectRequest(transaction.id));
|
|
190
190
|
return {
|
|
191
191
|
...transaction,
|
|
192
192
|
createdAt: new Date().getTime(),
|
|
@@ -410,7 +410,7 @@ export default class TransactionService {
|
|
|
410
410
|
}
|
|
411
411
|
async sendTransaction(transaction) {
|
|
412
412
|
// Send Transaction
|
|
413
|
-
const emitter = await (transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : transaction.chainType === 'evm' ? this.signAndSendEvmTransaction(transaction) : transaction.chainType === 'cardano' ? this.signAndSendCardanoTransaction(transaction) : this.signAndSendTonTransaction(transaction));
|
|
413
|
+
const emitter = await (transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : transaction.chainType === 'evm' ? this.signAndSendEvmTransaction(transaction) : transaction.chainType === 'cardano' ? this.signAndSendCardanoTransaction(transaction) : transaction.chainType === 'ton' ? this.signAndSendTonTransaction(transaction) : this.signAndSendBitcoinTransaction(transaction));
|
|
414
414
|
const {
|
|
415
415
|
eventsHandler,
|
|
416
416
|
step
|
|
@@ -669,6 +669,7 @@ export default class TransactionService {
|
|
|
669
669
|
extrinsicHash: transaction.extrinsicHash,
|
|
670
670
|
time: transaction.createdAt,
|
|
671
671
|
fee: transaction.estimateFee,
|
|
672
|
+
blockTime: undefined,
|
|
672
673
|
blockNumber: 0,
|
|
673
674
|
// Will be added in next step
|
|
674
675
|
blockHash: '',
|
|
@@ -1055,6 +1056,24 @@ export default class TransactionService {
|
|
|
1055
1056
|
if ([ExtrinsicType.STAKING_JOIN_POOL, ExtrinsicType.STAKING_BOND, ExtrinsicType.JOIN_YIELD_POOL, ExtrinsicType.MINT_LDOT, ExtrinsicType.MINT_QDOT, ExtrinsicType.MINT_SDOT, ExtrinsicType.MINT_STDOT, ExtrinsicType.MINT_VDOT, ExtrinsicType.MINT_VMANTA].includes(transaction.extrinsicType)) {
|
|
1056
1057
|
this.handlePostEarningTransaction(id);
|
|
1057
1058
|
}
|
|
1059
|
+
|
|
1060
|
+
// Trigger balance update for Bitcoin transactions after receiving extrinsicHash
|
|
1061
|
+
if (ExtrinsicType.TRANSFER_BALANCE && transaction.chainType === 'bitcoin') {
|
|
1062
|
+
const balanceService = this.state.balanceService;
|
|
1063
|
+
const inputData = parseTransactionData(transaction.data);
|
|
1064
|
+
try {
|
|
1065
|
+
const sender = keyring.getPair(inputData.from);
|
|
1066
|
+
balanceService.refreshBalanceForAddress(sender.address, transaction.chain, inputData.tokenSlug, transaction.extrinsicType).catch(error => console.error('Failed to run balance subscription:', error));
|
|
1067
|
+
} catch (e) {
|
|
1068
|
+
console.error(e);
|
|
1069
|
+
}
|
|
1070
|
+
try {
|
|
1071
|
+
const recipient = keyring.getPair(inputData.to);
|
|
1072
|
+
balanceService.refreshBalanceForAddress(recipient.address, transaction.chain, inputData.tokenSlug, transaction.extrinsicType).catch(error => console.error('Failed to run balance subscription:', error));
|
|
1073
|
+
} catch (e) {
|
|
1074
|
+
console.error(e);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1058
1077
|
}
|
|
1059
1078
|
handlePostProcessing(id) {
|
|
1060
1079
|
// must be done after success/failure to make sure the transaction is finalized
|
|
@@ -1093,6 +1112,7 @@ export default class TransactionService {
|
|
|
1093
1112
|
onSuccess({
|
|
1094
1113
|
blockHash,
|
|
1095
1114
|
blockNumber,
|
|
1115
|
+
blockTime,
|
|
1096
1116
|
extrinsicHash,
|
|
1097
1117
|
id
|
|
1098
1118
|
}) {
|
|
@@ -1107,7 +1127,8 @@ export default class TransactionService {
|
|
|
1107
1127
|
extrinsicHash,
|
|
1108
1128
|
status: ExtrinsicStatus.SUCCESS,
|
|
1109
1129
|
blockNumber: blockNumber || 0,
|
|
1110
|
-
blockHash: blockHash || ''
|
|
1130
|
+
blockHash: blockHash || '',
|
|
1131
|
+
blockTime
|
|
1111
1132
|
}).catch(console.error);
|
|
1112
1133
|
const info = isHex(extrinsicHash) ? extrinsicHash : getBaseTransactionInfo(transaction, this.state.chainService.getChainInfoMap());
|
|
1113
1134
|
this.state.notificationService.notify({
|
|
@@ -1180,14 +1201,14 @@ export default class TransactionService {
|
|
|
1180
1201
|
errors,
|
|
1181
1202
|
extrinsicHash
|
|
1182
1203
|
});
|
|
1183
|
-
this.historyService.updateHistoryByExtrinsicHash(transaction.extrinsicHash, {
|
|
1204
|
+
this.state.historyService.updateHistoryByExtrinsicHash(transaction.extrinsicHash, {
|
|
1184
1205
|
extrinsicHash: extrinsicHash || transaction.extrinsicHash,
|
|
1185
1206
|
status: nextStatus,
|
|
1186
1207
|
blockNumber: blockNumber || 0,
|
|
1187
1208
|
blockHash: blockHash || ''
|
|
1188
1209
|
}).catch(console.error);
|
|
1189
|
-
const info = isHex(transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash) ? transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash : getBaseTransactionInfo(transaction, this.chainService.getChainInfoMap());
|
|
1190
|
-
this.notificationService.notify({
|
|
1210
|
+
const info = isHex(transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash) ? transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash : getBaseTransactionInfo(transaction, this.state.chainService.getChainInfoMap());
|
|
1211
|
+
this.state.notificationService.notify({
|
|
1191
1212
|
type: NotificationType.ERROR,
|
|
1192
1213
|
title: t('Transaction timed out'),
|
|
1193
1214
|
message: t('Transaction {{info}} timed out', {
|
|
@@ -1201,7 +1222,7 @@ export default class TransactionService {
|
|
|
1201
1222
|
notifyViaBrowser: true
|
|
1202
1223
|
});
|
|
1203
1224
|
}
|
|
1204
|
-
this.eventService.emit('transaction.timeout', transaction);
|
|
1225
|
+
this.state.eventService.emit('transaction.timeout', transaction);
|
|
1205
1226
|
}
|
|
1206
1227
|
generateHashPayload(chain, transaction) {
|
|
1207
1228
|
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
@@ -1864,6 +1885,104 @@ export default class TransactionService {
|
|
|
1864
1885
|
});
|
|
1865
1886
|
return emitter;
|
|
1866
1887
|
}
|
|
1888
|
+
emitterEventTransaction = (emitter, eventData, chain, payload) => {
|
|
1889
|
+
// Emit signed event
|
|
1890
|
+
emitter.emit('signed', eventData);
|
|
1891
|
+
// Add start info
|
|
1892
|
+
emitter.emit('send', eventData);
|
|
1893
|
+
const event = this.state.chainService.getBitcoinApi(chain).api.sendRawTransaction(payload);
|
|
1894
|
+
event.on('extrinsicHash', txHash => {
|
|
1895
|
+
eventData.extrinsicHash = txHash;
|
|
1896
|
+
emitter.emit('extrinsicHash', eventData);
|
|
1897
|
+
});
|
|
1898
|
+
event.on('success', transactionStatus => {
|
|
1899
|
+
console.log(transactionStatus);
|
|
1900
|
+
eventData.blockHash = transactionStatus.block_hash || undefined;
|
|
1901
|
+
eventData.blockNumber = transactionStatus.block_height || undefined;
|
|
1902
|
+
eventData.blockTime = transactionStatus.block_time ? transactionStatus.block_time * 1000 : undefined;
|
|
1903
|
+
emitter.emit('success', eventData);
|
|
1904
|
+
});
|
|
1905
|
+
event.on('error', error => {
|
|
1906
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, error));
|
|
1907
|
+
emitter.emit('error', eventData);
|
|
1908
|
+
});
|
|
1909
|
+
};
|
|
1910
|
+
signAndSendBitcoinTransaction({
|
|
1911
|
+
address,
|
|
1912
|
+
chain,
|
|
1913
|
+
id,
|
|
1914
|
+
transaction,
|
|
1915
|
+
url
|
|
1916
|
+
}) {
|
|
1917
|
+
const tx = transaction;
|
|
1918
|
+
// const bitcoinApi = this.state.chainService.getBitcoinApi(chain);
|
|
1919
|
+
// const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
1920
|
+
|
|
1921
|
+
const accountPair = keyring.getPair(address);
|
|
1922
|
+
const account = pairToAccount(accountPair);
|
|
1923
|
+
const payload = {
|
|
1924
|
+
payload: undefined,
|
|
1925
|
+
payloadJson: undefined,
|
|
1926
|
+
account,
|
|
1927
|
+
canSign: true,
|
|
1928
|
+
hashPayload: tx.toHex(),
|
|
1929
|
+
id
|
|
1930
|
+
};
|
|
1931
|
+
const emitter = new EventEmitter();
|
|
1932
|
+
const eventData = {
|
|
1933
|
+
id,
|
|
1934
|
+
errors: [],
|
|
1935
|
+
warnings: [],
|
|
1936
|
+
extrinsicHash: id
|
|
1937
|
+
};
|
|
1938
|
+
const isInjected = !!account.isInjected;
|
|
1939
|
+
// const isExternal = !!account.isExternal;
|
|
1940
|
+
|
|
1941
|
+
if (isInjected) {
|
|
1942
|
+
throw new TransactionError(BasicTxErrorType.UNSUPPORTED);
|
|
1943
|
+
} else {
|
|
1944
|
+
this.state.requestService.addConfirmationBitcoin(id, url || EXTENSION_REQUEST_URL, 'bitcoinSendTransactionRequest', payload, {}).then(({
|
|
1945
|
+
isApproved,
|
|
1946
|
+
payload
|
|
1947
|
+
}) => {
|
|
1948
|
+
if (isApproved) {
|
|
1949
|
+
if (!payload) {
|
|
1950
|
+
throw new Error('Bad signature');
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
// Emit signed event
|
|
1954
|
+
emitter.emit('signed', eventData);
|
|
1955
|
+
// Add start info
|
|
1956
|
+
emitter.emit('send', eventData);
|
|
1957
|
+
const bitcoinApi = this.state.chainService.getBitcoinApi(chain);
|
|
1958
|
+
const event = bitcoinApi.api.sendRawTransaction(payload);
|
|
1959
|
+
event.on('extrinsicHash', txHash => {
|
|
1960
|
+
eventData.extrinsicHash = txHash;
|
|
1961
|
+
emitter.emit('extrinsicHash', eventData);
|
|
1962
|
+
});
|
|
1963
|
+
event.on('success', transactionStatus => {
|
|
1964
|
+
eventData.blockHash = transactionStatus.block_hash || undefined;
|
|
1965
|
+
eventData.blockNumber = transactionStatus.block_height || undefined;
|
|
1966
|
+
eventData.blockTime = transactionStatus.block_time ? transactionStatus.block_time * 1000 : undefined;
|
|
1967
|
+
emitter.emit('success', eventData);
|
|
1968
|
+
});
|
|
1969
|
+
event.on('error', error => {
|
|
1970
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, error));
|
|
1971
|
+
emitter.emit('error', eventData);
|
|
1972
|
+
});
|
|
1973
|
+
} else {
|
|
1974
|
+
this.removeTransaction(id);
|
|
1975
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.USER_REJECT_REQUEST));
|
|
1976
|
+
emitter.emit('error', eventData);
|
|
1977
|
+
}
|
|
1978
|
+
}).catch(e => {
|
|
1979
|
+
this.removeTransaction(id);
|
|
1980
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SIGN, e.message));
|
|
1981
|
+
emitter.emit('error', eventData);
|
|
1982
|
+
});
|
|
1983
|
+
}
|
|
1984
|
+
return emitter;
|
|
1985
|
+
}
|
|
1867
1986
|
handleTransactionTimeout(emitter, eventData) {
|
|
1868
1987
|
const timeout = setTimeout(() => {
|
|
1869
1988
|
const transaction = this.getTransaction(eventData.id);
|
|
@@ -3,11 +3,12 @@ import { SignTypedDataMessageV3V4 } from '@subwallet/extension-base/core/logic-v
|
|
|
3
3
|
import { TonTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
4
4
|
import { UniswapOrderInfo } from '@subwallet/extension-base/services/swap-service/handler/uniswap-handler';
|
|
5
5
|
import { BaseRequestSign, BriefProcessStep, ProcessTransactionData, TransactionFee } from '@subwallet/extension-base/types';
|
|
6
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
6
7
|
import EventEmitter from 'eventemitter3';
|
|
7
8
|
import { TransactionConfig } from 'web3-core';
|
|
8
9
|
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
|
|
9
10
|
import { EventRecord } from '@polkadot/types/interfaces';
|
|
10
|
-
export interface SWTransactionBase extends ValidateTransactionResponse, Partial<Pick<BaseRequestSign, 'ignoreWarnings'>>, TransactionFee {
|
|
11
|
+
export interface SWTransactionBase extends ValidateTransactionResponse, Partial<Pick<BaseRequestSign, 'ignoreWarnings'>>, TransactionFee, SWTransactionEmitter {
|
|
11
12
|
id: string;
|
|
12
13
|
url?: string;
|
|
13
14
|
isInternal: boolean;
|
|
@@ -31,7 +32,7 @@ export interface SWTransactionBase extends ValidateTransactionResponse, Partial<
|
|
|
31
32
|
step?: BriefProcessStep;
|
|
32
33
|
}
|
|
33
34
|
export interface SWTransaction extends SWTransactionBase {
|
|
34
|
-
transaction: SubmittableExtrinsic | TransactionConfig | TonTransactionConfig;
|
|
35
|
+
transaction: SubmittableExtrinsic | TransactionConfig | TonTransactionConfig | Psbt;
|
|
35
36
|
}
|
|
36
37
|
export interface SWPermitTransaction extends SWTransactionBase {
|
|
37
38
|
transaction: SignTypedDataMessageV3V4;
|
|
@@ -45,6 +46,9 @@ export interface SWDutchTransaction extends SWTransactionBase {
|
|
|
45
46
|
export interface SWTransactionResult extends Omit<SWTransactionBase, 'transaction' | 'additionalValidator' | 'eventsHandler' | 'process'> {
|
|
46
47
|
process?: ProcessTransactionData;
|
|
47
48
|
}
|
|
49
|
+
export interface SWTransactionEmitter {
|
|
50
|
+
emitterTransaction?: TransactionEmitter;
|
|
51
|
+
}
|
|
48
52
|
declare type SwInputBase = Pick<SWTransactionBase, 'address' | 'url' | 'data' | 'extrinsicType' | 'chain' | 'chainType' | 'ignoreWarnings' | 'transferNativeAmount'> & Partial<Pick<SWTransactionBase, 'additionalValidator' | 'eventsHandler'>>;
|
|
49
53
|
export interface SWTransactionInput extends SwInputBase, Partial<Pick<SWTransactionBase, 'estimateFee' | 'signAfterCreate' | 'isPassConfirmation' | 'step' | 'errorOnTimeOut' | 'xcmFeeDryRun'>>, TransactionFee {
|
|
50
54
|
id?: string;
|
|
@@ -66,6 +70,11 @@ export interface SWDutchTransactionInput extends Omit<SWTransactionInput, 'trans
|
|
|
66
70
|
export declare type SWTransactionResponse = SwInputBase & Pick<SWTransactionBase, 'warnings' | 'errors'> & Partial<Pick<SWTransactionBase, 'id' | 'extrinsicHash' | 'status' | 'estimateFee' | 'xcmFeeDryRun'>> & TransactionFee & {
|
|
67
71
|
processId?: string;
|
|
68
72
|
};
|
|
73
|
+
export declare type BitcoinTransactionData = {
|
|
74
|
+
data: Psbt;
|
|
75
|
+
dataBase64: string;
|
|
76
|
+
dataToHex: string;
|
|
77
|
+
};
|
|
69
78
|
export declare type ValidateTransactionResponseInput = SWTransactionInput;
|
|
70
79
|
export declare type TransactionEmitter = EventEmitter<TransactionEventMap>;
|
|
71
80
|
export interface TransactionEventResponse extends ValidateTransactionResponse {
|
|
@@ -77,6 +86,7 @@ export interface TransactionEventResponse extends ValidateTransactionResponse {
|
|
|
77
86
|
eventLogs?: EventRecord[];
|
|
78
87
|
nonce?: number;
|
|
79
88
|
startBlock?: number;
|
|
89
|
+
blockTime?: number;
|
|
80
90
|
}
|
|
81
91
|
export interface TransactionEventMap {
|
|
82
92
|
send: (response: TransactionEventResponse) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { _getBlockExplorerFromChain, _isChainTestNet, _isPureCardanoChain, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
4
|
+
import { _getBlockExplorerFromChain, _isChainTestNet, _isPureBitcoinChain, _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
6
|
import { hexAddPrefix, isHex, u8aToHex } from '@polkadot/util';
|
|
7
7
|
import { decodeAddress } from '@polkadot/util-crypto';
|
|
@@ -28,8 +28,8 @@ function getBlockExplorerAccountRoute(explorerLink) {
|
|
|
28
28
|
if (explorerLink.includes('statescan.io')) {
|
|
29
29
|
return '#/accounts';
|
|
30
30
|
}
|
|
31
|
-
if (explorerLink.includes('explorer.
|
|
32
|
-
return '
|
|
31
|
+
if (explorerLink.includes('explorer.gen6.app')) {
|
|
32
|
+
return '#/accounts';
|
|
33
33
|
}
|
|
34
34
|
if (explorerLink.includes('astral.autonomys')) {
|
|
35
35
|
return 'accounts';
|
|
@@ -40,7 +40,7 @@ function getBlockExplorerAccountRoute(explorerLink) {
|
|
|
40
40
|
return 'address';
|
|
41
41
|
}
|
|
42
42
|
function getBlockExplorerTxRoute(chainInfo) {
|
|
43
|
-
if (_isPureEvmChain(chainInfo)) {
|
|
43
|
+
if (_isPureEvmChain(chainInfo) || _isPureBitcoinChain(chainInfo)) {
|
|
44
44
|
return 'tx';
|
|
45
45
|
}
|
|
46
46
|
if (_isPureCardanoChain(chainInfo)) {
|
|
@@ -49,6 +49,9 @@ function getBlockExplorerTxRoute(chainInfo) {
|
|
|
49
49
|
if (['aventus', 'deeper_network'].includes(chainInfo.slug)) {
|
|
50
50
|
return 'transaction';
|
|
51
51
|
}
|
|
52
|
+
if (['gen6_public'].includes(chainInfo.slug)) {
|
|
53
|
+
return '#/extrinsics';
|
|
54
|
+
}
|
|
52
55
|
const explorerLink = _getBlockExplorerFromChain(chainInfo);
|
|
53
56
|
if (explorerLink && explorerLink.includes('statescan.io')) {
|
|
54
57
|
return '#/extrinsics';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiRequestContext } from '@subwallet/extension-base/strategy/api-request-strategy/types';
|
|
2
|
+
export declare class BaseApiRequestContext implements ApiRequestContext {
|
|
3
|
+
callRate: number;
|
|
4
|
+
limitRate: number;
|
|
5
|
+
intervalCheck: number;
|
|
6
|
+
maxRetry: number;
|
|
7
|
+
private rollbackRateTime;
|
|
8
|
+
private timeoutRollbackRate;
|
|
9
|
+
constructor(options?: {
|
|
10
|
+
limitRate?: number;
|
|
11
|
+
intervalCheck?: number;
|
|
12
|
+
maxRetry?: number;
|
|
13
|
+
});
|
|
14
|
+
reduceLimitRate(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export class BaseApiRequestContext {
|
|
5
|
+
callRate = 2; // limit per interval check
|
|
6
|
+
limitRate = 2; // max rate per interval check
|
|
7
|
+
intervalCheck = 1000; // interval check in ms
|
|
8
|
+
maxRetry = 9; // interval check in ms
|
|
9
|
+
rollbackRateTime = 30 * 1000; // rollback rate time in ms
|
|
10
|
+
timeoutRollbackRate = undefined;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.callRate = (options === null || options === void 0 ? void 0 : options.limitRate) || this.callRate;
|
|
13
|
+
this.limitRate = (options === null || options === void 0 ? void 0 : options.limitRate) || this.limitRate;
|
|
14
|
+
this.intervalCheck = (options === null || options === void 0 ? void 0 : options.intervalCheck) || this.intervalCheck;
|
|
15
|
+
this.maxRetry = (options === null || options === void 0 ? void 0 : options.maxRetry) || this.maxRetry;
|
|
16
|
+
}
|
|
17
|
+
reduceLimitRate() {
|
|
18
|
+
clearTimeout(this.timeoutRollbackRate);
|
|
19
|
+
this.callRate = Math.ceil(this.limitRate / 2);
|
|
20
|
+
this.timeoutRollbackRate = setTimeout(() => {
|
|
21
|
+
this.callRate = this.limitRate;
|
|
22
|
+
}, this.rollbackRateTime);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiRequest, ApiRequestContext, ApiRequestStrategy } from './types';
|
|
2
|
+
export declare abstract class BaseApiRequestStrategy implements ApiRequestStrategy {
|
|
3
|
+
private nextId;
|
|
4
|
+
private isRunning;
|
|
5
|
+
private requestMap;
|
|
6
|
+
private context;
|
|
7
|
+
private processInterval;
|
|
8
|
+
private getId;
|
|
9
|
+
protected constructor(context: ApiRequestContext);
|
|
10
|
+
addRequest<T>(run: ApiRequest<T>['run'], ordinal: number): Promise<T>;
|
|
11
|
+
abstract isRateLimited(error: Error): boolean;
|
|
12
|
+
private process;
|
|
13
|
+
stop(): void;
|
|
14
|
+
setContext(context: ApiRequestContext): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { SWError } from '@subwallet/extension-base/background/errors/SWError';
|
|
5
|
+
export class BaseApiRequestStrategy {
|
|
6
|
+
nextId = 0;
|
|
7
|
+
isRunning = false;
|
|
8
|
+
requestMap = {};
|
|
9
|
+
processInterval = undefined;
|
|
10
|
+
getId() {
|
|
11
|
+
return this.nextId++;
|
|
12
|
+
}
|
|
13
|
+
constructor(context) {
|
|
14
|
+
this.context = context;
|
|
15
|
+
}
|
|
16
|
+
addRequest(run, ordinal) {
|
|
17
|
+
const newId = this.getId();
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
this.requestMap[newId] = {
|
|
20
|
+
id: newId,
|
|
21
|
+
status: 'pending',
|
|
22
|
+
retry: -1,
|
|
23
|
+
ordinal,
|
|
24
|
+
run,
|
|
25
|
+
resolve,
|
|
26
|
+
reject
|
|
27
|
+
};
|
|
28
|
+
if (!this.isRunning) {
|
|
29
|
+
this.process();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
process() {
|
|
34
|
+
this.stop();
|
|
35
|
+
this.isRunning = true;
|
|
36
|
+
const maxRetry = this.context.maxRetry;
|
|
37
|
+
const interval = setInterval(() => {
|
|
38
|
+
const remainingRequests = Object.values(this.requestMap);
|
|
39
|
+
if (remainingRequests.length === 0) {
|
|
40
|
+
this.isRunning = false;
|
|
41
|
+
clearInterval(interval);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Get first this.limit requests base on id
|
|
46
|
+
const requests = remainingRequests.filter(request => request.status !== 'running').sort((a, b) => a.id - b.id).sort((a, b) => a.ordinal - b.ordinal).slice(0, this.context.callRate);
|
|
47
|
+
|
|
48
|
+
// Start requests
|
|
49
|
+
requests.forEach(request => {
|
|
50
|
+
request.status = 'running';
|
|
51
|
+
request.run().then(rs => {
|
|
52
|
+
request.resolve(rs);
|
|
53
|
+
}).catch(e => {
|
|
54
|
+
const isRateLimited = this.isRateLimited(e);
|
|
55
|
+
|
|
56
|
+
// Limit rate
|
|
57
|
+
if (isRateLimited) {
|
|
58
|
+
if (request.retry < maxRetry) {
|
|
59
|
+
request.status = 'pending';
|
|
60
|
+
request.retry++;
|
|
61
|
+
this.context.reduceLimitRate();
|
|
62
|
+
} else {
|
|
63
|
+
// Reject request
|
|
64
|
+
request.reject(new SWError('MAX_RETRY', String(e)));
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
request.reject(new SWError('UNKNOWN', String(e)));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}, this.context.intervalCheck);
|
|
72
|
+
this.processInterval = interval;
|
|
73
|
+
}
|
|
74
|
+
stop() {
|
|
75
|
+
clearInterval(this.processInterval);
|
|
76
|
+
this.processInterval = undefined;
|
|
77
|
+
}
|
|
78
|
+
setContext(context) {
|
|
79
|
+
this.stop();
|
|
80
|
+
this.context = context;
|
|
81
|
+
this.process();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface ApiRequestContext {
|
|
2
|
+
callRate: number;
|
|
3
|
+
limitRate: number;
|
|
4
|
+
intervalCheck: number;
|
|
5
|
+
maxRetry: number;
|
|
6
|
+
reduceLimitRate: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface ApiRequestStrategy {
|
|
9
|
+
addRequest: <T>(run: ApiRequest<T>['run'], ordinal: number) => Promise<T>;
|
|
10
|
+
setContext: (context: ApiRequestContext) => void;
|
|
11
|
+
stop: () => void;
|
|
12
|
+
}
|
|
13
|
+
export interface ApiRequest<T> {
|
|
14
|
+
id: number;
|
|
15
|
+
retry: number;
|
|
16
|
+
/** Serve smaller first */
|
|
17
|
+
ordinal: number;
|
|
18
|
+
status: 'pending' | 'running';
|
|
19
|
+
run: () => Promise<any>;
|
|
20
|
+
resolve: (value: any) => T;
|
|
21
|
+
reject: (error?: any) => void;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import fetch from 'cross-fetch';
|
|
5
|
+
export const postRequest = (url, body, headers, jsonBody = true) => {
|
|
6
|
+
return fetch(url, {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
headers: headers || {
|
|
9
|
+
'Content-Type': 'application/json'
|
|
10
|
+
},
|
|
11
|
+
body: jsonBody ? JSON.stringify(body) : body
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export const getRequest = (url, params, headers) => {
|
|
15
|
+
const queryString = params ? Object.keys(params).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`).join('&') : '';
|
|
16
|
+
const _url = `${url}?${queryString}`;
|
|
17
|
+
return fetch(_url, {
|
|
18
|
+
method: 'GET',
|
|
19
|
+
headers: headers || {
|
|
20
|
+
'Content-Type': 'application/json'
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -116,7 +116,7 @@ export declare enum AccountChainType {
|
|
|
116
116
|
CARDANO = "cardano"
|
|
117
117
|
}
|
|
118
118
|
export declare const ACCOUNT_CHAIN_TYPE_ORDINAL_MAP: Record<string, number>;
|
|
119
|
-
export declare const SUPPORTED_ACCOUNT_CHAIN_TYPES:
|
|
119
|
+
export declare const SUPPORTED_ACCOUNT_CHAIN_TYPES: AccountChainType[];
|
|
120
120
|
export declare enum AccountActions {
|
|
121
121
|
DERIVE = "DERIVE",
|
|
122
122
|
EXPORT_MNEMONIC = "EXPORT_MNEMONIC",
|
|
@@ -74,7 +74,7 @@ export const ACCOUNT_CHAIN_TYPE_ORDINAL_MAP = {
|
|
|
74
74
|
[AccountChainType.CARDANO]: 4,
|
|
75
75
|
[AccountChainType.BITCOIN]: 5
|
|
76
76
|
};
|
|
77
|
-
export const SUPPORTED_ACCOUNT_CHAIN_TYPES = [
|
|
77
|
+
export const SUPPORTED_ACCOUNT_CHAIN_TYPES = [AccountChainType.SUBSTRATE, AccountChainType.ETHEREUM, AccountChainType.TON, AccountChainType.CARDANO, AccountChainType.BITCOIN];
|
|
78
78
|
export let AccountActions;
|
|
79
79
|
|
|
80
80
|
/**
|
package/types/balance/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
3
3
|
import { _BalanceMetadata, APIItemState, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
|
-
import { _CardanoApi, _EvmApi, _SubstrateApi, _TonApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
|
+
import { _BitcoinApi, _CardanoApi, _EvmApi, _SubstrateApi, _TonApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
5
|
import { BN } from '@polkadot/util';
|
|
6
6
|
export interface TokenBalanceRaw {
|
|
7
7
|
reserved: BN;
|
|
@@ -55,3 +55,6 @@ export interface SubscribeTonPalletBalance extends SubscribeBasePalletBalance {
|
|
|
55
55
|
export interface SusbcribeCardanoPalletBalance extends SubscribeBasePalletBalance {
|
|
56
56
|
cardanoApi: _CardanoApi;
|
|
57
57
|
}
|
|
58
|
+
export interface SusbcribeBitcoinPalletBalance extends SubscribeBasePalletBalance {
|
|
59
|
+
bitcoinApi: _BitcoinApi;
|
|
60
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { PsbtTransactionArg } from '@subwallet/extension-base/background/KoniTypes';
|
|
1
2
|
import { BaseRequestSign } from '@subwallet/extension-base/types';
|
|
3
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
2
4
|
import { FeeChainType, FeeDetail, TransactionFee } from '../fee';
|
|
3
5
|
export interface RequestSubscribeTransfer extends TransactionFee {
|
|
4
6
|
address: string;
|
|
7
|
+
to?: string;
|
|
5
8
|
chain: string;
|
|
6
9
|
value: string;
|
|
7
10
|
token: string;
|
|
@@ -15,6 +18,9 @@ export interface ResponseSubscribeTransfer {
|
|
|
15
18
|
feePercentageSpecialCase?: number;
|
|
16
19
|
error?: string;
|
|
17
20
|
}
|
|
21
|
+
export interface RequestSubmitTransferWithId extends RequestSubmitTransfer {
|
|
22
|
+
id?: string;
|
|
23
|
+
}
|
|
18
24
|
export interface RequestSubmitTransfer extends BaseRequestSign, TransactionFee {
|
|
19
25
|
chain: string;
|
|
20
26
|
from: string;
|
|
@@ -24,3 +30,14 @@ export interface RequestSubmitTransfer extends BaseRequestSign, TransactionFee {
|
|
|
24
30
|
value: string;
|
|
25
31
|
transferBounceable?: boolean;
|
|
26
32
|
}
|
|
33
|
+
export interface RequestSubmitSignPsbtTransfer extends BaseRequestSign {
|
|
34
|
+
id: string;
|
|
35
|
+
chain: string;
|
|
36
|
+
from: string;
|
|
37
|
+
to: string;
|
|
38
|
+
value: string;
|
|
39
|
+
txInput: PsbtTransactionArg[];
|
|
40
|
+
txOutput: PsbtTransactionArg[];
|
|
41
|
+
tokenSlug: string;
|
|
42
|
+
psbt: Psbt;
|
|
43
|
+
}
|