@onekeyfe/inpage-providers-hub 2.0.0 → 2.0.2

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.
@@ -5,11 +5,11 @@ import { ConstraintFn, FindResultType, Selector } from './type';
5
5
  * don't document to querySelector because it maybe not work in shadowRoot,
6
6
  * instead of it, use the containerElement
7
7
  */
8
- export declare function findIconAndNameByParent(containerElement: HTMLElement, walletName: RegExp, constraints?: {
8
+ export declare function findIconAndNameByName(containerElement: HTMLElement, walletName: RegExp, icon?: 'auto-search-icon' | ((text: Text) => HTMLElement | null | undefined), constraints?: {
9
9
  text: ConstraintFn[];
10
10
  icon: ConstraintFn[];
11
11
  }): FindResultType | null;
12
- export declare function findIconAndNameDirectly(iconSelector: Selector | (() => HTMLElement | null | undefined), textSelector: 'auto-search-text' | ((icon: HTMLElement) => HTMLElement | null | undefined) | (Selector & Record<never, never>), name: RegExp, container?: HTMLElement | Document, constraints?: {
12
+ export declare function findIconAndNameByIcon(iconSelector: Selector | (() => HTMLElement | null | undefined), textSelector: 'auto-search-text' | ((icon: HTMLElement) => HTMLElement | null | undefined), name: RegExp, container?: HTMLElement | Document, constraints?: {
13
13
  text: ConstraintFn[];
14
14
  icon: ConstraintFn[];
15
15
  }, searchLevel?: number): FindResultType | null;
@@ -1,5 +1,5 @@
1
1
  import { MAX_LEVELS, MAX_SEARCH_LEVELS_By_IMG } from './consts';
2
- import { findWalletIconByParent, isWalletIconSizeMatch } from './imgUtils';
2
+ import { findWalletIconByParent, isWalletIconLessEqualThan } from './imgUtils';
3
3
  import { findWalletTextByParent } from './textUtils';
4
4
  import { arrayify, isClickable, isInExternalLink, universalLog } from './utils';
5
5
  /**
@@ -8,9 +8,9 @@ import { arrayify, isClickable, isInExternalLink, universalLog } from './utils';
8
8
  * don't document to querySelector because it maybe not work in shadowRoot,
9
9
  * instead of it, use the containerElement
10
10
  */
11
- export function findIconAndNameByParent(containerElement, walletName, constraints = {
11
+ export function findIconAndNameByName(containerElement, walletName, icon = 'auto-search-icon', constraints = {
12
12
  text: [isClickable],
13
- icon: [isWalletIconSizeMatch, isClickable],
13
+ icon: [isWalletIconLessEqualThan, isClickable],
14
14
  }) {
15
15
  const textNode = findWalletTextByParent(containerElement, walletName, constraints.text);
16
16
  if (!textNode || !textNode.parentElement) {
@@ -21,18 +21,26 @@ export function findIconAndNameByParent(containerElement, walletName, constraint
21
21
  universalLog.log(`${walletName.toString()} is in external link`);
22
22
  return null;
23
23
  }
24
- let parent = textNode.parentElement;
25
24
  let iconNode = undefined;
26
- let level = 0;
27
- while (parent && parent !== (containerElement === null || containerElement === void 0 ? void 0 : containerElement.parentElement) && level++ < MAX_LEVELS) {
28
- const walletIcon = findWalletIconByParent(parent, constraints.icon);
29
- //TODO: unnecessary to traverse the parent node if the icon have more than one
30
- if (!walletIcon) {
31
- parent = parent.parentElement;
32
- continue;
25
+ if (typeof icon === 'function') {
26
+ iconNode = icon(textNode);
27
+ }
28
+ else if (icon === 'auto-search-icon') {
29
+ let parent = textNode.parentElement;
30
+ let level = 0;
31
+ while (parent && parent !== (containerElement === null || containerElement === void 0 ? void 0 : containerElement.parentElement) && level++ < MAX_LEVELS) {
32
+ const walletIcon = findWalletIconByParent(parent, constraints.icon);
33
+ if (!walletIcon) {
34
+ parent = parent.parentElement;
35
+ continue;
36
+ }
37
+ iconNode = walletIcon;
38
+ break;
33
39
  }
34
- iconNode = walletIcon;
35
- break;
40
+ }
41
+ else {
42
+ universalLog.warn('icon paramter should be a function or auto-search-icon');
43
+ return null;
36
44
  }
37
45
  if (!iconNode) {
38
46
  universalLog.log(`no wallet ${walletName.toString()} icon node found`);
@@ -41,8 +49,7 @@ export function findIconAndNameByParent(containerElement, walletName, constraint
41
49
  // make sure the icon and text are both existed
42
50
  return { iconNode, textNode };
43
51
  }
44
- export function findIconAndNameDirectly(iconSelector, textSelector, name, container = document, constraints = { text: [], icon: [] }, searchLevel = MAX_SEARCH_LEVELS_By_IMG) {
45
- var _a;
52
+ export function findIconAndNameByIcon(iconSelector, textSelector, name, container = document, constraints = { text: [], icon: [] }, searchLevel = MAX_SEARCH_LEVELS_By_IMG) {
46
53
  const iconElements = typeof iconSelector === 'string'
47
54
  ? container.querySelectorAll(iconSelector)
48
55
  : arrayify(iconSelector());
@@ -51,6 +58,7 @@ export function findIconAndNameDirectly(iconSelector, textSelector, name, contai
51
58
  return null;
52
59
  }
53
60
  const iconElement = Array.from(iconElements)[0];
61
+ //find the text node by img
54
62
  let textNode = null;
55
63
  if (textSelector === 'auto-search-text') {
56
64
  const containerEle = container instanceof HTMLElement ? container : document.body;
@@ -58,14 +66,6 @@ export function findIconAndNameDirectly(iconSelector, textSelector, name, contai
58
66
  ? findTextByImg(iconElement, name, containerEle, constraints.text, searchLevel)
59
67
  : null;
60
68
  }
61
- else if (typeof textSelector === 'string') {
62
- const textContainer = (_a = Array.from(container.querySelectorAll(textSelector))) === null || _a === void 0 ? void 0 : _a.filter(Boolean);
63
- if ((textContainer === null || textContainer === void 0 ? void 0 : textContainer.length) > 1) {
64
- universalLog.warn('more one wallet text found ,please check the selector');
65
- return null;
66
- }
67
- textNode = findWalletTextByParent(textContainer[0], name, constraints.text);
68
- }
69
69
  else if (typeof textSelector === 'function') {
70
70
  const containerEle = iconElement && textSelector(iconElement);
71
71
  textNode =
@@ -90,7 +90,7 @@ export function findTextByImg(img, walletName, containerLimit, constraints, maxL
90
90
  let text = null;
91
91
  let parent = img;
92
92
  let level = 0;
93
- while (parent && parent != containerLimit && level++ < maxLevel) {
93
+ while (parent && parent != containerLimit.parentElement && level++ < maxLevel) {
94
94
  text = findWalletTextByParent(parent, walletName, constraints);
95
95
  if (text) {
96
96
  return text;
@@ -10,4 +10,5 @@ export declare function findIconNodesByParent(parent: HTMLElement): HTMLElement[
10
10
  * make sure that there is only one icon node match walletIcon to ignore hidden icon and other icon
11
11
  */
12
12
  export declare function findWalletIconByParent(parent: HTMLElement, constraints: ConstraintFn[]): HTMLElement | null;
13
- export declare function isWalletIconSizeMatch(walletIcon: HTMLElement): boolean;
13
+ export declare function isWalletIconSizeMatch(walletIcon: HTMLElement, min?: number, max?: number): boolean;
14
+ export declare function isWalletIconLessEqualThan(walletIcon: HTMLElement): boolean;
@@ -11,9 +11,6 @@ export function replaceIcon(originalNode, newIconSrc) {
11
11
  if (originalNode instanceof HTMLImageElement) {
12
12
  originalNode.src = newIconSrc;
13
13
  originalNode.removeAttribute('srcset');
14
- originalNode.style.width = width;
15
- originalNode.style.height = height;
16
- originalNode.classList.add(...Array.from(originalNode.classList));
17
14
  return originalNode;
18
15
  }
19
16
  else {
@@ -54,27 +51,26 @@ export function findIconNodesByParent(parent) {
54
51
  export function findWalletIconByParent(parent, constraints) {
55
52
  const iconNodes = findIconNodesByParent(parent);
56
53
  if (iconNodes.length === 0) {
57
- universalLog.warn(`no icon node found`, parent);
54
+ universalLog.warn(`no icon node found for parent`, parent);
58
55
  return null;
59
56
  }
60
57
  if (iconNodes.length > 1) {
61
58
  universalLog.warn(`more than one icon node found`, iconNodes.length, iconNodes);
62
- return null;
59
+ throw new Error('more than one icon node found');
63
60
  }
64
61
  const icon = iconNodes[0];
65
62
  if (constraints.some((f) => !f(icon))) {
66
- universalLog.warn('it doesnt satisfy the constraints');
67
- return null;
63
+ throw new Error('it doesnt satisfy the constraints');
68
64
  }
69
65
  return icon;
70
66
  }
71
- //TODO: deal with lazy loading image
72
- export function isWalletIconSizeMatch(walletIcon) {
67
+ //NOTE: use function isWalletIconLessEqualThan with lazy loading image
68
+ export function isWalletIconSizeMatch(walletIcon, min = ICON_MIN_SIZE, max = ICON_MAX_SIZE) {
73
69
  const { width, height } = walletIcon.getBoundingClientRect();
74
- const isMatch = width < ICON_MAX_SIZE &&
75
- width > ICON_MIN_SIZE &&
76
- height < ICON_MAX_SIZE &&
77
- height > ICON_MIN_SIZE;
70
+ const isMatch = width <= max && width >= min && height <= max && height >= min;
78
71
  !isMatch && universalLog.log('wallet icon size doesnot match: ', width, height);
79
72
  return isMatch;
80
73
  }
74
+ export function isWalletIconLessEqualThan(walletIcon) {
75
+ return isWalletIconSizeMatch(walletIcon, 0, ICON_MAX_SIZE);
76
+ }
@@ -1,6 +1,6 @@
1
1
  import { hackConnectButton } from '../hackConnectButton';
2
2
  import { sitesConfig } from './config';
3
- import { findIconAndNameByParent as defaultFindIconAndName } from './findIconAndName';
3
+ import { findIconAndNameByName as defaultFindIconAndName } from './findIconAndName';
4
4
  import { replaceIcon as defaultReplaceIcon } from './imgUtils';
5
5
  import { replaceText as defaultReplaceText } from './textUtils';
6
6
  import { createWalletId, universalLog } from './utils';
@@ -47,7 +47,7 @@ function hackWalletConnectButton(sites) {
47
47
  universalLog.warn('containerElement is null, container=', container);
48
48
  continue;
49
49
  }
50
- result = defaultFindIconAndName(containerElement, name, constraintMap);
50
+ result = defaultFindIconAndName(containerElement, name, 'auto-search-icon', constraintMap);
51
51
  }
52
52
  if (!result) {
53
53
  universalLog.warn('no result found');
@@ -1,9 +1,9 @@
1
- import { findIconAndNameByParent } from './findIconAndName';
1
+ import { findIconAndNameByName } from './findIconAndName';
2
2
  import { isClickable, universalLog } from './utils';
3
- import { isWalletIconSizeMatch } from './imgUtils';
3
+ import { isWalletIconLessEqualThan } from './imgUtils';
4
4
  export function findIconAndNameInShadowRoot(hostSelector, containerSelector, walletName, constraints = {
5
5
  text: [isClickable],
6
- icon: [isWalletIconSizeMatch, isClickable],
6
+ icon: [isWalletIconLessEqualThan, isClickable],
7
7
  }) {
8
8
  const shadowRoots = Array.from(document.querySelectorAll(hostSelector))
9
9
  .filter(Boolean)
@@ -21,5 +21,5 @@ export function findIconAndNameInShadowRoot(hostSelector, containerSelector, wal
21
21
  universalLog.warn('findIconAndNameInShadowRoot,length=', length);
22
22
  return null;
23
23
  }
24
- return findIconAndNameByParent(containerElements[0], walletName, constraints);
24
+ return findIconAndNameByName(containerElements[0], walletName, 'auto-search-icon', constraints);
25
25
  }
@@ -1,6 +1,9 @@
1
1
  import { ConstraintFn } from './type';
2
2
  export declare function makeTextEllipse(textNode: HTMLElement, option?: Partial<CSSStyleDeclaration>): void;
3
3
  export declare function makeTextWrap(textNode: HTMLElement): void;
4
+ export declare function makeTextWordBreak(textNode: HTMLElement): void;
5
+ export declare function makeTextAlignLeft(textNode: HTMLElement): void;
6
+ export declare function makeTextAlignCenter(textNode: HTMLElement): void;
4
7
  export declare function replaceText(textNode: Text, newText: string): Text;
5
8
  /**
6
9
  * @description:
@@ -9,6 +9,15 @@ export function makeTextEllipse(textNode, option = {}) {
9
9
  export function makeTextWrap(textNode) {
10
10
  textNode.style.whiteSpace = 'normal';
11
11
  }
12
+ export function makeTextWordBreak(textNode) {
13
+ textNode.style.wordBreak = 'break-word';
14
+ }
15
+ export function makeTextAlignLeft(textNode) {
16
+ textNode.style.textAlign = 'left';
17
+ }
18
+ export function makeTextAlignCenter(textNode) {
19
+ textNode.style.textAlign = 'center';
20
+ }
12
21
  export function replaceText(textNode, newText) {
13
22
  const newTextNode = document.createTextNode(newText);
14
23
  textNode.replaceWith(newTextNode);
@@ -17,7 +17,6 @@ export type IWindowOneKeyHub = {
17
17
  phantom?: {
18
18
  solana?: ProviderSolana;
19
19
  };
20
- starcoin?: any;
21
20
  aptos?: ProviderAptos;
22
21
  petra?: ProviderAptos;
23
22
  martian?: ProviderAptosMartian;
@@ -1,12 +1,12 @@
1
1
  import { ProviderEthereum, shimWeb3, registerEIP6963Provider } from '@onekeyfe/onekey-eth-provider';
2
2
  import { ProviderPrivate } from '@onekeyfe/onekey-private-provider';
3
3
  import { ProviderSolana, registerSolanaWallet } from '@onekeyfe/onekey-solana-provider';
4
- import { ProviderStarcoin } from '@onekeyfe/onekey-starcoin-provider';
4
+ // import { ProviderStarcoin } from '@onekeyfe/onekey-starcoin-provider';
5
5
  import { ProviderAptosMartian } from '@onekeyfe/onekey-aptos-provider';
6
6
  import { ProviderConflux } from '@onekeyfe/onekey-conflux-provider';
7
7
  import { ProviderTron } from '@onekeyfe/onekey-tron-provider';
8
8
  import { ProviderCardano, defineWindowCardanoProperty } from '@onekeyfe/onekey-cardano-provider';
9
- import { ProviderPrivateExternalAccount } from '@onekeyfe/onekey-private-external-account-provider';
9
+ // import { ProviderPrivateExternalAccount } from '@onekeyfe/onekey-private-external-account-provider';
10
10
  import { ProviderCosmos } from '@onekeyfe/onekey-cosmos-provider';
11
11
  import { ProviderPolkadot, registerPolkadot } from '@onekeyfe/onekey-polkadot-provider';
12
12
  import { defineWindowProperty, checkWalletSwitchEnable, } from '@onekeyfe/cross-inpage-provider-core';
@@ -33,9 +33,9 @@ function injectWeb3Provider() {
33
33
  const solana = new ProviderSolana({
34
34
  bridge,
35
35
  });
36
- const starcoin = new ProviderStarcoin({
37
- bridge,
38
- });
36
+ // const starcoin = new ProviderStarcoin({
37
+ // bridge,
38
+ // });
39
39
  const martian = new ProviderAptosMartian({
40
40
  bridge,
41
41
  });
@@ -66,13 +66,14 @@ function injectWeb3Provider() {
66
66
  const btc = new ProviderBtc({ bridge });
67
67
  const btcWallet = new ProviderBtcWallet({ bridge });
68
68
  const algorand = new ProviderAlgo({ bridge });
69
- const $privateExternalAccount = new ProviderPrivateExternalAccount({ bridge });
69
+ // const $privateExternalAccount = new ProviderPrivateExternalAccount({ bridge });
70
70
  // providerHub
71
71
  const $onekey = Object.assign(Object.assign({}, window.$onekey), { jsBridge: bridge, $private,
72
- $privateExternalAccount,
72
+ // $privateExternalAccount,
73
73
  ethereum,
74
- solana,
75
- starcoin, aptos: martian, conflux,
74
+ solana,
75
+ // starcoin,
76
+ aptos: martian, conflux,
76
77
  tron, sollet: null, sui,
77
78
  cardano,
78
79
  cosmos,
@@ -105,7 +106,7 @@ function injectWeb3Provider() {
105
106
  }
106
107
  defineWindowProperty('solana', solana);
107
108
  defineWindowProperty('phantom', { solana });
108
- defineWindowProperty('starcoin', starcoin);
109
+ // defineWindowProperty('starcoin', starcoin);
109
110
  defineWindowProperty('aptos', martian);
110
111
  defineWindowProperty('petra', martian, { enumerable: true });
111
112
  defineWindowProperty('martian', martianProxy, { enumerable: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/inpage-providers-hub",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "keywords": [
5
5
  "cross-inpage-provider"
6
6
  ],
@@ -26,27 +26,27 @@
26
26
  "prebuild": "rm -rf dist",
27
27
  "build": "tsc && tsc --project tsconfig.cjs.json",
28
28
  "test": "npx playwright test",
29
+ "test:report": "npx playwright show-report reports",
29
30
  "start": "tsc --watch"
30
31
  },
31
32
  "dependencies": {
32
- "@onekeyfe/cross-inpage-provider-core": "2.0.0",
33
- "@onekeyfe/cross-inpage-provider-types": "2.0.0",
34
- "@onekeyfe/onekey-algo-provider": "2.0.0",
35
- "@onekeyfe/onekey-aptos-provider": "2.0.0",
36
- "@onekeyfe/onekey-btc-provider": "2.0.0",
37
- "@onekeyfe/onekey-cardano-provider": "2.0.0",
38
- "@onekeyfe/onekey-conflux-provider": "2.0.0",
39
- "@onekeyfe/onekey-cosmos-provider": "2.0.0",
40
- "@onekeyfe/onekey-eth-provider": "2.0.0",
41
- "@onekeyfe/onekey-nostr-provider": "2.0.0",
42
- "@onekeyfe/onekey-polkadot-provider": "2.0.0",
43
- "@onekeyfe/onekey-private-external-account-provider": "2.0.0",
44
- "@onekeyfe/onekey-private-provider": "2.0.0",
45
- "@onekeyfe/onekey-solana-provider": "2.0.0",
46
- "@onekeyfe/onekey-starcoin-provider": "2.0.0",
47
- "@onekeyfe/onekey-sui-provider": "2.0.0",
48
- "@onekeyfe/onekey-tron-provider": "2.0.0",
49
- "@onekeyfe/onekey-webln-provider": "2.0.0",
33
+ "@onekeyfe/cross-inpage-provider-core": "2.0.2",
34
+ "@onekeyfe/cross-inpage-provider-types": "2.0.2",
35
+ "@onekeyfe/onekey-algo-provider": "2.0.2",
36
+ "@onekeyfe/onekey-aptos-provider": "2.0.2",
37
+ "@onekeyfe/onekey-btc-provider": "2.0.2",
38
+ "@onekeyfe/onekey-cardano-provider": "2.0.2",
39
+ "@onekeyfe/onekey-conflux-provider": "2.0.2",
40
+ "@onekeyfe/onekey-cosmos-provider": "2.0.2",
41
+ "@onekeyfe/onekey-eth-provider": "2.0.2",
42
+ "@onekeyfe/onekey-nostr-provider": "2.0.2",
43
+ "@onekeyfe/onekey-polkadot-provider": "2.0.2",
44
+ "@onekeyfe/onekey-private-external-account-provider": "2.0.2",
45
+ "@onekeyfe/onekey-private-provider": "2.0.2",
46
+ "@onekeyfe/onekey-solana-provider": "2.0.2",
47
+ "@onekeyfe/onekey-sui-provider": "2.0.2",
48
+ "@onekeyfe/onekey-tron-provider": "2.0.2",
49
+ "@onekeyfe/onekey-webln-provider": "2.0.2",
50
50
  "web3": "^1.7.3"
51
51
  },
52
52
  "devDependencies": {
@@ -54,5 +54,5 @@
54
54
  "@types/node": "^20.12.7",
55
55
  "playwright": "^1.43.1"
56
56
  },
57
- "gitHead": "4e9109e35064cc7dafe3a4f86a33f497ad9567ec"
57
+ "gitHead": "c1fc3cc6ea25726034b1f610fd1de95be8faf6c2"
58
58
  }