@tomo-inc/inject-providers 0.0.15 → 0.0.17

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/index.cjs CHANGED
@@ -35,13 +35,12 @@ var __spreadValues = (a, b) => {
35
35
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
36
36
 
37
37
  // src/utils/dapp-info.ts
38
- var $ = document.querySelector.bind(document);
39
38
  async function getDappInfo() {
40
39
  var _a;
41
40
  return {
42
41
  origin: (_a = window.top) == null ? void 0 : _a.location.origin,
43
42
  // host: window.location.hostname,
44
- favicon: await getSiteIcon(),
43
+ favicon: await getSiteIcon(window),
45
44
  title: getSiteName(window),
46
45
  desc: getSiteDesc(window)
47
46
  };
@@ -82,13 +81,17 @@ function getSiteDesc(windowObject) {
82
81
  }
83
82
  async function getSiteIcon(windowObject) {
84
83
  var _a, _b;
85
- const icon = ((_a = $('head > link[rel~="icon"]')) == null ? void 0 : _a.href) || ((_b = $('head > meta[itemprop="image"]')) == null ? void 0 : _b.content);
84
+ const doc = windowObject.document;
85
+ const icon = ((_a = doc.querySelector('head > link[rel~="icon"]')) == null ? void 0 : _a.href) || ((_b = doc.querySelector('head > meta[itemprop="image"]')) == null ? void 0 : _b.content);
86
86
  if (!icon) {
87
87
  return "";
88
88
  }
89
- const isOK = await imgExists(icon);
90
- if (isOK) {
91
- return icon;
89
+ try {
90
+ const isOK = await imgExists(icon);
91
+ if (isOK) {
92
+ return icon;
93
+ }
94
+ } catch (e) {
92
95
  }
93
96
  return "";
94
97
  }
@@ -1036,7 +1039,7 @@ var EvmProvider = class extends events.EventEmitter {
1036
1039
  if (method2 in connectFuns && connectFuns[method2]) {
1037
1040
  this._handleAccountsChanged(data || [], true);
1038
1041
  }
1039
- if (method2 === "wallet_switchEthereumChain" || method2 === "eth_chainId") {
1042
+ if (method2 === "wallet_switchEthereumChain") {
1040
1043
  this._handleChainChanged({ chainId: data, isConnected: true });
1041
1044
  }
1042
1045
  return data;
@@ -1574,6 +1577,9 @@ var PhantomProvider = class extends events.EventEmitter {
1574
1577
  );
1575
1578
  };
1576
1579
  this.getAccount = async () => {
1580
+ if (this.publicKey) {
1581
+ return { publicKey: this.publicKey, address: this.publicKey.toBase58() };
1582
+ }
1577
1583
  return this._request({
1578
1584
  method: "getAccount",
1579
1585
  params: {}
@@ -1660,7 +1666,8 @@ Resources:`;
1660
1666
  }
1661
1667
  },
1662
1668
  (data) => {
1663
- return hexToTx(data.signature);
1669
+ const hex = typeof data === "string" ? data : data.signature;
1670
+ return hexToTx(hex);
1664
1671
  }
1665
1672
  );
1666
1673
  };
@@ -1690,9 +1697,10 @@ Resources:`;
1690
1697
  }
1691
1698
  },
1692
1699
  (data) => {
1693
- if (data && data.signature) {
1694
- const signature = bs58__default.default.decode(data.signature);
1695
- data = __spreadValues(__spreadValues({}, data), { signature });
1700
+ const sig = typeof data === "string" ? data : data == null ? void 0 : data.signature;
1701
+ if (sig) {
1702
+ const signature = bs58__default.default.decode(sig);
1703
+ return { signature };
1696
1704
  }
1697
1705
  return data;
1698
1706
  }
package/dist/index.js CHANGED
@@ -29,13 +29,12 @@ var __spreadValues = (a, b) => {
29
29
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
30
30
 
31
31
  // src/utils/dapp-info.ts
32
- var $ = document.querySelector.bind(document);
33
32
  async function getDappInfo() {
34
33
  var _a;
35
34
  return {
36
35
  origin: (_a = window.top) == null ? void 0 : _a.location.origin,
37
36
  // host: window.location.hostname,
38
- favicon: await getSiteIcon(),
37
+ favicon: await getSiteIcon(window),
39
38
  title: getSiteName(window),
40
39
  desc: getSiteDesc(window)
41
40
  };
@@ -76,13 +75,17 @@ function getSiteDesc(windowObject) {
76
75
  }
77
76
  async function getSiteIcon(windowObject) {
78
77
  var _a, _b;
79
- const icon = ((_a = $('head > link[rel~="icon"]')) == null ? void 0 : _a.href) || ((_b = $('head > meta[itemprop="image"]')) == null ? void 0 : _b.content);
78
+ const doc = windowObject.document;
79
+ const icon = ((_a = doc.querySelector('head > link[rel~="icon"]')) == null ? void 0 : _a.href) || ((_b = doc.querySelector('head > meta[itemprop="image"]')) == null ? void 0 : _b.content);
80
80
  if (!icon) {
81
81
  return "";
82
82
  }
83
- const isOK = await imgExists(icon);
84
- if (isOK) {
85
- return icon;
83
+ try {
84
+ const isOK = await imgExists(icon);
85
+ if (isOK) {
86
+ return icon;
87
+ }
88
+ } catch (e) {
86
89
  }
87
90
  return "";
88
91
  }
@@ -1030,7 +1033,7 @@ var EvmProvider = class extends EventEmitter {
1030
1033
  if (method2 in connectFuns && connectFuns[method2]) {
1031
1034
  this._handleAccountsChanged(data || [], true);
1032
1035
  }
1033
- if (method2 === "wallet_switchEthereumChain" || method2 === "eth_chainId") {
1036
+ if (method2 === "wallet_switchEthereumChain") {
1034
1037
  this._handleChainChanged({ chainId: data, isConnected: true });
1035
1038
  }
1036
1039
  return data;
@@ -1568,6 +1571,9 @@ var PhantomProvider = class extends EventEmitter {
1568
1571
  );
1569
1572
  };
1570
1573
  this.getAccount = async () => {
1574
+ if (this.publicKey) {
1575
+ return { publicKey: this.publicKey, address: this.publicKey.toBase58() };
1576
+ }
1571
1577
  return this._request({
1572
1578
  method: "getAccount",
1573
1579
  params: {}
@@ -1654,7 +1660,8 @@ Resources:`;
1654
1660
  }
1655
1661
  },
1656
1662
  (data) => {
1657
- return hexToTx(data.signature);
1663
+ const hex = typeof data === "string" ? data : data.signature;
1664
+ return hexToTx(hex);
1658
1665
  }
1659
1666
  );
1660
1667
  };
@@ -1684,9 +1691,10 @@ Resources:`;
1684
1691
  }
1685
1692
  },
1686
1693
  (data) => {
1687
- if (data && data.signature) {
1688
- const signature = bs58.decode(data.signature);
1689
- data = __spreadValues(__spreadValues({}, data), { signature });
1694
+ const sig = typeof data === "string" ? data : data == null ? void 0 : data.signature;
1695
+ if (sig) {
1696
+ const signature = bs58.decode(sig);
1697
+ return { signature };
1690
1698
  }
1691
1699
  return data;
1692
1700
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomo-inc/inject-providers",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "author": "tomo.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -25,12 +25,13 @@
25
25
  "json-rpc-middleware-stream": "^3.0.0",
26
26
  "tronweb": "^6.0.3",
27
27
  "viem": "^2.38.3",
28
- "@tomo-inc/wallet-utils": "0.0.17"
28
+ "@tomo-inc/wallet-utils": "0.0.19"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^20.0.0",
32
32
  "@types/supertest": "^2.0.12",
33
33
  "@vitest/browser": "^3.2.4",
34
+ "@vitest/coverage-v8": "^3.2.4",
34
35
  "playwright": "^1.44.1",
35
36
  "supertest": "^6.3.0",
36
37
  "tsup": "^8.0.0",
package/project.json CHANGED
@@ -50,7 +50,7 @@
50
50
  "executor": "nx:run-commands",
51
51
  "outputs": ["{projectRoot}/coverage"],
52
52
  "options": {
53
- "command": "vitest run",
53
+ "command": "vitest run --coverage",
54
54
  "cwd": "packages/inject-providers"
55
55
  }
56
56
  },