@subwallet/extension-base 1.1.2-1 → 1.1.3-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.
Files changed (51) hide show
  1. package/background/KoniTypes.d.ts +18 -0
  2. package/background/KoniTypes.js +2 -1
  3. package/cjs/background/KoniTypes.js +4 -2
  4. package/cjs/koni/api/dotsama/transfer.js +0 -2
  5. package/cjs/koni/background/handlers/Extension.js +179 -120
  6. package/cjs/koni/background/handlers/State.js +73 -48
  7. package/cjs/packageInfo.js +1 -1
  8. package/cjs/services/chain-service/constants.js +2 -1
  9. package/cjs/services/chain-service/handler/SubstrateApi.js +8 -0
  10. package/cjs/services/chain-service/handler/manta/MantaPrivateHandler.js +1 -1
  11. package/cjs/services/chain-service/handler/manta/manta-extension-sdk-empty.js +13 -0
  12. package/cjs/services/chain-service/index.js +11 -6
  13. package/cjs/services/request-service/handler/PopupHandler.js +2 -2
  14. package/cjs/services/request-service/helper/index.js +2 -26
  15. package/cjs/services/storage-service/db-stores/Metadata.js +1 -1
  16. package/cjs/services/wallet-connect-service/constants.js +8 -5
  17. package/cjs/services/wallet-connect-service/index.js +50 -36
  18. package/cjs/utils/environment.js +32 -2
  19. package/cjs/utils/index.js +21 -5
  20. package/cjs/utils/registry.js +25 -0
  21. package/koni/api/dotsama/transfer.js +0 -2
  22. package/koni/background/handlers/Extension.d.ts +2 -0
  23. package/koni/background/handlers/Extension.js +72 -15
  24. package/koni/background/handlers/State.d.ts +7 -2
  25. package/koni/background/handlers/State.js +73 -48
  26. package/package.json +17 -6
  27. package/packageInfo.js +1 -1
  28. package/services/chain-service/constants.d.ts +1 -0
  29. package/services/chain-service/constants.js +2 -1
  30. package/services/chain-service/handler/SubstrateApi.js +8 -0
  31. package/services/chain-service/handler/manta/MantaPrivateHandler.d.ts +1 -1
  32. package/services/chain-service/handler/manta/MantaPrivateHandler.js +1 -1
  33. package/services/chain-service/handler/manta/manta-extension-sdk-empty.d.ts +4 -0
  34. package/services/chain-service/handler/manta/manta-extension-sdk-empty.js +5 -0
  35. package/services/chain-service/index.d.ts +2 -1
  36. package/services/chain-service/index.js +11 -6
  37. package/services/request-service/handler/PopupHandler.js +1 -1
  38. package/services/request-service/helper/index.d.ts +0 -2
  39. package/services/request-service/helper/index.js +0 -23
  40. package/services/request-service/types.d.ts +0 -1
  41. package/services/storage-service/db-stores/Metadata.js +1 -1
  42. package/services/wallet-connect-service/constants.d.ts +2 -1
  43. package/services/wallet-connect-service/constants.js +5 -3
  44. package/services/wallet-connect-service/index.d.ts +0 -1
  45. package/services/wallet-connect-service/index.js +50 -36
  46. package/utils/environment.d.ts +4 -1
  47. package/utils/environment.js +28 -1
  48. package/utils/index.d.ts +2 -0
  49. package/utils/index.js +4 -1
  50. package/utils/registry.d.ts +4 -0
  51. package/utils/registry.js +18 -0
@@ -24,6 +24,7 @@ var _eip155RequestHandler = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default
24
24
  var _koniState = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("koniState");
25
25
  var _client = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("client");
26
26
  var _option = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("option");
27
+ var _haveData = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("haveData");
27
28
  var _initClient = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("initClient");
28
29
  var _updateSessions = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("updateSessions");
29
30
  var _onSessionProposal = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("onSessionProposal");
@@ -55,6 +56,10 @@ class WalletConnectService {
55
56
  Object.defineProperty(this, _initClient, {
56
57
  value: _initClient2
57
58
  });
59
+ Object.defineProperty(this, _haveData, {
60
+ get: _get_haveData,
61
+ set: void 0
62
+ });
58
63
  Object.defineProperty(this, _requestService, {
59
64
  writable: true,
60
65
  value: void 0
@@ -104,66 +109,64 @@ class WalletConnectService {
104
109
  (0, _classPrivateFieldLooseBase2.default)(this, _option)[_option] = Object.assign({}, (0, _classPrivateFieldLooseBase2.default)(this, _option)[_option], newOption);
105
110
  await (0, _classPrivateFieldLooseBase2.default)(this, _initClient)[_initClient]();
106
111
  }
107
- getSessions() {
108
- var _classPrivateFieldLoo3;
109
- (0, _classPrivateFieldLooseBase2.default)(this, _checkClient)[_checkClient]();
110
- console.log((_classPrivateFieldLoo3 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo3 === void 0 ? void 0 : _classPrivateFieldLoo3.session.values);
111
- }
112
112
  async connect(uri) {
113
- var _classPrivateFieldLoo4;
113
+ var _classPrivateFieldLoo3;
114
+ if (!(0, _classPrivateFieldLooseBase2.default)(this, _haveData)[_haveData]) {
115
+ await (0, _classPrivateFieldLooseBase2.default)(this, _initClient)[_initClient](true);
116
+ }
114
117
  (0, _classPrivateFieldLooseBase2.default)(this, _checkClient)[_checkClient]();
115
- await ((_classPrivateFieldLoo4 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo4 === void 0 ? void 0 : _classPrivateFieldLoo4.pair({
118
+ await ((_classPrivateFieldLoo3 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo3 === void 0 ? void 0 : _classPrivateFieldLoo3.pair({
116
119
  uri
117
120
  }));
118
121
  }
119
122
  async approveSession(result) {
120
- var _classPrivateFieldLoo5;
123
+ var _classPrivateFieldLoo4;
121
124
  (0, _classPrivateFieldLooseBase2.default)(this, _checkClient)[_checkClient]();
122
- await ((_classPrivateFieldLoo5 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo5 === void 0 ? void 0 : _classPrivateFieldLoo5.approve(result));
125
+ await ((_classPrivateFieldLoo4 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo4 === void 0 ? void 0 : _classPrivateFieldLoo4.approve(result));
123
126
  (0, _classPrivateFieldLooseBase2.default)(this, _updateSessions)[_updateSessions]();
124
127
  }
125
128
  async rejectSession(id) {
126
- var _classPrivateFieldLoo6;
129
+ var _classPrivateFieldLoo5;
127
130
  (0, _classPrivateFieldLooseBase2.default)(this, _checkClient)[_checkClient]();
128
- await ((_classPrivateFieldLoo6 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo6 === void 0 ? void 0 : _classPrivateFieldLoo6.reject({
131
+ await ((_classPrivateFieldLoo5 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo5 === void 0 ? void 0 : _classPrivateFieldLoo5.reject({
129
132
  id: id,
130
133
  reason: (0, _utils2.getSdkError)('USER_REJECTED')
131
134
  }));
132
135
  }
133
136
  async responseRequest(response) {
134
- var _classPrivateFieldLoo7;
137
+ var _classPrivateFieldLoo6;
135
138
  (0, _classPrivateFieldLooseBase2.default)(this, _checkClient)[_checkClient]();
136
- await ((_classPrivateFieldLoo7 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo7 === void 0 ? void 0 : _classPrivateFieldLoo7.respond(response));
139
+ await ((_classPrivateFieldLoo6 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo6 === void 0 ? void 0 : _classPrivateFieldLoo6.respond(response));
137
140
  }
138
141
  async resetWallet(resetAll) {
139
- var _classPrivateFieldLoo8, _classPrivateFieldLoo10, _classPrivateFieldLoo12;
142
+ var _classPrivateFieldLoo7, _classPrivateFieldLoo9, _classPrivateFieldLoo11;
140
143
  (0, _classPrivateFieldLooseBase2.default)(this, _removeListener)[_removeListener]();
141
144
 
142
145
  // Disconnect session
143
- const sessions = ((_classPrivateFieldLoo8 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo8 === void 0 ? void 0 : _classPrivateFieldLoo8.session.values) || [];
146
+ const sessions = ((_classPrivateFieldLoo7 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo7 === void 0 ? void 0 : _classPrivateFieldLoo7.session.values) || [];
144
147
  for (const session of sessions) {
145
- var _classPrivateFieldLoo9;
146
- (_classPrivateFieldLoo9 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo9 === void 0 ? void 0 : _classPrivateFieldLoo9.disconnect({
148
+ var _classPrivateFieldLoo8;
149
+ (_classPrivateFieldLoo8 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo8 === void 0 ? void 0 : _classPrivateFieldLoo8.disconnect({
147
150
  topic: session.topic,
148
151
  reason: (0, _utils2.getSdkError)('USER_DISCONNECTED')
149
152
  }).catch(console.error);
150
153
  }
151
154
 
152
155
  // Disconnect pair
153
- const pairs = ((_classPrivateFieldLoo10 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo10 === void 0 ? void 0 : _classPrivateFieldLoo10.pairing.values) || [];
156
+ const pairs = ((_classPrivateFieldLoo9 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo9 === void 0 ? void 0 : _classPrivateFieldLoo9.pairing.values) || [];
154
157
  for (const pair of pairs) {
155
- var _classPrivateFieldLoo11;
156
- (_classPrivateFieldLoo11 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo11 === void 0 ? void 0 : _classPrivateFieldLoo11.disconnect({
158
+ var _classPrivateFieldLoo10;
159
+ (_classPrivateFieldLoo10 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo10 === void 0 ? void 0 : _classPrivateFieldLoo10.disconnect({
157
160
  topic: pair.topic,
158
161
  reason: (0, _utils2.getSdkError)('USER_DISCONNECTED')
159
162
  }).catch(console.error);
160
163
  }
161
- const keys = (await ((_classPrivateFieldLoo12 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo12 === void 0 ? void 0 : _classPrivateFieldLoo12.core.storage.getKeys())) || [];
164
+ const keys = (await ((_classPrivateFieldLoo11 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo11 === void 0 ? void 0 : _classPrivateFieldLoo11.core.storage.getKeys())) || [];
162
165
  const deleteKeys = resetAll ? keys : keys.filter(key => key.startsWith('wc@'));
163
166
  for (const key of deleteKeys) {
164
167
  try {
165
- var _classPrivateFieldLoo13;
166
- await ((_classPrivateFieldLoo13 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo13 === void 0 ? void 0 : _classPrivateFieldLoo13.core.storage.removeItem(key));
168
+ var _classPrivateFieldLoo12;
169
+ await ((_classPrivateFieldLoo12 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo12 === void 0 ? void 0 : _classPrivateFieldLoo12.core.storage.removeItem(key));
167
170
  } catch (e) {
168
171
  console.error(e);
169
172
  }
@@ -171,8 +174,8 @@ class WalletConnectService {
171
174
  await (0, _classPrivateFieldLooseBase2.default)(this, _initClient)[_initClient]();
172
175
  }
173
176
  async disconnect(topic) {
174
- var _classPrivateFieldLoo14;
175
- await ((_classPrivateFieldLoo14 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo14 === void 0 ? void 0 : _classPrivateFieldLoo14.disconnect({
177
+ var _classPrivateFieldLoo13;
178
+ await ((_classPrivateFieldLoo13 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo13 === void 0 ? void 0 : _classPrivateFieldLoo13.disconnect({
176
179
  topic: topic,
177
180
  reason: (0, _utils2.getSdkError)('USER_DISCONNECTED')
178
181
  }));
@@ -180,9 +183,20 @@ class WalletConnectService {
180
183
  }
181
184
  }
182
185
  exports.default = WalletConnectService;
183
- async function _initClient2() {
186
+ function _get_haveData() {
187
+ const sessionStorage = localStorage.getItem('wc@2:client:0.3//session');
188
+ const pairingStorage = localStorage.getItem('wc@2:core:0.3//pairing');
189
+ const subscriptionStorage = localStorage.getItem('wc@2:core:0.3//subscription');
190
+ const sessions = sessionStorage ? JSON.parse(sessionStorage) : [];
191
+ const pairings = pairingStorage ? JSON.parse(pairingStorage) : [];
192
+ const subscriptions = subscriptionStorage ? JSON.parse(subscriptionStorage) : [];
193
+ return !!sessions.length || !!pairings.length || !!subscriptions.length;
194
+ }
195
+ async function _initClient2(force) {
184
196
  (0, _classPrivateFieldLooseBase2.default)(this, _removeListener)[_removeListener]();
185
- (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client] = await _signClient.default.init((0, _classPrivateFieldLooseBase2.default)(this, _option)[_option]);
197
+ if (force || (0, _classPrivateFieldLooseBase2.default)(this, _haveData)[_haveData]) {
198
+ (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client] = await _signClient.default.init((0, _classPrivateFieldLooseBase2.default)(this, _option)[_option]);
199
+ }
186
200
  (0, _classPrivateFieldLooseBase2.default)(this, _updateSessions)[_updateSessions]();
187
201
  (0, _classPrivateFieldLooseBase2.default)(this, _createListener)[_createListener]();
188
202
  }
@@ -252,18 +266,18 @@ function _onSessionRequest2(requestEvent) {
252
266
  }
253
267
  }
254
268
  function _createListener2() {
255
- var _classPrivateFieldLoo15, _classPrivateFieldLoo16, _classPrivateFieldLoo17, _classPrivateFieldLoo18, _classPrivateFieldLoo19, _classPrivateFieldLoo20;
256
- (_classPrivateFieldLoo15 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo15 === void 0 ? void 0 : _classPrivateFieldLoo15.on('session_proposal', (0, _classPrivateFieldLooseBase2.default)(this, _onSessionProposal)[_onSessionProposal].bind(this));
257
- (_classPrivateFieldLoo16 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo16 === void 0 ? void 0 : _classPrivateFieldLoo16.on('session_request', (0, _classPrivateFieldLooseBase2.default)(this, _onSessionRequest)[_onSessionRequest].bind(this));
258
- (_classPrivateFieldLoo17 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo17 === void 0 ? void 0 : _classPrivateFieldLoo17.on('session_ping', data => console.log('ping', data));
259
- (_classPrivateFieldLoo18 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo18 === void 0 ? void 0 : _classPrivateFieldLoo18.on('session_event', data => console.log('event', data));
260
- (_classPrivateFieldLoo19 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo19 === void 0 ? void 0 : _classPrivateFieldLoo19.on('session_update', data => console.log('update', data));
261
- (_classPrivateFieldLoo20 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo20 === void 0 ? void 0 : _classPrivateFieldLoo20.on('session_delete', (0, _classPrivateFieldLooseBase2.default)(this, _updateSessions)[_updateSessions].bind(this));
269
+ var _classPrivateFieldLoo14, _classPrivateFieldLoo15, _classPrivateFieldLoo16, _classPrivateFieldLoo17, _classPrivateFieldLoo18, _classPrivateFieldLoo19;
270
+ (_classPrivateFieldLoo14 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo14 === void 0 ? void 0 : _classPrivateFieldLoo14.on('session_proposal', (0, _classPrivateFieldLooseBase2.default)(this, _onSessionProposal)[_onSessionProposal].bind(this));
271
+ (_classPrivateFieldLoo15 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo15 === void 0 ? void 0 : _classPrivateFieldLoo15.on('session_request', (0, _classPrivateFieldLooseBase2.default)(this, _onSessionRequest)[_onSessionRequest].bind(this));
272
+ (_classPrivateFieldLoo16 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo16 === void 0 ? void 0 : _classPrivateFieldLoo16.on('session_ping', data => console.log('ping', data));
273
+ (_classPrivateFieldLoo17 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo17 === void 0 ? void 0 : _classPrivateFieldLoo17.on('session_event', data => console.log('event', data));
274
+ (_classPrivateFieldLoo18 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo18 === void 0 ? void 0 : _classPrivateFieldLoo18.on('session_update', data => console.log('update', data));
275
+ (_classPrivateFieldLoo19 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo19 === void 0 ? void 0 : _classPrivateFieldLoo19.on('session_delete', (0, _classPrivateFieldLooseBase2.default)(this, _updateSessions)[_updateSessions].bind(this));
262
276
  }
263
277
  function _removeListener2() {
264
278
  _constants.ALL_WALLET_CONNECT_EVENT.forEach(event => {
265
- var _classPrivateFieldLoo21;
266
- (_classPrivateFieldLoo21 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo21 === void 0 ? void 0 : _classPrivateFieldLoo21.removeAllListeners(event);
279
+ var _classPrivateFieldLoo20;
280
+ (_classPrivateFieldLoo20 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo20 === void 0 ? void 0 : _classPrivateFieldLoo20.removeAllListeners(event);
267
281
  });
268
282
  }
269
283
  function _checkClient2() {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.RuntimeInfo = void 0;
6
+ exports.getOS = exports.TARGET_ENV = exports.RuntimeInfo = exports.MODULE_SUPPORT = void 0;
7
7
  var _KoniTypes = require("../background/KoniTypes");
8
8
  // Copyright 2019-2022 @polkadot/extension authors & contributors
9
9
  // SPDX-License-Identifier: Apache-2.0
@@ -63,4 +63,34 @@ function detectRuntimeEnvironment() {
63
63
  }
64
64
  }
65
65
  const RuntimeInfo = detectRuntimeEnvironment();
66
- exports.RuntimeInfo = RuntimeInfo;
66
+ exports.RuntimeInfo = RuntimeInfo;
67
+ const getOS = () => {
68
+ var _window$navigator, _window$navigator$use;
69
+ const userAgent = window.navigator.userAgent;
70
+ // @ts-ignore
71
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
72
+ const platform = ((_window$navigator = window.navigator) === null || _window$navigator === void 0 ? void 0 : (_window$navigator$use = _window$navigator.userAgentData) === null || _window$navigator$use === void 0 ? void 0 : _window$navigator$use.platform) || window.navigator.platform;
73
+ const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'];
74
+ const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
75
+ const iosPlatforms = ['iPhone', 'iPad', 'iPod'];
76
+ let os = 'Unknown';
77
+ if (macosPlatforms.indexOf(platform) !== -1) {
78
+ os = 'Mac OS';
79
+ } else if (iosPlatforms.indexOf(platform) !== -1) {
80
+ os = 'iOS';
81
+ } else if (windowsPlatforms.indexOf(platform) !== -1) {
82
+ os = 'Windows';
83
+ } else if (/Android/.test(userAgent)) {
84
+ os = 'Android';
85
+ } else if (/Linux/.test(platform)) {
86
+ os = 'Linux';
87
+ }
88
+ return os;
89
+ };
90
+ exports.getOS = getOS;
91
+ const TARGET_ENV = process.env.TARGET_ENV || 'extension';
92
+ exports.TARGET_ENV = TARGET_ENV;
93
+ const MODULE_SUPPORT = {
94
+ MANTA_ZK: TARGET_ENV === 'extension'
95
+ };
96
+ exports.MODULE_SUPPORT = MODULE_SUPPORT;
@@ -9,6 +9,7 @@ var _exportNames = {
9
9
  nonEmptyArr: true,
10
10
  isEmptyArray: true,
11
11
  isAccountAll: true,
12
+ isMobile: true,
12
13
  reformatAddress: true,
13
14
  filterAddressByNetworkKey: true,
14
15
  categoryAddresses: true,
@@ -55,7 +56,7 @@ exports.hexToStr = hexToStr;
55
56
  exports.hexToUTF16 = hexToUTF16;
56
57
  exports.inJestTest = inJestTest;
57
58
  exports.isAccountAll = isAccountAll;
58
- exports.isEmptyArray = exports.isDef = exports.isAddressesEqual = void 0;
59
+ exports.isMobile = exports.isEmptyArray = exports.isDef = exports.isAddressesEqual = void 0;
59
60
  exports.isSameAddress = isSameAddress;
60
61
  exports.isUrl = isUrl;
61
62
  exports.isValidSubstrateAddress = exports.isValidProvider = void 0;
@@ -70,6 +71,7 @@ exports.utf16ToString = utf16ToString;
70
71
  exports.waitTimeout = waitTimeout;
71
72
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
72
73
  var _constants = require("@subwallet/extension-base/constants");
74
+ var _environment = require("@subwallet/extension-base/utils/environment");
73
75
  var _util = require("@polkadot/util");
74
76
  var _utilCrypto = require("@polkadot/util-crypto");
75
77
  var _canDerive = require("./canDerive");
@@ -85,15 +87,15 @@ Object.keys(_array).forEach(function (key) {
85
87
  }
86
88
  });
87
89
  });
88
- var _environment = require("./environment");
89
- Object.keys(_environment).forEach(function (key) {
90
+ var _environment2 = require("./environment");
91
+ Object.keys(_environment2).forEach(function (key) {
90
92
  if (key === "default" || key === "__esModule") return;
91
93
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
92
- if (key in exports && exports[key] === _environment[key]) return;
94
+ if (key in exports && exports[key] === _environment2[key]) return;
93
95
  Object.defineProperty(exports, key, {
94
96
  enumerable: true,
95
97
  get: function () {
96
- return _environment[key];
98
+ return _environment2[key];
97
99
  }
98
100
  });
99
101
  });
@@ -109,6 +111,18 @@ Object.keys(_lazy).forEach(function (key) {
109
111
  }
110
112
  });
111
113
  });
114
+ var _registry = require("./registry");
115
+ Object.keys(_registry).forEach(function (key) {
116
+ if (key === "default" || key === "__esModule") return;
117
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
118
+ if (key in exports && exports[key] === _registry[key]) return;
119
+ Object.defineProperty(exports, key, {
120
+ enumerable: true,
121
+ get: function () {
122
+ return _registry[key];
123
+ }
124
+ });
125
+ });
112
126
  var _translate = require("./translate");
113
127
  Object.keys(_translate).forEach(function (key) {
114
128
  if (key === "default" || key === "__esModule") return;
@@ -135,6 +149,8 @@ exports.isEmptyArray = isEmptyArray;
135
149
  function isAccountAll(address) {
136
150
  return address === _constants.ALL_ACCOUNT_KEY;
137
151
  }
152
+ const isMobile = _KoniTypes.MobileOS.includes((0, _environment.getOS)());
153
+ exports.isMobile = isMobile;
138
154
  function reformatAddress(address) {
139
155
  let networkPrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 42;
140
156
  let isEthereum = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createRegistry = void 0;
7
+ var _utils = require("@subwallet/extension-base/services/chain-service/utils");
8
+ var _types = require("@polkadot/types");
9
+ // Copyright 2019-2022 @subwallet/extension-base
10
+ // SPDX-License-Identifier: Apache-2.0
11
+
12
+ const createRegistry = (chain, rawMetadata) => {
13
+ var _chain$substrateInfo;
14
+ const registry = new _types.TypeRegistry();
15
+ const metadata = new _types.Metadata(registry, rawMetadata);
16
+ registry.setMetadata(metadata);
17
+ const tokenInfo = (0, _utils._getChainNativeTokenBasicInfo)(chain);
18
+ registry.setChainProperties(registry.createType('ChainProperties', {
19
+ ss58Format: ((_chain$substrateInfo = chain.substrateInfo) === null || _chain$substrateInfo === void 0 ? void 0 : _chain$substrateInfo.addressPrefix) || 42,
20
+ tokenDecimals: tokenInfo.decimals,
21
+ tokenSymbol: tokenInfo.symbol
22
+ }));
23
+ return registry;
24
+ };
25
+ exports.createRegistry = createRegistry;
@@ -167,8 +167,6 @@ export const createTransferExtrinsic = async ({
167
167
  // }
168
168
  } else if (_TRANSFER_CHAIN_GROUP.sora_substrate.includes(networkKey) && isTxAssetsSupported) {
169
169
  transfer = api.tx.assets.transfer(_getTokenOnChainAssetId(tokenInfo), to, value);
170
- } else if (_TRANSFER_CHAIN_GROUP.avail.includes(networkKey)) {
171
- /* empty */
172
170
  } else if (isTxBalancesSupported && _isNativeToken(tokenInfo)) {
173
171
  if (transferAll) {
174
172
  transfer = api.tx.balances.transferAll(to, false);
@@ -78,6 +78,7 @@ export default class KoniExtension {
78
78
  private setEnableChainPatrol;
79
79
  private setShowZeroBalance;
80
80
  private setLanguage;
81
+ private setShowBalance;
81
82
  private subscribeAuthUrls;
82
83
  private _saveCurrentAccountAddress;
83
84
  private updateCurrentAccountAddress;
@@ -201,5 +202,6 @@ export default class KoniExtension {
201
202
  private disableMantaPay;
202
203
  private subscribeMantaPayConfig;
203
204
  private subscribeMantaPaySyncState;
205
+ private findRawMetadata;
204
206
  handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
205
207
  }
@@ -20,7 +20,7 @@ import { getPoolingBondingExtrinsic, getPoolingUnbondingExtrinsic, validatePoolB
20
20
  import { getERC20TransactionObject, getERC721Transaction, getEVMTransactionObject } from '@subwallet/extension-base/koni/api/tokens/evm/transfer';
21
21
  import { getPSP34TransferExtrinsic } from '@subwallet/extension-base/koni/api/tokens/wasm';
22
22
  import { createXcmExtrinsic } from '@subwallet/extension-base/koni/api/xcm';
23
- import { _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
23
+ import { _API_OPTIONS_CHAIN_GROUP, _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
24
24
  import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
25
25
  import { _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _getTokenMinAmount, _isAssetSmartContractNft, _isChainEvmCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isTokenEvmSmartContract, _isTokenTransferredByEvm } from '@subwallet/extension-base/services/chain-service/utils';
26
26
  import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
@@ -879,6 +879,12 @@ export default class KoniExtension {
879
879
  this.#koniState.updateSetting('language', language);
880
880
  return true;
881
881
  }
882
+ setShowBalance({
883
+ enable
884
+ }) {
885
+ this.#koniState.updateSetting('isShowBalance', enable);
886
+ return true;
887
+ }
882
888
  async subscribeAuthUrls(id, port) {
883
889
  const cb = createSubscription(id, port);
884
890
  const authorizeUrlSubscription = this.#koniState.subscribeAuthorizeUrlSubject().subscribe({
@@ -1479,6 +1485,8 @@ export default class KoniExtension {
1479
1485
 
1480
1486
  const additionalValidator = async inputTransaction => {
1481
1487
  const minAmount = tokenInfo.minAmount || '0';
1488
+
1489
+ // Check ed for sender
1482
1490
  if (!isTransferNativeToken) {
1483
1491
  const {
1484
1492
  value: balance
@@ -1494,10 +1502,12 @@ export default class KoniExtension {
1494
1502
  const {
1495
1503
  value: receiverBalance
1496
1504
  } = await this.getAddressFreeBalance({
1497
- address: from,
1505
+ address: to,
1498
1506
  networkKey,
1499
1507
  token: tokenSlug
1500
1508
  });
1509
+
1510
+ // Check ed for receiver
1501
1511
  if (new BigN(receiverBalance).plus(transferAmount.value).lt(minAmount)) {
1502
1512
  const atLeast = new BigN(minAmount).minus(receiverBalance).plus((tokenInfo.decimals || 0) === 0 ? 0 : 1);
1503
1513
  const atLeastStr = formatNumber(atLeast, tokenInfo.decimals || 0, balanceFormatter);
@@ -1561,16 +1571,24 @@ export default class KoniExtension {
1561
1571
  additionalValidator = async inputTransaction => {
1562
1572
  const destMinAmount = destinationTokenInfo.minAmount || '0';
1563
1573
  const atLeast = new BigN(destMinAmount).multipliedBy(XCM_MIN_AMOUNT_RATIO);
1574
+
1575
+ // Check ed for receiver
1564
1576
  if (new BigN(value).lt(atLeast)) {
1565
1577
  const atLeastStr = formatNumber(atLeast, destinationTokenInfo.decimals || 0, balanceFormatter);
1566
1578
  inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, `You must transfer at least ${atLeastStr} ${originTokenInfo.symbol} to keep the destination account alive`));
1567
1579
  }
1568
1580
  const srcMinAmount = originTokenInfo.minAmount || '0';
1569
1581
  const isTransferNativeToken = originTokenInfo.assetType === _AssetType.NATIVE;
1582
+
1583
+ // Check ed for sender
1570
1584
  if (!isTransferNativeToken) {
1571
1585
  const {
1572
1586
  value: balance
1573
- } = await this.#koniState.balanceService.getTokenFreeBalance(from, originNetworkKey, originTokenInfo.slug);
1587
+ } = await this.getAddressFreeBalance({
1588
+ address: from,
1589
+ networkKey: originNetworkKey,
1590
+ token: originTokenInfo.slug
1591
+ });
1574
1592
  if (new BigN(balance).minus(value).lt(srcMinAmount)) {
1575
1593
  inputTransaction.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT, ''));
1576
1594
  }
@@ -2747,7 +2765,7 @@ export default class KoniExtension {
2747
2765
  const {
2748
2766
  payload
2749
2767
  } = request;
2750
- const registry = new TypeRegistry();
2768
+ let registry = new TypeRegistry();
2751
2769
  let isEvm = false;
2752
2770
  if (isJsonPayload(payload)) {
2753
2771
  // Get the metadata for the genesisHash
@@ -2759,6 +2777,15 @@ export default class KoniExtension {
2759
2777
  registry.register(currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.types);
2760
2778
  }
2761
2779
  const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
2780
+ if (chainInfo && _API_OPTIONS_CHAIN_GROUP.avail.includes(chainInfo.slug)) {
2781
+ const isChainActive = this.#koniState.getChainStateByKey(chainInfo.slug).active;
2782
+ if (!isChainActive) {
2783
+ reject(new Error('Unable to sign'));
2784
+ return false;
2785
+ } else {
2786
+ registry = this.#koniState.getSubstrateApi(chainInfo.slug).api.registry;
2787
+ }
2788
+ }
2762
2789
  if (chainInfo) {
2763
2790
  isEvm = _isChainEvmCompatible(chainInfo);
2764
2791
  }
@@ -3201,6 +3228,7 @@ export default class KoniExtension {
3201
3228
  return new Promise(resolve => setTimeout(resolve, 1500));
3202
3229
  }
3203
3230
  try {
3231
+ var _this$koniState$chain, _this$koniState$chain2;
3204
3232
  await this.#koniState.chainService.enableChain(_DEFAULT_MANTA_ZK_CHAIN);
3205
3233
  this.#koniState.chainService.setMantaZkAssetSettings(true);
3206
3234
  const mnemonic = this.keyringExportMnemonic({
@@ -3219,16 +3247,16 @@ export default class KoniExtension {
3219
3247
  await this.saveCurrentAccountAddress({
3220
3248
  address
3221
3249
  });
3222
- const unsubSyncProgress = await this.#koniState.chainService.mantaPay.subscribeSyncProgress();
3250
+ const unsubSyncProgress = await ((_this$koniState$chain = this.#koniState.chainService) === null || _this$koniState$chain === void 0 ? void 0 : (_this$koniState$chain2 = _this$koniState$chain.mantaPay) === null || _this$koniState$chain2 === void 0 ? void 0 : _this$koniState$chain2.subscribeSyncProgress());
3223
3251
  console.debug('Start initial sync for MantaPay');
3224
3252
  this.#koniState.initialSyncMantaPay(address).then(() => {
3225
3253
  console.debug('Finished initial sync for MantaPay');
3226
3254
  this.#skipAutoLock = false;
3227
- unsubSyncProgress();
3255
+ unsubSyncProgress && unsubSyncProgress();
3228
3256
  }).catch(e => {
3229
3257
  console.error('Error syncing MantaPay', e);
3230
3258
  this.#skipAutoLock = false;
3231
- unsubSyncProgress();
3259
+ unsubSyncProgress && unsubSyncProgress();
3232
3260
  });
3233
3261
  return {
3234
3262
  success: !!result,
@@ -3250,29 +3278,32 @@ export default class KoniExtension {
3250
3278
  }
3251
3279
  }
3252
3280
  async initSyncMantaPay(address) {
3253
- if (this.#koniState.chainService.mantaPay.getSyncState().isSyncing) {
3281
+ var _this$koniState$chain3, _this$koniState$chain4, _this$koniState$chain5, _this$koniState$chain6;
3282
+ if ((_this$koniState$chain3 = this.#koniState.chainService) !== null && _this$koniState$chain3 !== void 0 && (_this$koniState$chain4 = _this$koniState$chain3.mantaPay) !== null && _this$koniState$chain4 !== void 0 && _this$koniState$chain4.getSyncState().isSyncing) {
3254
3283
  return;
3255
3284
  }
3256
3285
  this.#skipAutoLock = true;
3257
3286
  await this.saveCurrentAccountAddress({
3258
3287
  address
3259
3288
  });
3260
- const unsubSyncProgress = await this.#koniState.chainService.mantaPay.subscribeSyncProgress();
3289
+ const unsubSyncProgress = await ((_this$koniState$chain5 = this.#koniState.chainService) === null || _this$koniState$chain5 === void 0 ? void 0 : (_this$koniState$chain6 = _this$koniState$chain5.mantaPay) === null || _this$koniState$chain6 === void 0 ? void 0 : _this$koniState$chain6.subscribeSyncProgress());
3261
3290
  console.debug('Start initial sync for MantaPay');
3262
3291
  this.#koniState.initialSyncMantaPay(address).then(() => {
3292
+ var _this$koniState$chain7, _this$koniState$chain8;
3263
3293
  console.debug('Finished initial sync for MantaPay');
3264
3294
  this.#skipAutoLock = false;
3265
- unsubSyncProgress();
3295
+ unsubSyncProgress && unsubSyncProgress();
3266
3296
  // make sure the sync state is set, just in case it gets unsubscribed
3267
- this.#koniState.chainService.mantaPay.setSyncState({
3297
+ (_this$koniState$chain7 = this.#koniState.chainService) === null || _this$koniState$chain7 === void 0 ? void 0 : (_this$koniState$chain8 = _this$koniState$chain7.mantaPay) === null || _this$koniState$chain8 === void 0 ? void 0 : _this$koniState$chain8.setSyncState({
3268
3298
  progress: 100,
3269
3299
  isSyncing: false
3270
3300
  });
3271
3301
  }).catch(e => {
3302
+ var _this$koniState$chain9, _this$koniState$chain10;
3272
3303
  console.error('Error syncing MantaPay', e);
3273
3304
  this.#skipAutoLock = false;
3274
- unsubSyncProgress();
3275
- this.#koniState.chainService.mantaPay.setSyncState({
3305
+ unsubSyncProgress && unsubSyncProgress();
3306
+ (_this$koniState$chain9 = this.#koniState.chainService) === null || _this$koniState$chain9 === void 0 ? void 0 : (_this$koniState$chain10 = _this$koniState$chain9.mantaPay) === null || _this$koniState$chain10 === void 0 ? void 0 : _this$koniState$chain10.setSyncState({
3276
3307
  progress: 0,
3277
3308
  isSyncing: false
3278
3309
  });
@@ -3295,8 +3326,9 @@ export default class KoniExtension {
3295
3326
  return this.#koniState.getMantaPayConfig('calamari');
3296
3327
  }
3297
3328
  subscribeMantaPaySyncState(id, port) {
3329
+ var _this$koniState$subsc, _this$koniState$chain11, _this$koniState$chain12;
3298
3330
  const cb = createSubscription(id, port);
3299
- const syncingStateSubscription = this.#koniState.subscribeMantaPaySyncState().subscribe({
3331
+ const syncingStateSubscription = (_this$koniState$subsc = this.#koniState.subscribeMantaPaySyncState()) === null || _this$koniState$subsc === void 0 ? void 0 : _this$koniState$subsc.subscribe({
3300
3332
  next: rs => {
3301
3333
  cb(rs);
3302
3334
  }
@@ -3305,7 +3337,26 @@ export default class KoniExtension {
3305
3337
  port.onDisconnect.addListener(() => {
3306
3338
  this.cancelSubscription(id);
3307
3339
  });
3308
- return this.#koniState.chainService.mantaPay.getSyncState();
3340
+ return ((_this$koniState$chain11 = this.#koniState.chainService) === null || _this$koniState$chain11 === void 0 ? void 0 : (_this$koniState$chain12 = _this$koniState$chain11.mantaPay) === null || _this$koniState$chain12 === void 0 ? void 0 : _this$koniState$chain12.getSyncState()) || {
3341
+ isSyncing: false,
3342
+ progress: 0,
3343
+ needManualSync: false
3344
+ };
3345
+ }
3346
+
3347
+ /// Metadata
3348
+
3349
+ async findRawMetadata({
3350
+ genesisHash
3351
+ }) {
3352
+ const {
3353
+ metadata,
3354
+ specVersion
3355
+ } = await this.#koniState.findMetadata(genesisHash);
3356
+ return {
3357
+ rawMetadata: metadata,
3358
+ specVersion
3359
+ };
3309
3360
  }
3310
3361
 
3311
3362
  // --------------------------------------------------------------
@@ -3417,6 +3468,8 @@ export default class KoniExtension {
3417
3468
  return this.setShowZeroBalance(request);
3418
3469
  case 'pri(settings.saveLanguage)':
3419
3470
  return this.setLanguage(request);
3471
+ case 'pri(settings.saveShowBalance)':
3472
+ return this.setShowBalance(request);
3420
3473
  case 'pri(price.getPrice)':
3421
3474
  return await this.getPrice();
3422
3475
  case 'pri(price.getSubscription)':
@@ -3710,6 +3763,10 @@ export default class KoniExtension {
3710
3763
  return await this.disableMantaPay(request);
3711
3764
  case 'pri(mantaPay.subscribeSyncingState)':
3712
3765
  return this.subscribeMantaPaySyncState(id, port);
3766
+
3767
+ // Metadata
3768
+ case 'pri(metadata.find)':
3769
+ return this.findRawMetadata(request);
3713
3770
  // Default
3714
3771
  default:
3715
3772
  throw new Error(`Unable to handle message of type ${type}`);
@@ -1,6 +1,6 @@
1
1
  /// <reference types="chrome" />
2
2
  import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
3
- import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, BalanceItem, BalanceJson, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
3
+ import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, BalanceItem, BalanceJson, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
4
4
  import { AccountJson, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning } from '@subwallet/extension-base/background/types';
5
5
  import { BalanceService } from '@subwallet/extension-base/services/balance-service';
6
6
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
@@ -139,6 +139,7 @@ export default class KoniState {
139
139
  getSettings(callback: (settings: UiSettings) => void): void;
140
140
  setSettings(settings: UiSettings, callback?: () => void): void;
141
141
  updateSetting<T extends keyof UiSettings>(key: T, value: UiSettings[T]): void;
142
+ setShowBalance(value: boolean): void;
142
143
  subscribeSettingsSubject(): Subject<RequestSettingsType>;
143
144
  getAccountAddress(): string | null;
144
145
  getDecodedAddresses(address?: string): string[];
@@ -236,6 +237,10 @@ export default class KoniState {
236
237
  subscribeMantaPayBalance(): () => void;
237
238
  syncMantaPay(): Promise<void>;
238
239
  getMantaPayZkBalance(address: string, tokenInfo: _ChainAsset): Promise<AmountData>;
239
- subscribeMantaPaySyncState(): Subject<import("@subwallet/extension-base/background/KoniTypes").MantaPaySyncState>;
240
+ subscribeMantaPaySyncState(): Subject<MantaPaySyncState>;
241
+ findMetadata(hash: string): Promise<{
242
+ metadata: string;
243
+ specVersion: number;
244
+ }>;
240
245
  }
241
246
  export {};