@subwallet/extension-base 0.8.1-wr2x → 0.8.1-wr3
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 +31 -1
- package/background/KoniTypes.js +15 -1
- package/background/errors/BalanceError.d.ts +6 -0
- package/background/errors/BalanceError.js +33 -0
- package/background/handlers/State.js +2 -1
- package/cjs/background/KoniTypes.js +18 -2
- package/cjs/background/errors/BalanceError.js +39 -0
- package/cjs/background/handlers/State.js +2 -1
- package/cjs/koni/api/dotsama/balance.js +1 -0
- package/cjs/koni/background/handlers/Extension.js +140 -94
- package/cjs/koni/background/handlers/State.js +15 -11
- package/cjs/services/balance-service/index.js +95 -2
- package/cjs/services/chain-service/utils.js +13 -3
- package/cjs/services/notification-service/NotificationService.js +23 -1
- package/cjs/services/request-service/handler/PopupHandler.js +10 -16
- package/cjs/services/request-service/index.js +2 -6
- package/cjs/services/setting-service/SettingService.js +2 -1
- package/cjs/services/storage-service/DatabaseService.js +3 -2
- package/cjs/services/storage-service/db-stores/Balance.js +0 -25
- package/cjs/services/transaction-service/index.js +22 -6
- package/koni/api/dotsama/balance.d.ts +1 -0
- package/koni/api/dotsama/balance.js +1 -1
- package/koni/background/handlers/Extension.d.ts +4 -0
- package/koni/background/handlers/Extension.js +58 -14
- package/koni/background/handlers/State.d.ts +3 -1
- package/koni/background/handlers/State.js +15 -11
- package/package.json +8 -3
- package/services/balance-service/index.d.ts +7 -5
- package/services/balance-service/index.js +95 -2
- package/services/chain-service/utils.d.ts +1 -1
- package/services/chain-service/utils.js +13 -3
- package/services/notification-service/NotificationService.d.ts +6 -1
- package/services/notification-service/NotificationService.js +23 -1
- package/services/request-service/handler/PopupHandler.d.ts +0 -1
- package/services/request-service/handler/PopupHandler.js +10 -15
- package/services/request-service/index.d.ts +3 -2
- package/services/request-service/index.js +2 -6
- package/services/setting-service/SettingService.js +2 -1
- package/services/storage-service/DatabaseService.d.ts +2 -1
- package/services/storage-service/DatabaseService.js +3 -2
- package/services/storage-service/db-stores/Balance.js +0 -25
- package/services/transaction-service/index.d.ts +3 -1
- package/services/transaction-service/index.js +23 -7
- package/cjs/background/errors/EvmRpcError.js +0 -21
- package/cjs/background/errors/SubWalletProviderError.js +0 -17
- package/cjs/constants/ethereum.js +0 -19
- package/cjs/utils/eth/parseTransactionData.js +0 -284
|
@@ -11,12 +11,12 @@ var _helpers = require("@subwallet/extension-base/background/handlers/helpers");
|
|
|
11
11
|
var _subscriptions = require("@subwallet/extension-base/background/handlers/subscriptions");
|
|
12
12
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
13
13
|
var _constants = require("@subwallet/extension-base/constants");
|
|
14
|
-
var _balance = require("@subwallet/extension-base/koni/api/dotsama/balance");
|
|
15
14
|
var _balanceService = require("@subwallet/extension-base/services/balance-service");
|
|
16
15
|
var _chainService = require("@subwallet/extension-base/services/chain-service");
|
|
17
16
|
var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
|
|
18
17
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
19
18
|
var _historyService = require("@subwallet/extension-base/services/history-service");
|
|
19
|
+
var _NotificationService = _interopRequireDefault(require("@subwallet/extension-base/services/notification-service/NotificationService"));
|
|
20
20
|
var _priceService = require("@subwallet/extension-base/services/price-service");
|
|
21
21
|
var _requestService = _interopRequireDefault(require("@subwallet/extension-base/services/request-service"));
|
|
22
22
|
var _SettingService = _interopRequireDefault(require("@subwallet/extension-base/services/setting-service/SettingService"));
|
|
@@ -94,22 +94,20 @@ class KoniState {
|
|
|
94
94
|
fastInterval: []
|
|
95
95
|
};
|
|
96
96
|
lazyMap = {};
|
|
97
|
-
|
|
98
|
-
// TODO: consider making chainService public (or getter) and call function directly
|
|
99
|
-
|
|
100
97
|
ready = false;
|
|
101
98
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
99
|
constructor() {
|
|
103
100
|
let providers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
104
101
|
this.providers = providers;
|
|
105
102
|
this.dbService = new _DatabaseService.default();
|
|
103
|
+
this.notificationService = new _NotificationService.default();
|
|
106
104
|
this.chainService = new _chainService.ChainService(this.dbService);
|
|
107
105
|
this.settingService = new _SettingService.default();
|
|
108
|
-
this.requestService = new _requestService.default(this.chainService);
|
|
106
|
+
this.requestService = new _requestService.default(this.chainService, this.settingService);
|
|
109
107
|
this.priceService = new _priceService.PriceService(this.dbService, this.chainService);
|
|
110
|
-
this.balanceService = new _balanceService.BalanceService(
|
|
108
|
+
this.balanceService = new _balanceService.BalanceService(this.chainService);
|
|
111
109
|
this.historyService = new _historyService.HistoryService(this.dbService, this.chainService);
|
|
112
|
-
this.transactionService = new _transactionService.default(this.chainService, this.requestService, this.balanceService, this.historyService);
|
|
110
|
+
this.transactionService = new _transactionService.default(this.chainService, this.requestService, this.balanceService, this.historyService, this.notificationService);
|
|
113
111
|
this.subscription = new _subscription.KoniSubscription(this, this.dbService);
|
|
114
112
|
this.cron = new _cron.KoniCron(this, this.subscription, this.dbService);
|
|
115
113
|
this.logger = (0, _util.logger)('State');
|
|
@@ -188,10 +186,6 @@ class KoniState {
|
|
|
188
186
|
saveMetadata(meta) {
|
|
189
187
|
this.requestService.saveMetadata(meta);
|
|
190
188
|
}
|
|
191
|
-
setNotification(notification) {
|
|
192
|
-
this.requestService.setNotification(notification);
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
189
|
sign(url, request, account) {
|
|
196
190
|
return this.requestService.sign(url, request, account);
|
|
197
191
|
}
|
|
@@ -682,6 +676,16 @@ class KoniState {
|
|
|
682
676
|
});
|
|
683
677
|
});
|
|
684
678
|
}
|
|
679
|
+
setCamera(value) {
|
|
680
|
+
this.settingService.getSettings(settings => {
|
|
681
|
+
const newSettings = {
|
|
682
|
+
...settings,
|
|
683
|
+
camera: value
|
|
684
|
+
};
|
|
685
|
+
console.log(newSettings, value);
|
|
686
|
+
this.settingService.setSettings(newSettings);
|
|
687
|
+
});
|
|
688
|
+
}
|
|
685
689
|
subscribeSettingsSubject() {
|
|
686
690
|
return this.settingService.getSubject();
|
|
687
691
|
}
|
|
@@ -4,12 +4,105 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BalanceService = void 0;
|
|
7
|
+
var _BalanceError = require("@subwallet/extension-base/background/errors/BalanceError");
|
|
8
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
|
+
var _balance = require("@subwallet/extension-base/koni/api/dotsama/balance");
|
|
10
|
+
var _handlers = require("@subwallet/extension-base/koni/background/handlers");
|
|
11
|
+
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
12
|
+
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
13
|
+
var _utils2 = require("@subwallet/extension-base/utils");
|
|
7
14
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
15
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
16
|
|
|
10
17
|
class BalanceService {
|
|
11
|
-
constructor(
|
|
12
|
-
this.
|
|
18
|
+
constructor(chainService) {
|
|
19
|
+
this.chainService = chainService;
|
|
20
|
+
|
|
21
|
+
// Todo: Load data from db to balanceSubject
|
|
22
|
+
// Todo: Start subscribe balance and data
|
|
23
|
+
// Todo: Listen change and apply to balanceSubject
|
|
24
|
+
// Todo: Active/Chain
|
|
25
|
+
// Todo: Add/remove account
|
|
26
|
+
// Todo: Add new account
|
|
27
|
+
// Todo: Optimize get balance for single account and chain with cache
|
|
28
|
+
// Todo: Move everything of fetching balance to this service
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async subscribeTokenFreeBalance(address, chain, tokenSlug, callback) {
|
|
32
|
+
const chainInfo = this.chainService.getChainInfoByKey(chain);
|
|
33
|
+
const chainState = this.chainService.getChainStateByKey(chain);
|
|
34
|
+
if (!chainInfo || !chainState || !chainState.active) {
|
|
35
|
+
return Promise.reject(new _BalanceError.BalanceError(_KoniTypes.BalanceErrorType.NETWORK_ERROR, `Chain ${chain} is not active`));
|
|
36
|
+
}
|
|
37
|
+
const tSlug = tokenSlug || (0, _utils._getChainNativeTokenSlug)(chainInfo);
|
|
38
|
+
const tokenInfo = this.chainService.getAssetBySlug(tSlug);
|
|
39
|
+
if (!tokenInfo) {
|
|
40
|
+
return Promise.reject(new _BalanceError.BalanceError(_KoniTypes.BalanceErrorType.TOKEN_ERROR, `Token ${tSlug} is not supported`));
|
|
41
|
+
}
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
let hasError = true;
|
|
44
|
+
const unsub = this.subscribeBalance([address], [chain], rs => {
|
|
45
|
+
if (rs.tokenSlug === tSlug) {
|
|
46
|
+
hasError = false;
|
|
47
|
+
const balance = {
|
|
48
|
+
value: rs.free,
|
|
49
|
+
decimals: tokenInfo.decimals || 0,
|
|
50
|
+
symbol: tokenInfo.symbol
|
|
51
|
+
};
|
|
52
|
+
if (callback) {
|
|
53
|
+
callback(balance);
|
|
54
|
+
} else {
|
|
55
|
+
// Auto unsubscribe if no callback
|
|
56
|
+
unsub();
|
|
57
|
+
}
|
|
58
|
+
resolve([unsub, balance]);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
if (hasError) {
|
|
63
|
+
unsub();
|
|
64
|
+
reject(new Error('Get Balance Timeout'));
|
|
65
|
+
}
|
|
66
|
+
}, 9999);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async getTokenFreeBalance(address, chain, tokenSlug) {
|
|
70
|
+
const [, balance] = await this.subscribeTokenFreeBalance(address, chain, tokenSlug);
|
|
71
|
+
return balance;
|
|
72
|
+
}
|
|
73
|
+
subscribeBalance(addresses, chains, callback) {
|
|
74
|
+
const [substrateAddresses, evmAddresses] = (0, _utils2.categoryAddresses)(addresses);
|
|
75
|
+
const chainInfoMap = this.chainService.getChainInfoMap();
|
|
76
|
+
const chainStateMap = this.chainService.getChainStateMap();
|
|
77
|
+
const substrateApiMap = this.chainService.getSubstrateApiMap();
|
|
78
|
+
const evmApiMap = this.chainService.getEvmApiMap();
|
|
79
|
+
|
|
80
|
+
// Get data from chain or all chains
|
|
81
|
+
const chainList = chains || Object.keys(chainInfoMap);
|
|
82
|
+
// Filter active chain only
|
|
83
|
+
const useChainInfos = chainList.filter(c => chainStateMap[c] && chainStateMap[c].active).map(c => chainInfoMap[c]);
|
|
84
|
+
|
|
85
|
+
// Looping over each chain
|
|
86
|
+
const unsubList = useChainInfos.map(async chainInfo => {
|
|
87
|
+
const chainSlug = chainInfo.slug;
|
|
88
|
+
const useAddresses = (0, _utils._isChainEvmCompatible)(chainInfo) ? evmAddresses : substrateAddresses;
|
|
89
|
+
if ((0, _utils._isPureEvmChain)(chainInfo)) {
|
|
90
|
+
const nativeTokenInfo = _handlers.state.getNativeTokenInfo(chainSlug);
|
|
91
|
+
return (0, _balance.subscribeEVMBalance)(chainSlug, useAddresses, evmApiMap, callback, nativeTokenInfo);
|
|
92
|
+
}
|
|
93
|
+
if (!useAddresses || useAddresses.length === 0 || _constants._PURE_EVM_CHAINS.indexOf(chainSlug) > -1) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const networkAPI = await substrateApiMap[chainSlug].isReady;
|
|
97
|
+
return (0, _balance.subscribeSubstrateBalance)(useAddresses, chainInfo, chainSlug, networkAPI, evmApiMap, callback);
|
|
98
|
+
});
|
|
99
|
+
return () => {
|
|
100
|
+
unsubList.forEach(subProm => {
|
|
101
|
+
subProm.then(unsub => {
|
|
102
|
+
unsub && unsub();
|
|
103
|
+
}).catch(console.error);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
13
106
|
}
|
|
14
107
|
}
|
|
15
108
|
exports.BalanceService = BalanceService;
|
|
@@ -339,12 +339,22 @@ function _getAssetDecimals(assetInfo) {
|
|
|
339
339
|
return assetInfo.decimals || 0;
|
|
340
340
|
}
|
|
341
341
|
function _getBlockExplorerFromChain(chainInfo) {
|
|
342
|
-
|
|
342
|
+
let blockExplorer;
|
|
343
343
|
if (_isPureEvmChain(chainInfo)) {
|
|
344
344
|
var _chainInfo$evmInfo4;
|
|
345
|
-
|
|
345
|
+
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo4 = chainInfo.evmInfo) === null || _chainInfo$evmInfo4 === void 0 ? void 0 : _chainInfo$evmInfo4.blockExplorer;
|
|
346
|
+
} else {
|
|
347
|
+
var _chainInfo$substrateI12;
|
|
348
|
+
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI12 = chainInfo.substrateInfo) === null || _chainInfo$substrateI12 === void 0 ? void 0 : _chainInfo$substrateI12.blockExplorer;
|
|
349
|
+
}
|
|
350
|
+
if (!blockExplorer) {
|
|
351
|
+
return undefined;
|
|
352
|
+
}
|
|
353
|
+
if (blockExplorer !== '' && !blockExplorer.endsWith('/')) {
|
|
354
|
+
return `${blockExplorer}/`;
|
|
355
|
+
} else {
|
|
356
|
+
return blockExplorer;
|
|
346
357
|
}
|
|
347
|
-
return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI12 = chainInfo.substrateInfo) === null || _chainInfo$substrateI12 === void 0 ? void 0 : _chainInfo$substrateI12.blockExplorer) || '';
|
|
348
358
|
}
|
|
349
359
|
function _parseMetadataForSmartContractAsset(contractAddress) {
|
|
350
360
|
return {
|
|
@@ -4,12 +4,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _rxjs = require("rxjs");
|
|
7
8
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
10
|
|
|
10
11
|
class NotificationService {
|
|
12
|
+
notificationSubject = new _rxjs.BehaviorSubject([]);
|
|
13
|
+
getNotificationSubject() {
|
|
14
|
+
return this.notificationSubject;
|
|
15
|
+
}
|
|
16
|
+
notify(notification) {
|
|
17
|
+
const now = new Date().getTime();
|
|
18
|
+
// Get values in last 30 seconds only
|
|
19
|
+
const notifications = this.notificationSubject.value.filter(n => n.id < now - 30000);
|
|
20
|
+
|
|
21
|
+
// Push notification
|
|
22
|
+
notifications.push({
|
|
23
|
+
...notification,
|
|
24
|
+
id: now
|
|
25
|
+
});
|
|
26
|
+
this.notificationSubject.next(notifications);
|
|
27
|
+
if (notification.notifyViaBrowser) {
|
|
28
|
+
var _notification$action;
|
|
29
|
+
NotificationService.createBrowserNotification(notification.title, notification.message, notification === null || notification === void 0 ? void 0 : (_notification$action = notification.action) === null || _notification$action === void 0 ? void 0 : _notification$action.url);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
11
33
|
// Create a new chrome notification with link
|
|
12
|
-
static
|
|
34
|
+
static createBrowserNotification(title, message, link) {
|
|
13
35
|
chrome.notifications.create({
|
|
14
36
|
type: 'basic',
|
|
15
37
|
title,
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
7
|
var _helpers = require("@subwallet/extension-base/background/handlers/helpers");
|
|
9
|
-
var _uiSettings = _interopRequireDefault(require("@polkadot/ui-settings"));
|
|
10
8
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
11
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
10
|
|
|
@@ -27,10 +25,17 @@ const NORMAL_WINDOW_OPTS = {
|
|
|
27
25
|
};
|
|
28
26
|
class PopupHandler {
|
|
29
27
|
#requestService;
|
|
30
|
-
#notification =
|
|
28
|
+
#notification = 'popup';
|
|
31
29
|
#windows = [];
|
|
32
30
|
constructor(requestService) {
|
|
33
31
|
this.#requestService = requestService;
|
|
32
|
+
const updateNotification = rs => {
|
|
33
|
+
this.#notification = rs.browserConfirmationType;
|
|
34
|
+
};
|
|
35
|
+
requestService.settingService.getSettings(updateNotification);
|
|
36
|
+
requestService.settingService.getSubject().subscribe({
|
|
37
|
+
next: updateNotification
|
|
38
|
+
});
|
|
34
39
|
}
|
|
35
40
|
updateIconV2(shouldClose) {
|
|
36
41
|
const numRequests = this.#requestService.numRequests;
|
|
@@ -45,10 +50,6 @@ class PopupHandler {
|
|
|
45
50
|
this.popupClose();
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
|
-
setNotification(notification) {
|
|
49
|
-
this.#notification = notification;
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
53
|
get popup() {
|
|
53
54
|
return this.#windows;
|
|
54
55
|
}
|
|
@@ -58,19 +59,12 @@ class PopupHandler {
|
|
|
58
59
|
}
|
|
59
60
|
popupOpen() {
|
|
60
61
|
if (this.#notification !== 'extension') {
|
|
61
|
-
if (this.#notification === 'window') {
|
|
62
|
-
chrome.windows.create(NORMAL_WINDOW_OPTS, window => {
|
|
63
|
-
if (window) {
|
|
64
|
-
this.#windows.push(window.id || 0);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
62
|
chrome.windows.getCurrent(win => {
|
|
69
63
|
const popupOptions = {
|
|
70
|
-
...POPUP_WINDOW_OPTS
|
|
64
|
+
...(this.#notification === 'window' ? NORMAL_WINDOW_OPTS : POPUP_WINDOW_OPTS)
|
|
71
65
|
};
|
|
72
66
|
if (win) {
|
|
73
|
-
popupOptions.left = (win.left || 0) + (win.width || 0) - (
|
|
67
|
+
popupOptions.left = (win.left || 0) + (win.width || 0) - (popupOptions.width || 0) - 20;
|
|
74
68
|
popupOptions.top = (win.top || 0) + 80;
|
|
75
69
|
}
|
|
76
70
|
chrome.windows.create(popupOptions, window => {
|
|
@@ -24,8 +24,9 @@ class RequestService {
|
|
|
24
24
|
#evmRequestHandler;
|
|
25
25
|
|
|
26
26
|
// Common
|
|
27
|
-
constructor(chainService) {
|
|
27
|
+
constructor(chainService, settingService) {
|
|
28
28
|
this.#chainService = chainService;
|
|
29
|
+
this.settingService = settingService;
|
|
29
30
|
this.#popupHandler = new _PopupHandler.default(this);
|
|
30
31
|
this.#metadataRequestHandler = new _MetadataRequestHandler.default(this);
|
|
31
32
|
this.#authRequestHandler = new _AuthRequestHandler.default(this, this.#chainService);
|
|
@@ -51,11 +52,6 @@ class RequestService {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
// Popup
|
|
54
|
-
|
|
55
|
-
setNotification(notification) {
|
|
56
|
-
this.#popupHandler.setNotification(notification);
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
55
|
get popup() {
|
|
60
56
|
return this.#popupHandler.popup;
|
|
61
57
|
}
|
|
@@ -41,9 +41,7 @@ class DatabaseService {
|
|
|
41
41
|
}
|
|
42
42
|
async getPriceStore() {
|
|
43
43
|
try {
|
|
44
|
-
console.log('abcd');
|
|
45
44
|
const rs = await this.stores.price.table.get('usd');
|
|
46
|
-
console.log('abcd', rs);
|
|
47
45
|
return rs;
|
|
48
46
|
} catch (e) {
|
|
49
47
|
return undefined;
|
|
@@ -51,6 +49,9 @@ class DatabaseService {
|
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
// Balance
|
|
52
|
+
async getStoredBalance() {
|
|
53
|
+
return this.stores.balance.table.toArray();
|
|
54
|
+
}
|
|
54
55
|
async updateBalanceStore(address, item) {
|
|
55
56
|
if (item.state === _KoniTypes.APIItemState.READY) {
|
|
56
57
|
this.logger.log(`Updating balance for [${item.tokenSlug}]`);
|
|
@@ -28,30 +28,5 @@ class BalanceStore extends _BaseStoreWithAddress.default {
|
|
|
28
28
|
async removeBySlugs(tokenSlugs) {
|
|
29
29
|
return this.table.where('tokenSlug').anyOfIgnoreCase(tokenSlugs).delete();
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
// private balanceSub!: Subscription;
|
|
33
|
-
// liveQueryBalance (address: string, cb: (result: BalanceJson) => void) {
|
|
34
|
-
// if (this.balanceSub) {
|
|
35
|
-
// this.balanceSub.unsubscribe();
|
|
36
|
-
// }
|
|
37
|
-
//
|
|
38
|
-
// const subscription = liveQuery(
|
|
39
|
-
// () => this.table.where('address').equals(address).toArray()
|
|
40
|
-
// );
|
|
41
|
-
//
|
|
42
|
-
// this.balanceSub = subscription.subscribe({
|
|
43
|
-
// next: (rs) => {
|
|
44
|
-
// const data = this.convertToJsonObject(rs);
|
|
45
|
-
//
|
|
46
|
-
// if (Object.keys(data).length) {
|
|
47
|
-
// const res: BalanceJson = { details: data };
|
|
48
|
-
//
|
|
49
|
-
// cb(res);
|
|
50
|
-
// }
|
|
51
|
-
// }
|
|
52
|
-
// });
|
|
53
|
-
//
|
|
54
|
-
// return this.balanceSub;
|
|
55
|
-
// }
|
|
56
31
|
}
|
|
57
32
|
exports.default = BalanceStore;
|
|
@@ -10,7 +10,6 @@ var _TransactionError = require("@subwallet/extension-base/background/errors/Tra
|
|
|
10
10
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
11
11
|
var _TransactionWarning = require("@subwallet/extension-base/background/warnings/TransactionWarning");
|
|
12
12
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
13
|
-
var _NotificationService = _interopRequireDefault(require("@subwallet/extension-base/services/notification-service/NotificationService"));
|
|
14
13
|
var _constants = require("@subwallet/extension-base/services/request-service/constants");
|
|
15
14
|
var _helpers = require("@subwallet/extension-base/services/transaction-service/helpers");
|
|
16
15
|
var _utils2 = require("@subwallet/extension-base/services/transaction-service/utils");
|
|
@@ -30,11 +29,12 @@ class TransactionService {
|
|
|
30
29
|
get transactions() {
|
|
31
30
|
return this.transactionSubject.getValue();
|
|
32
31
|
}
|
|
33
|
-
constructor(chainService, requestService, balanceService, historyService) {
|
|
32
|
+
constructor(chainService, requestService, balanceService, historyService, notificationService) {
|
|
34
33
|
this.chainService = chainService;
|
|
35
34
|
this.requestService = requestService;
|
|
36
35
|
this.balanceService = balanceService;
|
|
37
36
|
this.historyService = historyService;
|
|
37
|
+
this.notificationService = notificationService;
|
|
38
38
|
}
|
|
39
39
|
get allTransactions() {
|
|
40
40
|
return Object.values(this.transactions);
|
|
@@ -129,10 +129,10 @@ class TransactionService {
|
|
|
129
129
|
// Balance
|
|
130
130
|
const transferNative = validationResponse.transferNativeAmount || '0';
|
|
131
131
|
const nativeTokenInfo = this.chainService.getNativeTokenInfo(chain);
|
|
132
|
-
const balance = await this.balanceService.
|
|
132
|
+
const balance = await this.balanceService.getTokenFreeBalance(address, chain, nativeTokenInfo.slug);
|
|
133
133
|
const existentialDeposit = nativeTokenInfo.minAmount || '0';
|
|
134
134
|
const feeNum = parseInt(estimateFee.value);
|
|
135
|
-
const balanceNum = parseInt(balance);
|
|
135
|
+
const balanceNum = parseInt(balance.value);
|
|
136
136
|
const edNum = parseInt(existentialDeposit);
|
|
137
137
|
const transferNativeNum = parseInt(transferNative);
|
|
138
138
|
if (transferNativeNum + feeNum > balanceNum) {
|
|
@@ -403,7 +403,15 @@ class TransactionService {
|
|
|
403
403
|
blockNumber: blockNumber || 0,
|
|
404
404
|
blockHash: blockHash || ''
|
|
405
405
|
}).catch(console.error);
|
|
406
|
-
|
|
406
|
+
this.notificationService.notify({
|
|
407
|
+
type: _KoniTypes.NotificationType.SUCCESS,
|
|
408
|
+
title: 'Transaction completed',
|
|
409
|
+
message: `Transaction ${transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash} completed`,
|
|
410
|
+
action: {
|
|
411
|
+
url: this.getTransactionLink(id)
|
|
412
|
+
},
|
|
413
|
+
notifyViaBrowser: true
|
|
414
|
+
});
|
|
407
415
|
}
|
|
408
416
|
onFailed(_ref3) {
|
|
409
417
|
let {
|
|
@@ -426,7 +434,15 @@ class TransactionService {
|
|
|
426
434
|
blockNumber: blockNumber || 0,
|
|
427
435
|
blockHash: blockHash || ''
|
|
428
436
|
}).catch(console.error);
|
|
429
|
-
|
|
437
|
+
this.notificationService.notify({
|
|
438
|
+
type: _KoniTypes.NotificationType.ERROR,
|
|
439
|
+
title: 'Transaction failed',
|
|
440
|
+
message: `Transaction ${transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash} failed`,
|
|
441
|
+
action: {
|
|
442
|
+
url: this.getTransactionLink(id)
|
|
443
|
+
},
|
|
444
|
+
notifyViaBrowser: true
|
|
445
|
+
});
|
|
430
446
|
}
|
|
431
447
|
|
|
432
448
|
// Log transaction errors
|
|
@@ -2,6 +2,7 @@ import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
|
2
2
|
import { BalanceItem } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
4
|
export declare function subscribeBalance(addresses: string[], chainInfoMap: Record<string, _ChainInfo>, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, callback: (rs: BalanceItem) => void): () => void;
|
|
5
|
+
export declare function subscribeSubstrateBalance(addresses: string[], chainInfo: _ChainInfo, chain: string, networkAPI: _SubstrateApi, evmApiMap: Record<string, _EvmApi>, callBack: (rs: BalanceItem) => void): Promise<() => void>;
|
|
5
6
|
export declare function subscribeEVMBalance(chain: string, addresses: string[], evmApiMap: Record<string, _EvmApi>, callback: (rs: BalanceItem) => void, tokenInfo: _ChainAsset): () => void;
|
|
6
7
|
export declare function getFreeBalance(chain: string, address: string, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, tokenSlug?: string): Promise<string>;
|
|
7
8
|
export declare function subscribeFreeBalance(chain: string, address: string, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, token: string | undefined, update: (balance: string) => void): Promise<() => void>;
|
|
@@ -38,7 +38,7 @@ export function subscribeBalance(addresses, chainInfoMap, substrateApiMap, evmAp
|
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
async function subscribeSubstrateBalance(addresses, chainInfo, chain, networkAPI, evmApiMap, callBack) {
|
|
41
|
+
export async function subscribeSubstrateBalance(addresses, chainInfo, chain, networkAPI, evmApiMap, callBack) {
|
|
42
42
|
let unsubNativeToken;
|
|
43
43
|
if (_BALANCE_CHAIN_GROUP.crab.includes(chain)) {
|
|
44
44
|
unsubNativeToken = subscribeDarwiniaBalance(addresses, chainInfo, chain, networkAPI.api, callBack);
|
|
@@ -52,6 +52,7 @@ export default class KoniExtension {
|
|
|
52
52
|
private _forgetAllSite;
|
|
53
53
|
private forgetAllSite;
|
|
54
54
|
private getNonReadonlyAccounts;
|
|
55
|
+
private isAddressValidWithAuthType;
|
|
55
56
|
private filterAccountsByAccountAuthType;
|
|
56
57
|
private _changeAuthorizationAll;
|
|
57
58
|
private changeAuthorizationAll;
|
|
@@ -68,6 +69,7 @@ export default class KoniExtension {
|
|
|
68
69
|
private toggleBalancesVisibility;
|
|
69
70
|
private saveAccountAllLogo;
|
|
70
71
|
private saveTheme;
|
|
72
|
+
private setCamera;
|
|
71
73
|
private saveBrowserConfirmationType;
|
|
72
74
|
private subscribeSettings;
|
|
73
75
|
private subscribeAuthUrls;
|
|
@@ -125,6 +127,7 @@ export default class KoniExtension {
|
|
|
125
127
|
private upsertCustomToken;
|
|
126
128
|
private deleteCustomAsset;
|
|
127
129
|
private validateCustomAsset;
|
|
130
|
+
private getAddressFreeBalance;
|
|
128
131
|
private subscribeAddressFreeBalance;
|
|
129
132
|
private transferCheckReferenceCount;
|
|
130
133
|
private transferCheckSupporting;
|
|
@@ -181,5 +184,6 @@ export default class KoniExtension {
|
|
|
181
184
|
private getSupportedSmartContractTypes;
|
|
182
185
|
private getTransaction;
|
|
183
186
|
private subscribeTransactions;
|
|
187
|
+
private subscribeNotifications;
|
|
184
188
|
handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
|
|
185
189
|
}
|