@subwallet/extension-base 1.3.73-0 → 1.3.74-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 +42 -5
- package/background/KoniTypes.js +14 -1
- package/cjs/background/KoniTypes.js +16 -2
- package/cjs/core/logic-validation/transfer.js +35 -57
- package/cjs/koni/background/handlers/Extension.js +599 -144
- package/cjs/koni/background/handlers/State.js +5 -2
- package/cjs/koni/background/handlers/Tabs.js +3 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +0 -2
- package/cjs/services/chain-service/handler/SubstrateApi.js +6 -1
- package/cjs/services/chain-service/index.js +1 -0
- package/cjs/services/chain-service/utils/index.js +4 -0
- package/cjs/services/event-service/index.js +1 -0
- package/cjs/services/fee-service/utils/index.js +4 -4
- package/cjs/services/inapp-notification-service/consts.js +4 -2
- package/cjs/services/inapp-notification-service/index.js +51 -6
- package/cjs/services/inapp-notification-service/interfaces.js +2 -0
- package/cjs/services/inapp-notification-service/utils/common.js +4 -0
- package/cjs/services/keyring-service/context/account-context.js +44 -0
- package/cjs/services/keyring-service/context/handlers/Multisig.js +186 -0
- package/cjs/services/keyring-service/context/state.js +12 -0
- package/cjs/services/multisig-service/index.js +627 -0
- package/cjs/services/multisig-service/utils.js +242 -0
- package/cjs/services/request-service/handler/SubstrateRequestHandler.js +25 -0
- package/cjs/services/request-service/index.js +5 -1
- package/cjs/services/storage-service/DatabaseService.js +5 -2
- package/cjs/services/storage-service/db-stores/InappNotification.js +20 -2
- package/cjs/services/substrate-proxy-service/index.js +22 -7
- package/cjs/services/transaction-service/helpers/index.js +8 -0
- package/cjs/services/transaction-service/index.js +348 -147
- package/cjs/services/transaction-service/types.js +18 -1
- package/cjs/types/account/info/keyring.js +5 -0
- package/cjs/types/account/info/proxy.js +1 -0
- package/cjs/types/multisig/index.js +14 -0
- package/cjs/types/transaction/error.js +9 -2
- package/cjs/utils/account/transform.js +28 -4
- package/cjs/utils/logger/Logger.js +294 -0
- package/cjs/utils/logger/index.js +42 -0
- package/cjs/utils/logger/types.js +1 -0
- package/core/logic-validation/transfer.d.ts +2 -2
- package/core/logic-validation/transfer.js +10 -32
- package/koni/background/handlers/Extension.d.ts +7 -0
- package/koni/background/handlers/Extension.js +498 -43
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +5 -2
- package/koni/background/handlers/Tabs.js +3 -2
- package/package.json +42 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +0 -2
- package/services/chain-service/handler/SubstrateApi.js +7 -2
- package/services/chain-service/index.js +1 -0
- package/services/chain-service/types.d.ts +1 -1
- package/services/chain-service/utils/index.js +4 -0
- package/services/event-service/index.d.ts +1 -0
- package/services/event-service/index.js +1 -0
- package/services/event-service/types.d.ts +1 -0
- package/services/fee-service/utils/index.js +4 -4
- package/services/inapp-notification-service/consts.d.ts +3 -1
- package/services/inapp-notification-service/consts.js +5 -3
- package/services/inapp-notification-service/index.d.ts +3 -2
- package/services/inapp-notification-service/index.js +51 -6
- package/services/inapp-notification-service/interfaces.d.ts +18 -2
- package/services/inapp-notification-service/interfaces.js +2 -0
- package/services/inapp-notification-service/utils/common.d.ts +1 -0
- package/services/inapp-notification-service/utils/common.js +3 -0
- package/services/keyring-service/context/account-context.d.ts +9 -1
- package/services/keyring-service/context/account-context.js +44 -0
- package/services/keyring-service/context/handlers/Multisig.d.ts +18 -0
- package/services/keyring-service/context/handlers/Multisig.js +180 -0
- package/services/keyring-service/context/state.d.ts +2 -0
- package/services/keyring-service/context/state.js +12 -0
- package/services/multisig-service/index.d.ts +245 -0
- package/services/multisig-service/index.js +620 -0
- package/services/multisig-service/utils.d.ts +95 -0
- package/services/multisig-service/utils.js +227 -0
- package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -0
- package/services/request-service/handler/SubstrateRequestHandler.js +25 -0
- package/services/request-service/index.d.ts +2 -1
- package/services/request-service/index.js +5 -1
- package/services/storage-service/DatabaseService.d.ts +3 -2
- package/services/storage-service/DatabaseService.js +5 -2
- package/services/storage-service/db-stores/InappNotification.d.ts +3 -2
- package/services/storage-service/db-stores/InappNotification.js +20 -2
- package/services/substrate-proxy-service/index.d.ts +4 -1
- package/services/substrate-proxy-service/index.js +22 -8
- package/services/transaction-service/helpers/index.js +8 -0
- package/services/transaction-service/index.d.ts +31 -0
- package/services/transaction-service/index.js +270 -69
- package/services/transaction-service/types.d.ts +28 -3
- package/services/transaction-service/types.js +12 -1
- package/types/account/info/keyring.d.ts +14 -1
- package/types/account/info/keyring.js +6 -0
- package/types/account/info/proxy.d.ts +1 -0
- package/types/account/info/proxy.js +1 -0
- package/types/multisig/index.d.ts +76 -0
- package/types/multisig/index.js +8 -0
- package/types/notification/index.d.ts +8 -0
- package/types/substrateProxyAccount/index.d.ts +26 -1
- package/types/transaction/error.d.ts +6 -1
- package/types/transaction/error.js +7 -1
- package/types/transaction/request.d.ts +0 -1
- package/utils/account/transform.js +28 -4
- package/utils/logger/Logger.d.ts +31 -0
- package/utils/logger/Logger.js +267 -0
- package/utils/logger/index.d.ts +15 -0
- package/utils/logger/index.js +29 -0
- package/utils/logger/types.d.ts +23 -0
- package/utils/logger/types.js +1 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DEFAULT_MAX_WEIGHT = exports.DEFAULT_BLOCK_HASH = void 0;
|
|
7
|
+
exports.calcDepositAmount = calcDepositAmount;
|
|
8
|
+
exports.createInitMultisigExtrinsic = createInitMultisigExtrinsic;
|
|
9
|
+
exports.decodeCallData = decodeCallData;
|
|
10
|
+
exports.genPendingMultisigTxKey = genPendingMultisigTxKey;
|
|
11
|
+
exports.getCallData = getCallData;
|
|
12
|
+
exports.getMultisigTxType = getMultisigTxType;
|
|
13
|
+
var _index = require("@subwallet/extension-base/services/multisig-service/index");
|
|
14
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
15
|
+
var _utilCrypto = require("@polkadot/util-crypto");
|
|
16
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
17
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
18
|
+
|
|
19
|
+
const DEFAULT_BLOCK_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
20
|
+
exports.DEFAULT_BLOCK_HASH = DEFAULT_BLOCK_HASH;
|
|
21
|
+
const DEFAULT_MAX_WEIGHT = {
|
|
22
|
+
refTime: '0',
|
|
23
|
+
proofSize: '0'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Request interface for getting call data from a block
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Request interface for decoding call data
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Response interface for decoded call data
|
|
36
|
+
*/
|
|
37
|
+
exports.DEFAULT_MAX_WEIGHT = DEFAULT_MAX_WEIGHT;
|
|
38
|
+
/**
|
|
39
|
+
* Extracts call data from a block's extrinsic
|
|
40
|
+
* Finds the inner call within multisig extrinsic and verifies it matches the call hash
|
|
41
|
+
* @param block - Block containing the extrinsic
|
|
42
|
+
* @param callHash - Expected hash of the call data
|
|
43
|
+
* @param extrinsicIndex - Index of the extrinsic in the block
|
|
44
|
+
* @returns Hex-encoded call data if found and verified, undefined otherwise
|
|
45
|
+
*/
|
|
46
|
+
function getCallData(_ref) {
|
|
47
|
+
let {
|
|
48
|
+
block,
|
|
49
|
+
callHash,
|
|
50
|
+
extrinsicIndex
|
|
51
|
+
} = _ref;
|
|
52
|
+
const extrinsic = block.extrinsics[extrinsicIndex];
|
|
53
|
+
if (!extrinsic) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const innerCall = findInnerExtrinsicCall(extrinsic);
|
|
57
|
+
if (!innerCall) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const callData = innerCall === null || innerCall === void 0 ? void 0 : innerCall.toHex();
|
|
61
|
+
if (!callData || !((0, _utilCrypto.blake2AsHex)(callData) === callHash)) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
return callData;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Type guard to check if a codec is a Call type
|
|
69
|
+
* @param codec - Codec object to check
|
|
70
|
+
* @returns True if the codec is a Call, false otherwise
|
|
71
|
+
*/
|
|
72
|
+
function isCall(codec) {
|
|
73
|
+
return 'args' in codec && 'method' in codec && 'section' in codec;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Finds the inner call within a multisig extrinsic
|
|
78
|
+
* Handles nested calls in multisig.asMulti and batchAll operations
|
|
79
|
+
* @param extrinsic - Extrinsic to search for inner call
|
|
80
|
+
* @returns The inner Call if found, null otherwise
|
|
81
|
+
*/
|
|
82
|
+
function findInnerExtrinsicCall(extrinsic) {
|
|
83
|
+
const findAsMulti = method => {
|
|
84
|
+
const MULTISIG_EXTRINSIC_CALL_INDEX = 3;
|
|
85
|
+
const WRAP_EXTRINSIC_CALL_INDEX = 2;
|
|
86
|
+
if (!method) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const {
|
|
90
|
+
method: callMethod,
|
|
91
|
+
section
|
|
92
|
+
} = method.toHuman();
|
|
93
|
+
if (callMethod === 'asMulti' && section === 'multisig') {
|
|
94
|
+
const arg = method.args[MULTISIG_EXTRINSIC_CALL_INDEX];
|
|
95
|
+
return isCall(arg) ? arg : null;
|
|
96
|
+
}
|
|
97
|
+
if (callMethod === 'batchAll' && method.args.length > 0) {
|
|
98
|
+
const firstArg = method.args[0];
|
|
99
|
+
for (const item of firstArg) {
|
|
100
|
+
if (isCall(item)) {
|
|
101
|
+
const result = findAsMulti(item);
|
|
102
|
+
if (result) {
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (method.args && method.args.length > WRAP_EXTRINSIC_CALL_INDEX) {
|
|
109
|
+
const wrappedArg = method.args[WRAP_EXTRINSIC_CALL_INDEX];
|
|
110
|
+
if (isCall(wrappedArg)) {
|
|
111
|
+
return findAsMulti(wrappedArg);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
};
|
|
116
|
+
return findAsMulti(extrinsic.method);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Decodes call data into a human-readable format
|
|
121
|
+
* @param api - Polkadot API instance
|
|
122
|
+
* @param callData - Hex-encoded call data to decode
|
|
123
|
+
* @returns Decoded call data with method, section, and args, or undefined if callData is not provided
|
|
124
|
+
*/
|
|
125
|
+
function decodeCallData(_ref2) {
|
|
126
|
+
let {
|
|
127
|
+
api,
|
|
128
|
+
callData
|
|
129
|
+
} = _ref2;
|
|
130
|
+
if (callData) {
|
|
131
|
+
return api.createType('Call', callData).toHuman();
|
|
132
|
+
}
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Determines the type of multisig extrinsic based on decoded call data
|
|
138
|
+
* Maps pallet methods to extrinsic types (Transfer, Staking, Lending, etc.)
|
|
139
|
+
* @param decodedCallData - Decoded call data containing section and method
|
|
140
|
+
* @returns The type of multisig extrinsic, or UNKNOWN if not recognized
|
|
141
|
+
*/
|
|
142
|
+
function getMultisigTxType(decodedCallData) {
|
|
143
|
+
if (!decodedCallData) {
|
|
144
|
+
return _index.MultisigTxType.UNKNOWN;
|
|
145
|
+
}
|
|
146
|
+
const sectionMethod = `${decodedCallData.section}.${decodedCallData.method}`;
|
|
147
|
+
if (_index.MULTISIG_TX_TYPE_MAP.transfer.includes(sectionMethod)) {
|
|
148
|
+
return _index.MultisigTxType.TRANSFER;
|
|
149
|
+
}
|
|
150
|
+
if (_index.MULTISIG_TX_TYPE_MAP.transfer_nft.includes(sectionMethod)) {
|
|
151
|
+
return _index.MultisigTxType.TRANSFER_NFT;
|
|
152
|
+
}
|
|
153
|
+
if (_index.MULTISIG_TX_TYPE_MAP.staking.includes(sectionMethod)) {
|
|
154
|
+
return _index.MultisigTxType.STAKING;
|
|
155
|
+
}
|
|
156
|
+
if (_index.MULTISIG_TX_TYPE_MAP.redeem.includes(sectionMethod)) {
|
|
157
|
+
return _index.MultisigTxType.REDEEM;
|
|
158
|
+
}
|
|
159
|
+
if (_index.MULTISIG_TX_TYPE_MAP.unstake.includes(sectionMethod)) {
|
|
160
|
+
return _index.MultisigTxType.UNSTAKE;
|
|
161
|
+
}
|
|
162
|
+
if (_index.MULTISIG_TX_TYPE_MAP.withdraw.includes(sectionMethod)) {
|
|
163
|
+
return _index.MultisigTxType.WITHDRAW;
|
|
164
|
+
}
|
|
165
|
+
if (_index.MULTISIG_TX_TYPE_MAP.cancelUnstake.includes(sectionMethod)) {
|
|
166
|
+
return _index.MultisigTxType.CANCEL_UNSTAKE;
|
|
167
|
+
}
|
|
168
|
+
if (_index.MULTISIG_TX_TYPE_MAP.claim.includes(sectionMethod)) {
|
|
169
|
+
return _index.MultisigTxType.CLAIM_REWARD;
|
|
170
|
+
}
|
|
171
|
+
if (_index.MULTISIG_TX_TYPE_MAP.nominate.includes(sectionMethod)) {
|
|
172
|
+
return _index.MultisigTxType.NOMINATE;
|
|
173
|
+
}
|
|
174
|
+
if (_index.MULTISIG_TX_TYPE_MAP.lending.includes(sectionMethod)) {
|
|
175
|
+
return _index.MultisigTxType.LENDING;
|
|
176
|
+
}
|
|
177
|
+
if (_index.MULTISIG_TX_TYPE_MAP.govVote.includes(sectionMethod)) {
|
|
178
|
+
return _index.MultisigTxType.GOV_VOTE;
|
|
179
|
+
}
|
|
180
|
+
if (_index.MULTISIG_TX_TYPE_MAP.govUnlockVote.includes(sectionMethod)) {
|
|
181
|
+
return _index.MultisigTxType.GOV_UNLOCK_VOTE;
|
|
182
|
+
}
|
|
183
|
+
if (_index.MULTISIG_TX_TYPE_MAP.govRemoveVote.includes(sectionMethod)) {
|
|
184
|
+
return _index.MultisigTxType.GOV_REMOVE_VOTE;
|
|
185
|
+
}
|
|
186
|
+
if (_index.MULTISIG_TX_TYPE_MAP.swap.includes(sectionMethod)) {
|
|
187
|
+
return _index.MultisigTxType.SWAP;
|
|
188
|
+
}
|
|
189
|
+
if (_index.MULTISIG_TX_TYPE_MAP.setTokenPayFee.includes(sectionMethod)) {
|
|
190
|
+
return _index.MultisigTxType.SET_TOKEN_PAY_FEE;
|
|
191
|
+
}
|
|
192
|
+
if (_index.MULTISIG_TX_TYPE_MAP.addProxy.includes(sectionMethod)) {
|
|
193
|
+
return _index.MultisigTxType.ADD_PROXY;
|
|
194
|
+
}
|
|
195
|
+
if (_index.MULTISIG_TX_TYPE_MAP.removeProxy.includes(sectionMethod)) {
|
|
196
|
+
return _index.MultisigTxType.REMOVE_PROXY;
|
|
197
|
+
}
|
|
198
|
+
return _index.MultisigTxType.UNKNOWN;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Generates a unique key for a pending multisig extrinsic
|
|
203
|
+
* Used as the key in the PendingMultisigTxMap
|
|
204
|
+
* @param chain - Chain identifier
|
|
205
|
+
* @param multisigAddress - Multisig address
|
|
206
|
+
* @param signerAddress - Address of the signer
|
|
207
|
+
* @param extrinsicHash - Hash of the extrinsic
|
|
208
|
+
* @returns Unique key string for the extrinsic
|
|
209
|
+
*/
|
|
210
|
+
function genPendingMultisigTxKey(chain, multisigAddress, signerAddress, extrinsicHash) {
|
|
211
|
+
return `${chain}___${multisigAddress}___${signerAddress}______${extrinsicHash}`;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Calculate deposit amount: depositAmount = depositBase + threshold * depositFactor
|
|
216
|
+
* In case threshold equal to 1, return undefined
|
|
217
|
+
* @param depositBase - Base deposit amount as a string
|
|
218
|
+
* @param threshold - Multisig threshold
|
|
219
|
+
* @param depositFactor - Deposit factor per additional signer as a string
|
|
220
|
+
* @returns Calculated deposit amount as a string
|
|
221
|
+
*/
|
|
222
|
+
function calcDepositAmount(depositBase, threshold, depositFactor) {
|
|
223
|
+
if (threshold === 1) {
|
|
224
|
+
return '0';
|
|
225
|
+
}
|
|
226
|
+
return (BigInt(depositBase) + BigInt(threshold) * BigInt(depositFactor)).toString();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Creates an init multisig extrinsic using the asMulti method
|
|
231
|
+
* @param api - Polkadot API instance
|
|
232
|
+
* @param threshold - Multisig threshold
|
|
233
|
+
* @param signers - Array of signer addresses
|
|
234
|
+
* @param signer - Address of the current signer
|
|
235
|
+
* @param extrinsic - Original extrinsic to be wrapped in multisig
|
|
236
|
+
* @returns SubmittableExtrinsic representing the multisig transaction
|
|
237
|
+
*/
|
|
238
|
+
function createInitMultisigExtrinsic(api, threshold, signers, signer, extrinsic) {
|
|
239
|
+
const otherSignatories = signers.filter(s => !(0, _utils.isSameAddress)(s, signer));
|
|
240
|
+
return api.tx.multisig.asMulti(threshold, (0, _utilCrypto.sortAddresses)(otherSignatories), null, extrinsic, DEFAULT_MAX_WEIGHT // default max weight for init multisig tx
|
|
241
|
+
);
|
|
242
|
+
}
|
|
@@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
+
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
8
9
|
var _RequestExtrinsicSign = _interopRequireDefault(require("@subwallet/extension-base/background/RequestExtrinsicSign"));
|
|
10
|
+
var _types = require("@subwallet/extension-base/types");
|
|
9
11
|
var _getId = require("@subwallet/extension-base/utils/getId");
|
|
10
12
|
var _request = require("@subwallet/extension-base/utils/request");
|
|
11
13
|
var _rxjs = require("rxjs");
|
|
@@ -104,6 +106,29 @@ class SubstrateRequestHandler {
|
|
|
104
106
|
onSign === null || onSign === void 0 ? void 0 : onSign(id);
|
|
105
107
|
});
|
|
106
108
|
}
|
|
109
|
+
|
|
110
|
+
// used for wrapped tx where we don't want to show popup for internal requests
|
|
111
|
+
// transaction is multisig or proxy transaction
|
|
112
|
+
async signWrappedTransaction(id, address, url, payload, onSign) {
|
|
113
|
+
const isAlwaysRequired = await this.#requestService.settingService.isAlwaysRequired;
|
|
114
|
+
if (isAlwaysRequired && !onSign) {
|
|
115
|
+
this.#requestService.keyringService.lock();
|
|
116
|
+
}
|
|
117
|
+
if (!this.#substrateRequests[id]) {
|
|
118
|
+
return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.USER_REJECT_REQUEST));
|
|
119
|
+
}
|
|
120
|
+
return new Promise((resolve, reject) => {
|
|
121
|
+
this.#substrateRequests[id] = {
|
|
122
|
+
...this.signComplete(id, resolve, reject),
|
|
123
|
+
address,
|
|
124
|
+
id,
|
|
125
|
+
request: new _RequestExtrinsicSign.default(payload),
|
|
126
|
+
url: url
|
|
127
|
+
};
|
|
128
|
+
this.signSubject.next(this.allSubstrateRequests);
|
|
129
|
+
onSign === null || onSign === void 0 ? void 0 : onSign(id);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
107
132
|
resetWallet() {
|
|
108
133
|
for (const request of Object.values(this.#substrateRequests)) {
|
|
109
134
|
request.reject(new Error('Reset wallet'));
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _BitcoinRequestHandler = _interopRequireDefault(require("@subwallet/extension-base/services/request-service/handler/BitcoinRequestHandler"));
|
|
9
9
|
var _CardanoRequestHandler = _interopRequireDefault(require("@subwallet/extension-base/services/request-service/handler/CardanoRequestHandler"));
|
|
10
|
+
var _types = require("@subwallet/extension-base/services/transaction-service/types");
|
|
10
11
|
var _TonRequestHandler = _interopRequireDefault(require("./handler/TonRequestHandler"));
|
|
11
12
|
var _handler = require("./handler");
|
|
12
13
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
@@ -174,7 +175,10 @@ class RequestService {
|
|
|
174
175
|
getSignRequest(id) {
|
|
175
176
|
return this.#substrateRequestHandler.getSignRequest(id);
|
|
176
177
|
}
|
|
177
|
-
async signInternalTransaction(id, address, url, payload, onSign) {
|
|
178
|
+
async signInternalTransaction(id, address, url, payload, onSign, isWrappedTx) {
|
|
179
|
+
if (isWrappedTx === _types.SubstrateTransactionWrappingStatus.WRAP_RESULT) {
|
|
180
|
+
return this.#substrateRequestHandler.signWrappedTransaction(id, address, url, payload, onSign);
|
|
181
|
+
}
|
|
178
182
|
return this.#substrateRequestHandler.signTransaction(id, address, url, payload, onSign);
|
|
179
183
|
}
|
|
180
184
|
addConfirmation(id, url, type, payload) {
|
|
@@ -590,6 +590,9 @@ class DatabaseService {
|
|
|
590
590
|
cleanUpOldNotifications(overdueTime) {
|
|
591
591
|
return this.stores.inappNotification.cleanUpOldNotifications(overdueTime);
|
|
592
592
|
}
|
|
593
|
+
cleanUpNotificationByIds(ids) {
|
|
594
|
+
return this.stores.inappNotification.cleanUpNotificationsByIds(ids);
|
|
595
|
+
}
|
|
593
596
|
subscribeUnreadNotificationsCountMap() {
|
|
594
597
|
return this.stores.inappNotification.subscribeUnreadNotificationsCount();
|
|
595
598
|
}
|
|
@@ -599,8 +602,8 @@ class DatabaseService {
|
|
|
599
602
|
upsertNotifications(notifications) {
|
|
600
603
|
return this.stores.inappNotification.bulkUpsert(notifications);
|
|
601
604
|
}
|
|
602
|
-
markAllRead(
|
|
603
|
-
return this.stores.inappNotification.markAllRead(
|
|
605
|
+
markAllRead(params) {
|
|
606
|
+
return this.stores.inappNotification.markAllRead(params);
|
|
604
607
|
}
|
|
605
608
|
switchReadStatus(params) {
|
|
606
609
|
return this.stores.inappNotification.switchReadStatus(params);
|
|
@@ -9,6 +9,7 @@ var _constants = require("@subwallet/extension-base/constants");
|
|
|
9
9
|
var _interfaces = require("@subwallet/extension-base/services/inapp-notification-service/interfaces");
|
|
10
10
|
var _utils = require("@subwallet/extension-base/services/inapp-notification-service/utils");
|
|
11
11
|
var _BaseStore = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/BaseStore"));
|
|
12
|
+
var _utils2 = require("@subwallet/extension-base/utils");
|
|
12
13
|
var _dexie = require("dexie");
|
|
13
14
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
14
15
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -22,6 +23,7 @@ class InappNotificationStore extends _BaseStore.default {
|
|
|
22
23
|
}
|
|
23
24
|
async getNotificationsByParams(params) {
|
|
24
25
|
const {
|
|
26
|
+
metadata,
|
|
25
27
|
notificationTab,
|
|
26
28
|
proxyId
|
|
27
29
|
} = params;
|
|
@@ -33,6 +35,15 @@ class InappNotificationStore extends _BaseStore.default {
|
|
|
33
35
|
const filteredTable = this.table.filter(item => {
|
|
34
36
|
const matchesProxyId = item.proxyId === proxyId;
|
|
35
37
|
const matchesReadStatus = item.isRead === (0, _utils.getIsTabRead)(notificationTab);
|
|
38
|
+
if (metadata !== null && metadata !== void 0 && metadata.multisigAddress && metadata !== null && metadata !== void 0 && metadata.chain && notificationTab === _interfaces.NotificationTab.MULTISIG) {
|
|
39
|
+
// @Todo This condition is service only for multisig subscribe service to get all filter by multisig address
|
|
40
|
+
// then clear it when tx is completed
|
|
41
|
+
// So, if use this condition to service other feature, need to re-check carefully
|
|
42
|
+
const multisigMetadata = item.metadata;
|
|
43
|
+
const multisigAddressOfNotification = multisigMetadata === null || multisigMetadata === void 0 ? void 0 : multisigMetadata.multisigAddress;
|
|
44
|
+
const chain = multisigMetadata === null || multisigMetadata === void 0 ? void 0 : multisigMetadata.chain;
|
|
45
|
+
return !!multisigAddressOfNotification && (0, _utils2.isSameAddress)(multisigAddressOfNotification, metadata.multisigAddress) && chain === metadata.chain;
|
|
46
|
+
}
|
|
36
47
|
if (isTabAll) {
|
|
37
48
|
return matchesProxyId;
|
|
38
49
|
}
|
|
@@ -53,6 +64,9 @@ class InappNotificationStore extends _BaseStore.default {
|
|
|
53
64
|
const currentTimestamp = Date.now();
|
|
54
65
|
return this.table.filter(item => item.time <= currentTimestamp - overdueTime).delete();
|
|
55
66
|
}
|
|
67
|
+
async cleanUpNotificationsByIds(ids) {
|
|
68
|
+
return this.table.where('id').anyOf(ids).delete();
|
|
69
|
+
}
|
|
56
70
|
subscribeUnreadNotificationsCount() {
|
|
57
71
|
return (0, _dexie.liveQuery)(async () => {
|
|
58
72
|
return await this.getUnreadNotificationsCountMap();
|
|
@@ -65,9 +79,13 @@ class InappNotificationStore extends _BaseStore.default {
|
|
|
65
79
|
return countMap;
|
|
66
80
|
}, {});
|
|
67
81
|
}
|
|
68
|
-
markAllRead(
|
|
82
|
+
markAllRead(params) {
|
|
83
|
+
const {
|
|
84
|
+
proxyId,
|
|
85
|
+
excludeNotificationIds = []
|
|
86
|
+
} = params;
|
|
69
87
|
if (proxyId === _constants.ALL_ACCOUNT_KEY) {
|
|
70
|
-
return this.table.toCollection().modify({
|
|
88
|
+
return this.table.toCollection().filter(notification => !excludeNotificationIds.includes(notification.id)).modify({
|
|
71
89
|
isRead: true
|
|
72
90
|
});
|
|
73
91
|
}
|
|
@@ -4,6 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
exports.createInitSubstrateProxyExtrinsic = createInitSubstrateProxyExtrinsic;
|
|
7
8
|
exports.default = void 0;
|
|
8
9
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
9
10
|
var _types = require("@subwallet/extension-base/types");
|
|
@@ -13,6 +14,9 @@ var _constant = require("./constant");
|
|
|
13
14
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
14
15
|
// SPDX-License-Identifier: Apache-2.0
|
|
15
16
|
|
|
17
|
+
function createInitSubstrateProxyExtrinsic(api, proxiedAddress, extrinsic) {
|
|
18
|
+
return api.tx.proxy.proxy(proxiedAddress, null, extrinsic);
|
|
19
|
+
}
|
|
16
20
|
class SubstrateProxyAccountService {
|
|
17
21
|
constructor(state) {
|
|
18
22
|
this.state = state;
|
|
@@ -39,6 +43,7 @@ class SubstrateProxyAccountService {
|
|
|
39
43
|
const baseDeposit = ((_substrateApi$api$con = substrateApi.api.consts.proxy.proxyDepositBase) === null || _substrateApi$api$con === void 0 ? void 0 : _substrateApi$api$con.toString()) || '0';
|
|
40
44
|
const factorDeposit = ((_substrateApi$api$con2 = substrateApi.api.consts.proxy.proxyDepositFactor) === null || _substrateApi$api$con2 === void 0 ? void 0 : _substrateApi$api$con2.toString()) || '0';
|
|
41
45
|
const deposit = new _bignumber.default(baseDeposit).plus(factorDeposit);
|
|
46
|
+
const allAccounts = this.state.keyringService.context.accounts;
|
|
42
47
|
const [_substrateProxyAccounts, currentSubstrateProxyDeposit] = result.toPrimitive();
|
|
43
48
|
|
|
44
49
|
// Mapping on-chain data to our defined type
|
|
@@ -53,11 +58,21 @@ class SubstrateProxyAccountService {
|
|
|
53
58
|
});
|
|
54
59
|
if (type) {
|
|
55
60
|
const allowedSet = new Set([...(_constant.txTypeToSubstrateProxyMap[type] || []), 'Any']);
|
|
56
|
-
substrateProxyAccounts = substrateProxyAccounts.filter(p =>
|
|
61
|
+
substrateProxyAccounts = substrateProxyAccounts.filter(p => {
|
|
62
|
+
if (!p.proxyId) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const accountProxy = allAccounts[p.proxyId];
|
|
66
|
+
const substrateAccount = accountProxy === null || accountProxy === void 0 ? void 0 : accountProxy.accounts.find(acc => acc.chainType === _types.AccountChainType.SUBSTRATE);
|
|
67
|
+
if (!substrateAccount || !substrateAccount.transactionActions.includes(type)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return allowedSet.has(p.substrateProxyType);
|
|
71
|
+
});
|
|
57
72
|
}
|
|
58
73
|
if (excludedSubstrateProxyAccounts && excludedSubstrateProxyAccounts.length > 0) {
|
|
59
74
|
substrateProxyAccounts = substrateProxyAccounts.filter(p => {
|
|
60
|
-
return !excludedSubstrateProxyAccounts.some(excluded => excluded.
|
|
75
|
+
return !excludedSubstrateProxyAccounts.some(excluded => excluded.substrateProxyAddress === p.substrateProxyAddress && excluded.substrateProxyType === p.substrateProxyType);
|
|
61
76
|
});
|
|
62
77
|
}
|
|
63
78
|
const estimateSubstrateProxyDeposit = new _bignumber.default(currentSubstrateProxyDeposit).plus(factorDeposit);
|
|
@@ -86,7 +101,7 @@ class SubstrateProxyAccountService {
|
|
|
86
101
|
}
|
|
87
102
|
|
|
88
103
|
// Validate adding proxy account
|
|
89
|
-
async validateAddSubstrateProxyAccount(params
|
|
104
|
+
async validateAddSubstrateProxyAccount(params) {
|
|
90
105
|
var _substrateApi$api$con3, _substrateApi$api$con4, _substrateApi$api$con5, _substrateApi$api$con6;
|
|
91
106
|
const {
|
|
92
107
|
address,
|
|
@@ -95,6 +110,9 @@ class SubstrateProxyAccountService {
|
|
|
95
110
|
} = params;
|
|
96
111
|
const substrateApi = this.getSubstrateApi(chain);
|
|
97
112
|
await substrateApi.isReady;
|
|
113
|
+
if (!substrateApi.api.tx.proxy || !substrateApi.api.tx.proxy.addProxy) {
|
|
114
|
+
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED)];
|
|
115
|
+
}
|
|
98
116
|
const addProxyTx = substrateApi.api.tx.proxy.addProxy;
|
|
99
117
|
const proxyTypeArg = addProxyTx.meta.args.find(arg => arg.name.toString() === 'proxyType');
|
|
100
118
|
if (proxyTypeArg) {
|
|
@@ -105,9 +123,6 @@ class SubstrateProxyAccountService {
|
|
|
105
123
|
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED, 'This proxy type is not supported on the chosen network. Select another one and try again')];
|
|
106
124
|
}
|
|
107
125
|
}
|
|
108
|
-
if (!substrateApi.api.tx.proxy || !substrateApi.api.tx.proxy.addProxy) {
|
|
109
|
-
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED)];
|
|
110
|
-
}
|
|
111
126
|
|
|
112
127
|
// Validate max proxies accounts limit
|
|
113
128
|
const maxSubstrateProxies = ((_substrateApi$api$con3 = substrateApi.api.consts.proxy.maxProxies) === null || _substrateApi$api$con3 === void 0 ? void 0 : (_substrateApi$api$con4 = _substrateApi$api$con3.toNumber) === null || _substrateApi$api$con4 === void 0 ? void 0 : _substrateApi$api$con4.call(_substrateApi$api$con3)) || 0;
|
|
@@ -125,7 +140,7 @@ class SubstrateProxyAccountService {
|
|
|
125
140
|
const baseDeposit = ((_substrateApi$api$con5 = substrateApi.api.consts.proxy.proxyDepositBase) === null || _substrateApi$api$con5 === void 0 ? void 0 : _substrateApi$api$con5.toString()) || '0';
|
|
126
141
|
const factorDeposit = ((_substrateApi$api$con6 = substrateApi.api.consts.proxy.proxyDepositFactor) === null || _substrateApi$api$con6 === void 0 ? void 0 : _substrateApi$api$con6.toString()) || '0';
|
|
127
142
|
const requiredDeposit = proxyList.length === 0 ? new _bignumber.default(baseDeposit).plus(factorDeposit) : new _bignumber.default(factorDeposit);
|
|
128
|
-
const totalRequired = new _bignumber.default(requiredDeposit).plus(
|
|
143
|
+
const totalRequired = new _bignumber.default(requiredDeposit).plus(estimatedFee);
|
|
129
144
|
if (bnTransferableBalance.lt(totalRequired)) {
|
|
130
145
|
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.NOT_ENOUGH_BALANCE)];
|
|
131
146
|
}
|
|
@@ -82,6 +82,14 @@ const typeName = type => {
|
|
|
82
82
|
return 'Unlock votes';
|
|
83
83
|
case _KoniTypes.ExtrinsicType.CHANGE_EARNING_VALIDATOR:
|
|
84
84
|
return 'Change validator';
|
|
85
|
+
case _KoniTypes.ExtrinsicType.MULTISIG_APPROVE_TX:
|
|
86
|
+
return 'Approve multisig extrinsic';
|
|
87
|
+
case _KoniTypes.ExtrinsicType.MULTISIG_EXECUTE_TX:
|
|
88
|
+
return 'Execute multisig extrinsic';
|
|
89
|
+
case _KoniTypes.ExtrinsicType.MULTISIG_CANCEL_TX:
|
|
90
|
+
return 'Cancel multisig extrinsic';
|
|
91
|
+
case _KoniTypes.ExtrinsicType.MULTISIG_INIT_TX:
|
|
92
|
+
return 'Initiate multisig extrinsic';
|
|
85
93
|
case _KoniTypes.ExtrinsicType.UNKNOWN:
|
|
86
94
|
default:
|
|
87
95
|
return 'unknown';
|