@subwallet/extension-base 1.3.22-0 → 1.3.24-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +77 -4
- package/background/KoniTypes.js +2 -0
- package/cjs/background/KoniTypes.js +2 -0
- package/cjs/constants/environment.js +4 -2
- package/cjs/constants/index.js +21 -4
- package/cjs/constants/signing.js +6 -2
- package/cjs/core/logic-validation/recipientAddress.js +9 -1
- package/cjs/core/logic-validation/transfer.js +57 -36
- package/cjs/core/types.js +1 -0
- package/cjs/core/utils.js +12 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/api/dotsama/crowdloan.js +1 -1
- package/cjs/koni/api/nft/index.js +9 -16
- package/cjs/koni/api/staking/index.js +3 -4
- package/cjs/koni/background/handlers/Extension.js +343 -185
- package/cjs/koni/background/handlers/State.js +17 -2
- package/cjs/koni/background/handlers/Tabs.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/cardano/consts.js +11 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/index.js +63 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/utils.js +74 -0
- package/cjs/services/balance-service/helpers/subscribe/index.js +21 -7
- package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +2 -2
- package/cjs/services/balance-service/index.js +4 -2
- package/cjs/services/balance-service/transfer/cardano-transfer.js +122 -0
- package/cjs/services/balance-service/transfer/smart-contract.js +24 -3
- package/cjs/services/balance-service/transfer/token.js +4 -4
- package/cjs/services/chain-service/handler/CardanoApi.js +176 -0
- package/cjs/services/chain-service/handler/CardanoChainHandler.js +83 -0
- package/cjs/services/chain-service/handler/TonApi.js +2 -5
- package/cjs/services/chain-service/index.js +40 -7
- package/cjs/services/chain-service/utils/index.js +40 -11
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/cjs/services/earning-service/service.js +6 -12
- package/cjs/services/fee-service/service.js +19 -8
- package/cjs/services/fee-service/utils/tokenPayFee.js +151 -0
- package/cjs/services/history-service/index.js +4 -6
- package/cjs/services/inapp-notification-service/index.js +12 -4
- package/cjs/services/keyring-service/context/account-context.js +17 -2
- package/cjs/services/keyring-service/context/handlers/Derive.js +10 -7
- package/cjs/services/keyring-service/context/handlers/Migration.js +268 -0
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/cjs/services/keyring-service/context/handlers/Secret.js +1 -1
- package/cjs/services/keyring-service/utils.js +18 -0
- package/cjs/services/request-service/handler/CardanoRequestHandler.js +172 -0
- package/cjs/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/cjs/services/request-service/handler/MetadataRequestHandler.js +5 -13
- package/cjs/services/request-service/index.js +22 -4
- package/cjs/services/setting-service/constants.js +10 -1
- package/cjs/services/storage-service/DatabaseService.js +3 -0
- package/cjs/services/storage-service/db-stores/InappNotification.js +6 -0
- package/cjs/services/swap-service/handler/asset-hub/handler.js +0 -59
- package/cjs/services/swap-service/handler/chainflip-handler.js +33 -281
- package/cjs/services/swap-service/handler/hydradx-handler.js +23 -190
- package/cjs/services/swap-service/handler/simpleswap-handler.js +1 -222
- package/cjs/services/swap-service/handler/uniswap-handler.js +331 -0
- package/cjs/services/swap-service/index.js +31 -22
- package/cjs/services/swap-service/utils.js +21 -38
- package/cjs/services/transaction-service/helpers/index.js +6 -1
- package/cjs/services/transaction-service/index.js +286 -26
- package/cjs/services/transaction-service/utils.js +5 -1
- package/cjs/types/account/info/keyring.js +12 -1
- package/cjs/types/fee/cardano.js +1 -0
- package/cjs/types/swap/index.js +7 -2
- package/cjs/utils/account/analyze.js +2 -1
- package/cjs/utils/account/common.js +29 -20
- package/cjs/utils/account/derive/info/solo.js +9 -4
- package/cjs/utils/account/derive/validate.js +36 -2
- package/cjs/utils/account/transform.js +38 -13
- package/cjs/utils/fee/transfer.js +87 -21
- package/cjs/utils/index.js +2 -2
- package/cjs/utils/staticData/index.js +7 -2
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- package/constants/index.d.ts +6 -1
- package/constants/index.js +14 -1
- package/constants/signing.js +6 -2
- package/core/logic-validation/recipientAddress.js +11 -3
- package/core/logic-validation/transfer.d.ts +1 -1
- package/core/logic-validation/transfer.js +33 -12
- package/core/substrate/xcm-parser.d.ts +1 -1
- package/core/types.d.ts +1 -0
- package/core/types.js +1 -0
- package/core/utils.d.ts +1 -0
- package/core/utils.js +13 -3
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/api/dotsama/crowdloan.js +3 -3
- package/koni/api/nft/index.js +10 -16
- package/koni/api/nft/story_odyssey_nft/index.d.ts +1 -1
- package/koni/api/staking/index.js +4 -5
- package/koni/background/handlers/Extension.d.ts +9 -0
- package/koni/background/handlers/Extension.js +225 -69
- package/koni/background/handlers/State.d.ts +6 -2
- package/koni/background/handlers/State.js +18 -3
- package/koni/background/handlers/Tabs.js +1 -1
- package/package.json +76 -9
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/cardano/consts.d.ts +1 -0
- package/services/balance-service/helpers/subscribe/cardano/consts.js +4 -0
- package/services/balance-service/helpers/subscribe/cardano/index.d.ts +2 -0
- package/services/balance-service/helpers/subscribe/cardano/index.js +57 -0
- package/services/balance-service/helpers/subscribe/cardano/types.d.ts +34 -0
- package/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.d.ts +15 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.js +62 -0
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/index.js +23 -9
- package/services/balance-service/helpers/subscribe/ton/utils.d.ts +1 -1
- package/services/balance-service/helpers/subscribe/ton/utils.js +1 -1
- package/services/balance-service/index.js +4 -2
- package/services/balance-service/transfer/cardano-transfer.d.ts +24 -0
- package/services/balance-service/transfer/cardano-transfer.js +114 -0
- package/services/balance-service/transfer/smart-contract.d.ts +4 -2
- package/services/balance-service/transfer/smart-contract.js +24 -3
- package/services/balance-service/transfer/token.d.ts +1 -1
- package/services/balance-service/transfer/token.js +2 -2
- package/services/chain-service/handler/CardanoApi.d.ts +38 -0
- package/services/chain-service/handler/CardanoApi.js +167 -0
- package/services/chain-service/handler/CardanoChainHandler.d.ts +17 -0
- package/services/chain-service/handler/CardanoChainHandler.js +75 -0
- package/services/chain-service/handler/TonApi.js +3 -6
- package/services/chain-service/handler/types.d.ts +1 -0
- package/services/chain-service/index.d.ts +4 -1
- package/services/chain-service/index.js +41 -8
- package/services/chain-service/types.d.ts +9 -1
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +32 -11
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/services/earning-service/service.js +8 -14
- package/services/fee-service/interfaces.d.ts +25 -0
- package/services/fee-service/service.js +19 -8
- package/services/fee-service/utils/tokenPayFee.d.ts +8 -0
- package/services/fee-service/utils/tokenPayFee.js +141 -0
- package/services/history-service/index.js +6 -8
- package/services/inapp-notification-service/index.d.ts +3 -4
- package/services/inapp-notification-service/index.js +14 -6
- package/services/keyring-service/context/account-context.d.ts +6 -2
- package/services/keyring-service/context/account-context.js +17 -2
- package/services/keyring-service/context/handlers/Derive.d.ts +1 -1
- package/services/keyring-service/context/handlers/Derive.js +10 -8
- package/services/keyring-service/context/handlers/Migration.d.ts +17 -0
- package/services/keyring-service/context/handlers/Migration.js +258 -0
- package/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/services/keyring-service/context/handlers/Secret.js +2 -2
- package/services/keyring-service/utils.d.ts +2 -0
- package/services/keyring-service/utils.js +11 -0
- package/services/request-service/handler/CardanoRequestHandler.d.ts +16 -0
- package/services/request-service/handler/CardanoRequestHandler.js +163 -0
- package/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -1
- package/services/request-service/handler/MetadataRequestHandler.js +5 -13
- package/services/request-service/index.d.ts +7 -4
- package/services/request-service/index.js +21 -7
- package/services/setting-service/constants.d.ts +3 -0
- package/services/setting-service/constants.js +6 -0
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +3 -0
- package/services/storage-service/db-stores/InappNotification.d.ts +1 -0
- package/services/storage-service/db-stores/InappNotification.js +6 -0
- package/services/swap-service/handler/asset-hub/handler.d.ts +1 -4
- package/services/swap-service/handler/asset-hub/handler.js +2 -61
- package/services/swap-service/handler/base-handler.d.ts +1 -4
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -9
- package/services/swap-service/handler/chainflip-handler.js +31 -280
- package/services/swap-service/handler/hydradx-handler.d.ts +1 -6
- package/services/swap-service/handler/hydradx-handler.js +13 -180
- package/services/swap-service/handler/simpleswap-handler.d.ts +1 -4
- package/services/swap-service/handler/simpleswap-handler.js +5 -226
- package/services/swap-service/handler/uniswap-handler.d.ts +41 -0
- package/services/swap-service/handler/uniswap-handler.js +323 -0
- package/services/swap-service/index.js +30 -22
- package/services/swap-service/utils.d.ts +1 -5
- package/services/swap-service/utils.js +7 -21
- package/services/transaction-service/helpers/index.d.ts +2 -0
- package/services/transaction-service/helpers/index.js +4 -0
- package/services/transaction-service/index.d.ts +8 -2
- package/services/transaction-service/index.js +273 -17
- package/services/transaction-service/types.d.ts +7 -0
- package/services/transaction-service/utils.js +7 -2
- package/types/account/info/keyring.d.ts +4 -1
- package/types/account/info/keyring.js +9 -0
- package/types/account/info/proxy.d.ts +2 -0
- package/types/balance/index.d.ts +4 -1
- package/types/fee/base.d.ts +1 -1
- package/types/fee/cardano.d.ts +18 -0
- package/types/fee/cardano.js +1 -0
- package/types/fee/option.d.ts +1 -1
- package/types/fee/subscription.d.ts +4 -3
- package/types/swap/index.d.ts +11 -3
- package/types/swap/index.js +7 -2
- package/utils/account/analyze.js +2 -1
- package/utils/account/common.d.ts +11 -6
- package/utils/account/common.js +28 -19
- package/utils/account/derive/info/solo.js +10 -5
- package/utils/account/derive/validate.d.ts +1 -0
- package/utils/account/derive/validate.js +34 -1
- package/utils/account/transform.d.ts +2 -1
- package/utils/account/transform.js +37 -13
- package/utils/fee/transfer.d.ts +3 -2
- package/utils/fee/transfer.js +90 -24
- package/utils/index.js +4 -4
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/oldChainPrefix.json +1 -0
|
@@ -15,7 +15,8 @@ class FeeService {
|
|
|
15
15
|
chainFeeSubscriptionMap = {
|
|
16
16
|
evm: {},
|
|
17
17
|
substrate: {},
|
|
18
|
-
ton: {}
|
|
18
|
+
ton: {},
|
|
19
|
+
cardano: {}
|
|
19
20
|
};
|
|
20
21
|
constructor(state) {
|
|
21
22
|
this.state = state;
|
|
@@ -109,21 +110,31 @@ class FeeService {
|
|
|
109
110
|
const api = this.state.getEvmApi(chain);
|
|
110
111
|
|
|
111
112
|
// TODO: Handle case type === evm and not have api
|
|
112
|
-
if (type === 'evm'
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
if (type === 'evm') {
|
|
114
|
+
if (api) {
|
|
115
|
+
(0, _utils2.calculateGasFeeParams)(api, chain).then(info => {
|
|
116
|
+
observer.next(info);
|
|
117
|
+
}).catch(e => {
|
|
118
|
+
console.warn(`Cannot get fee param for ${chain}`, e);
|
|
119
|
+
observer.next({
|
|
120
|
+
type: 'evm',
|
|
121
|
+
gasPrice: '0',
|
|
122
|
+
baseGasFee: undefined,
|
|
123
|
+
options: undefined
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
console.warn(`Cannot get fee param for ${chain}`, 'Cannot get api');
|
|
117
128
|
observer.next({
|
|
118
129
|
type: 'evm',
|
|
119
130
|
gasPrice: '0',
|
|
120
131
|
baseGasFee: undefined,
|
|
121
132
|
options: undefined
|
|
122
133
|
});
|
|
123
|
-
}
|
|
134
|
+
}
|
|
124
135
|
} else {
|
|
125
136
|
observer.next({
|
|
126
|
-
type
|
|
137
|
+
type,
|
|
127
138
|
busyNetwork: false,
|
|
128
139
|
options: {
|
|
129
140
|
slow: {
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.batchExtrinsicSetFeeHydration = batchExtrinsicSetFeeHydration;
|
|
8
|
+
exports.getAssetHubTokensCanPayFee = getAssetHubTokensCanPayFee;
|
|
9
|
+
exports.getHydrationRate = getHydrationRate;
|
|
10
|
+
exports.getHydrationTokensCanPayFee = getHydrationTokensCanPayFee;
|
|
11
|
+
var _types = require("@subwallet/chain-list/types");
|
|
12
|
+
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
13
|
+
var _utils2 = require("@subwallet/extension-base/services/swap-service/handler/asset-hub/utils");
|
|
14
|
+
var _subwalletApiSdk = _interopRequireDefault(require("@subwallet/subwallet-api-sdk"));
|
|
15
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
16
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
17
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
18
|
+
|
|
19
|
+
async function getAssetHubTokensCanPayFee(request) {
|
|
20
|
+
const {
|
|
21
|
+
chainService,
|
|
22
|
+
feeAmount,
|
|
23
|
+
nativeBalanceInfo,
|
|
24
|
+
nativeTokenInfo,
|
|
25
|
+
substrateApi,
|
|
26
|
+
tokensHasBalanceInfoMap
|
|
27
|
+
} = request;
|
|
28
|
+
const tokensList = [nativeBalanceInfo];
|
|
29
|
+
if (!(nativeTokenInfo.metadata && nativeTokenInfo.metadata.multilocation)) {
|
|
30
|
+
return tokensList;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ensure nativeTokenInfo and localTokenInfo have multi-location metadata beforehand to improve performance.
|
|
34
|
+
const tokensHasBalanceSlug = Object.keys(tokensHasBalanceInfoMap);
|
|
35
|
+
const tokenInfos = tokensHasBalanceSlug.map(tokenSlug => chainService.getAssetBySlug(tokenSlug)).filter(token => token.originChain === substrateApi.chainSlug && token.assetType !== _types._AssetType.NATIVE && token.metadata && token.metadata.multilocation);
|
|
36
|
+
await Promise.all(tokenInfos.map(async tokenInfo => {
|
|
37
|
+
try {
|
|
38
|
+
const tokenSlug = tokenInfo.slug;
|
|
39
|
+
const reserve = await (0, _utils2.getReserveForPool)(substrateApi.api, nativeTokenInfo, tokenInfo);
|
|
40
|
+
if (!reserve || !reserve[0] || !reserve[1] || reserve[0] === '0' || reserve[1] === '0') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const rate = new _bignumber.default(reserve[1]).div(reserve[0]).toFixed();
|
|
44
|
+
const tokenCanPayFee = {
|
|
45
|
+
slug: tokenSlug,
|
|
46
|
+
free: tokensHasBalanceInfoMap[tokenSlug].free,
|
|
47
|
+
rate
|
|
48
|
+
};
|
|
49
|
+
if (feeAmount === undefined) {
|
|
50
|
+
tokensList.push(tokenCanPayFee);
|
|
51
|
+
} else {
|
|
52
|
+
const amount = (0, _utils2.estimateTokensForPool)(feeAmount, reserve);
|
|
53
|
+
const liquidityError = (0, _utils2.checkLiquidityForPool)(amount, reserve[0], reserve[1]);
|
|
54
|
+
if (!liquidityError) {
|
|
55
|
+
tokensList.push(tokenCanPayFee);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.error('error when fetching pool with token', tokenInfo.slug, e);
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
return tokensList;
|
|
63
|
+
}
|
|
64
|
+
async function getHydrationTokensCanPayFee(request) {
|
|
65
|
+
const {
|
|
66
|
+
address,
|
|
67
|
+
chainService,
|
|
68
|
+
nativeBalanceInfo,
|
|
69
|
+
nativeTokenInfo,
|
|
70
|
+
substrateApi,
|
|
71
|
+
tokensHasBalanceInfoMap
|
|
72
|
+
} = request;
|
|
73
|
+
const tokensList = [nativeBalanceInfo];
|
|
74
|
+
const _acceptedCurrencies = await substrateApi.api.query.multiTransactionPayment.acceptedCurrencies.entries();
|
|
75
|
+
const supportedAssetIds = _acceptedCurrencies.map(_assetId => {
|
|
76
|
+
const assetId = _assetId[0].toHuman();
|
|
77
|
+
return assetId[0].replaceAll(',', '');
|
|
78
|
+
});
|
|
79
|
+
const nativePriceId = (0, _utils._getAssetPriceId)(nativeTokenInfo);
|
|
80
|
+
if (!nativePriceId) {
|
|
81
|
+
return tokensList;
|
|
82
|
+
}
|
|
83
|
+
const tokenInfos = Object.keys(tokensHasBalanceInfoMap).map(tokenSlug => chainService.getAssetBySlug(tokenSlug)).filter(token => token.originChain === substrateApi.chainSlug && token.assetType !== _types._AssetType.NATIVE && !!token.metadata && !!token.metadata.assetId);
|
|
84
|
+
await Promise.all(tokenInfos.map(async tokenInfo => {
|
|
85
|
+
const priceId = (0, _utils._getAssetPriceId)(tokenInfo);
|
|
86
|
+
const rate = await getHydrationRate(address, nativeTokenInfo, tokenInfo);
|
|
87
|
+
if (priceId && rate) {
|
|
88
|
+
if (supportedAssetIds.includes((0, _utils._getTokenOnChainAssetId)(tokenInfo))) {
|
|
89
|
+
tokensList.push({
|
|
90
|
+
slug: tokenInfo.slug,
|
|
91
|
+
free: tokensHasBalanceInfoMap[tokenInfo.slug].free,
|
|
92
|
+
rate: rate.toString()
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}));
|
|
97
|
+
return tokensList;
|
|
98
|
+
}
|
|
99
|
+
function batchExtrinsicSetFeeHydration(substrateApi, tx, feeSetting, assetId) {
|
|
100
|
+
const api = substrateApi.api;
|
|
101
|
+
const isSettingLocalFee = feeSetting && feeSetting !== 0;
|
|
102
|
+
const isAttendToSetLocalFee = assetId && assetId !== '0';
|
|
103
|
+
if (!tx) {
|
|
104
|
+
return tx;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// current native - set native
|
|
108
|
+
if (!isSettingLocalFee && !isAttendToSetLocalFee) {
|
|
109
|
+
return tx;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// current native - set local
|
|
113
|
+
if (!isSettingLocalFee && isAttendToSetLocalFee) {
|
|
114
|
+
return api.tx.utility.batchAll([api.tx.multiTransactionPayment.setCurrency(assetId), tx, api.tx.multiTransactionPayment.setCurrency('0')]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// current local - set native
|
|
118
|
+
if (isSettingLocalFee && !isAttendToSetLocalFee) {
|
|
119
|
+
return api.tx.utility.batchAll([api.tx.multiTransactionPayment.setCurrency('0'), tx]);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// current local - set local
|
|
123
|
+
if (isSettingLocalFee && isAttendToSetLocalFee) {
|
|
124
|
+
if (assetId === feeSetting.toString()) {
|
|
125
|
+
// current local = set local
|
|
126
|
+
return api.tx.utility.batchAll([tx, api.tx.multiTransactionPayment.setCurrency('0')]);
|
|
127
|
+
} else {
|
|
128
|
+
// current local != set local
|
|
129
|
+
return api.tx.utility.batchAll([api.tx.multiTransactionPayment.setCurrency(assetId), tx, api.tx.multiTransactionPayment.setCurrency('0')]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return tx;
|
|
133
|
+
}
|
|
134
|
+
async function getHydrationRate(address, hdx, desToken) {
|
|
135
|
+
var _subwalletApiSdk$swap;
|
|
136
|
+
const quoteRate = await ((_subwalletApiSdk$swap = _subwalletApiSdk.default.swapApi) === null || _subwalletApiSdk$swap === void 0 ? void 0 : _subwalletApiSdk$swap.getHydrationRate({
|
|
137
|
+
address,
|
|
138
|
+
pair: {
|
|
139
|
+
slug: `${hdx.slug}___${desToken.slug}`,
|
|
140
|
+
from: hdx.slug,
|
|
141
|
+
to: desToken.slug
|
|
142
|
+
}
|
|
143
|
+
}));
|
|
144
|
+
if (!quoteRate) {
|
|
145
|
+
return undefined;
|
|
146
|
+
} else {
|
|
147
|
+
const hdxDecimal = (0, _utils._getAssetDecimals)(hdx);
|
|
148
|
+
const desTokenDecimal = (0, _utils._getAssetDecimals)(desToken);
|
|
149
|
+
return new _bignumber.default(quoteRate).multipliedBy(10 ** (desTokenDecimal - hdxDecimal)).toFixed();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -151,19 +151,17 @@ class HistoryService {
|
|
|
151
151
|
}
|
|
152
152
|
subscribeHistories(chain, proxyId, cb) {
|
|
153
153
|
const addresses = this.keyringService.context.getDecodedAddresses(proxyId, false);
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
substrate
|
|
157
|
-
} = (0, _utils2.categoryAddresses)(addresses);
|
|
154
|
+
const evmAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.EVM]);
|
|
155
|
+
const substrateAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.SUBSTRATE]);
|
|
158
156
|
const subscription = this.historySubject.subscribe(items => {
|
|
159
157
|
cb(items.filter(filterHistoryItemByAddressAndChain(chain, addresses)));
|
|
160
158
|
});
|
|
161
159
|
const chainInfo = this.chainService.getChainInfoByKey(chain);
|
|
162
160
|
if ((0, _utils._isChainSubstrateCompatible)(chainInfo)) {
|
|
163
161
|
if ((0, _utils._isChainEvmCompatible)(chainInfo)) {
|
|
164
|
-
this.fetchSubscanTransactionHistory(chain,
|
|
162
|
+
this.fetchSubscanTransactionHistory(chain, evmAddresses);
|
|
165
163
|
} else {
|
|
166
|
-
this.fetchSubscanTransactionHistory(chain,
|
|
164
|
+
this.fetchSubscanTransactionHistory(chain, substrateAddresses);
|
|
167
165
|
}
|
|
168
166
|
}
|
|
169
167
|
return {
|
|
@@ -177,12 +177,17 @@ class InappNotificationService {
|
|
|
177
177
|
}
|
|
178
178
|
getCategorizedAddresses() {
|
|
179
179
|
const addresses = this.keyringService.context.getAllAddresses();
|
|
180
|
-
|
|
180
|
+
const evmAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.EVM]);
|
|
181
|
+
const substrateAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.SUBSTRATE]);
|
|
182
|
+
return {
|
|
183
|
+
evmAddresses: evmAddresses,
|
|
184
|
+
substrateAddresses: substrateAddresses
|
|
185
|
+
};
|
|
181
186
|
}
|
|
182
187
|
createAvailBridgeClaimNotification() {
|
|
183
188
|
const {
|
|
184
|
-
|
|
185
|
-
|
|
189
|
+
evmAddresses,
|
|
190
|
+
substrateAddresses
|
|
186
191
|
} = this.getCategorizedAddresses();
|
|
187
192
|
const chainAssets = this.chainService.getAssetRegistry();
|
|
188
193
|
let ASSET_TYPE;
|
|
@@ -269,7 +274,7 @@ class InappNotificationService {
|
|
|
269
274
|
// Polygon Claimable Handle
|
|
270
275
|
async createPolygonClaimableTransactions() {
|
|
271
276
|
const {
|
|
272
|
-
|
|
277
|
+
evmAddresses
|
|
273
278
|
} = this.getCategorizedAddresses();
|
|
274
279
|
const etherChains = [_chainList.COMMON_ASSETS.ETH, _chainList.COMMON_ASSETS.ETH_SEPOLIA];
|
|
275
280
|
const polygonAssets = Object.values(this.chainService.getAssetRegistry()).filter(asset => etherChains.includes(asset.slug));
|
|
@@ -440,5 +445,8 @@ class InappNotificationService {
|
|
|
440
445
|
removeAccountNotifications(proxyId) {
|
|
441
446
|
this.dbService.removeAccountNotifications(proxyId).catch(console.error);
|
|
442
447
|
}
|
|
448
|
+
migrateNotificationProxyId(proxyIds, newProxyId, newName) {
|
|
449
|
+
this.dbService.updateNotificationProxyId(proxyIds, newProxyId, newName);
|
|
450
|
+
}
|
|
443
451
|
}
|
|
444
452
|
exports.InappNotificationService = InappNotificationService;
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.AccountContext = void 0;
|
|
7
|
+
var _Migration = require("@subwallet/extension-base/services/keyring-service/context/handlers/Migration");
|
|
7
8
|
var _handlers = require("./handlers");
|
|
8
9
|
var _state = require("./state");
|
|
9
10
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
@@ -21,6 +22,7 @@ class AccountContext {
|
|
|
21
22
|
this.ledgerHandler = new _handlers.AccountLedgerHandler(this.parentService, this.state);
|
|
22
23
|
this.modifyHandler = new _handlers.AccountModifyHandler(this.parentService, this.state);
|
|
23
24
|
this.secretHandler = new _handlers.AccountSecretHandler(this.parentService, this.state);
|
|
25
|
+
this.migrationHandler = new _Migration.AccountMigrationHandler(this.parentService, this.state);
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
// TODO: Merge to value
|
|
@@ -230,8 +232,8 @@ class AccountContext {
|
|
|
230
232
|
}
|
|
231
233
|
|
|
232
234
|
/* Derive account proxy */
|
|
233
|
-
derivationAccountProxyCreate(request) {
|
|
234
|
-
return this.deriveHandler.derivationAccountProxyCreate(request);
|
|
235
|
+
derivationAccountProxyCreate(request, isMigration) {
|
|
236
|
+
return this.deriveHandler.derivationAccountProxyCreate(request, isMigration);
|
|
235
237
|
}
|
|
236
238
|
|
|
237
239
|
/* Derive */
|
|
@@ -247,6 +249,19 @@ class AccountContext {
|
|
|
247
249
|
|
|
248
250
|
/* Inject */
|
|
249
251
|
|
|
252
|
+
/* Migration */
|
|
253
|
+
async migrateUnifiedAndFetchEligibleSoloAccounts(request, setMigratingModeFn) {
|
|
254
|
+
return await this.migrationHandler.migrateUnifiedAndFetchEligibleSoloAccounts(request, setMigratingModeFn);
|
|
255
|
+
}
|
|
256
|
+
migrateSoloAccount(request) {
|
|
257
|
+
return this.migrationHandler.migrateSoloToUnifiedAccount(request);
|
|
258
|
+
}
|
|
259
|
+
pingSession(request) {
|
|
260
|
+
return this.migrationHandler.pingSession(request);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/* Migration */
|
|
264
|
+
|
|
250
265
|
/* Others */
|
|
251
266
|
|
|
252
267
|
removeNoneHardwareGenesisHash() {
|
|
@@ -15,7 +15,7 @@ var _Base = require("./Base");
|
|
|
15
15
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
|
-
const validDeriveKeypairTypes = [..._types2.SubstrateKeypairTypes, ..._types2.EthereumKeypairTypes, 'ton'];
|
|
18
|
+
const validDeriveKeypairTypes = [..._types2.SubstrateKeypairTypes, ..._types2.EthereumKeypairTypes, 'ton', 'cardano'];
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @class AccountDeriveHandler
|
|
@@ -220,6 +220,7 @@ class AccountDeriveHandler extends _Base.AccountBaseHandler {
|
|
|
220
220
|
* Derive account proxy
|
|
221
221
|
* */
|
|
222
222
|
derivationAccountProxyCreate(request) {
|
|
223
|
+
let isMigration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
223
224
|
const {
|
|
224
225
|
name,
|
|
225
226
|
proxyId: deriveId,
|
|
@@ -230,7 +231,7 @@ class AccountDeriveHandler extends _Base.AccountBaseHandler {
|
|
|
230
231
|
const rootId = this.state.value.accounts[parentProxyId].parentId || parentProxyId;
|
|
231
232
|
const rootProxyId = this.state.belongUnifiedAccount(rootId) || rootId;
|
|
232
233
|
const nameExists = this.state.checkNameExists(name);
|
|
233
|
-
if (nameExists) {
|
|
234
|
+
if (nameExists && !isMigration) {
|
|
234
235
|
throw new _types.SWCommonAccountError(_types.CommonAccountErrorType.ACCOUNT_NAME_EXISTED);
|
|
235
236
|
}
|
|
236
237
|
const validateRs = this.validateDerivePath({
|
|
@@ -354,11 +355,13 @@ class AccountDeriveHandler extends _Base.AccountBaseHandler {
|
|
|
354
355
|
}
|
|
355
356
|
const addresses = pairs.map(pair => pair.address);
|
|
356
357
|
const exists = this.state.checkAddressExists(addresses);
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
358
|
+
if (!isMigration) {
|
|
359
|
+
(0, _util.assert)(!exists, (0, _i18next.t)('Account already exists under the name "{{name}}"', {
|
|
360
|
+
replace: {
|
|
361
|
+
name: (exists === null || exists === void 0 ? void 0 : exists.name) || (exists === null || exists === void 0 ? void 0 : exists.address) || ''
|
|
362
|
+
}
|
|
363
|
+
}));
|
|
364
|
+
}
|
|
362
365
|
childAccountProxy && this.state.upsertAccountProxyByKey(childAccountProxy);
|
|
363
366
|
this.state.upsertModifyPairs(modifyPairs);
|
|
364
367
|
for (const childPair of pairs) {
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SESSION_TIMEOUT = exports.AccountMigrationHandler = void 0;
|
|
7
|
+
var _Base = require("@subwallet/extension-base/services/keyring-service/context/handlers/Base");
|
|
8
|
+
var _types = require("@subwallet/extension-base/types");
|
|
9
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
10
|
+
var _getId = require("@subwallet/extension-base/utils/getId");
|
|
11
|
+
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
12
|
+
var _utilCrypto = require("@polkadot/util-crypto");
|
|
13
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
14
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
15
|
+
|
|
16
|
+
const SESSION_TIMEOUT = 10000;
|
|
17
|
+
exports.SESSION_TIMEOUT = SESSION_TIMEOUT;
|
|
18
|
+
class AccountMigrationHandler extends _Base.AccountBaseHandler {
|
|
19
|
+
sessionIdToPassword = {};
|
|
20
|
+
pingSession(_ref) {
|
|
21
|
+
let {
|
|
22
|
+
sessionId
|
|
23
|
+
} = _ref;
|
|
24
|
+
if (!this.sessionIdToPassword[sessionId]) {
|
|
25
|
+
// todo: if no persistent sessionId, should we jump to enter password again?
|
|
26
|
+
throw Error(`Session ID ${sessionId} not found.`);
|
|
27
|
+
}
|
|
28
|
+
clearTimeout(this.sessionIdToPassword[sessionId].timeoutId);
|
|
29
|
+
this.sessionIdToPassword[sessionId].timeoutId = setTimeout(() => {
|
|
30
|
+
delete this.sessionIdToPassword[sessionId];
|
|
31
|
+
}, SESSION_TIMEOUT);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
async migrateUnifiedAndFetchEligibleSoloAccounts(request, setMigratingModeFn) {
|
|
35
|
+
// Migrate unified -> unified
|
|
36
|
+
const password = request.password;
|
|
37
|
+
const allAccountProxies = Object.values(this.state.accounts);
|
|
38
|
+
const UACanBeMigrated = this.getUACanBeMigrated(allAccountProxies);
|
|
39
|
+
const UACanBeMigratedSortedByParent = this.sortUAByParent(UACanBeMigrated); // master account must be migrated before derived account
|
|
40
|
+
const migratedUnifiedAccountIds = await this.migrateUnifiedToUnifiedAccount(password, UACanBeMigratedSortedByParent, setMigratingModeFn);
|
|
41
|
+
|
|
42
|
+
// Get solo accounts can be migrated
|
|
43
|
+
const soloAccountsNeedToBeMigrated = this.getSoloAccountsNeedToBeMigrated(allAccountProxies);
|
|
44
|
+
const soloAccountsNeedToBeMigratedGroup = this.groupSoloAccountByMnemonic(password, soloAccountsNeedToBeMigrated);
|
|
45
|
+
const eligibleSoloAccountMap = this.accountProxiesToEligibleSoloAccountMap(soloAccountsNeedToBeMigratedGroup);
|
|
46
|
+
|
|
47
|
+
// Create persistent mapping sessionId <-> password
|
|
48
|
+
const uniqueId = Date.now().toString();
|
|
49
|
+
const timeoutId = setTimeout(() => delete this.sessionIdToPassword[uniqueId], SESSION_TIMEOUT * 2);
|
|
50
|
+
this.sessionIdToPassword[uniqueId] = {
|
|
51
|
+
password,
|
|
52
|
+
timeoutId
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
migratedUnifiedAccountIds,
|
|
56
|
+
soloAccounts: eligibleSoloAccountMap,
|
|
57
|
+
sessionId: uniqueId
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async migrateUnifiedToUnifiedAccount(password, accountProxies, setMigratingModeFn) {
|
|
61
|
+
_uiKeyring.keyring.unlockKeyring(password);
|
|
62
|
+
this.parentService.updateKeyringState();
|
|
63
|
+
setMigratingModeFn();
|
|
64
|
+
const unifiedAccountIds = [];
|
|
65
|
+
const modifiedPairs = structuredClone(this.state.modifyPairs);
|
|
66
|
+
const {
|
|
67
|
+
derivedUnifiedAccounts,
|
|
68
|
+
masterUnifiedAccounts
|
|
69
|
+
} = accountProxies.reduce((accountInfo, account) => {
|
|
70
|
+
const isDerivedAccount = !!account.parentId;
|
|
71
|
+
isDerivedAccount ? accountInfo.derivedUnifiedAccounts.push(account) : accountInfo.masterUnifiedAccounts.push(account);
|
|
72
|
+
return accountInfo;
|
|
73
|
+
}, {
|
|
74
|
+
derivedUnifiedAccounts: [],
|
|
75
|
+
masterUnifiedAccounts: []
|
|
76
|
+
});
|
|
77
|
+
try {
|
|
78
|
+
for (const unifiedAccount of masterUnifiedAccounts) {
|
|
79
|
+
const proxyId = unifiedAccount.id;
|
|
80
|
+
const mnemonic = this.parentService.context.exportAccountProxyMnemonic({
|
|
81
|
+
password,
|
|
82
|
+
proxyId
|
|
83
|
+
}).result;
|
|
84
|
+
const newChainTypes = Object.values(_types.AccountChainType).filter(type => !unifiedAccount.chainTypes.includes(type) && _types.SUPPORTED_ACCOUNT_CHAIN_TYPES.includes(type));
|
|
85
|
+
const keypairTypes = newChainTypes.map(chainType => (0, _utils.getDefaultKeypairTypeFromAccountChainType)(chainType));
|
|
86
|
+
keypairTypes.forEach(type => {
|
|
87
|
+
const suri = (0, _utils.getSuri)(mnemonic, type);
|
|
88
|
+
const pair = _uiKeyring.keyring.createFromUri(suri, {}, type);
|
|
89
|
+
const address = pair.address;
|
|
90
|
+
modifiedPairs[address] = {
|
|
91
|
+
accountProxyId: proxyId,
|
|
92
|
+
migrated: true,
|
|
93
|
+
key: address
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
keypairTypes.forEach(type => {
|
|
97
|
+
const suri = (0, _utils.getSuri)(mnemonic, type);
|
|
98
|
+
const {
|
|
99
|
+
derivePath
|
|
100
|
+
} = (0, _utilCrypto.keyExtractSuri)(suri);
|
|
101
|
+
const metadata = {
|
|
102
|
+
name: unifiedAccount.name,
|
|
103
|
+
derivationPath: derivePath ? derivePath.substring(1) : undefined
|
|
104
|
+
};
|
|
105
|
+
const rs = _uiKeyring.keyring.addUri(suri, metadata, type);
|
|
106
|
+
const address = rs.pair.address;
|
|
107
|
+
this.state._addAddressToAuthList(address, true);
|
|
108
|
+
});
|
|
109
|
+
this.state.upsertModifyPairs(modifiedPairs);
|
|
110
|
+
unifiedAccountIds.push(proxyId);
|
|
111
|
+
}
|
|
112
|
+
await new Promise(resolve => setTimeout(resolve, 1800)); // Wait last master unified account migrated. // todo: can be optimized later by await a promise resolve if master account is migrating
|
|
113
|
+
|
|
114
|
+
for (const unifiedAccount of derivedUnifiedAccounts) {
|
|
115
|
+
this.parentService.context.derivationAccountProxyCreate({
|
|
116
|
+
name: unifiedAccount.name,
|
|
117
|
+
suri: unifiedAccount.suri || '',
|
|
118
|
+
proxyId: unifiedAccount.parentId || ''
|
|
119
|
+
}, true);
|
|
120
|
+
unifiedAccountIds.push(unifiedAccount.id);
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.error('Migration unified account failed with error:', error);
|
|
124
|
+
} finally {
|
|
125
|
+
_uiKeyring.keyring.lockAll(false);
|
|
126
|
+
this.parentService.updateKeyringState();
|
|
127
|
+
}
|
|
128
|
+
return unifiedAccountIds;
|
|
129
|
+
}
|
|
130
|
+
getUACanBeMigrated(accountProxies) {
|
|
131
|
+
return accountProxies.filter(account => this.state.isUnifiedAccount(account.id) && account.isNeedMigrateUnifiedAccount);
|
|
132
|
+
}
|
|
133
|
+
getSoloAccountsNeedToBeMigrated(accountProxies) {
|
|
134
|
+
return accountProxies.filter(account => !this.state.isUnifiedAccount(account.id) && account.isNeedMigrateUnifiedAccount);
|
|
135
|
+
}
|
|
136
|
+
groupSoloAccountByMnemonic(password, accountProxies) {
|
|
137
|
+
const parentService = this.parentService;
|
|
138
|
+
return accountProxies.reduce(function (rs, item) {
|
|
139
|
+
const oldProxyId = item.id;
|
|
140
|
+
const mnemonic = parentService.context.exportAccountProxyMnemonic({
|
|
141
|
+
password,
|
|
142
|
+
proxyId: oldProxyId
|
|
143
|
+
}).result;
|
|
144
|
+
const upcomingProxyId = (0, _utils.createAccountProxyId)(mnemonic);
|
|
145
|
+
if (!rs[upcomingProxyId]) {
|
|
146
|
+
rs[upcomingProxyId] = [];
|
|
147
|
+
}
|
|
148
|
+
rs[upcomingProxyId].push(item);
|
|
149
|
+
return rs;
|
|
150
|
+
}, {});
|
|
151
|
+
}
|
|
152
|
+
accountProxiesToEligibleSoloAccountMap(accountProxyMap) {
|
|
153
|
+
const eligibleSoloAccountMap = {};
|
|
154
|
+
Object.entries(accountProxyMap).forEach(_ref2 => {
|
|
155
|
+
let [upcomingProxyId, accounts] = _ref2;
|
|
156
|
+
eligibleSoloAccountMap[upcomingProxyId] = accounts.map(account => {
|
|
157
|
+
return {
|
|
158
|
+
upcomingProxyId,
|
|
159
|
+
proxyId: account.accounts[0].proxyId,
|
|
160
|
+
address: account.accounts[0].address,
|
|
161
|
+
name: account.name,
|
|
162
|
+
chainType: account.chainTypes[0]
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
return eligibleSoloAccountMap;
|
|
167
|
+
}
|
|
168
|
+
sortUAByParent(accountProxies) {
|
|
169
|
+
const undefinedToStr = str => str !== null && str !== void 0 ? str : '';
|
|
170
|
+
return accountProxies.sort((a, b) => undefinedToStr(a.parentId) < undefinedToStr(b.parentId) ? -1 : undefinedToStr(a.parentId) > undefinedToStr(b.parentId) ? 1 : 0);
|
|
171
|
+
}
|
|
172
|
+
migrateSoloToUnifiedAccount(request) {
|
|
173
|
+
const {
|
|
174
|
+
accountName,
|
|
175
|
+
sessionId,
|
|
176
|
+
soloAccounts
|
|
177
|
+
} = request;
|
|
178
|
+
const password = this.sessionIdToPassword[sessionId].password;
|
|
179
|
+
_uiKeyring.keyring.unlockKeyring(password);
|
|
180
|
+
this.parentService.updateKeyringState();
|
|
181
|
+
const modifiedPairs = structuredClone(this.state.modifyPairs);
|
|
182
|
+
const firstAccountInfo = soloAccounts[0];
|
|
183
|
+
const upcomingProxyId = firstAccountInfo.upcomingProxyId;
|
|
184
|
+
const firstAccountOldProxyId = firstAccountInfo.proxyId;
|
|
185
|
+
try {
|
|
186
|
+
const mnemonic = this.parentService.context.exportAccountProxyMnemonic({
|
|
187
|
+
password,
|
|
188
|
+
proxyId: firstAccountOldProxyId
|
|
189
|
+
}).result;
|
|
190
|
+
const keypairTypes = _types.SUPPORTED_ACCOUNT_CHAIN_TYPES.map(chainType => (0, _utils.getDefaultKeypairTypeFromAccountChainType)(chainType));
|
|
191
|
+
keypairTypes.forEach(type => {
|
|
192
|
+
const suri = (0, _utils.getSuri)(mnemonic, type);
|
|
193
|
+
const pair = _uiKeyring.keyring.createFromUri(suri, {}, type);
|
|
194
|
+
const address = pair.address;
|
|
195
|
+
modifiedPairs[address] = {
|
|
196
|
+
accountProxyId: upcomingProxyId,
|
|
197
|
+
migrated: true,
|
|
198
|
+
key: address
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
this.state.upsertAccountProxyByKey({
|
|
202
|
+
id: upcomingProxyId,
|
|
203
|
+
name: accountName,
|
|
204
|
+
isMigrationDone: false
|
|
205
|
+
});
|
|
206
|
+
const soloAccountProxyIds = [];
|
|
207
|
+
keypairTypes.forEach(type => {
|
|
208
|
+
const suri = (0, _utils.getSuri)(mnemonic, type);
|
|
209
|
+
const {
|
|
210
|
+
derivePath
|
|
211
|
+
} = (0, _utilCrypto.keyExtractSuri)(suri);
|
|
212
|
+
const metadata = {
|
|
213
|
+
name: accountName.concat(' - ').concat((0, _getId.generateRandomString)()),
|
|
214
|
+
derivationPath: derivePath ? derivePath.substring(1) : undefined
|
|
215
|
+
};
|
|
216
|
+
const rs = _uiKeyring.keyring.addUri(suri, metadata, type);
|
|
217
|
+
soloAccountProxyIds.push(rs.json.address);
|
|
218
|
+
const address = rs.pair.address;
|
|
219
|
+
this.state._addAddressToAuthList(address, true);
|
|
220
|
+
});
|
|
221
|
+
this.state.upsertModifyPairs(modifiedPairs);
|
|
222
|
+
this.migrateDerivedSoloAccountRelationship(soloAccounts);
|
|
223
|
+
this.state.upsertAccountProxyByKey({
|
|
224
|
+
id: upcomingProxyId,
|
|
225
|
+
name: accountName,
|
|
226
|
+
isMigrationDone: true
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Re-update account name
|
|
230
|
+
soloAccountProxyIds.forEach(oldProxyId => {
|
|
231
|
+
const pair = _uiKeyring.keyring.getPair(oldProxyId);
|
|
232
|
+
_uiKeyring.keyring.saveAccountMeta(pair, {
|
|
233
|
+
...pair.meta,
|
|
234
|
+
name: accountName
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// Update current account after migrating
|
|
239
|
+
const currentAccountProxyId = this.state.currentAccount.proxyId;
|
|
240
|
+
if (soloAccountProxyIds.includes(currentAccountProxyId)) {
|
|
241
|
+
this.state.saveCurrentAccountProxyId(upcomingProxyId);
|
|
242
|
+
}
|
|
243
|
+
} catch (error) {
|
|
244
|
+
console.error('Migration solo account failed with error', error);
|
|
245
|
+
} finally {
|
|
246
|
+
_uiKeyring.keyring.lockAll(false);
|
|
247
|
+
this.parentService.updateKeyringState();
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
migratedUnifiedAccountId: upcomingProxyId
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
migrateDerivedSoloAccountRelationship(soloAccounts) {
|
|
254
|
+
const accountProxies = this.state.accountProxies;
|
|
255
|
+
|
|
256
|
+
// Use Set.has & Map.get to optimize search performance
|
|
257
|
+
const proxyIdsSet = new Set(soloAccounts.map(account => account.proxyId));
|
|
258
|
+
const proxyIdToUpcomingProxyIdMap = new Map(soloAccounts.map(account => [account.proxyId, account.upcomingProxyId]));
|
|
259
|
+
for (const account of Object.values(accountProxies)) {
|
|
260
|
+
const currentParent = account.parentId;
|
|
261
|
+
if (currentParent && proxyIdsSet.has(currentParent)) {
|
|
262
|
+
accountProxies[account.id].parentId = proxyIdToUpcomingProxyIdMap.get(currentParent);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
this.state.upsertAccountProxy(accountProxies);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
exports.AccountMigrationHandler = AccountMigrationHandler;
|
|
@@ -36,7 +36,7 @@ class AccountMnemonicHandler extends _Base.AccountBaseHandler {
|
|
|
36
36
|
mnemonic: _seed,
|
|
37
37
|
type = 'general'
|
|
38
38
|
} = _ref;
|
|
39
|
-
const types = type === 'general' ? ['sr25519', 'ethereum', 'ton'] : ['ton-native'];
|
|
39
|
+
const types = type === 'general' ? ['sr25519', 'ethereum', 'ton', 'cardano'] : ['ton-native'];
|
|
40
40
|
const seed = _seed || type === 'general' ? (0, _utilCrypto.mnemonicGenerate)(length) : await (0, _keyring.tonMnemonicGenerate)(length);
|
|
41
41
|
const rs = {
|
|
42
42
|
mnemonic: seed,
|
|
@@ -107,7 +107,7 @@ class AccountMnemonicHandler extends _Base.AccountBaseHandler {
|
|
|
107
107
|
const addressDict = {};
|
|
108
108
|
let changedAccount = false;
|
|
109
109
|
const hasMasterPassword = _uiKeyring.keyring.keyring.hasMasterPassword;
|
|
110
|
-
const types = type ? [type] : ['sr25519', 'ethereum', 'ton'];
|
|
110
|
+
const types = type ? [type] : ['sr25519', 'ethereum', 'ton', 'cardano'];
|
|
111
111
|
if (!hasMasterPassword) {
|
|
112
112
|
if (!password) {
|
|
113
113
|
throw Error((0, _i18next.t)('The password of each account is needed to set up master password'));
|
|
@@ -55,7 +55,7 @@ class AccountSecretHandler extends _Base.AccountBaseHandler {
|
|
|
55
55
|
isReadOnly,
|
|
56
56
|
genesisHash: ''
|
|
57
57
|
};
|
|
58
|
-
if ([..._types2.BitcoinKeypairTypes, ..._types2.TonKeypairTypes].includes(type) && isReadOnly) {
|
|
58
|
+
if ([..._types2.BitcoinKeypairTypes, ..._types2.TonKeypairTypes, ..._types2.CardanoKeypairTypes].includes(type) && isReadOnly) {
|
|
59
59
|
meta.noPublicKey = true;
|
|
60
60
|
}
|
|
61
61
|
const result = _uiKeyring.default.keyring.addFromAddress(address, meta, null, type);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasAnyAccountForMigration = void 0;
|
|
7
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
10
|
+
const hasAnyAccountForMigration = allAccountProxies => {
|
|
11
|
+
for (const account of allAccountProxies) {
|
|
12
|
+
if (account.isNeedMigrateUnifiedAccount) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
};
|
|
18
|
+
exports.hasAnyAccountForMigration = hasAnyAccountForMigration;
|