@onekeyfe/inpage-providers-hub 1.0.6 → 1.0.7

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.
@@ -12,16 +12,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const hackConnectButton_1 = require("../hackConnectButton");
13
13
  const cross_inpage_provider_types_1 = require("@onekeyfe/cross-inpage-provider-types");
14
14
  const consts_1 = require("../consts");
15
+ const onekeyBtnBg = 'rgb(0, 184, 18)';
16
+ function setOnClickToConnectWallet({ element, uri }) {
17
+ element.onclick = (e) => {
18
+ var _a, _b;
19
+ e.preventDefault();
20
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
21
+ void ((_b = (_a = window.$onekey) === null || _a === void 0 ? void 0 : _a.$private) === null || _b === void 0 ? void 0 : _b.request({
22
+ method: 'wallet_connectToWalletConnect',
23
+ params: { uri },
24
+ }));
25
+ return false;
26
+ };
27
+ }
15
28
  (0, hackConnectButton_1.hackConnectButton)({
16
29
  urls: ['*'],
17
30
  providers: [cross_inpage_provider_types_1.IInjectedProviderNames.ethereum],
18
31
  replaceMethod() {
32
+ // $onekey.$walletInfo.platformEnv.isExtension
19
33
  const onekeyHub = window.$onekey;
20
34
  if (!onekeyHub || !onekeyHub.$walletInfo || !onekeyHub.$private) {
21
35
  return;
22
36
  }
37
+ const { isExtension, isDesktop, isNative } = onekeyHub.$walletInfo.platformEnv;
23
38
  const replaceFunc = ({ findName, icon, text, }) => {
24
- var _a, _b, _c, _d;
39
+ var _a, _b, _c, _d, _e;
25
40
  const headerText = document.getElementById('walletconnect-qrcode-text');
26
41
  if (!headerText) {
27
42
  return;
@@ -30,8 +45,26 @@ const consts_1 = require("../consts");
30
45
  if (!qrcodeContainer) {
31
46
  return;
32
47
  }
33
- if (['desktop', 'app', 'ios', 'android'].includes(((_a = onekeyHub === null || onekeyHub === void 0 ? void 0 : onekeyHub.$walletInfo) === null || _a === void 0 ? void 0 : _a.platform) || '') &&
34
- ((_c = (_b = qrcodeContainer === null || qrcodeContainer === void 0 ? void 0 : qrcodeContainer.classList) === null || _b === void 0 ? void 0 : _b.contains) === null || _c === void 0 ? void 0 : _c.call(_b, 'walletconnect-search__input'))) {
48
+ // **** android single connect button replacement
49
+ if ((_b = (_a = qrcodeContainer === null || qrcodeContainer === void 0 ? void 0 : qrcodeContainer.classList) === null || _a === void 0 ? void 0 : _a.contains) === null || _b === void 0 ? void 0 : _b.call(_a, 'walletconnect-connect__buttons__wrapper__android')) {
50
+ const btn = qrcodeContainer.querySelector('.walletconnect-connect__button');
51
+ if (!btn) {
52
+ return;
53
+ }
54
+ if (btn.dataset['isOneKeyReplaced']) {
55
+ return;
56
+ }
57
+ btn.dataset['isOneKeyReplaced'] = 'true';
58
+ btn.innerText = `${btn.innerText} ${text}`;
59
+ btn.style.backgroundColor = onekeyBtnBg;
60
+ setOnClickToConnectWallet({
61
+ element: btn,
62
+ uri: btn.href,
63
+ });
64
+ }
65
+ // **** deeplink buttons replacement
66
+ else if ((_d = (_c = qrcodeContainer === null || qrcodeContainer === void 0 ? void 0 : qrcodeContainer.classList) === null || _c === void 0 ? void 0 : _c.contains) === null || _d === void 0 ? void 0 : _d.call(_c, 'walletconnect-search__input')) {
67
+ const shouldHideOtherWallets = isDesktop || isNative;
35
68
  const inputEle = qrcodeContainer;
36
69
  const parent = headerText.parentNode;
37
70
  if (!parent) {
@@ -42,7 +75,8 @@ const consts_1 = require("../consts");
42
75
  if (!firstItem || !iconsContainer) {
43
76
  return;
44
77
  }
45
- if (firstItem.classList.contains('isOneKeyReplaced')) {
78
+ const newItemAdded = parent.querySelector('.isOneKeyReplaced.walletconnect-connect__button__icon_anchor');
79
+ if (newItemAdded) {
46
80
  return;
47
81
  }
48
82
  const img = firstItem.querySelector('.walletconnect-connect__button__icon');
@@ -55,36 +89,48 @@ const consts_1 = require("../consts");
55
89
  }
56
90
  const uri = new URL(firstItem === null || firstItem === void 0 ? void 0 : firstItem.href).searchParams.get('uri');
57
91
  if (uri && uri.startsWith('wc:')) {
58
- span.innerText = text;
59
- img.style.backgroundImage = `url(${icon || ''})`;
60
- img.style.backgroundColor = 'rgb(0, 184, 18)';
61
- // const item = firstItem.cloneNode(true) as HTMLElement;
62
- firstItem.classList.add('isOneKeyReplaced');
63
- firstItem.onclick = (e) => {
64
- var _a;
65
- e.preventDefault();
66
- void ((_a = onekeyHub === null || onekeyHub === void 0 ? void 0 : onekeyHub.$private) === null || _a === void 0 ? void 0 : _a.request({
67
- method: 'wallet_connectToWalletConnect',
68
- params: { uri },
69
- }));
70
- return false;
71
- };
72
- for (const item of Array.from((iconsContainer === null || iconsContainer === void 0 ? void 0 : iconsContainer.children) || [])) {
73
- const itemEl = item;
74
- if (itemEl && itemEl.style) {
75
- itemEl.style.display = 'none';
92
+ const newItem = firstItem.cloneNode(true);
93
+ const newItemImg = newItem.querySelector('.walletconnect-connect__button__icon');
94
+ const newItemSpan = newItem.querySelector('.walletconnect-connect__button__text');
95
+ if (newItemSpan) {
96
+ newItemSpan.innerText = text;
97
+ }
98
+ if (newItemImg) {
99
+ newItemImg.style.backgroundImage = `url(${icon || ''})`;
100
+ newItemImg.style.backgroundColor = onekeyBtnBg;
101
+ }
102
+ newItem.classList.add('isOneKeyReplaced');
103
+ // TODO use universal link
104
+ newItem.href = `onekey-wallet:///wc?uri=${encodeURIComponent(uri)}`;
105
+ if (shouldHideOtherWallets) {
106
+ setOnClickToConnectWallet({
107
+ element: newItem,
108
+ uri,
109
+ });
110
+ }
111
+ // hide all other wallets
112
+ if (shouldHideOtherWallets) {
113
+ for (const item of Array.from((iconsContainer === null || iconsContainer === void 0 ? void 0 : iconsContainer.children) || [])) {
114
+ const itemEl = item;
115
+ if (itemEl && itemEl.style) {
116
+ itemEl.style.display = 'none';
117
+ }
76
118
  }
119
+ iconsContainer.style.display = 'flex';
120
+ iconsContainer.style.justifyContent = 'center';
121
+ iconsContainer.style.alignItems = 'center';
77
122
  }
78
- iconsContainer.style.display = 'flex';
79
- iconsContainer.style.justifyContent = 'center';
80
- iconsContainer.style.alignItems = 'center';
81
123
  iconsContainer.style.minHeight = '150px';
82
- firstItem.style.display = 'block';
83
- inputEle.remove();
84
- const footerContainer = (_d = iconsContainer === null || iconsContainer === void 0 ? void 0 : iconsContainer.parentNode) === null || _d === void 0 ? void 0 : _d.querySelector('.walletconnect-modal__footer');
85
- footerContainer === null || footerContainer === void 0 ? void 0 : footerContainer.remove();
124
+ iconsContainer.prepend(newItem);
125
+ // remove input and footer pagination
126
+ if (shouldHideOtherWallets) {
127
+ inputEle.remove();
128
+ const footerContainer = (_e = iconsContainer === null || iconsContainer === void 0 ? void 0 : iconsContainer.parentNode) === null || _e === void 0 ? void 0 : _e.querySelector('.walletconnect-modal__footer');
129
+ footerContainer === null || footerContainer === void 0 ? void 0 : footerContainer.remove();
130
+ }
86
131
  }
87
132
  }
133
+ // **** qrcode replacement
88
134
  else {
89
135
  const svg = qrcodeContainer === null || qrcodeContainer === void 0 ? void 0 : qrcodeContainer.querySelector('svg.walletconnect-qrcode__image');
90
136
  if (!svg) {
@@ -10,16 +10,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { createNewImageToContainer, createWalletConnectToButton, detectQrcodeFromSvg, hackConnectButton, } from '../hackConnectButton';
11
11
  import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types';
12
12
  import { WALLET_CONNECT_INFO } from '../consts';
13
+ const onekeyBtnBg = 'rgb(0, 184, 18)';
14
+ function setOnClickToConnectWallet({ element, uri }) {
15
+ element.onclick = (e) => {
16
+ var _a, _b;
17
+ e.preventDefault();
18
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
19
+ void ((_b = (_a = window.$onekey) === null || _a === void 0 ? void 0 : _a.$private) === null || _b === void 0 ? void 0 : _b.request({
20
+ method: 'wallet_connectToWalletConnect',
21
+ params: { uri },
22
+ }));
23
+ return false;
24
+ };
25
+ }
13
26
  hackConnectButton({
14
27
  urls: ['*'],
15
28
  providers: [IInjectedProviderNames.ethereum],
16
29
  replaceMethod() {
30
+ // $onekey.$walletInfo.platformEnv.isExtension
17
31
  const onekeyHub = window.$onekey;
18
32
  if (!onekeyHub || !onekeyHub.$walletInfo || !onekeyHub.$private) {
19
33
  return;
20
34
  }
35
+ const { isExtension, isDesktop, isNative } = onekeyHub.$walletInfo.platformEnv;
21
36
  const replaceFunc = ({ findName, icon, text, }) => {
22
- var _a, _b, _c, _d;
37
+ var _a, _b, _c, _d, _e;
23
38
  const headerText = document.getElementById('walletconnect-qrcode-text');
24
39
  if (!headerText) {
25
40
  return;
@@ -28,8 +43,26 @@ hackConnectButton({
28
43
  if (!qrcodeContainer) {
29
44
  return;
30
45
  }
31
- if (['desktop', 'app', 'ios', 'android'].includes(((_a = onekeyHub === null || onekeyHub === void 0 ? void 0 : onekeyHub.$walletInfo) === null || _a === void 0 ? void 0 : _a.platform) || '') &&
32
- ((_c = (_b = qrcodeContainer === null || qrcodeContainer === void 0 ? void 0 : qrcodeContainer.classList) === null || _b === void 0 ? void 0 : _b.contains) === null || _c === void 0 ? void 0 : _c.call(_b, 'walletconnect-search__input'))) {
46
+ // **** android single connect button replacement
47
+ if ((_b = (_a = qrcodeContainer === null || qrcodeContainer === void 0 ? void 0 : qrcodeContainer.classList) === null || _a === void 0 ? void 0 : _a.contains) === null || _b === void 0 ? void 0 : _b.call(_a, 'walletconnect-connect__buttons__wrapper__android')) {
48
+ const btn = qrcodeContainer.querySelector('.walletconnect-connect__button');
49
+ if (!btn) {
50
+ return;
51
+ }
52
+ if (btn.dataset['isOneKeyReplaced']) {
53
+ return;
54
+ }
55
+ btn.dataset['isOneKeyReplaced'] = 'true';
56
+ btn.innerText = `${btn.innerText} ${text}`;
57
+ btn.style.backgroundColor = onekeyBtnBg;
58
+ setOnClickToConnectWallet({
59
+ element: btn,
60
+ uri: btn.href,
61
+ });
62
+ }
63
+ // **** deeplink buttons replacement
64
+ else if ((_d = (_c = qrcodeContainer === null || qrcodeContainer === void 0 ? void 0 : qrcodeContainer.classList) === null || _c === void 0 ? void 0 : _c.contains) === null || _d === void 0 ? void 0 : _d.call(_c, 'walletconnect-search__input')) {
65
+ const shouldHideOtherWallets = isDesktop || isNative;
33
66
  const inputEle = qrcodeContainer;
34
67
  const parent = headerText.parentNode;
35
68
  if (!parent) {
@@ -40,7 +73,8 @@ hackConnectButton({
40
73
  if (!firstItem || !iconsContainer) {
41
74
  return;
42
75
  }
43
- if (firstItem.classList.contains('isOneKeyReplaced')) {
76
+ const newItemAdded = parent.querySelector('.isOneKeyReplaced.walletconnect-connect__button__icon_anchor');
77
+ if (newItemAdded) {
44
78
  return;
45
79
  }
46
80
  const img = firstItem.querySelector('.walletconnect-connect__button__icon');
@@ -53,36 +87,48 @@ hackConnectButton({
53
87
  }
54
88
  const uri = new URL(firstItem === null || firstItem === void 0 ? void 0 : firstItem.href).searchParams.get('uri');
55
89
  if (uri && uri.startsWith('wc:')) {
56
- span.innerText = text;
57
- img.style.backgroundImage = `url(${icon || ''})`;
58
- img.style.backgroundColor = 'rgb(0, 184, 18)';
59
- // const item = firstItem.cloneNode(true) as HTMLElement;
60
- firstItem.classList.add('isOneKeyReplaced');
61
- firstItem.onclick = (e) => {
62
- var _a;
63
- e.preventDefault();
64
- void ((_a = onekeyHub === null || onekeyHub === void 0 ? void 0 : onekeyHub.$private) === null || _a === void 0 ? void 0 : _a.request({
65
- method: 'wallet_connectToWalletConnect',
66
- params: { uri },
67
- }));
68
- return false;
69
- };
70
- for (const item of Array.from((iconsContainer === null || iconsContainer === void 0 ? void 0 : iconsContainer.children) || [])) {
71
- const itemEl = item;
72
- if (itemEl && itemEl.style) {
73
- itemEl.style.display = 'none';
90
+ const newItem = firstItem.cloneNode(true);
91
+ const newItemImg = newItem.querySelector('.walletconnect-connect__button__icon');
92
+ const newItemSpan = newItem.querySelector('.walletconnect-connect__button__text');
93
+ if (newItemSpan) {
94
+ newItemSpan.innerText = text;
95
+ }
96
+ if (newItemImg) {
97
+ newItemImg.style.backgroundImage = `url(${icon || ''})`;
98
+ newItemImg.style.backgroundColor = onekeyBtnBg;
99
+ }
100
+ newItem.classList.add('isOneKeyReplaced');
101
+ // TODO use universal link
102
+ newItem.href = `onekey-wallet:///wc?uri=${encodeURIComponent(uri)}`;
103
+ if (shouldHideOtherWallets) {
104
+ setOnClickToConnectWallet({
105
+ element: newItem,
106
+ uri,
107
+ });
108
+ }
109
+ // hide all other wallets
110
+ if (shouldHideOtherWallets) {
111
+ for (const item of Array.from((iconsContainer === null || iconsContainer === void 0 ? void 0 : iconsContainer.children) || [])) {
112
+ const itemEl = item;
113
+ if (itemEl && itemEl.style) {
114
+ itemEl.style.display = 'none';
115
+ }
74
116
  }
117
+ iconsContainer.style.display = 'flex';
118
+ iconsContainer.style.justifyContent = 'center';
119
+ iconsContainer.style.alignItems = 'center';
75
120
  }
76
- iconsContainer.style.display = 'flex';
77
- iconsContainer.style.justifyContent = 'center';
78
- iconsContainer.style.alignItems = 'center';
79
121
  iconsContainer.style.minHeight = '150px';
80
- firstItem.style.display = 'block';
81
- inputEle.remove();
82
- const footerContainer = (_d = iconsContainer === null || iconsContainer === void 0 ? void 0 : iconsContainer.parentNode) === null || _d === void 0 ? void 0 : _d.querySelector('.walletconnect-modal__footer');
83
- footerContainer === null || footerContainer === void 0 ? void 0 : footerContainer.remove();
122
+ iconsContainer.prepend(newItem);
123
+ // remove input and footer pagination
124
+ if (shouldHideOtherWallets) {
125
+ inputEle.remove();
126
+ const footerContainer = (_e = iconsContainer === null || iconsContainer === void 0 ? void 0 : iconsContainer.parentNode) === null || _e === void 0 ? void 0 : _e.querySelector('.walletconnect-modal__footer');
127
+ footerContainer === null || footerContainer === void 0 ? void 0 : footerContainer.remove();
128
+ }
84
129
  }
85
130
  }
131
+ // **** qrcode replacement
86
132
  else {
87
133
  const svg = qrcodeContainer === null || qrcodeContainer === void 0 ? void 0 : qrcodeContainer.querySelector('svg.walletconnect-qrcode__image');
88
134
  if (!svg) {
@@ -21,6 +21,11 @@ export declare type IWindowOneKeyHub = {
21
21
  isLegacy: boolean;
22
22
  platform: string;
23
23
  version: string;
24
+ platformEnv: {
25
+ isExtension: boolean;
26
+ isDesktop: boolean;
27
+ isNative: boolean;
28
+ };
24
29
  };
25
30
  };
26
31
  declare function injectWeb3Provider(): unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/inpage-providers-hub",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "keywords": [
5
5
  "cross-inpage-provider"
6
6
  ],
@@ -28,14 +28,14 @@
28
28
  "start": "tsc --watch"
29
29
  },
30
30
  "dependencies": {
31
- "@onekeyfe/cross-inpage-provider-core": "1.0.6",
32
- "@onekeyfe/cross-inpage-provider-types": "1.0.6",
33
- "@onekeyfe/onekey-aptos-provider": "1.0.6",
34
- "@onekeyfe/onekey-eth-provider": "1.0.6",
35
- "@onekeyfe/onekey-private-provider": "1.0.6",
36
- "@onekeyfe/onekey-solana-provider": "1.0.6",
37
- "@onekeyfe/onekey-starcoin-provider": "1.0.6",
31
+ "@onekeyfe/cross-inpage-provider-core": "1.0.7",
32
+ "@onekeyfe/cross-inpage-provider-types": "1.0.7",
33
+ "@onekeyfe/onekey-aptos-provider": "1.0.7",
34
+ "@onekeyfe/onekey-eth-provider": "1.0.7",
35
+ "@onekeyfe/onekey-private-provider": "1.0.7",
36
+ "@onekeyfe/onekey-solana-provider": "1.0.7",
37
+ "@onekeyfe/onekey-starcoin-provider": "1.0.7",
38
38
  "web3": "^1.7.3"
39
39
  },
40
- "gitHead": "37fdf6261b83e043ae34aea663379e84da087e07"
40
+ "gitHead": "c712a3c8e4a53095e9cf2406b3801ae673a67e00"
41
41
  }