@tonconnect/sdk 0.0.5 → 0.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.
@@ -26,7 +26,7 @@ export declare class TonConnect implements ITonConnect {
26
26
  get wallet(): Wallet | null;
27
27
  private set wallet(value);
28
28
  constructor(options?: {
29
- dappMetedata?: DappMetadata;
29
+ dappMetedata?: Partial<DappMetadata>;
30
30
  storage?: IStorage;
31
31
  });
32
32
  /**
@@ -24,7 +24,7 @@ var TonConnect = /** @class */ (function () {
24
24
  */
25
25
  this.isInjectedProviderAvailable = injected_provider_1.InjectedProvider.isWalletInjected;
26
26
  this.dappSettings = {
27
- metadata: (options === null || options === void 0 ? void 0 : options.dappMetedata) || (0, web_api_1.getWebPageMetadata)(),
27
+ metadata: (0, options_1.mergeOptions)(options === null || options === void 0 ? void 0 : options.dappMetedata, (0, web_api_1.getWebPageMetadata)()),
28
28
  storage: (options === null || options === void 0 ? void 0 : options.storage) || new default_storage_1.DefaultStorage()
29
29
  };
30
30
  this.bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(this.dappSettings.storage);
@@ -10,6 +10,6 @@ function mergeOptions(options, defaultOptions) {
10
10
  var overwriteMerge = function (_, sourceArray, __) {
11
11
  return sourceArray;
12
12
  };
13
- return (0, deepmerge_1.default)(options, defaultOptions, { arrayMerge: overwriteMerge });
13
+ return (0, deepmerge_1.default)(defaultOptions, options, { arrayMerge: overwriteMerge });
14
14
  }
15
15
  exports.mergeOptions = mergeOptions;
@@ -3,9 +3,55 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getWebPageMetadata = void 0;
4
4
  function getWebPageMetadata() {
5
5
  return {
6
- url: (window === null || window === void 0 ? void 0 : window.location.href) || '',
7
- icon: (window === null || window === void 0 ? void 0 : window.location.origin) ? (window === null || window === void 0 ? void 0 : window.location.origin) + '/favicon.ico' : '',
6
+ url: (window === null || window === void 0 ? void 0 : window.location.origin) || '',
7
+ icon: getIconUrl(),
8
8
  name: (document === null || document === void 0 ? void 0 : document.title) || 'Unknown dapp'
9
9
  };
10
10
  }
11
11
  exports.getWebPageMetadata = getWebPageMetadata;
12
+ function getIconUrl() {
13
+ var appleTouchIcons = document.querySelectorAll("link[rel='apple-touch-icon']");
14
+ if (appleTouchIcons === null || appleTouchIcons === void 0 ? void 0 : appleTouchIcons.length) {
15
+ return getLargestSizeIconUrl(Array.from(appleTouchIcons));
16
+ }
17
+ var links = Array.from(document.querySelectorAll("link[rel*='icon']"));
18
+ var pngLinks = links.filter(function (link) { return link.href.endsWith('.png'); });
19
+ if (pngLinks.length) {
20
+ return getLargestSizeIconUrl(pngLinks);
21
+ }
22
+ var icoIcon = links.filter(function (link) { return link.href.endsWith('.ico'); })[0];
23
+ return (icoIcon === null || icoIcon === void 0 ? void 0 : icoIcon.href) || '';
24
+ }
25
+ function getLargestSizeIconUrl(links) {
26
+ var parsedLinks = links.map(parseIconLink);
27
+ var maxSizeIcon = parsedLinks.sort(function (a, b) { return (b.size > a.size ? 1 : -1); })[0];
28
+ return (maxSizeIcon === null || maxSizeIcon === void 0 ? void 0 : maxSizeIcon.href) || '';
29
+ }
30
+ function parseIconLink(link) {
31
+ var _a;
32
+ if (!((_a = link.sizes) === null || _a === void 0 ? void 0 : _a.value)) {
33
+ return {
34
+ href: link.href,
35
+ size: 0
36
+ };
37
+ }
38
+ var sizes = Array.from(link.sizes)
39
+ .map(function (size) {
40
+ var groups = size.match(/(\d+)x(\d+)/i);
41
+ if (!groups || !groups[1] || !groups[2]) {
42
+ return undefined;
43
+ }
44
+ return parseInt(groups[1]) * parseInt(groups[2]);
45
+ })
46
+ .filter(function (item) { return !!item; });
47
+ if (sizes.length === 0) {
48
+ return {
49
+ href: link.href,
50
+ size: 0
51
+ };
52
+ }
53
+ return {
54
+ href: link.href,
55
+ size: Math.max.apply(Math, sizes)
56
+ };
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonconnect/sdk",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "scripts": {
5
5
  "build": "npx rimraf lib && ttsc",
6
6
  "build:production": "npx rimraf lib && ttsc --sourceMap false"
@@ -26,7 +26,7 @@
26
26
  "dependencies": {
27
27
  "deepmerge": "^4.2.2",
28
28
  "tweetnacl": "^1.0.3",
29
- "@tonconnect/protocol": "^0.0.5"
29
+ "@tonconnect/protocol": "^0.0.6"
30
30
  },
31
31
  "files": [
32
32
  "lib"