@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.
- package/dist/cjs/connectButtonHack/universal/config.js +613 -178
- package/dist/cjs/connectButtonHack/universal/findIconAndName.js +26 -26
- package/dist/cjs/connectButtonHack/universal/imgUtils.js +11 -14
- package/dist/cjs/connectButtonHack/universal/index.js +1 -1
- package/dist/cjs/connectButtonHack/universal/shadowRoot.js +2 -2
- package/dist/cjs/connectButtonHack/universal/textUtils.js +13 -1
- package/dist/cjs/injectWeb3Provider.js +11 -10
- package/dist/connectButtonHack/universal/config.js +616 -181
- package/dist/connectButtonHack/universal/findIconAndName.d.ts +2 -2
- package/dist/connectButtonHack/universal/findIconAndName.js +24 -24
- package/dist/connectButtonHack/universal/imgUtils.d.ts +2 -1
- package/dist/connectButtonHack/universal/imgUtils.js +9 -13
- package/dist/connectButtonHack/universal/index.js +2 -2
- package/dist/connectButtonHack/universal/shadowRoot.js +4 -4
- package/dist/connectButtonHack/universal/textUtils.d.ts +3 -0
- package/dist/connectButtonHack/universal/textUtils.js +9 -0
- package/dist/injectWeb3Provider.d.ts +0 -1
- package/dist/injectWeb3Provider.js +11 -10
- package/package.json +20 -20
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findTextByImg = exports.
|
|
3
|
+
exports.findTextByImg = exports.findIconAndNameByIcon = exports.findIconAndNameByName = void 0;
|
|
4
4
|
const consts_1 = require("./consts");
|
|
5
5
|
const imgUtils_1 = require("./imgUtils");
|
|
6
6
|
const textUtils_1 = require("./textUtils");
|
|
@@ -11,9 +11,9 @@ const utils_1 = require("./utils");
|
|
|
11
11
|
* don't document to querySelector because it maybe not work in shadowRoot,
|
|
12
12
|
* instead of it, use the containerElement
|
|
13
13
|
*/
|
|
14
|
-
function
|
|
14
|
+
function findIconAndNameByName(containerElement, walletName, icon = 'auto-search-icon', constraints = {
|
|
15
15
|
text: [utils_1.isClickable],
|
|
16
|
-
icon: [imgUtils_1.
|
|
16
|
+
icon: [imgUtils_1.isWalletIconLessEqualThan, utils_1.isClickable],
|
|
17
17
|
}) {
|
|
18
18
|
const textNode = (0, textUtils_1.findWalletTextByParent)(containerElement, walletName, constraints.text);
|
|
19
19
|
if (!textNode || !textNode.parentElement) {
|
|
@@ -24,18 +24,26 @@ function findIconAndNameByParent(containerElement, walletName, constraints = {
|
|
|
24
24
|
utils_1.universalLog.log(`${walletName.toString()} is in external link`);
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
27
|
-
let parent = textNode.parentElement;
|
|
28
27
|
let iconNode = undefined;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
if (typeof icon === 'function') {
|
|
29
|
+
iconNode = icon(textNode);
|
|
30
|
+
}
|
|
31
|
+
else if (icon === 'auto-search-icon') {
|
|
32
|
+
let parent = textNode.parentElement;
|
|
33
|
+
let level = 0;
|
|
34
|
+
while (parent && parent !== (containerElement === null || containerElement === void 0 ? void 0 : containerElement.parentElement) && level++ < consts_1.MAX_LEVELS) {
|
|
35
|
+
const walletIcon = (0, imgUtils_1.findWalletIconByParent)(parent, constraints.icon);
|
|
36
|
+
if (!walletIcon) {
|
|
37
|
+
parent = parent.parentElement;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
iconNode = walletIcon;
|
|
41
|
+
break;
|
|
36
42
|
}
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
utils_1.universalLog.warn('icon paramter should be a function or auto-search-icon');
|
|
46
|
+
return null;
|
|
39
47
|
}
|
|
40
48
|
if (!iconNode) {
|
|
41
49
|
utils_1.universalLog.log(`no wallet ${walletName.toString()} icon node found`);
|
|
@@ -44,9 +52,8 @@ function findIconAndNameByParent(containerElement, walletName, constraints = {
|
|
|
44
52
|
// make sure the icon and text are both existed
|
|
45
53
|
return { iconNode, textNode };
|
|
46
54
|
}
|
|
47
|
-
exports.
|
|
48
|
-
function
|
|
49
|
-
var _a;
|
|
55
|
+
exports.findIconAndNameByName = findIconAndNameByName;
|
|
56
|
+
function findIconAndNameByIcon(iconSelector, textSelector, name, container = document, constraints = { text: [], icon: [] }, searchLevel = consts_1.MAX_SEARCH_LEVELS_By_IMG) {
|
|
50
57
|
const iconElements = typeof iconSelector === 'string'
|
|
51
58
|
? container.querySelectorAll(iconSelector)
|
|
52
59
|
: (0, utils_1.arrayify)(iconSelector());
|
|
@@ -55,6 +62,7 @@ function findIconAndNameDirectly(iconSelector, textSelector, name, container = d
|
|
|
55
62
|
return null;
|
|
56
63
|
}
|
|
57
64
|
const iconElement = Array.from(iconElements)[0];
|
|
65
|
+
//find the text node by img
|
|
58
66
|
let textNode = null;
|
|
59
67
|
if (textSelector === 'auto-search-text') {
|
|
60
68
|
const containerEle = container instanceof HTMLElement ? container : document.body;
|
|
@@ -62,14 +70,6 @@ function findIconAndNameDirectly(iconSelector, textSelector, name, container = d
|
|
|
62
70
|
? findTextByImg(iconElement, name, containerEle, constraints.text, searchLevel)
|
|
63
71
|
: null;
|
|
64
72
|
}
|
|
65
|
-
else if (typeof textSelector === 'string') {
|
|
66
|
-
const textContainer = (_a = Array.from(container.querySelectorAll(textSelector))) === null || _a === void 0 ? void 0 : _a.filter(Boolean);
|
|
67
|
-
if ((textContainer === null || textContainer === void 0 ? void 0 : textContainer.length) > 1) {
|
|
68
|
-
utils_1.universalLog.warn('more one wallet text found ,please check the selector');
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
textNode = (0, textUtils_1.findWalletTextByParent)(textContainer[0], name, constraints.text);
|
|
72
|
-
}
|
|
73
73
|
else if (typeof textSelector === 'function') {
|
|
74
74
|
const containerEle = iconElement && textSelector(iconElement);
|
|
75
75
|
textNode =
|
|
@@ -90,12 +90,12 @@ function findIconAndNameDirectly(iconSelector, textSelector, name, container = d
|
|
|
90
90
|
textNode,
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
exports.
|
|
93
|
+
exports.findIconAndNameByIcon = findIconAndNameByIcon;
|
|
94
94
|
function findTextByImg(img, walletName, containerLimit, constraints, maxLevel = consts_1.MAX_SEARCH_LEVELS_By_IMG) {
|
|
95
95
|
let text = null;
|
|
96
96
|
let parent = img;
|
|
97
97
|
let level = 0;
|
|
98
|
-
while (parent && parent != containerLimit && level++ < maxLevel) {
|
|
98
|
+
while (parent && parent != containerLimit.parentElement && level++ < maxLevel) {
|
|
99
99
|
text = (0, textUtils_1.findWalletTextByParent)(parent, walletName, constraints);
|
|
100
100
|
if (text) {
|
|
101
101
|
return text;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isWalletIconSizeMatch = exports.findWalletIconByParent = exports.findIconNodesByParent = exports.createImageEle = exports.replaceIcon = void 0;
|
|
3
|
+
exports.isWalletIconLessEqualThan = exports.isWalletIconSizeMatch = exports.findWalletIconByParent = exports.findIconNodesByParent = exports.createImageEle = exports.replaceIcon = void 0;
|
|
4
4
|
const consts_1 = require("./consts");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
/**
|
|
@@ -14,9 +14,6 @@ function replaceIcon(originalNode, newIconSrc) {
|
|
|
14
14
|
if (originalNode instanceof HTMLImageElement) {
|
|
15
15
|
originalNode.src = newIconSrc;
|
|
16
16
|
originalNode.removeAttribute('srcset');
|
|
17
|
-
originalNode.style.width = width;
|
|
18
|
-
originalNode.style.height = height;
|
|
19
|
-
originalNode.classList.add(...Array.from(originalNode.classList));
|
|
20
17
|
return originalNode;
|
|
21
18
|
}
|
|
22
19
|
else {
|
|
@@ -60,29 +57,29 @@ exports.findIconNodesByParent = findIconNodesByParent;
|
|
|
60
57
|
function findWalletIconByParent(parent, constraints) {
|
|
61
58
|
const iconNodes = findIconNodesByParent(parent);
|
|
62
59
|
if (iconNodes.length === 0) {
|
|
63
|
-
utils_1.universalLog.warn(`no icon node found`, parent);
|
|
60
|
+
utils_1.universalLog.warn(`no icon node found for parent`, parent);
|
|
64
61
|
return null;
|
|
65
62
|
}
|
|
66
63
|
if (iconNodes.length > 1) {
|
|
67
64
|
utils_1.universalLog.warn(`more than one icon node found`, iconNodes.length, iconNodes);
|
|
68
|
-
|
|
65
|
+
throw new Error('more than one icon node found');
|
|
69
66
|
}
|
|
70
67
|
const icon = iconNodes[0];
|
|
71
68
|
if (constraints.some((f) => !f(icon))) {
|
|
72
|
-
|
|
73
|
-
return null;
|
|
69
|
+
throw new Error('it doesnt satisfy the constraints');
|
|
74
70
|
}
|
|
75
71
|
return icon;
|
|
76
72
|
}
|
|
77
73
|
exports.findWalletIconByParent = findWalletIconByParent;
|
|
78
|
-
//
|
|
79
|
-
function isWalletIconSizeMatch(walletIcon) {
|
|
74
|
+
//NOTE: use function isWalletIconLessEqualThan with lazy loading image
|
|
75
|
+
function isWalletIconSizeMatch(walletIcon, min = consts_1.ICON_MIN_SIZE, max = consts_1.ICON_MAX_SIZE) {
|
|
80
76
|
const { width, height } = walletIcon.getBoundingClientRect();
|
|
81
|
-
const isMatch = width
|
|
82
|
-
width > consts_1.ICON_MIN_SIZE &&
|
|
83
|
-
height < consts_1.ICON_MAX_SIZE &&
|
|
84
|
-
height > consts_1.ICON_MIN_SIZE;
|
|
77
|
+
const isMatch = width <= max && width >= min && height <= max && height >= min;
|
|
85
78
|
!isMatch && utils_1.universalLog.log('wallet icon size doesnot match: ', width, height);
|
|
86
79
|
return isMatch;
|
|
87
80
|
}
|
|
88
81
|
exports.isWalletIconSizeMatch = isWalletIconSizeMatch;
|
|
82
|
+
function isWalletIconLessEqualThan(walletIcon) {
|
|
83
|
+
return isWalletIconSizeMatch(walletIcon, 0, consts_1.ICON_MAX_SIZE);
|
|
84
|
+
}
|
|
85
|
+
exports.isWalletIconLessEqualThan = isWalletIconLessEqualThan;
|
|
@@ -49,7 +49,7 @@ function hackWalletConnectButton(sites) {
|
|
|
49
49
|
utils_1.universalLog.warn('containerElement is null, container=', container);
|
|
50
50
|
continue;
|
|
51
51
|
}
|
|
52
|
-
result = (0, findIconAndName_1.
|
|
52
|
+
result = (0, findIconAndName_1.findIconAndNameByName)(containerElement, name, 'auto-search-icon', constraintMap);
|
|
53
53
|
}
|
|
54
54
|
if (!result) {
|
|
55
55
|
utils_1.universalLog.warn('no result found');
|
|
@@ -6,7 +6,7 @@ const utils_1 = require("./utils");
|
|
|
6
6
|
const imgUtils_1 = require("./imgUtils");
|
|
7
7
|
function findIconAndNameInShadowRoot(hostSelector, containerSelector, walletName, constraints = {
|
|
8
8
|
text: [utils_1.isClickable],
|
|
9
|
-
icon: [imgUtils_1.
|
|
9
|
+
icon: [imgUtils_1.isWalletIconLessEqualThan, utils_1.isClickable],
|
|
10
10
|
}) {
|
|
11
11
|
const shadowRoots = Array.from(document.querySelectorAll(hostSelector))
|
|
12
12
|
.filter(Boolean)
|
|
@@ -24,6 +24,6 @@ function findIconAndNameInShadowRoot(hostSelector, containerSelector, walletName
|
|
|
24
24
|
utils_1.universalLog.warn('findIconAndNameInShadowRoot,length=', length);
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
27
|
-
return (0, findIconAndName_1.
|
|
27
|
+
return (0, findIconAndName_1.findIconAndNameByName)(containerElements[0], walletName, 'auto-search-icon', constraints);
|
|
28
28
|
}
|
|
29
29
|
exports.findIconAndNameInShadowRoot = findIconAndNameInShadowRoot;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.findWalletTextByParent = exports.replaceText = exports.makeTextWrap = exports.makeTextEllipse = void 0;
|
|
6
|
+
exports.findWalletTextByParent = exports.replaceText = exports.makeTextAlignCenter = exports.makeTextAlignLeft = exports.makeTextWordBreak = exports.makeTextWrap = exports.makeTextEllipse = void 0;
|
|
7
7
|
const utilsDomNodes_1 = __importDefault(require("../utils/utilsDomNodes"));
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
9
|
function makeTextEllipse(textNode, option = {}) {
|
|
@@ -17,6 +17,18 @@ function makeTextWrap(textNode) {
|
|
|
17
17
|
textNode.style.whiteSpace = 'normal';
|
|
18
18
|
}
|
|
19
19
|
exports.makeTextWrap = makeTextWrap;
|
|
20
|
+
function makeTextWordBreak(textNode) {
|
|
21
|
+
textNode.style.wordBreak = 'break-word';
|
|
22
|
+
}
|
|
23
|
+
exports.makeTextWordBreak = makeTextWordBreak;
|
|
24
|
+
function makeTextAlignLeft(textNode) {
|
|
25
|
+
textNode.style.textAlign = 'left';
|
|
26
|
+
}
|
|
27
|
+
exports.makeTextAlignLeft = makeTextAlignLeft;
|
|
28
|
+
function makeTextAlignCenter(textNode) {
|
|
29
|
+
textNode.style.textAlign = 'center';
|
|
30
|
+
}
|
|
31
|
+
exports.makeTextAlignCenter = makeTextAlignCenter;
|
|
20
32
|
function replaceText(textNode, newText) {
|
|
21
33
|
const newTextNode = document.createTextNode(newText);
|
|
22
34
|
textNode.replaceWith(newTextNode);
|
|
@@ -4,12 +4,12 @@ exports.injectWeb3Provider = void 0;
|
|
|
4
4
|
const onekey_eth_provider_1 = require("@onekeyfe/onekey-eth-provider");
|
|
5
5
|
const onekey_private_provider_1 = require("@onekeyfe/onekey-private-provider");
|
|
6
6
|
const onekey_solana_provider_1 = require("@onekeyfe/onekey-solana-provider");
|
|
7
|
-
|
|
7
|
+
// import { ProviderStarcoin } from '@onekeyfe/onekey-starcoin-provider';
|
|
8
8
|
const onekey_aptos_provider_1 = require("@onekeyfe/onekey-aptos-provider");
|
|
9
9
|
const onekey_conflux_provider_1 = require("@onekeyfe/onekey-conflux-provider");
|
|
10
10
|
const onekey_tron_provider_1 = require("@onekeyfe/onekey-tron-provider");
|
|
11
11
|
const onekey_cardano_provider_1 = require("@onekeyfe/onekey-cardano-provider");
|
|
12
|
-
|
|
12
|
+
// import { ProviderPrivateExternalAccount } from '@onekeyfe/onekey-private-external-account-provider';
|
|
13
13
|
const onekey_cosmos_provider_1 = require("@onekeyfe/onekey-cosmos-provider");
|
|
14
14
|
const onekey_polkadot_provider_1 = require("@onekeyfe/onekey-polkadot-provider");
|
|
15
15
|
const cross_inpage_provider_core_1 = require("@onekeyfe/cross-inpage-provider-core");
|
|
@@ -36,9 +36,9 @@ function injectWeb3Provider() {
|
|
|
36
36
|
const solana = new onekey_solana_provider_1.ProviderSolana({
|
|
37
37
|
bridge,
|
|
38
38
|
});
|
|
39
|
-
const starcoin = new
|
|
40
|
-
|
|
41
|
-
});
|
|
39
|
+
// const starcoin = new ProviderStarcoin({
|
|
40
|
+
// bridge,
|
|
41
|
+
// });
|
|
42
42
|
const martian = new onekey_aptos_provider_1.ProviderAptosMartian({
|
|
43
43
|
bridge,
|
|
44
44
|
});
|
|
@@ -69,13 +69,14 @@ function injectWeb3Provider() {
|
|
|
69
69
|
const btc = new onekey_btc_provider_1.ProviderBtc({ bridge });
|
|
70
70
|
const btcWallet = new onekey_btc_provider_1.ProviderBtcWallet({ bridge });
|
|
71
71
|
const algorand = new onekey_algo_provider_1.ProviderAlgo({ bridge });
|
|
72
|
-
const $privateExternalAccount = new
|
|
72
|
+
// const $privateExternalAccount = new ProviderPrivateExternalAccount({ bridge });
|
|
73
73
|
// providerHub
|
|
74
74
|
const $onekey = Object.assign(Object.assign({}, window.$onekey), { jsBridge: bridge, $private,
|
|
75
|
-
$privateExternalAccount,
|
|
75
|
+
// $privateExternalAccount,
|
|
76
76
|
ethereum,
|
|
77
|
-
solana,
|
|
78
|
-
starcoin,
|
|
77
|
+
solana,
|
|
78
|
+
// starcoin,
|
|
79
|
+
aptos: martian, conflux,
|
|
79
80
|
tron, sollet: null, sui,
|
|
80
81
|
cardano,
|
|
81
82
|
cosmos,
|
|
@@ -108,7 +109,7 @@ function injectWeb3Provider() {
|
|
|
108
109
|
}
|
|
109
110
|
(0, cross_inpage_provider_core_1.defineWindowProperty)('solana', solana);
|
|
110
111
|
(0, cross_inpage_provider_core_1.defineWindowProperty)('phantom', { solana });
|
|
111
|
-
|
|
112
|
+
// defineWindowProperty('starcoin', starcoin);
|
|
112
113
|
(0, cross_inpage_provider_core_1.defineWindowProperty)('aptos', martian);
|
|
113
114
|
(0, cross_inpage_provider_core_1.defineWindowProperty)('petra', martian, { enumerable: true });
|
|
114
115
|
(0, cross_inpage_provider_core_1.defineWindowProperty)('martian', martianProxy, { enumerable: true });
|