@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.
- package/lib/ton-connect.d.ts +1 -1
- package/lib/ton-connect.js +1 -1
- package/lib/utils/options.js +1 -1
- package/lib/utils/web-api.js +48 -2
- package/package.json +2 -2
package/lib/ton-connect.d.ts
CHANGED
package/lib/ton-connect.js
CHANGED
|
@@ -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
|
|
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);
|
package/lib/utils/options.js
CHANGED
|
@@ -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)(
|
|
13
|
+
return (0, deepmerge_1.default)(defaultOptions, options, { arrayMerge: overwriteMerge });
|
|
14
14
|
}
|
|
15
15
|
exports.mergeOptions = mergeOptions;
|
package/lib/utils/web-api.js
CHANGED
|
@@ -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.
|
|
7
|
-
icon: (
|
|
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.
|
|
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.
|
|
29
|
+
"@tonconnect/protocol": "^0.0.6"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"lib"
|