@subwallet/extension-base 1.3.41-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/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 +59 -3
- 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/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/base/types.js +2 -0
- package/cjs/services/chain-service/constants.js +14 -3
- 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/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/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/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/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/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 +58 -4
- package/koni/background/handlers/State.d.ts +7 -3
- package/koni/background/handlers/State.js +52 -12
- package/package.json +144 -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/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/base/types.d.ts +2 -0
- package/services/base/types.js +2 -0
- package/services/chain-service/constants.d.ts +6 -0
- package/services/chain-service/constants.js +8 -2
- 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/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/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/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/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
package/core/utils.js
CHANGED
|
@@ -5,9 +5,10 @@ import { _AssetType } from '@subwallet/chain-list/types';
|
|
|
5
5
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
|
|
7
7
|
import { tonAddressInfo } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils';
|
|
8
|
-
import { _getTokenOnChainAssetId, _getXcmAssetMultilocation, _isBridgedToken, _isChainCardanoCompatible, _isChainEvmCompatible, _isChainSubstrateCompatible, _isChainTonCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
|
+
import { _getTokenOnChainAssetId, _getXcmAssetMultilocation, _isBridgedToken, _isChainBitcoinCompatible, _isChainCardanoCompatible, _isChainEvmCompatible, _isChainSubstrateCompatible, _isChainTonCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
9
|
import { isAddressAndChainCompatible, isSameAddress, reformatAddress } from '@subwallet/extension-base/utils';
|
|
10
10
|
import { isAddress, isCardanoTestnetAddress, isTonAddress } from '@subwallet/keyring';
|
|
11
|
+
import { getBitcoinAddressInfo, validateBitcoinAddress } from '@subwallet/keyring/utils';
|
|
11
12
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
12
13
|
export function getStrictMode(type, extrinsicType) {
|
|
13
14
|
if (type === BalanceAccountType.FrameSystemAccountInfo) {
|
|
@@ -55,7 +56,7 @@ export function _isValidAddressForEcosystem(validateRecipientParams) {
|
|
|
55
56
|
toAddress
|
|
56
57
|
} = validateRecipientParams;
|
|
57
58
|
if (!isAddressAndChainCompatible(toAddress, destChainInfo)) {
|
|
58
|
-
if (_isChainEvmCompatible(destChainInfo) || _isChainSubstrateCompatible(destChainInfo) || _isChainTonCompatible(destChainInfo) || _isChainCardanoCompatible(destChainInfo)) {
|
|
59
|
+
if (_isChainEvmCompatible(destChainInfo) || _isChainSubstrateCompatible(destChainInfo) || _isChainTonCompatible(destChainInfo) || _isChainCardanoCompatible(destChainInfo) || _isChainBitcoinCompatible(destChainInfo)) {
|
|
59
60
|
return 'Recipient address must be the same type as sender address';
|
|
60
61
|
}
|
|
61
62
|
return 'Unknown chain type';
|
|
@@ -96,6 +97,18 @@ export function _isValidCardanoAddressFormat(validateRecipientParams) {
|
|
|
96
97
|
}
|
|
97
98
|
return '';
|
|
98
99
|
}
|
|
100
|
+
export function _isValidBitcoinAddressFormat(validateRecipientParams) {
|
|
101
|
+
var _destChainInfo$bitcoi;
|
|
102
|
+
const {
|
|
103
|
+
destChainInfo,
|
|
104
|
+
toAddress
|
|
105
|
+
} = validateRecipientParams;
|
|
106
|
+
const addressInfo = validateBitcoinAddress(toAddress) ? getBitcoinAddressInfo(toAddress) : null;
|
|
107
|
+
if ((addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.network) !== ((_destChainInfo$bitcoi = destChainInfo.bitcoinInfo) === null || _destChainInfo$bitcoi === void 0 ? void 0 : _destChainInfo$bitcoi.bitcoinNetwork)) {
|
|
108
|
+
return `Recipient address must be a valid ${destChainInfo.name} address`;
|
|
109
|
+
}
|
|
110
|
+
return '';
|
|
111
|
+
}
|
|
99
112
|
export function _isNotDuplicateAddress(validateRecipientParams) {
|
|
100
113
|
const {
|
|
101
114
|
fromAddress,
|
|
@@ -157,9 +157,11 @@ export default class KoniExtension {
|
|
|
157
157
|
private subscribeConfirmations;
|
|
158
158
|
private subscribeConfirmationsTon;
|
|
159
159
|
private subscribeConfirmationsCardano;
|
|
160
|
+
private subscribeConfirmationsBitcoin;
|
|
160
161
|
private completeConfirmation;
|
|
161
162
|
private completeConfirmationTon;
|
|
162
163
|
private completeConfirmationCardano;
|
|
164
|
+
private completeConfirmationBitcoin;
|
|
163
165
|
private getNetworkJsonByChainId;
|
|
164
166
|
private parseSubstrateTransaction;
|
|
165
167
|
private parseEVMRLP;
|
|
@@ -25,6 +25,7 @@ import { getPoolingBondingExtrinsic, getPoolingUnbondingExtrinsic, validatePoolB
|
|
|
25
25
|
import { YIELD_EXTRINSIC_TYPES } from '@subwallet/extension-base/koni/api/yield/helper/utils';
|
|
26
26
|
import { DEFAULT_CARDANO_TTL_OFFSET } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/consts';
|
|
27
27
|
import { isBounceableAddress } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils';
|
|
28
|
+
import { createBitcoinTransaction } from '@subwallet/extension-base/services/balance-service/transfer/bitcoin-transfer';
|
|
28
29
|
import { createCardanoTransaction } from '@subwallet/extension-base/services/balance-service/transfer/cardano-transfer';
|
|
29
30
|
import { getERC20TransactionObject, getERC721Transaction, getEVMTransactionObject, getPSP34TransferExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/smart-contract';
|
|
30
31
|
import { createSubstrateExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/token';
|
|
@@ -37,7 +38,7 @@ import { _isPosChainBridge, getClaimPosBridge } from '@subwallet/extension-base/
|
|
|
37
38
|
import { estimateXcmFee } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
38
39
|
import { _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
|
|
39
40
|
import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
|
|
40
|
-
import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _isAssetSmartContractNft, _isChainEnabled, _isChainEvmCompatible, _isChainSubstrateCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isNativeTokenBySlug, _isPureEvmChain, _isTokenEvmSmartContract, _isTokenTransferredByCardano, _isTokenTransferredByEvm, _isTokenTransferredByTon } from '@subwallet/extension-base/services/chain-service/utils';
|
|
41
|
+
import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _isAssetSmartContractNft, _isChainEnabled, _isChainEvmCompatible, _isChainSubstrateCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isNativeTokenBySlug, _isPureEvmChain, _isTokenEvmSmartContract, _isTokenTransferredByBitcoin, _isTokenTransferredByCardano, _isTokenTransferredByEvm, _isTokenTransferredByTon } from '@subwallet/extension-base/services/chain-service/utils';
|
|
41
42
|
import { calculateToAmountByReservePool } from '@subwallet/extension-base/services/fee-service/utils';
|
|
42
43
|
import { batchExtrinsicSetFeeHydration, getAssetHubTokensCanPayFee, getHydrationTokensCanPayFee } from '@subwallet/extension-base/services/fee-service/utils/tokenPayFee';
|
|
43
44
|
import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
|
|
@@ -51,9 +52,11 @@ import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils
|
|
|
51
52
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
52
53
|
import { getKeypairTypeByAddress, isAddress, isCardanoAddress, isSubstrateAddress, isTonAddress } from '@subwallet/keyring';
|
|
53
54
|
import { CardanoKeypairTypes, EthereumKeypairTypes, SubstrateKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
|
|
55
|
+
import { isBitcoinAddress } from '@subwallet/keyring/utils/address/validate';
|
|
54
56
|
import { keyring } from '@subwallet/ui-keyring';
|
|
55
57
|
import { getSdkError } from '@walletconnect/utils';
|
|
56
58
|
import BigN from 'bignumber.js';
|
|
59
|
+
import * as bitcoin from 'bitcoinjs-lib';
|
|
57
60
|
import { t } from 'i18next';
|
|
58
61
|
import { combineLatest, Subject } from 'rxjs';
|
|
59
62
|
import { TypeRegistry } from '@polkadot/types';
|
|
@@ -1244,6 +1247,7 @@ export default class KoniExtension {
|
|
|
1244
1247
|
decimals: _getAssetDecimals(transferTokenInfo)
|
|
1245
1248
|
};
|
|
1246
1249
|
let transaction;
|
|
1250
|
+
let overrideFeeCustom;
|
|
1247
1251
|
const transferTokenAvailable = await this.getAddressTransferableBalance({
|
|
1248
1252
|
address: from,
|
|
1249
1253
|
networkKey: chain,
|
|
@@ -1315,6 +1319,38 @@ export default class KoniExtension {
|
|
|
1315
1319
|
cardanoApi,
|
|
1316
1320
|
nativeTokenInfo
|
|
1317
1321
|
});
|
|
1322
|
+
} else if (isBitcoinAddress(from) && isBitcoinAddress(to) && _isTokenTransferredByBitcoin(transferTokenInfo)) {
|
|
1323
|
+
// Note: Currently supports transferring only the native token, Bitcoin.
|
|
1324
|
+
chainType = ChainType.BITCOIN;
|
|
1325
|
+
const chainInfo = this.#koniState.getChainInfo(chain);
|
|
1326
|
+
const network = chainInfo.isTestnet ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
|
|
1327
|
+
const txVal = transferAll ? transferTokenAvailable.value : value || '0';
|
|
1328
|
+
const bitcoinApi = this.#koniState.getBitcoinApi(chain);
|
|
1329
|
+
const feeInfo = await this.#koniState.feeService.subscribeChainFee(getId(), chain, 'bitcoin');
|
|
1330
|
+
let calculatedBitcoinFeeRate;
|
|
1331
|
+
[transaction, transferAmount.value, calculatedBitcoinFeeRate] = await createBitcoinTransaction({
|
|
1332
|
+
bitcoinApi,
|
|
1333
|
+
chain,
|
|
1334
|
+
from,
|
|
1335
|
+
feeInfo,
|
|
1336
|
+
to,
|
|
1337
|
+
transferAll: !!transferAll,
|
|
1338
|
+
value: txVal,
|
|
1339
|
+
network: network
|
|
1340
|
+
});
|
|
1341
|
+
if (calculatedBitcoinFeeRate) {
|
|
1342
|
+
const feeRate = parseFloat(calculatedBitcoinFeeRate);
|
|
1343
|
+
if (!isNaN(feeRate)) {
|
|
1344
|
+
overrideFeeCustom = {
|
|
1345
|
+
feeRate
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
// TODO: This is a hotfix until transferMax for Bitcoin is supported.
|
|
1351
|
+
if (transferAll) {
|
|
1352
|
+
inputData.value = transferAmount.value;
|
|
1353
|
+
}
|
|
1318
1354
|
} else {
|
|
1319
1355
|
const substrateApi = this.#koniState.getSubstrateApi(chain);
|
|
1320
1356
|
[transaction, transferAmount.value] = await createSubstrateExtrinsic({
|
|
@@ -1405,8 +1441,8 @@ export default class KoniExtension {
|
|
|
1405
1441
|
warnings,
|
|
1406
1442
|
address: from,
|
|
1407
1443
|
chain,
|
|
1408
|
-
feeCustom,
|
|
1409
|
-
feeOption,
|
|
1444
|
+
feeCustom: overrideFeeCustom || feeCustom,
|
|
1445
|
+
feeOption: overrideFeeCustom ? 'custom' : feeOption,
|
|
1410
1446
|
tokenPayFeeSlug,
|
|
1411
1447
|
chainType,
|
|
1412
1448
|
transferNativeAmount,
|
|
@@ -1864,6 +1900,7 @@ export default class KoniExtension {
|
|
|
1864
1900
|
destChain: _destChain,
|
|
1865
1901
|
feeCustom,
|
|
1866
1902
|
feeOption,
|
|
1903
|
+
to,
|
|
1867
1904
|
token,
|
|
1868
1905
|
tokenPayFeeSlug,
|
|
1869
1906
|
value
|
|
@@ -1886,6 +1923,7 @@ export default class KoniExtension {
|
|
|
1886
1923
|
}
|
|
1887
1924
|
const _request = {
|
|
1888
1925
|
address: address,
|
|
1926
|
+
to: to,
|
|
1889
1927
|
value,
|
|
1890
1928
|
// todo: lazy subscribe to improve performance
|
|
1891
1929
|
cardanoApi: this.#koniState.chainService.getCardanoApi(chain),
|
|
@@ -1898,6 +1936,7 @@ export default class KoniExtension {
|
|
|
1898
1936
|
srcToken,
|
|
1899
1937
|
substrateApi: this.#koniState.chainService.getSubstrateApi(chain),
|
|
1900
1938
|
tonApi: this.#koniState.chainService.getTonApi(chain),
|
|
1939
|
+
bitcoinApi: this.#koniState.chainService.getBitcoinApi(chain),
|
|
1901
1940
|
isTransferLocalTokenAndPayThatTokenAsFee,
|
|
1902
1941
|
isTransferNativeTokenAndPayLocalTokenAsFee,
|
|
1903
1942
|
nativeToken
|
|
@@ -2095,6 +2134,15 @@ export default class KoniExtension {
|
|
|
2095
2134
|
});
|
|
2096
2135
|
return this.#koniState.getConfirmationsQueueSubjectCardano().getValue();
|
|
2097
2136
|
}
|
|
2137
|
+
subscribeConfirmationsBitcoin(id, port) {
|
|
2138
|
+
const cb = createSubscription(id, port);
|
|
2139
|
+
const subscription = this.#koniState.getConfirmationsQueueSubjectBitcoin().subscribe(cb);
|
|
2140
|
+
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
2141
|
+
port.onDisconnect.addListener(() => {
|
|
2142
|
+
this.cancelSubscription(id);
|
|
2143
|
+
});
|
|
2144
|
+
return this.#koniState.getConfirmationsQueueSubjectBitcoin().getValue();
|
|
2145
|
+
}
|
|
2098
2146
|
async completeConfirmation(request) {
|
|
2099
2147
|
return await this.#koniState.completeConfirmation(request);
|
|
2100
2148
|
}
|
|
@@ -2104,7 +2152,9 @@ export default class KoniExtension {
|
|
|
2104
2152
|
async completeConfirmationCardano(request) {
|
|
2105
2153
|
return await this.#koniState.completeConfirmationCardano(request);
|
|
2106
2154
|
}
|
|
2107
|
-
|
|
2155
|
+
async completeConfirmationBitcoin(request) {
|
|
2156
|
+
return await this.#koniState.completeConfirmationBitcoin(request);
|
|
2157
|
+
}
|
|
2108
2158
|
/// Sign Qr
|
|
2109
2159
|
|
|
2110
2160
|
getNetworkJsonByChainId(chainId) {
|
|
@@ -4640,12 +4690,16 @@ export default class KoniExtension {
|
|
|
4640
4690
|
return this.subscribeConfirmationsTon(id, port);
|
|
4641
4691
|
case 'pri(confirmationsCardano.subscribe)':
|
|
4642
4692
|
return this.subscribeConfirmationsCardano(id, port);
|
|
4693
|
+
case 'pri(confirmationsBitcoin.subscribe)':
|
|
4694
|
+
return this.subscribeConfirmationsBitcoin(id, port);
|
|
4643
4695
|
case 'pri(confirmations.complete)':
|
|
4644
4696
|
return await this.completeConfirmation(request);
|
|
4645
4697
|
case 'pri(confirmationsTon.complete)':
|
|
4646
4698
|
return await this.completeConfirmationTon(request);
|
|
4647
4699
|
case 'pri(confirmationsCardano.complete)':
|
|
4648
4700
|
return await this.completeConfirmationCardano(request);
|
|
4701
|
+
case 'pri(confirmationsBitcoin.complete)':
|
|
4702
|
+
return await this.completeConfirmationBitcoin(request);
|
|
4649
4703
|
|
|
4650
4704
|
/// Stake
|
|
4651
4705
|
case 'pri(bonding.getBondingOptions)':
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="chrome" />
|
|
2
2
|
import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs';
|
|
3
3
|
import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
|
|
4
|
-
import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, ChainStakingMetadata, ConfirmationsQueue, ConfirmationsQueueCardano, ConfirmationsQueueTon, CrowdloanItem, CrowdloanJson, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCardanoSignData, RequestCardanoSignTransaction, RequestConfirmationComplete, RequestConfirmationCompleteCardano, RequestConfirmationCompleteTon, RequestCrowdloanContributions, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCardanoSignData, ResponseCardanoSignTransaction, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
|
+
import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, ChainStakingMetadata, ConfirmationsQueue, ConfirmationsQueueBitcoin, ConfirmationsQueueCardano, ConfirmationsQueueTon, CrowdloanItem, CrowdloanJson, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCardanoSignData, RequestCardanoSignTransaction, RequestConfirmationComplete, RequestConfirmationCompleteBitcoin, RequestConfirmationCompleteCardano, RequestConfirmationCompleteTon, RequestCrowdloanContributions, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCardanoSignData, ResponseCardanoSignTransaction, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning } from '@subwallet/extension-base/background/types';
|
|
6
6
|
import { EnvConfig } from '@subwallet/extension-base/constants';
|
|
7
7
|
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
@@ -82,6 +82,7 @@ export default class KoniState {
|
|
|
82
82
|
private generalStatus;
|
|
83
83
|
private waitSleeping;
|
|
84
84
|
private waitStarting;
|
|
85
|
+
private waitStartingFull;
|
|
85
86
|
constructor(providers?: Providers);
|
|
86
87
|
get knownMetadata(): MetadataDef[];
|
|
87
88
|
injectMetadata(request: MetadataDef): boolean;
|
|
@@ -100,7 +101,6 @@ export default class KoniState {
|
|
|
100
101
|
init(): Promise<void>;
|
|
101
102
|
initMantaPay(password: string): Promise<void>;
|
|
102
103
|
private startSubscription;
|
|
103
|
-
onReady(): void;
|
|
104
104
|
updateKeyringState(isReady?: boolean, callback?: () => void): void;
|
|
105
105
|
private lazyNext;
|
|
106
106
|
getAuthRequestV2(id: string): AuthRequestV2;
|
|
@@ -196,6 +196,7 @@ export default class KoniState {
|
|
|
196
196
|
getTonApi(networkKey: string): import("../../../services/chain-service/handler/TonApi").TonApi;
|
|
197
197
|
getCardanoApiMap(): Record<string, import("../../../services/chain-service/handler/CardanoApi").CardanoApi>;
|
|
198
198
|
getCardanoApi(networkKey: string): import("../../../services/chain-service/handler/CardanoApi").CardanoApi;
|
|
199
|
+
getBitcoinApi(networkKey: string): import("../../../services/chain-service/handler/bitcoin/BitcoinApi").BitcoinApi;
|
|
199
200
|
getApiMap(): ApiMap;
|
|
200
201
|
refreshSubstrateApi(key: string): boolean;
|
|
201
202
|
refreshWeb3Api(key: string): void;
|
|
@@ -224,9 +225,11 @@ export default class KoniState {
|
|
|
224
225
|
getConfirmationsQueueSubject(): BehaviorSubject<ConfirmationsQueue>;
|
|
225
226
|
getConfirmationsQueueSubjectTon(): BehaviorSubject<ConfirmationsQueueTon>;
|
|
226
227
|
getConfirmationsQueueSubjectCardano(): BehaviorSubject<ConfirmationsQueueCardano>;
|
|
228
|
+
getConfirmationsQueueSubjectBitcoin(): BehaviorSubject<ConfirmationsQueueBitcoin>;
|
|
227
229
|
completeConfirmation(request: RequestConfirmationComplete): Promise<boolean>;
|
|
228
230
|
completeConfirmationTon(request: RequestConfirmationCompleteTon): Promise<boolean>;
|
|
229
231
|
completeConfirmationCardano(request: RequestConfirmationCompleteCardano): Promise<boolean>;
|
|
232
|
+
completeConfirmationBitcoin(request: RequestConfirmationCompleteBitcoin): Promise<boolean>;
|
|
230
233
|
private onMV3Update;
|
|
231
234
|
private storePreviousVersionData;
|
|
232
235
|
migrateMV3LocalStorage(data: string): Promise<boolean>;
|
|
@@ -241,7 +244,8 @@ export default class KoniState {
|
|
|
241
244
|
get activeChainSlugs(): string[];
|
|
242
245
|
sleep(): Promise<void>;
|
|
243
246
|
private _start;
|
|
244
|
-
|
|
247
|
+
private _startFull;
|
|
248
|
+
wakeup(fullWakeup?: boolean): Promise<void>;
|
|
245
249
|
cancelSubscription(id: string): boolean;
|
|
246
250
|
createUnsubscriptionHandle(id: string, unsubscribe: () => void): void;
|
|
247
251
|
get detectBalanceChainSlugMap(): Record<string, string>;
|
|
@@ -87,6 +87,7 @@ export default class KoniState {
|
|
|
87
87
|
generalStatus = ServiceStatus.INITIALIZING;
|
|
88
88
|
waitSleeping = null;
|
|
89
89
|
waitStarting = null;
|
|
90
|
+
waitStartingFull = null;
|
|
90
91
|
constructor(providers = {}) {
|
|
91
92
|
// Init subwallet api sdk
|
|
92
93
|
subwalletApiSdk.init({
|
|
@@ -97,11 +98,13 @@ export default class KoniState {
|
|
|
97
98
|
this.eventService = new EventService();
|
|
98
99
|
this.dbService = new DatabaseService(this.eventService);
|
|
99
100
|
this.keyringService = new KeyringService(this);
|
|
101
|
+
this.feeService = new FeeService(this);
|
|
102
|
+
this.transactionService = new TransactionService(this);
|
|
100
103
|
this.notificationService = new NotificationService();
|
|
101
104
|
this.chainService = new ChainService(this.dbService, this.eventService);
|
|
102
105
|
this.subscanService = SubscanService.getInstance();
|
|
103
106
|
this.settingService = new SettingService();
|
|
104
|
-
this.requestService = new RequestService(this.chainService, this.settingService, this.keyringService);
|
|
107
|
+
this.requestService = new RequestService(this.chainService, this.settingService, this.keyringService, this.feeService, this.transactionService);
|
|
105
108
|
this.priceService = new PriceService(this.dbService, this.eventService, this.chainService);
|
|
106
109
|
this.balanceService = new BalanceService(this);
|
|
107
110
|
this.historyService = new HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService, this.subscanService);
|
|
@@ -111,9 +114,7 @@ export default class KoniState {
|
|
|
111
114
|
this.campaignService = new CampaignService(this);
|
|
112
115
|
this.mktCampaignService = new MktCampaignService(this);
|
|
113
116
|
this.buyService = new BuyService(this);
|
|
114
|
-
this.transactionService = new TransactionService(this);
|
|
115
117
|
this.earningService = new EarningService(this);
|
|
116
|
-
this.feeService = new FeeService(this);
|
|
117
118
|
this.swapService = new SwapService(this);
|
|
118
119
|
this.inappNotificationService = new InappNotificationService(this.dbService, this.keyringService, this.eventService, this.chainService);
|
|
119
120
|
this.chainOnlineService = new ChainOnlineService(this.chainService, this.settingService, this.eventService, this.dbService);
|
|
@@ -123,7 +124,9 @@ export default class KoniState {
|
|
|
123
124
|
|
|
124
125
|
// Init state
|
|
125
126
|
if (targetIsWeb) {
|
|
126
|
-
this.init().
|
|
127
|
+
this.init().then(() => {
|
|
128
|
+
this.wakeup(true).catch(console.error);
|
|
129
|
+
}).catch(console.error);
|
|
127
130
|
}
|
|
128
131
|
}
|
|
129
132
|
|
|
@@ -218,7 +221,8 @@ export default class KoniState {
|
|
|
218
221
|
await this.earningService.init();
|
|
219
222
|
await this.swapService.init();
|
|
220
223
|
await this.inappNotificationService.init();
|
|
221
|
-
|
|
224
|
+
|
|
225
|
+
// this.onReady();
|
|
222
226
|
this.onAccountAdd();
|
|
223
227
|
this.onAccountRemove();
|
|
224
228
|
|
|
@@ -230,6 +234,9 @@ export default class KoniState {
|
|
|
230
234
|
this.chainService.subscribeChainInfoMap().subscribe(() => {
|
|
231
235
|
this.afterChainServiceInit();
|
|
232
236
|
});
|
|
237
|
+
|
|
238
|
+
// Mark app is ready
|
|
239
|
+
this.eventService.emit('general.init', true);
|
|
233
240
|
}
|
|
234
241
|
async initMantaPay(password) {
|
|
235
242
|
var _this$chainService, _this$chainService$ma;
|
|
@@ -253,11 +260,6 @@ export default class KoniState {
|
|
|
253
260
|
this.mantaPayConfigSubject.next(data);
|
|
254
261
|
});
|
|
255
262
|
}
|
|
256
|
-
onReady() {
|
|
257
|
-
// Todo: Need optimize in the future to, only run important services onetime to save resources
|
|
258
|
-
// Todo: If optimize must check activity of web-runner of mobile
|
|
259
|
-
this._start().catch(console.error);
|
|
260
|
-
}
|
|
261
263
|
updateKeyringState(isReady = true, callback) {
|
|
262
264
|
this.keyringService.updateKeyringState(isReady);
|
|
263
265
|
callback && callback();
|
|
@@ -740,6 +742,9 @@ export default class KoniState {
|
|
|
740
742
|
getCardanoApi(networkKey) {
|
|
741
743
|
return this.chainService.getCardanoApi(networkKey);
|
|
742
744
|
}
|
|
745
|
+
getBitcoinApi(networkKey) {
|
|
746
|
+
return this.chainService.getBitcoinApi(networkKey);
|
|
747
|
+
}
|
|
743
748
|
getApiMap() {
|
|
744
749
|
return {
|
|
745
750
|
substrate: this.chainService.getSubstrateApiMap(),
|
|
@@ -1245,6 +1250,9 @@ export default class KoniState {
|
|
|
1245
1250
|
getConfirmationsQueueSubjectCardano() {
|
|
1246
1251
|
return this.requestService.confirmationsQueueSubjectCardano;
|
|
1247
1252
|
}
|
|
1253
|
+
getConfirmationsQueueSubjectBitcoin() {
|
|
1254
|
+
return this.requestService.confirmationsQueueSubjectBitcoin;
|
|
1255
|
+
}
|
|
1248
1256
|
async completeConfirmation(request) {
|
|
1249
1257
|
return await this.requestService.completeConfirmation(request);
|
|
1250
1258
|
}
|
|
@@ -1254,6 +1262,9 @@ export default class KoniState {
|
|
|
1254
1262
|
async completeConfirmationCardano(request) {
|
|
1255
1263
|
return await this.requestService.completeConfirmationCardano(request);
|
|
1256
1264
|
}
|
|
1265
|
+
async completeConfirmationBitcoin(request) {
|
|
1266
|
+
return await this.requestService.completeConfirmationBitcoin(request);
|
|
1267
|
+
}
|
|
1257
1268
|
async onMV3Update() {
|
|
1258
1269
|
const migrationStatus = await SWStorage.instance.getItem('mv3_migration');
|
|
1259
1270
|
if (!migrationStatus || migrationStatus !== 'done') {
|
|
@@ -1404,8 +1415,12 @@ export default class KoniState {
|
|
|
1404
1415
|
});
|
|
1405
1416
|
}
|
|
1406
1417
|
async sleep() {
|
|
1418
|
+
// Wait for app initialized before sleep
|
|
1419
|
+
await this.eventService.waitAppInitialized;
|
|
1420
|
+
|
|
1407
1421
|
// Wait starting finish before sleep to avoid conflict
|
|
1408
1422
|
this.generalStatus === ServiceStatus.STARTING && this.waitStarting && (await this.waitStarting);
|
|
1423
|
+
this.generalStatus === ServiceStatus.STARTING_FULL && this.waitStartingFull && (await this.waitStartingFull);
|
|
1409
1424
|
this.eventService.emit('general.sleep', true);
|
|
1410
1425
|
|
|
1411
1426
|
// Avoid sleep multiple times
|
|
@@ -1434,6 +1449,9 @@ export default class KoniState {
|
|
|
1434
1449
|
this.waitSleeping = null;
|
|
1435
1450
|
}
|
|
1436
1451
|
async _start() {
|
|
1452
|
+
// Wait for app initialized before start
|
|
1453
|
+
await this.eventService.waitAppInitialized;
|
|
1454
|
+
|
|
1437
1455
|
// Wait sleep finish before start to avoid conflict
|
|
1438
1456
|
this.generalStatus === ServiceStatus.STOPPING && this.waitSleeping && (await this.waitSleeping);
|
|
1439
1457
|
|
|
@@ -1459,15 +1477,37 @@ export default class KoniState {
|
|
|
1459
1477
|
}
|
|
1460
1478
|
|
|
1461
1479
|
// Start services
|
|
1462
|
-
|
|
1480
|
+
this.eventService.emit('general.start', true);
|
|
1463
1481
|
|
|
1464
1482
|
// Complete starting
|
|
1465
1483
|
starting.resolve();
|
|
1466
1484
|
this.waitStarting = null;
|
|
1467
1485
|
this.generalStatus = ServiceStatus.STARTED;
|
|
1468
1486
|
}
|
|
1469
|
-
async
|
|
1487
|
+
async _startFull() {
|
|
1488
|
+
// Continue wait existed starting process
|
|
1489
|
+
if (this.generalStatus === ServiceStatus.STARTING) {
|
|
1490
|
+
await this.waitStarting;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
// Always start full from start state
|
|
1494
|
+
if (this.generalStatus !== ServiceStatus.STARTED) {
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
this.generalStatus = ServiceStatus.STARTING_FULL;
|
|
1498
|
+
const startingFull = createPromiseHandler();
|
|
1499
|
+
this.waitStartingFull = startingFull.promise;
|
|
1500
|
+
await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.balanceService.start(), this.earningService.start(), this.swapService.start(), this.inappNotificationService.start()]);
|
|
1501
|
+
this.eventService.emit('general.start_full', true);
|
|
1502
|
+
this.waitStartingFull = null;
|
|
1503
|
+
this.generalStatus = ServiceStatus.STARTED_FULL;
|
|
1504
|
+
startingFull.resolve();
|
|
1505
|
+
}
|
|
1506
|
+
async wakeup(fullWakeup = false) {
|
|
1470
1507
|
await this._start();
|
|
1508
|
+
if (fullWakeup) {
|
|
1509
|
+
await this._startFull();
|
|
1510
|
+
}
|
|
1471
1511
|
}
|
|
1472
1512
|
cancelSubscription(id) {
|
|
1473
1513
|
if (isSubscriptionRunning(id)) {
|