@subwallet/extension-base 1.1.2-1 → 1.1.4-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 +18 -0
- package/background/KoniTypes.js +2 -1
- package/cjs/background/KoniTypes.js +4 -2
- package/cjs/koni/api/dotsama/transfer.js +0 -2
- package/cjs/koni/api/nft/config.js +13 -13
- package/cjs/koni/api/nft/nft.js +1 -1
- package/cjs/koni/api/nft/rmrk_nft/index.js +57 -48
- package/cjs/koni/background/handlers/Extension.js +179 -120
- package/cjs/koni/background/handlers/State.js +73 -48
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +2 -1
- package/cjs/services/chain-service/handler/SubstrateApi.js +8 -0
- package/cjs/services/chain-service/handler/manta/MantaPrivateHandler.js +1 -1
- package/cjs/services/chain-service/handler/manta/manta-extension-sdk-empty.js +13 -0
- package/cjs/services/chain-service/index.js +20 -6
- package/cjs/services/request-service/handler/PopupHandler.js +2 -2
- package/cjs/services/request-service/helper/index.js +2 -26
- package/cjs/services/storage-service/db-stores/Metadata.js +1 -1
- package/cjs/services/wallet-connect-service/constants.js +8 -5
- package/cjs/services/wallet-connect-service/index.js +50 -36
- package/cjs/utils/environment.js +32 -2
- package/cjs/utils/index.js +21 -5
- package/cjs/utils/registry.js +25 -0
- package/koni/api/dotsama/transfer.js +0 -2
- package/koni/api/nft/config.d.ts +3 -3
- package/koni/api/nft/config.js +9 -9
- package/koni/api/nft/nft.js +1 -1
- package/koni/api/nft/rmrk_nft/index.d.ts +0 -1
- package/koni/api/nft/rmrk_nft/index.js +58 -49
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +72 -15
- package/koni/background/handlers/State.d.ts +7 -2
- package/koni/background/handlers/State.js +73 -48
- package/package.json +17 -6
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +2 -1
- package/services/chain-service/handler/SubstrateApi.js +8 -0
- package/services/chain-service/handler/manta/MantaPrivateHandler.d.ts +1 -1
- package/services/chain-service/handler/manta/MantaPrivateHandler.js +1 -1
- package/services/chain-service/handler/manta/manta-extension-sdk-empty.d.ts +4 -0
- package/services/chain-service/handler/manta/manta-extension-sdk-empty.js +5 -0
- package/services/chain-service/index.d.ts +2 -1
- package/services/chain-service/index.js +20 -6
- package/services/request-service/handler/PopupHandler.js +1 -1
- package/services/request-service/helper/index.d.ts +0 -2
- package/services/request-service/helper/index.js +0 -23
- package/services/request-service/types.d.ts +0 -1
- package/services/storage-service/db-stores/Metadata.js +1 -1
- package/services/wallet-connect-service/constants.d.ts +2 -1
- package/services/wallet-connect-service/constants.js +5 -3
- package/services/wallet-connect-service/index.d.ts +0 -1
- package/services/wallet-connect-service/index.js +50 -36
- package/utils/environment.d.ts +4 -1
- package/utils/environment.js +28 -1
- package/utils/index.d.ts +2 -0
- package/utils/index.js +4 -1
- package/utils/registry.d.ts +4 -0
- package/utils/registry.js +18 -0
|
@@ -14,7 +14,7 @@ export declare class ChainService {
|
|
|
14
14
|
private substrateChainHandler;
|
|
15
15
|
private evmChainHandler;
|
|
16
16
|
private mantaChainHandler;
|
|
17
|
-
get mantaPay(): MantaPrivateHandler;
|
|
17
|
+
get mantaPay(): MantaPrivateHandler | undefined;
|
|
18
18
|
private chainInfoMapSubject;
|
|
19
19
|
private chainStateMapSubject;
|
|
20
20
|
private assetRegistrySubject;
|
|
@@ -110,4 +110,5 @@ export declare class ChainService {
|
|
|
110
110
|
resetWallet(resetAll: boolean): void;
|
|
111
111
|
getMetadata(chain: string): import("dexie").PromiseExtended<IMetadataItem | undefined>;
|
|
112
112
|
upsertMetadata(chain: string, metadata: IMetadataItem): import("dexie").PromiseExtended<unknown>;
|
|
113
|
+
getMetadataByHash(hash: string): import("dexie").PromiseExtended<IMetadataItem | undefined>;
|
|
113
114
|
}
|
|
@@ -11,6 +11,7 @@ import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chai
|
|
|
11
11
|
import { _ChainConnectionStatus, _CUSTOM_PREFIX, _NFT_CONTRACT_STANDARDS, _SMART_CONTRACT_STANDARDS } from '@subwallet/extension-base/services/chain-service/types';
|
|
12
12
|
import { _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isEqualContractAddress, _isEqualSmartContractAsset, _isMantaZkAsset, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey } from '@subwallet/extension-base/services/chain-service/utils';
|
|
13
13
|
import AssetSettingStore from '@subwallet/extension-base/stores/AssetSetting';
|
|
14
|
+
import { MODULE_SUPPORT } from '@subwallet/extension-base/utils';
|
|
14
15
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
15
16
|
import Web3 from 'web3';
|
|
16
17
|
import { logger as createLogger } from '@polkadot/util/logger';
|
|
@@ -40,14 +41,14 @@ export class ChainService {
|
|
|
40
41
|
constructor(dbService, eventService) {
|
|
41
42
|
this.dbService = dbService;
|
|
42
43
|
this.eventService = eventService;
|
|
43
|
-
this.substrateChainHandler = new SubstrateChainHandler();
|
|
44
|
-
this.evmChainHandler = new EvmChainHandler();
|
|
45
|
-
this.mantaChainHandler = new MantaPrivateHandler(dbService);
|
|
46
44
|
this.chainInfoMapSubject.next(this.dataMap.chainInfoMap);
|
|
47
45
|
this.chainStateMapSubject.next(this.dataMap.chainStateMap);
|
|
48
|
-
this.chainInfoMapSubject.next(this.dataMap.chainInfoMap);
|
|
49
46
|
this.assetRegistrySubject.next(this.dataMap.assetRegistry);
|
|
50
47
|
this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
|
|
48
|
+
if (MODULE_SUPPORT.MANTA_ZK) {
|
|
49
|
+
console.log('Init Manta ZK');
|
|
50
|
+
this.mantaChainHandler = new MantaPrivateHandler(dbService);
|
|
51
|
+
}
|
|
51
52
|
this.substrateChainHandler = new SubstrateChainHandler(this);
|
|
52
53
|
this.evmChainHandler = new EvmChainHandler(this);
|
|
53
54
|
this.logger = createLogger('chain-service');
|
|
@@ -417,8 +418,9 @@ export class ChainService {
|
|
|
417
418
|
}
|
|
418
419
|
};
|
|
419
420
|
if (chainInfo.substrateInfo !== null && chainInfo.substrateInfo !== undefined) {
|
|
420
|
-
if (_MANTA_ZK_CHAIN_GROUP.includes(chainInfo.slug)) {
|
|
421
|
-
|
|
421
|
+
if (_MANTA_ZK_CHAIN_GROUP.includes(chainInfo.slug) && MODULE_SUPPORT.MANTA_ZK && this.mantaChainHandler) {
|
|
422
|
+
var _this$mantaChainHandl;
|
|
423
|
+
const apiPromise = await ((_this$mantaChainHandl = this.mantaChainHandler) === null || _this$mantaChainHandl === void 0 ? void 0 : _this$mantaChainHandl.initMantaPay(endpoint, chainInfo.slug));
|
|
422
424
|
const chainApi = await this.substrateChainHandler.initApi(chainInfo.slug, endpoint, {
|
|
423
425
|
providerName,
|
|
424
426
|
externalApiPromise: apiPromise,
|
|
@@ -695,6 +697,15 @@ export class ChainService {
|
|
|
695
697
|
async initAssetRegistry(deprecatedCustomChainMap) {
|
|
696
698
|
const storedAssetRegistry = await this.dbService.getAllAssetStore();
|
|
697
699
|
const latestAssetRegistry = await this.fetchLatestData(_CHAIN_ASSET_SRC, ChainAssetMap);
|
|
700
|
+
|
|
701
|
+
// Fill out zk assets from latestAssetRegistry if not supported
|
|
702
|
+
if (!MODULE_SUPPORT.MANTA_ZK) {
|
|
703
|
+
Object.keys(latestAssetRegistry).forEach(slug => {
|
|
704
|
+
if (_isMantaZkAsset(latestAssetRegistry[slug])) {
|
|
705
|
+
delete latestAssetRegistry[slug];
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
}
|
|
698
709
|
if (storedAssetRegistry.length === 0) {
|
|
699
710
|
this.dataMap.assetRegistry = latestAssetRegistry;
|
|
700
711
|
} else {
|
|
@@ -1304,4 +1315,7 @@ export class ChainService {
|
|
|
1304
1315
|
upsertMetadata(chain, metadata) {
|
|
1305
1316
|
return this.dbService.stores.metadata.upsertMetadata(chain, metadata);
|
|
1306
1317
|
}
|
|
1318
|
+
getMetadataByHash(hash) {
|
|
1319
|
+
return this.dbService.stores.metadata.getMetadataByGenesisHash(hash);
|
|
1320
|
+
}
|
|
1307
1321
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
|
|
5
|
-
import { getOS } from '@subwallet/extension-base/services/request-service/helper';
|
|
6
5
|
import { DEFAULT_NOTIFICATION_TYPE } from '@subwallet/extension-base/services/setting-service/constants';
|
|
6
|
+
import { getOS } from '@subwallet/extension-base/utils';
|
|
7
7
|
const NOTIFICATION_URL = chrome.extension.getURL('notification.html');
|
|
8
8
|
const OS = getOS();
|
|
9
9
|
const extraHeight = OS === 'Linux' ? 0 : 28;
|
|
@@ -41,27 +41,4 @@ export const extractMetadata = store => {
|
|
|
41
41
|
def
|
|
42
42
|
}) => addMetadata(def));
|
|
43
43
|
});
|
|
44
|
-
};
|
|
45
|
-
export const getOS = () => {
|
|
46
|
-
var _window$navigator, _window$navigator$use;
|
|
47
|
-
const userAgent = window.navigator.userAgent;
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
50
|
-
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;
|
|
51
|
-
const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'];
|
|
52
|
-
const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
|
|
53
|
-
const iosPlatforms = ['iPhone', 'iPad', 'iPod'];
|
|
54
|
-
let os = 'Unknown';
|
|
55
|
-
if (macosPlatforms.indexOf(platform) !== -1) {
|
|
56
|
-
os = 'Mac OS';
|
|
57
|
-
} else if (iosPlatforms.indexOf(platform) !== -1) {
|
|
58
|
-
os = 'iOS';
|
|
59
|
-
} else if (windowsPlatforms.indexOf(platform) !== -1) {
|
|
60
|
-
os = 'Windows';
|
|
61
|
-
} else if (/Android/.test(userAgent)) {
|
|
62
|
-
os = 'Android';
|
|
63
|
-
} else if (/Linux/.test(platform)) {
|
|
64
|
-
os = 'Linux';
|
|
65
|
-
}
|
|
66
|
-
return os;
|
|
67
44
|
};
|
|
@@ -10,7 +10,7 @@ export default class MetadataStore extends BaseStoreWithChain {
|
|
|
10
10
|
return this.table.put(metadata, chain);
|
|
11
11
|
}
|
|
12
12
|
getMetadataByGenesisHash(genesisHash) {
|
|
13
|
-
return this.table.
|
|
13
|
+
return this.table.get(genesisHash);
|
|
14
14
|
}
|
|
15
15
|
updateMetadataByGenesisHash(genesisHash, metadata) {
|
|
16
16
|
return this.table.put(metadata, genesisHash);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WalletConnectSigningMethod } from '@subwallet/extension-base/services/wallet-connect-service/types';
|
|
2
2
|
import { SignClientTypes } from '@walletconnect/types';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const PROJECT_ID_EXTENSION = "6da34c0b48164d27681924dd9a46d6be";
|
|
4
|
+
export declare const PROJECT_ID_MOBILE = "6da34c0b48164d27681924dd9a46d6be";
|
|
4
5
|
export declare const RELAY_URL = "wss://relay.walletconnect.com";
|
|
5
6
|
export declare const DEFAULT_WALLET_CONNECT_OPTIONS: SignClientTypes.Options;
|
|
6
7
|
export declare const ALL_WALLET_CONNECT_EVENT: SignClientTypes.Event[];
|
|
@@ -2,17 +2,19 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { EIP155_SIGNING_METHODS, POLKADOT_SIGNING_METHODS } from '@subwallet/extension-base/services/wallet-connect-service/types';
|
|
5
|
-
|
|
5
|
+
import { isMobile } from '@subwallet/extension-base/utils';
|
|
6
|
+
export const PROJECT_ID_EXTENSION = '6da34c0b48164d27681924dd9a46d6be';
|
|
7
|
+
export const PROJECT_ID_MOBILE = '6da34c0b48164d27681924dd9a46d6be';
|
|
6
8
|
export const RELAY_URL = 'wss://relay.walletconnect.com';
|
|
7
9
|
export const DEFAULT_WALLET_CONNECT_OPTIONS = {
|
|
8
10
|
logger: 'debug',
|
|
9
|
-
projectId:
|
|
11
|
+
projectId: !isMobile ? PROJECT_ID_EXTENSION : PROJECT_ID_MOBILE,
|
|
10
12
|
relayUrl: RELAY_URL,
|
|
11
13
|
metadata: {
|
|
12
14
|
name: 'SubWallet',
|
|
13
15
|
description: 'React Wallet for WalletConnect',
|
|
14
16
|
url: 'https://www.subwallet.app/',
|
|
15
|
-
icons: ['https://
|
|
17
|
+
icons: ['https://raw.githubusercontent.com/Koniverse/SubWallet-Extension/master/packages/extension-koni/public/images/icon-128.png']
|
|
16
18
|
}
|
|
17
19
|
};
|
|
18
20
|
export const ALL_WALLET_CONNECT_EVENT = ['session_proposal', 'session_update', 'session_extend', 'session_ping', 'session_delete', 'session_expire', 'session_request', 'session_request_sent', 'session_event', 'proposal_expire'];
|
|
@@ -10,7 +10,6 @@ export default class WalletConnectService {
|
|
|
10
10
|
get sessions(): SessionTypes.Struct[];
|
|
11
11
|
getSession(topic: string): SessionTypes.Struct;
|
|
12
12
|
changeOption(newOption: Omit<SignClientTypes.Options, 'projectId'>): Promise<void>;
|
|
13
|
-
getSessions(): void;
|
|
14
13
|
connect(uri: string): Promise<void>;
|
|
15
14
|
approveSession(result: ResultApproveWalletConnectSession): Promise<void>;
|
|
16
15
|
rejectSession(id: number): Promise<void>;
|
|
@@ -18,6 +18,7 @@ var _eip155RequestHandler = /*#__PURE__*/_classPrivateFieldLooseKey("eip155Reque
|
|
|
18
18
|
var _koniState = /*#__PURE__*/_classPrivateFieldLooseKey("koniState");
|
|
19
19
|
var _client = /*#__PURE__*/_classPrivateFieldLooseKey("client");
|
|
20
20
|
var _option = /*#__PURE__*/_classPrivateFieldLooseKey("option");
|
|
21
|
+
var _haveData = /*#__PURE__*/_classPrivateFieldLooseKey("haveData");
|
|
21
22
|
var _initClient = /*#__PURE__*/_classPrivateFieldLooseKey("initClient");
|
|
22
23
|
var _updateSessions = /*#__PURE__*/_classPrivateFieldLooseKey("updateSessions");
|
|
23
24
|
var _onSessionProposal = /*#__PURE__*/_classPrivateFieldLooseKey("onSessionProposal");
|
|
@@ -48,6 +49,10 @@ export default class WalletConnectService {
|
|
|
48
49
|
Object.defineProperty(this, _initClient, {
|
|
49
50
|
value: _initClient2
|
|
50
51
|
});
|
|
52
|
+
Object.defineProperty(this, _haveData, {
|
|
53
|
+
get: _get_haveData,
|
|
54
|
+
set: void 0
|
|
55
|
+
});
|
|
51
56
|
Object.defineProperty(this, _requestService, {
|
|
52
57
|
writable: true,
|
|
53
58
|
value: void 0
|
|
@@ -97,66 +102,64 @@ export default class WalletConnectService {
|
|
|
97
102
|
_classPrivateFieldLooseBase(this, _option)[_option] = Object.assign({}, _classPrivateFieldLooseBase(this, _option)[_option], newOption);
|
|
98
103
|
await _classPrivateFieldLooseBase(this, _initClient)[_initClient]();
|
|
99
104
|
}
|
|
100
|
-
getSessions() {
|
|
101
|
-
var _classPrivateFieldLoo3;
|
|
102
|
-
_classPrivateFieldLooseBase(this, _checkClient)[_checkClient]();
|
|
103
|
-
console.log((_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo3 === void 0 ? void 0 : _classPrivateFieldLoo3.session.values);
|
|
104
|
-
}
|
|
105
105
|
async connect(uri) {
|
|
106
|
-
var
|
|
106
|
+
var _classPrivateFieldLoo3;
|
|
107
|
+
if (!_classPrivateFieldLooseBase(this, _haveData)[_haveData]) {
|
|
108
|
+
await _classPrivateFieldLooseBase(this, _initClient)[_initClient](true);
|
|
109
|
+
}
|
|
107
110
|
_classPrivateFieldLooseBase(this, _checkClient)[_checkClient]();
|
|
108
|
-
await ((
|
|
111
|
+
await ((_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo3 === void 0 ? void 0 : _classPrivateFieldLoo3.pair({
|
|
109
112
|
uri
|
|
110
113
|
}));
|
|
111
114
|
}
|
|
112
115
|
async approveSession(result) {
|
|
113
|
-
var
|
|
116
|
+
var _classPrivateFieldLoo4;
|
|
114
117
|
_classPrivateFieldLooseBase(this, _checkClient)[_checkClient]();
|
|
115
|
-
await ((
|
|
118
|
+
await ((_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo4 === void 0 ? void 0 : _classPrivateFieldLoo4.approve(result));
|
|
116
119
|
_classPrivateFieldLooseBase(this, _updateSessions)[_updateSessions]();
|
|
117
120
|
}
|
|
118
121
|
async rejectSession(id) {
|
|
119
|
-
var
|
|
122
|
+
var _classPrivateFieldLoo5;
|
|
120
123
|
_classPrivateFieldLooseBase(this, _checkClient)[_checkClient]();
|
|
121
|
-
await ((
|
|
124
|
+
await ((_classPrivateFieldLoo5 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo5 === void 0 ? void 0 : _classPrivateFieldLoo5.reject({
|
|
122
125
|
id: id,
|
|
123
126
|
reason: getSdkError('USER_REJECTED')
|
|
124
127
|
}));
|
|
125
128
|
}
|
|
126
129
|
async responseRequest(response) {
|
|
127
|
-
var
|
|
130
|
+
var _classPrivateFieldLoo6;
|
|
128
131
|
_classPrivateFieldLooseBase(this, _checkClient)[_checkClient]();
|
|
129
|
-
await ((
|
|
132
|
+
await ((_classPrivateFieldLoo6 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo6 === void 0 ? void 0 : _classPrivateFieldLoo6.respond(response));
|
|
130
133
|
}
|
|
131
134
|
async resetWallet(resetAll) {
|
|
132
|
-
var
|
|
135
|
+
var _classPrivateFieldLoo7, _classPrivateFieldLoo9, _classPrivateFieldLoo11;
|
|
133
136
|
_classPrivateFieldLooseBase(this, _removeListener)[_removeListener]();
|
|
134
137
|
|
|
135
138
|
// Disconnect session
|
|
136
|
-
const sessions = ((
|
|
139
|
+
const sessions = ((_classPrivateFieldLoo7 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo7 === void 0 ? void 0 : _classPrivateFieldLoo7.session.values) || [];
|
|
137
140
|
for (const session of sessions) {
|
|
138
|
-
var
|
|
139
|
-
(
|
|
141
|
+
var _classPrivateFieldLoo8;
|
|
142
|
+
(_classPrivateFieldLoo8 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo8 === void 0 ? void 0 : _classPrivateFieldLoo8.disconnect({
|
|
140
143
|
topic: session.topic,
|
|
141
144
|
reason: getSdkError('USER_DISCONNECTED')
|
|
142
145
|
}).catch(console.error);
|
|
143
146
|
}
|
|
144
147
|
|
|
145
148
|
// Disconnect pair
|
|
146
|
-
const pairs = ((
|
|
149
|
+
const pairs = ((_classPrivateFieldLoo9 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo9 === void 0 ? void 0 : _classPrivateFieldLoo9.pairing.values) || [];
|
|
147
150
|
for (const pair of pairs) {
|
|
148
|
-
var
|
|
149
|
-
(
|
|
151
|
+
var _classPrivateFieldLoo10;
|
|
152
|
+
(_classPrivateFieldLoo10 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo10 === void 0 ? void 0 : _classPrivateFieldLoo10.disconnect({
|
|
150
153
|
topic: pair.topic,
|
|
151
154
|
reason: getSdkError('USER_DISCONNECTED')
|
|
152
155
|
}).catch(console.error);
|
|
153
156
|
}
|
|
154
|
-
const keys = (await ((
|
|
157
|
+
const keys = (await ((_classPrivateFieldLoo11 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo11 === void 0 ? void 0 : _classPrivateFieldLoo11.core.storage.getKeys())) || [];
|
|
155
158
|
const deleteKeys = resetAll ? keys : keys.filter(key => key.startsWith('wc@'));
|
|
156
159
|
for (const key of deleteKeys) {
|
|
157
160
|
try {
|
|
158
|
-
var
|
|
159
|
-
await ((
|
|
161
|
+
var _classPrivateFieldLoo12;
|
|
162
|
+
await ((_classPrivateFieldLoo12 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo12 === void 0 ? void 0 : _classPrivateFieldLoo12.core.storage.removeItem(key));
|
|
160
163
|
} catch (e) {
|
|
161
164
|
console.error(e);
|
|
162
165
|
}
|
|
@@ -164,17 +167,28 @@ export default class WalletConnectService {
|
|
|
164
167
|
await _classPrivateFieldLooseBase(this, _initClient)[_initClient]();
|
|
165
168
|
}
|
|
166
169
|
async disconnect(topic) {
|
|
167
|
-
var
|
|
168
|
-
await ((
|
|
170
|
+
var _classPrivateFieldLoo13;
|
|
171
|
+
await ((_classPrivateFieldLoo13 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo13 === void 0 ? void 0 : _classPrivateFieldLoo13.disconnect({
|
|
169
172
|
topic: topic,
|
|
170
173
|
reason: getSdkError('USER_DISCONNECTED')
|
|
171
174
|
}));
|
|
172
175
|
_classPrivateFieldLooseBase(this, _updateSessions)[_updateSessions]();
|
|
173
176
|
}
|
|
174
177
|
}
|
|
175
|
-
|
|
178
|
+
function _get_haveData() {
|
|
179
|
+
const sessionStorage = localStorage.getItem('wc@2:client:0.3//session');
|
|
180
|
+
const pairingStorage = localStorage.getItem('wc@2:core:0.3//pairing');
|
|
181
|
+
const subscriptionStorage = localStorage.getItem('wc@2:core:0.3//subscription');
|
|
182
|
+
const sessions = sessionStorage ? JSON.parse(sessionStorage) : [];
|
|
183
|
+
const pairings = pairingStorage ? JSON.parse(pairingStorage) : [];
|
|
184
|
+
const subscriptions = subscriptionStorage ? JSON.parse(subscriptionStorage) : [];
|
|
185
|
+
return !!sessions.length || !!pairings.length || !!subscriptions.length;
|
|
186
|
+
}
|
|
187
|
+
async function _initClient2(force) {
|
|
176
188
|
_classPrivateFieldLooseBase(this, _removeListener)[_removeListener]();
|
|
177
|
-
|
|
189
|
+
if (force || _classPrivateFieldLooseBase(this, _haveData)[_haveData]) {
|
|
190
|
+
_classPrivateFieldLooseBase(this, _client)[_client] = await SignClient.init(_classPrivateFieldLooseBase(this, _option)[_option]);
|
|
191
|
+
}
|
|
178
192
|
_classPrivateFieldLooseBase(this, _updateSessions)[_updateSessions]();
|
|
179
193
|
_classPrivateFieldLooseBase(this, _createListener)[_createListener]();
|
|
180
194
|
}
|
|
@@ -244,18 +258,18 @@ function _onSessionRequest2(requestEvent) {
|
|
|
244
258
|
}
|
|
245
259
|
}
|
|
246
260
|
function _createListener2() {
|
|
247
|
-
var _classPrivateFieldLoo15, _classPrivateFieldLoo16, _classPrivateFieldLoo17, _classPrivateFieldLoo18, _classPrivateFieldLoo19
|
|
248
|
-
(
|
|
249
|
-
(
|
|
250
|
-
(
|
|
251
|
-
(
|
|
252
|
-
(
|
|
253
|
-
(
|
|
261
|
+
var _classPrivateFieldLoo14, _classPrivateFieldLoo15, _classPrivateFieldLoo16, _classPrivateFieldLoo17, _classPrivateFieldLoo18, _classPrivateFieldLoo19;
|
|
262
|
+
(_classPrivateFieldLoo14 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo14 === void 0 ? void 0 : _classPrivateFieldLoo14.on('session_proposal', _classPrivateFieldLooseBase(this, _onSessionProposal)[_onSessionProposal].bind(this));
|
|
263
|
+
(_classPrivateFieldLoo15 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo15 === void 0 ? void 0 : _classPrivateFieldLoo15.on('session_request', _classPrivateFieldLooseBase(this, _onSessionRequest)[_onSessionRequest].bind(this));
|
|
264
|
+
(_classPrivateFieldLoo16 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo16 === void 0 ? void 0 : _classPrivateFieldLoo16.on('session_ping', data => console.log('ping', data));
|
|
265
|
+
(_classPrivateFieldLoo17 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo17 === void 0 ? void 0 : _classPrivateFieldLoo17.on('session_event', data => console.log('event', data));
|
|
266
|
+
(_classPrivateFieldLoo18 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo18 === void 0 ? void 0 : _classPrivateFieldLoo18.on('session_update', data => console.log('update', data));
|
|
267
|
+
(_classPrivateFieldLoo19 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo19 === void 0 ? void 0 : _classPrivateFieldLoo19.on('session_delete', _classPrivateFieldLooseBase(this, _updateSessions)[_updateSessions].bind(this));
|
|
254
268
|
}
|
|
255
269
|
function _removeListener2() {
|
|
256
270
|
ALL_WALLET_CONNECT_EVENT.forEach(event => {
|
|
257
|
-
var
|
|
258
|
-
(
|
|
271
|
+
var _classPrivateFieldLoo20;
|
|
272
|
+
(_classPrivateFieldLoo20 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo20 === void 0 ? void 0 : _classPrivateFieldLoo20.removeAllListeners(event);
|
|
259
273
|
});
|
|
260
274
|
}
|
|
261
275
|
function _checkClient2() {
|
package/utils/environment.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import { RuntimeEnvironmentInfo } from '../background/KoniTypes';
|
|
1
|
+
import { EnvironmentSupport, OSType, RuntimeEnvironmentInfo, TargetEnvironment } from '../background/KoniTypes';
|
|
2
2
|
export declare const RuntimeInfo: RuntimeEnvironmentInfo;
|
|
3
|
+
export declare const getOS: () => OSType;
|
|
4
|
+
export declare const TARGET_ENV: TargetEnvironment;
|
|
5
|
+
export declare const MODULE_SUPPORT: EnvironmentSupport;
|
package/utils/environment.js
CHANGED
|
@@ -56,4 +56,31 @@ function detectRuntimeEnvironment() {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
export const RuntimeInfo = detectRuntimeEnvironment();
|
|
59
|
+
export const RuntimeInfo = detectRuntimeEnvironment();
|
|
60
|
+
export const getOS = () => {
|
|
61
|
+
var _window$navigator, _window$navigator$use;
|
|
62
|
+
const userAgent = window.navigator.userAgent;
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
65
|
+
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;
|
|
66
|
+
const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'];
|
|
67
|
+
const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
|
|
68
|
+
const iosPlatforms = ['iPhone', 'iPad', 'iPod'];
|
|
69
|
+
let os = 'Unknown';
|
|
70
|
+
if (macosPlatforms.indexOf(platform) !== -1) {
|
|
71
|
+
os = 'Mac OS';
|
|
72
|
+
} else if (iosPlatforms.indexOf(platform) !== -1) {
|
|
73
|
+
os = 'iOS';
|
|
74
|
+
} else if (windowsPlatforms.indexOf(platform) !== -1) {
|
|
75
|
+
os = 'Windows';
|
|
76
|
+
} else if (/Android/.test(userAgent)) {
|
|
77
|
+
os = 'Android';
|
|
78
|
+
} else if (/Linux/.test(platform)) {
|
|
79
|
+
os = 'Linux';
|
|
80
|
+
}
|
|
81
|
+
return os;
|
|
82
|
+
};
|
|
83
|
+
export const TARGET_ENV = process.env.TARGET_ENV || 'extension';
|
|
84
|
+
export const MODULE_SUPPORT = {
|
|
85
|
+
MANTA_ZK: TARGET_ENV === 'extension'
|
|
86
|
+
};
|
package/utils/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const isDef: (x: any) => boolean;
|
|
|
8
8
|
export declare const nonEmptyArr: (x: any) => boolean;
|
|
9
9
|
export declare const isEmptyArray: (x: any) => boolean;
|
|
10
10
|
export declare function isAccountAll(address?: string): boolean;
|
|
11
|
+
export declare const isMobile: boolean;
|
|
11
12
|
export declare function reformatAddress(address: string, networkPrefix?: number, isEthereum?: boolean): string;
|
|
12
13
|
export declare function filterAddressByNetworkKey(addresses: string[], networkKey: string, isEthereum?: boolean): string[];
|
|
13
14
|
export declare function categoryAddresses(addresses: string[]): string[][];
|
|
@@ -41,4 +42,5 @@ export declare const stripUrl: (url: string) => string;
|
|
|
41
42
|
export * from './array';
|
|
42
43
|
export * from './environment';
|
|
43
44
|
export * from './lazy';
|
|
45
|
+
export * from './registry';
|
|
44
46
|
export * from './translate';
|
package/utils/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { CrowdloanParaState } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
|
+
import { CrowdloanParaState, MobileOS } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
6
|
+
import { getOS } from '@subwallet/extension-base/utils/environment';
|
|
6
7
|
import { assert, BN, hexToU8a, isHex } from '@polkadot/util';
|
|
7
8
|
import { decodeAddress, encodeAddress, ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
|
|
8
9
|
export { canDerive } from "./canDerive.js";
|
|
@@ -13,6 +14,7 @@ export const isEmptyArray = x => !Array.isArray(x) || Array.isArray(x) && x.leng
|
|
|
13
14
|
export function isAccountAll(address) {
|
|
14
15
|
return address === ALL_ACCOUNT_KEY;
|
|
15
16
|
}
|
|
17
|
+
export const isMobile = MobileOS.includes(getOS());
|
|
16
18
|
export function reformatAddress(address, networkPrefix = 42, isEthereum = false) {
|
|
17
19
|
try {
|
|
18
20
|
if (!address || address === '') {
|
|
@@ -287,4 +289,5 @@ export const stripUrl = url => {
|
|
|
287
289
|
export * from "./array.js";
|
|
288
290
|
export * from "./environment.js";
|
|
289
291
|
export * from "./lazy.js";
|
|
292
|
+
export * from "./registry.js";
|
|
290
293
|
export * from "./translate.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { _getChainNativeTokenBasicInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
|
+
import { Metadata, TypeRegistry } from '@polkadot/types';
|
|
6
|
+
export const createRegistry = (chain, rawMetadata) => {
|
|
7
|
+
var _chain$substrateInfo;
|
|
8
|
+
const registry = new TypeRegistry();
|
|
9
|
+
const metadata = new Metadata(registry, rawMetadata);
|
|
10
|
+
registry.setMetadata(metadata);
|
|
11
|
+
const tokenInfo = _getChainNativeTokenBasicInfo(chain);
|
|
12
|
+
registry.setChainProperties(registry.createType('ChainProperties', {
|
|
13
|
+
ss58Format: ((_chain$substrateInfo = chain.substrateInfo) === null || _chain$substrateInfo === void 0 ? void 0 : _chain$substrateInfo.addressPrefix) || 42,
|
|
14
|
+
tokenDecimals: tokenInfo.decimals,
|
|
15
|
+
tokenSymbol: tokenInfo.symbol
|
|
16
|
+
}));
|
|
17
|
+
return registry;
|
|
18
|
+
};
|