@subwallet/extension-base 1.3.22-0 → 1.3.23-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +75 -2
- package/background/KoniTypes.js +2 -0
- package/cjs/background/KoniTypes.js +2 -0
- package/cjs/constants/environment.js +4 -2
- package/cjs/constants/signing.js +6 -2
- package/cjs/core/logic-validation/recipientAddress.js +9 -1
- package/cjs/core/logic-validation/transfer.js +35 -29
- package/cjs/core/types.js +1 -0
- package/cjs/core/utils.js +12 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/api/dotsama/crowdloan.js +1 -1
- package/cjs/koni/api/nft/index.js +9 -16
- package/cjs/koni/api/staking/index.js +3 -4
- package/cjs/koni/background/handlers/Extension.js +234 -96
- package/cjs/koni/background/handlers/State.js +15 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/cardano/consts.js +11 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/index.js +63 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/utils.js +74 -0
- package/cjs/services/balance-service/helpers/subscribe/index.js +21 -7
- package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +2 -2
- package/cjs/services/balance-service/index.js +4 -2
- package/cjs/services/balance-service/transfer/cardano-transfer.js +122 -0
- package/cjs/services/balance-service/transfer/token.js +4 -4
- package/cjs/services/chain-service/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 +29 -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/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/index.js +20 -2
- 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 +278 -21
- package/cjs/services/transaction-service/utils.js +5 -1
- package/cjs/types/account/info/keyring.js +12 -1
- package/cjs/types/fee/cardano.js +1 -0
- package/cjs/types/swap/index.js +7 -2
- package/cjs/utils/account/analyze.js +2 -1
- package/cjs/utils/account/common.js +29 -20
- package/cjs/utils/account/derive/info/solo.js +9 -4
- package/cjs/utils/account/derive/validate.js +36 -2
- package/cjs/utils/account/transform.js +38 -13
- package/cjs/utils/fee/transfer.js +40 -7
- package/cjs/utils/index.js +2 -2
- package/cjs/utils/staticData/index.js +7 -2
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- package/constants/signing.js +6 -2
- package/core/logic-validation/recipientAddress.js +11 -3
- package/core/logic-validation/transfer.js +9 -3
- package/core/substrate/xcm-parser.d.ts +1 -1
- package/core/types.d.ts +1 -0
- package/core/types.js +1 -0
- package/core/utils.d.ts +1 -0
- package/core/utils.js +13 -3
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/api/dotsama/crowdloan.js +3 -3
- package/koni/api/nft/index.js +10 -16
- package/koni/api/nft/story_odyssey_nft/index.d.ts +1 -1
- package/koni/api/staking/index.js +4 -5
- package/koni/background/handlers/Extension.d.ts +9 -0
- package/koni/background/handlers/Extension.js +144 -8
- package/koni/background/handlers/State.d.ts +5 -1
- package/koni/background/handlers/State.js +16 -1
- package/package.json +71 -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/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 +3 -1
- package/services/chain-service/index.js +29 -7
- package/services/chain-service/types.d.ts +9 -1
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +32 -11
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/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/service.js +19 -8
- package/services/history-service/index.js +6 -8
- package/services/inapp-notification-service/index.d.ts +3 -4
- package/services/inapp-notification-service/index.js +14 -6
- package/services/keyring-service/context/account-context.d.ts +6 -2
- package/services/keyring-service/context/account-context.js +17 -2
- package/services/keyring-service/context/handlers/Derive.d.ts +1 -1
- package/services/keyring-service/context/handlers/Derive.js +10 -8
- package/services/keyring-service/context/handlers/Migration.d.ts +17 -0
- package/services/keyring-service/context/handlers/Migration.js +258 -0
- package/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/services/keyring-service/context/handlers/Secret.js +2 -2
- package/services/keyring-service/utils.d.ts +2 -0
- package/services/keyring-service/utils.js +11 -0
- package/services/request-service/handler/CardanoRequestHandler.d.ts +16 -0
- package/services/request-service/handler/CardanoRequestHandler.js +163 -0
- package/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/services/request-service/index.d.ts +6 -3
- package/services/request-service/index.js +19 -5
- package/services/setting-service/constants.d.ts +3 -0
- package/services/setting-service/constants.js +6 -0
- package/services/storage-service/DatabaseService.d.ts +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 +263 -10
- package/services/transaction-service/types.d.ts +7 -0
- package/services/transaction-service/utils.js +7 -2
- package/types/account/info/keyring.d.ts +4 -1
- package/types/account/info/keyring.js +9 -0
- package/types/account/info/proxy.d.ts +2 -0
- package/types/balance/index.d.ts +4 -1
- package/types/fee/base.d.ts +1 -1
- package/types/fee/cardano.d.ts +18 -0
- package/types/fee/cardano.js +1 -0
- package/types/fee/subscription.d.ts +4 -3
- package/types/swap/index.d.ts +11 -3
- package/types/swap/index.js +7 -2
- package/utils/account/analyze.js +2 -1
- package/utils/account/common.d.ts +11 -6
- package/utils/account/common.js +28 -19
- package/utils/account/derive/info/solo.js +10 -5
- package/utils/account/derive/validate.d.ts +1 -0
- package/utils/account/derive/validate.js +34 -1
- package/utils/account/transform.d.ts +2 -1
- package/utils/account/transform.js +37 -13
- package/utils/fee/transfer.d.ts +2 -1
- package/utils/fee/transfer.js +44 -11
- package/utils/index.js +4 -4
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/oldChainPrefix.json +1 -0
|
@@ -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;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _request = require("@subwallet/extension-base/utils/request");
|
|
8
|
+
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
9
|
+
var _i18next = require("i18next");
|
|
10
|
+
var _rxjs = require("rxjs");
|
|
11
|
+
var _logger = require("@polkadot/util/logger");
|
|
12
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
13
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
14
|
+
|
|
15
|
+
class CardanoRequestHandler {
|
|
16
|
+
#requestService;
|
|
17
|
+
#logger;
|
|
18
|
+
confirmationsQueueSubjectCardano = new _rxjs.BehaviorSubject({
|
|
19
|
+
cardanoSignatureRequest: {},
|
|
20
|
+
cardanoSendTransactionRequest: {},
|
|
21
|
+
cardanoWatchTransactionRequest: {}
|
|
22
|
+
});
|
|
23
|
+
confirmationsPromiseMap = {};
|
|
24
|
+
constructor(requestService) {
|
|
25
|
+
this.#requestService = requestService;
|
|
26
|
+
this.#logger = (0, _logger.logger)('CardanoRequestHandler');
|
|
27
|
+
}
|
|
28
|
+
get numCardanoRequests() {
|
|
29
|
+
let count = 0;
|
|
30
|
+
Object.values(this.confirmationsQueueSubjectCardano.getValue()).forEach(x => {
|
|
31
|
+
count += Object.keys(x).length;
|
|
32
|
+
});
|
|
33
|
+
return count;
|
|
34
|
+
}
|
|
35
|
+
getConfirmationsQueueSubjectCardano() {
|
|
36
|
+
return this.confirmationsQueueSubjectCardano;
|
|
37
|
+
}
|
|
38
|
+
async addConfirmationCardano(id, url, type, payload) {
|
|
39
|
+
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
40
|
+
let validator = arguments.length > 5 ? arguments[5] : undefined;
|
|
41
|
+
const confirmations = this.confirmationsQueueSubjectCardano.getValue();
|
|
42
|
+
const confirmationType = confirmations[type];
|
|
43
|
+
const payloadJson = JSON.stringify({});
|
|
44
|
+
const isInternal = (0, _request.isInternalRequest)(url);
|
|
45
|
+
if (['cardanoSendTransactionRequest', 'cardanoSignatureRequest'].includes(type)) {
|
|
46
|
+
const isAlwaysRequired = await this.#requestService.settingService.isAlwaysRequired;
|
|
47
|
+
if (isAlwaysRequired) {
|
|
48
|
+
this.#requestService.keyringService.lock();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Check duplicate request
|
|
53
|
+
const duplicated = Object.values(confirmationType).find(c => c.url === url && c.payloadJson === payloadJson);
|
|
54
|
+
if (duplicated) {
|
|
55
|
+
throw new Error('Cardano duplicate request'); // update this message.
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
confirmationType[id] = {
|
|
59
|
+
id,
|
|
60
|
+
url,
|
|
61
|
+
isInternal,
|
|
62
|
+
payload,
|
|
63
|
+
payloadJson,
|
|
64
|
+
...options
|
|
65
|
+
};
|
|
66
|
+
const promise = new Promise((resolve, reject) => {
|
|
67
|
+
this.confirmationsPromiseMap[id] = {
|
|
68
|
+
validator: validator,
|
|
69
|
+
resolver: {
|
|
70
|
+
resolve: resolve,
|
|
71
|
+
reject: reject
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
this.confirmationsQueueSubjectCardano.next(confirmations);
|
|
76
|
+
if (!isInternal) {
|
|
77
|
+
this.#requestService.popupOpen();
|
|
78
|
+
}
|
|
79
|
+
this.#requestService.updateIconV2();
|
|
80
|
+
return promise;
|
|
81
|
+
}
|
|
82
|
+
async completeConfirmationCardano(request) {
|
|
83
|
+
const confirmations = this.confirmationsQueueSubjectCardano.getValue();
|
|
84
|
+
for (const ct in request) {
|
|
85
|
+
const type = ct;
|
|
86
|
+
const result = request[type];
|
|
87
|
+
const {
|
|
88
|
+
id
|
|
89
|
+
} = result;
|
|
90
|
+
const {
|
|
91
|
+
resolver,
|
|
92
|
+
validator
|
|
93
|
+
} = this.confirmationsPromiseMap[id];
|
|
94
|
+
const confirmation = confirmations[type][id];
|
|
95
|
+
if (!resolver || !confirmation) {
|
|
96
|
+
this.#logger.error((0, _i18next.t)('Unable to proceed. Please try again'), type, id);
|
|
97
|
+
throw new Error((0, _i18next.t)('Unable to proceed. Please try again'));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Fill signature for some special type
|
|
101
|
+
await this.decorateResult(type, confirmation, result);
|
|
102
|
+
|
|
103
|
+
// Validate response from confirmation popup some info like password, response format....
|
|
104
|
+
const error = validator && validator(result);
|
|
105
|
+
if (error) {
|
|
106
|
+
resolver.reject(error);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Delete confirmations from queue
|
|
110
|
+
delete this.confirmationsPromiseMap[id];
|
|
111
|
+
delete confirmations[type][id];
|
|
112
|
+
this.confirmationsQueueSubjectCardano.next(confirmations);
|
|
113
|
+
|
|
114
|
+
// Update icon, and close queue
|
|
115
|
+
this.#requestService.updateIconV2(this.#requestService.numAllRequests === 0);
|
|
116
|
+
resolver.resolve(result);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// TODO: Review later
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
async decorateResult(t, request, result) {
|
|
123
|
+
if (result.payload === '') {
|
|
124
|
+
if (t === 'cardanoSignatureRequest') {
|
|
125
|
+
// result.payload = await this.signMessage(request as ConfirmationDefinitions['evmSignatureRequest'][0]);
|
|
126
|
+
} else if (t === 'cardanoSendTransactionRequest') {
|
|
127
|
+
result.payload = this.signTransactionCardano(request);
|
|
128
|
+
}
|
|
129
|
+
if (t === 'cardanoSignatureRequest' || t === 'cardanoSendTransactionRequest') {
|
|
130
|
+
const isAlwaysRequired = await this.#requestService.settingService.isAlwaysRequired;
|
|
131
|
+
if (isAlwaysRequired) {
|
|
132
|
+
this.#requestService.keyringService.lock();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
signTransactionCardano(confirmation) {
|
|
138
|
+
// alibaba
|
|
139
|
+
const transaction = confirmation.payload;
|
|
140
|
+
const {
|
|
141
|
+
cardanoPayload,
|
|
142
|
+
from
|
|
143
|
+
} = transaction;
|
|
144
|
+
const pair = _uiKeyring.keyring.getPair(from);
|
|
145
|
+
if (pair.isLocked) {
|
|
146
|
+
_uiKeyring.keyring.unlockPair(pair.address);
|
|
147
|
+
}
|
|
148
|
+
return pair.cardano.sign(cardanoPayload);
|
|
149
|
+
}
|
|
150
|
+
resetWallet() {
|
|
151
|
+
const confirmations = this.confirmationsQueueSubjectCardano.getValue();
|
|
152
|
+
for (const [type, requests] of Object.entries(confirmations)) {
|
|
153
|
+
for (const confirmation of Object.values(requests)) {
|
|
154
|
+
const {
|
|
155
|
+
id
|
|
156
|
+
} = confirmation;
|
|
157
|
+
const {
|
|
158
|
+
resolver
|
|
159
|
+
} = this.confirmationsPromiseMap[id];
|
|
160
|
+
if (!resolver || !confirmation) {
|
|
161
|
+
console.error('Not found confirmation', type, id);
|
|
162
|
+
} else {
|
|
163
|
+
resolver.reject(new Error('Reset wallet'));
|
|
164
|
+
}
|
|
165
|
+
delete this.confirmationsPromiseMap[id];
|
|
166
|
+
delete confirmations[type][id];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
this.confirmationsQueueSubjectCardano.next(confirmations);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.default = CardanoRequestHandler;
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
+
var _CardanoRequestHandler = _interopRequireDefault(require("@subwallet/extension-base/services/request-service/handler/CardanoRequestHandler"));
|
|
8
9
|
var _TonRequestHandler = _interopRequireDefault(require("./handler/TonRequestHandler"));
|
|
9
10
|
var _handler = require("./handler");
|
|
10
11
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
@@ -19,6 +20,7 @@ class RequestService {
|
|
|
19
20
|
#substrateRequestHandler;
|
|
20
21
|
#evmRequestHandler;
|
|
21
22
|
#tonRequestHandler;
|
|
23
|
+
#cardanoRequestHandler;
|
|
22
24
|
#connectWCRequestHandler;
|
|
23
25
|
#notSupportWCRequestHandler;
|
|
24
26
|
|
|
@@ -33,6 +35,7 @@ class RequestService {
|
|
|
33
35
|
this.#substrateRequestHandler = new _handler.SubstrateRequestHandler(this);
|
|
34
36
|
this.#evmRequestHandler = new _handler.EvmRequestHandler(this);
|
|
35
37
|
this.#tonRequestHandler = new _TonRequestHandler.default(this);
|
|
38
|
+
this.#cardanoRequestHandler = new _CardanoRequestHandler.default(this);
|
|
36
39
|
this.#connectWCRequestHandler = new _handler.ConnectWCRequestHandler(this);
|
|
37
40
|
this.#notSupportWCRequestHandler = new _handler.NotSupportWCRequestHandler(this);
|
|
38
41
|
|
|
@@ -40,7 +43,7 @@ class RequestService {
|
|
|
40
43
|
this.updateIconV2();
|
|
41
44
|
}
|
|
42
45
|
get numAllRequests() {
|
|
43
|
-
return this.allSubstrateRequests.length + this.numEvmRequests + this.numTonRequests;
|
|
46
|
+
return this.allSubstrateRequests.length + this.numEvmRequests + this.numTonRequests + this.numCardanoRequests;
|
|
44
47
|
}
|
|
45
48
|
updateIconV2(shouldClose) {
|
|
46
49
|
this.#popupHandler.updateIconV2(shouldClose);
|
|
@@ -150,12 +153,18 @@ class RequestService {
|
|
|
150
153
|
get numTonRequests() {
|
|
151
154
|
return this.#tonRequestHandler.numTonRequests;
|
|
152
155
|
}
|
|
156
|
+
get numCardanoRequests() {
|
|
157
|
+
return this.#cardanoRequestHandler.numCardanoRequests;
|
|
158
|
+
}
|
|
153
159
|
get confirmationsQueueSubject() {
|
|
154
160
|
return this.#evmRequestHandler.getConfirmationsQueueSubject();
|
|
155
161
|
}
|
|
156
162
|
get confirmationsQueueSubjectTon() {
|
|
157
163
|
return this.#tonRequestHandler.getConfirmationsQueueSubjectTon();
|
|
158
164
|
}
|
|
165
|
+
get confirmationsQueueSubjectCardano() {
|
|
166
|
+
return this.#cardanoRequestHandler.getConfirmationsQueueSubjectCardano();
|
|
167
|
+
}
|
|
159
168
|
getSignRequest(id) {
|
|
160
169
|
return this.#substrateRequestHandler.getSignRequest(id);
|
|
161
170
|
}
|
|
@@ -172,12 +181,20 @@ class RequestService {
|
|
|
172
181
|
let validator = arguments.length > 5 ? arguments[5] : undefined;
|
|
173
182
|
return this.#tonRequestHandler.addConfirmationTon(id, url, type, payload, options, validator);
|
|
174
183
|
}
|
|
184
|
+
addConfirmationCardano(id, url, type, payload) {
|
|
185
|
+
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
186
|
+
let validator = arguments.length > 5 ? arguments[5] : undefined;
|
|
187
|
+
return this.#cardanoRequestHandler.addConfirmationCardano(id, url, type, payload, options, validator);
|
|
188
|
+
}
|
|
175
189
|
async completeConfirmation(request) {
|
|
176
190
|
return await this.#evmRequestHandler.completeConfirmation(request);
|
|
177
191
|
}
|
|
178
192
|
async completeConfirmationTon(request) {
|
|
179
193
|
return await this.#tonRequestHandler.completeConfirmationTon(request);
|
|
180
194
|
}
|
|
195
|
+
async completeConfirmationCardano(request) {
|
|
196
|
+
return await this.#cardanoRequestHandler.completeConfirmationCardano(request);
|
|
197
|
+
}
|
|
181
198
|
updateConfirmation(id, type, payload) {
|
|
182
199
|
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
183
200
|
let validator = arguments.length > 4 ? arguments[4] : undefined;
|
|
@@ -220,13 +237,14 @@ class RequestService {
|
|
|
220
237
|
|
|
221
238
|
// General methods
|
|
222
239
|
get numRequests() {
|
|
223
|
-
return this.numMetaRequests + this.numAuthRequests + this.numSubstrateRequests + this.numEvmRequests + this.numConnectWCRequests + this.numNotSupportWCRequests + this.numTonRequests;
|
|
240
|
+
return this.numMetaRequests + this.numAuthRequests + this.numSubstrateRequests + this.numEvmRequests + this.numConnectWCRequests + this.numNotSupportWCRequests + this.numTonRequests + this.numCardanoRequests;
|
|
224
241
|
}
|
|
225
242
|
resetWallet() {
|
|
226
243
|
this.#authRequestHandler.resetWallet();
|
|
227
244
|
this.#substrateRequestHandler.resetWallet();
|
|
228
245
|
this.#evmRequestHandler.resetWallet();
|
|
229
246
|
this.#tonRequestHandler.resetWallet();
|
|
247
|
+
this.#cardanoRequestHandler.resetWallet();
|
|
230
248
|
this.#metadataRequestHandler.resetWallet();
|
|
231
249
|
this.#connectWCRequestHandler.resetWallet();
|
|
232
250
|
this.#notSupportWCRequestHandler.resetWallet();
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.DEFAULT_UNLOCK_TYPE = exports.DEFAULT_THEME = exports.DEFAULT_SHOW_ZERO_BALANCE = exports.DEFAULT_SHOW_BALANCE = exports.DEFAULT_SETTING = exports.DEFAULT_NOTIFICATION_TYPE = exports.DEFAULT_NOTIFICATION_SETUP = exports.DEFAULT_LANGUAGE = exports.DEFAULT_CURRENCY = exports.DEFAULT_CHAIN_PATROL_ENABLE = exports.DEFAULT_CAMERA_ENABLE = exports.DEFAULT_AUTO_LOCK_TIME = exports.DEFAULT_ALL_LOGO = exports.DEFAULT_ALLOW_ONE_SIGN = void 0;
|
|
6
|
+
exports.DEFAULT_UNLOCK_TYPE = exports.DEFAULT_UNIFIED_ACCOUNT_MIGRATION_IN_PROGRESS = exports.DEFAULT_UNIFIED_ACCOUNT_MIGRATION_IN_DONE = exports.DEFAULT_THEME = exports.DEFAULT_SHOW_ZERO_BALANCE = exports.DEFAULT_SHOW_BALANCE = exports.DEFAULT_SETTING = exports.DEFAULT_NOTIFICATION_TYPE = exports.DEFAULT_NOTIFICATION_SETUP = exports.DEFAULT_LANGUAGE = exports.DEFAULT_CURRENCY = exports.DEFAULT_CHAIN_PATROL_ENABLE = exports.DEFAULT_CAMERA_ENABLE = exports.DEFAULT_AUTO_LOCK_TIME = exports.DEFAULT_ALL_LOGO = exports.DEFAULT_ALLOW_ONE_SIGN = exports.DEFAULT_ACKNOWLEDGED_MIGRATION_STATUS = void 0;
|
|
7
7
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
8
8
|
var _utils = require("@subwallet/extension-base/utils");
|
|
9
9
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
@@ -48,6 +48,12 @@ const DEFAULT_NOTIFICATION_SETUP = {
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
exports.DEFAULT_NOTIFICATION_SETUP = DEFAULT_NOTIFICATION_SETUP;
|
|
51
|
+
const DEFAULT_ACKNOWLEDGED_MIGRATION_STATUS = false;
|
|
52
|
+
exports.DEFAULT_ACKNOWLEDGED_MIGRATION_STATUS = DEFAULT_ACKNOWLEDGED_MIGRATION_STATUS;
|
|
53
|
+
const DEFAULT_UNIFIED_ACCOUNT_MIGRATION_IN_PROGRESS = false;
|
|
54
|
+
exports.DEFAULT_UNIFIED_ACCOUNT_MIGRATION_IN_PROGRESS = DEFAULT_UNIFIED_ACCOUNT_MIGRATION_IN_PROGRESS;
|
|
55
|
+
const DEFAULT_UNIFIED_ACCOUNT_MIGRATION_IN_DONE = false;
|
|
56
|
+
exports.DEFAULT_UNIFIED_ACCOUNT_MIGRATION_IN_DONE = DEFAULT_UNIFIED_ACCOUNT_MIGRATION_IN_DONE;
|
|
51
57
|
const DEFAULT_SETTING = {
|
|
52
58
|
language: DEFAULT_LANGUAGE,
|
|
53
59
|
currency: DEFAULT_CURRENCY,
|
|
@@ -61,6 +67,9 @@ const DEFAULT_SETTING = {
|
|
|
61
67
|
timeAutoLock: DEFAULT_AUTO_LOCK_TIME,
|
|
62
68
|
enableChainPatrol: DEFAULT_CHAIN_PATROL_ENABLE,
|
|
63
69
|
notificationSetup: DEFAULT_NOTIFICATION_SETUP,
|
|
70
|
+
isAcknowledgedUnifiedAccountMigration: DEFAULT_ACKNOWLEDGED_MIGRATION_STATUS,
|
|
71
|
+
isUnifiedAccountMigrationInProgress: DEFAULT_UNIFIED_ACCOUNT_MIGRATION_IN_PROGRESS,
|
|
72
|
+
isUnifiedAccountMigrationDone: DEFAULT_UNIFIED_ACCOUNT_MIGRATION_IN_DONE,
|
|
64
73
|
walletReference: '',
|
|
65
74
|
allowOneSign: DEFAULT_ALLOW_ONE_SIGN
|
|
66
75
|
};
|
|
@@ -607,6 +607,9 @@ class DatabaseService {
|
|
|
607
607
|
removeAccountNotifications(proxyId) {
|
|
608
608
|
return this.stores.inappNotification.removeAccountNotifications(proxyId);
|
|
609
609
|
}
|
|
610
|
+
updateNotificationProxyId(proxyIds, newProxyId, newName) {
|
|
611
|
+
return this.stores.inappNotification.updateNotificationProxyId(proxyIds, newProxyId, newName);
|
|
612
|
+
}
|
|
610
613
|
async exportDB() {
|
|
611
614
|
const blob = await (0, _dexieExportImport.exportDB)(this._db, {
|
|
612
615
|
filter: (table, value, key) => {
|
|
@@ -43,6 +43,12 @@ class InappNotificationStore extends _BaseStore.default {
|
|
|
43
43
|
});
|
|
44
44
|
return filteredTable.toArray();
|
|
45
45
|
}
|
|
46
|
+
updateNotificationProxyId(proxyIds, newProxyId, newName) {
|
|
47
|
+
this.table.where('proxyId').anyOfIgnoreCase(proxyIds).modify(item => {
|
|
48
|
+
item.proxyId = newProxyId;
|
|
49
|
+
item.title = item.title.replace(/\[.*?\]/, `[${newName}]`);
|
|
50
|
+
}).catch(console.error);
|
|
51
|
+
}
|
|
46
52
|
async cleanUpOldNotifications(overdueTime) {
|
|
47
53
|
const currentTimestamp = Date.now();
|
|
48
54
|
return this.table.filter(item => item.time <= currentTimestamp - overdueTime).delete();
|