@tonconnect/sdk 0.0.14 → 0.0.16
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/README.md +4 -30
- package/lib/models/wallet/index.d.ts +1 -1
- package/lib/models/wallet/index.js +3 -0
- package/lib/models/wallet/wallet-connection-source.d.ts +1 -1
- package/lib/models/wallet/wallet-info.d.ts +31 -0
- package/lib/models/wallet/wallet-info.js +7 -0
- package/lib/models/wallet/wallet.d.ts +1 -1
- package/lib/provider/bridge/bridge-provider.js +1 -3
- package/lib/provider/injected/injected-provider.d.ts +1 -0
- package/lib/provider/injected/injected-provider.js +9 -5
- package/lib/provider/injected/models/injected-wallet-api.d.ts +1 -0
- package/lib/ton-connect.d.ts +4 -6
- package/lib/ton-connect.interface.d.ts +3 -10
- package/lib/ton-connect.js +9 -27
- package/lib/wallets-list-manager.d.ts +4 -11
- package/lib/wallets-list-manager.js +41 -68
- package/package.json +2 -2
- package/lib/models/wallet/wallet-config.d.ts +0 -28
- package/lib/models/wallet/wallet-config.js +0 -2
package/README.md
CHANGED
|
@@ -33,9 +33,9 @@ connector.onStatusChange(
|
|
|
33
33
|
TonConnect is build to support different wallets. You can fetch all supported wallets list and show a custom wallet selection dialog for user
|
|
34
34
|
|
|
35
35
|
```ts
|
|
36
|
-
const
|
|
36
|
+
const walletsList = await connector.getWallets();
|
|
37
37
|
|
|
38
|
-
/*
|
|
38
|
+
/* walletsList is
|
|
39
39
|
{
|
|
40
40
|
name: string;
|
|
41
41
|
imageUrl: string;
|
|
@@ -44,38 +44,12 @@ const { allWalletsList, injectedWalletsList, remoteConnectionWalletsList } = awa
|
|
|
44
44
|
universalLinkBase?: string;
|
|
45
45
|
bridgeUrl?: string;
|
|
46
46
|
jsBridgeKey?: string;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
injectedWalletsList is (all injected to the page available wallets)
|
|
50
|
-
{
|
|
51
|
-
name: string;
|
|
52
|
-
imageUrl: string;
|
|
53
|
-
tondns?: string;
|
|
54
|
-
aboutUrl: string;
|
|
55
|
-
jsBridgeKey: string;
|
|
56
|
-
}[]
|
|
57
|
-
|
|
58
|
-
remoteConnectionWalletsList is (all wallets available via http bridge (QR code))
|
|
59
|
-
{
|
|
60
|
-
name: string;
|
|
61
|
-
imageUrl: string;
|
|
62
|
-
tondns?: string;
|
|
63
|
-
aboutUrl: string;
|
|
64
|
-
universalLinkBase: string;
|
|
65
|
-
bridgeUrl: string;
|
|
47
|
+
injected?: boolean; // true if this wallet is injected to the webpage
|
|
48
|
+
embedded?: boolean; // true if dapp is opened inside this wallet's browser
|
|
66
49
|
}[]
|
|
67
50
|
*/
|
|
68
51
|
```
|
|
69
52
|
|
|
70
|
-
### Check if your app is opened inside some wallet's browser
|
|
71
|
-
|
|
72
|
-
If your app is opened inside some wallet's browser you shouldn't show a wallet selection dialog. Just connect dapp to the host-wallet when 'connect' button is clicked
|
|
73
|
-
|
|
74
|
-
```ts
|
|
75
|
-
const walletConnectionSourceOrNull = await connector.inWhichWalletBrowser();
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
|
|
79
53
|
## Initialize a wallet connection when user clicks to 'connect' button in your app
|
|
80
54
|
### Initialize a remote wallet connection via universal link
|
|
81
55
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { Account } from './account';
|
|
2
2
|
export type { Wallet } from './wallet';
|
|
3
3
|
export type { WalletConnectionSource } from './wallet-connection-source';
|
|
4
|
-
export
|
|
4
|
+
export { WalletInfo, WalletInfoInjected, WalletInfoRemote, isWalletInfoInjected } from './wallet-info';
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isWalletInfoInjected = void 0;
|
|
4
|
+
var wallet_info_1 = require("./wallet-info");
|
|
5
|
+
Object.defineProperty(exports, "isWalletInfoInjected", { enumerable: true, get: function () { return wallet_info_1.isWalletInfoInjected; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare type WalletConnectionSource = WalletConnectionSourceHTTP | WalletConnectionSourceJS;
|
|
2
2
|
export interface WalletConnectionSourceHTTP {
|
|
3
|
-
|
|
3
|
+
universalLink: string;
|
|
4
4
|
bridgeUrl: string;
|
|
5
5
|
}
|
|
6
6
|
export interface WalletConnectionSourceJS {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface WalletInfoBase {
|
|
2
|
+
name: string;
|
|
3
|
+
imageUrl: string;
|
|
4
|
+
tondns?: string;
|
|
5
|
+
aboutUrl: string;
|
|
6
|
+
}
|
|
7
|
+
export interface WalletInfoRemote extends WalletInfoBase {
|
|
8
|
+
universalLink: string;
|
|
9
|
+
bridgeUrl: string;
|
|
10
|
+
}
|
|
11
|
+
export interface WalletInfoInjected extends WalletInfoBase {
|
|
12
|
+
jsBridgeKey: string;
|
|
13
|
+
injected: boolean;
|
|
14
|
+
embedded: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare type WalletInfo = WalletInfoRemote | WalletInfoInjected | (WalletInfoRemote & WalletInfoInjected);
|
|
17
|
+
export interface WalletInfoDTOBase {
|
|
18
|
+
name: string;
|
|
19
|
+
image: string;
|
|
20
|
+
tondns?: string;
|
|
21
|
+
about_url: string;
|
|
22
|
+
}
|
|
23
|
+
export interface WalletInfoRemoteDTO extends WalletInfoDTOBase {
|
|
24
|
+
universal_url: string;
|
|
25
|
+
bridge_url: string;
|
|
26
|
+
}
|
|
27
|
+
export interface WalletInfoInjectedDTO extends WalletInfoDTOBase {
|
|
28
|
+
js_bridge_key: string;
|
|
29
|
+
}
|
|
30
|
+
export declare type WalletInfoDTO = WalletInfoRemoteDTO | WalletInfoInjectedDTO | (WalletInfoRemoteDTO & WalletInfoInjectedDTO);
|
|
31
|
+
export declare function isWalletInfoInjected(value: WalletInfo): value is WalletInfoInjected;
|
|
@@ -7,7 +7,6 @@ var ton_connect_error_1 = require("../../errors/ton-connect.error");
|
|
|
7
7
|
var bridge_gateway_1 = require("./bridge-gateway");
|
|
8
8
|
var bridge_connection_storage_1 = require("../../storage/bridge-connection-storage");
|
|
9
9
|
var protocol = tslib_1.__importStar(require("../../resources/protocol.json"));
|
|
10
|
-
var url_1 = require("../../utils/url");
|
|
11
10
|
var BridgeProvider = /** @class */ (function () {
|
|
12
11
|
function BridgeProvider(storage, walletConnectionSource) {
|
|
13
12
|
this.storage = storage;
|
|
@@ -175,8 +174,7 @@ var BridgeProvider = /** @class */ (function () {
|
|
|
175
174
|
});
|
|
176
175
|
};
|
|
177
176
|
BridgeProvider.prototype.generateUniversalLink = function (message) {
|
|
178
|
-
var
|
|
179
|
-
var url = new URL(urlString);
|
|
177
|
+
var url = new URL(this.walletConnectionSource.universalLink);
|
|
180
178
|
url.searchParams.append('v', protocol.version.toString());
|
|
181
179
|
url.searchParams.append('id', this.session.sessionCrypto.sessionId);
|
|
182
180
|
url.searchParams.append('r', protocol_1.Base64.encode(JSON.stringify(message), true));
|
|
@@ -18,6 +18,7 @@ export declare class InjectedProvider<T extends string = string> implements Inte
|
|
|
18
18
|
restoreConnection(): Promise<void>;
|
|
19
19
|
closeConnection(): void;
|
|
20
20
|
disconnect(): Promise<void>;
|
|
21
|
+
private closeAllListeners;
|
|
21
22
|
listen(eventsCallback: (e: WalletEvent) => void): () => void;
|
|
22
23
|
sendRequest<T extends RpcMethod>(request: WithoutId<AppRequest<T>>): Promise<WithoutId<WalletResponse<T>>>;
|
|
23
24
|
private makeSubscriptions;
|
|
@@ -96,17 +96,21 @@ var InjectedProvider = /** @class */ (function () {
|
|
|
96
96
|
});
|
|
97
97
|
};
|
|
98
98
|
InjectedProvider.prototype.closeConnection = function () {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
if (this.listenSubscriptions) {
|
|
100
|
+
this.injectedWallet.disconnect();
|
|
101
|
+
}
|
|
102
|
+
this.closeAllListeners();
|
|
103
103
|
};
|
|
104
104
|
InjectedProvider.prototype.disconnect = function () {
|
|
105
|
+
this.closeAllListeners();
|
|
106
|
+
this.injectedWallet.disconnect();
|
|
107
|
+
return Promise.resolve();
|
|
108
|
+
};
|
|
109
|
+
InjectedProvider.prototype.closeAllListeners = function () {
|
|
105
110
|
var _a;
|
|
106
111
|
this.listenSubscriptions = false;
|
|
107
112
|
this.listeners = [];
|
|
108
113
|
(_a = this.unsubscribeCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
109
|
-
return Promise.resolve();
|
|
110
114
|
};
|
|
111
115
|
InjectedProvider.prototype.listen = function (eventsCallback) {
|
|
112
116
|
var _this = this;
|
package/lib/ton-connect.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { TonConnectError } from "./errors/ton-connect.error";
|
|
2
|
-
import { Account, DappMetadata, Wallet, WalletConnectionSource } from "./models";
|
|
2
|
+
import { Account, DappMetadata, Wallet, WalletConnectionSource, WalletInfo } from "./models";
|
|
3
3
|
import { SendTransactionRequest, SendTransactionResponse } from "./models/methods";
|
|
4
4
|
import { ConnectAdditionalRequest } from "./models/methods/connect/connect-additional-request";
|
|
5
|
-
import { JSBridgeWalletConfig } from "./models/wallet/wallet-config";
|
|
6
5
|
import { WalletConnectionSourceJS } from "./models/wallet/wallet-connection-source";
|
|
7
6
|
import { IStorage } from "./storage/models/storage.interface";
|
|
8
7
|
import { ITonConnect } from "./ton-connect.interface";
|
|
9
|
-
import { WalletsListManager } from "./wallets-list-manager";
|
|
10
8
|
export declare class TonConnect implements ITonConnect {
|
|
11
|
-
walletsList
|
|
9
|
+
private readonly walletsList;
|
|
12
10
|
private readonly dappSettings;
|
|
13
11
|
private readonly bridgeConnectionStorage;
|
|
14
12
|
private _wallet;
|
|
@@ -33,9 +31,9 @@ export declare class TonConnect implements ITonConnect {
|
|
|
33
31
|
storage?: IStorage;
|
|
34
32
|
});
|
|
35
33
|
/**
|
|
36
|
-
*
|
|
34
|
+
* Returns available wallets list.
|
|
37
35
|
*/
|
|
38
|
-
|
|
36
|
+
getWallets(): Promise<WalletInfo[]>;
|
|
39
37
|
/**
|
|
40
38
|
* Allows to subscribe to connection status changes and handle connection errors.
|
|
41
39
|
* @param callback will be called after connections status changes with actual wallet or null.
|
|
@@ -2,7 +2,7 @@ import { TonConnectError } from "./errors";
|
|
|
2
2
|
import { Account, WalletConnectionSource, Wallet } from "./models";
|
|
3
3
|
import { SendTransactionRequest, SendTransactionResponse } from "./models/methods";
|
|
4
4
|
import { ConnectAdditionalRequest } from "./models/methods/connect/connect-additional-request";
|
|
5
|
-
import {
|
|
5
|
+
import { WalletInfo } from "./models/wallet/wallet-info";
|
|
6
6
|
import { WalletConnectionSourceJS } from "./models/wallet/wallet-connection-source";
|
|
7
7
|
export interface ITonConnect {
|
|
8
8
|
/**
|
|
@@ -18,16 +18,9 @@ export interface ITonConnect {
|
|
|
18
18
|
*/
|
|
19
19
|
wallet: Wallet | null;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Returns available wallets list.
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
|
-
getWalletsList: () => Promise<WalletConfig[]>;
|
|
25
|
-
getInjectedWalletsList: () => Promise<JSBridgeWalletConfig[]>;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* If app is opened in some wallet's browser returns that wallet config. Else returns null;
|
|
29
|
-
*/
|
|
30
|
-
inWhichWalletBrowser(): Promise<JSBridgeWalletConfig | null>;
|
|
23
|
+
getWallets(): Promise<WalletInfo[]>;
|
|
31
24
|
/**
|
|
32
25
|
* Allows to subscribe to connection status changes and handle connection errors.
|
|
33
26
|
* @param callback will be called after connections status changes with actual wallet or null.
|
package/lib/ton-connect.js
CHANGED
|
@@ -65,26 +65,10 @@ var TonConnect = /** @class */ (function () {
|
|
|
65
65
|
configurable: true
|
|
66
66
|
});
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
68
|
+
* Returns available wallets list.
|
|
69
69
|
*/
|
|
70
|
-
TonConnect.prototype.
|
|
71
|
-
return
|
|
72
|
-
var injectedWalletsList;
|
|
73
|
-
return tslib_1.__generator(this, function (_a) {
|
|
74
|
-
switch (_a.label) {
|
|
75
|
-
case 0: return [4 /*yield*/, this.walletsList.getInjectedWalletsList()];
|
|
76
|
-
case 1:
|
|
77
|
-
injectedWalletsList = _a.sent();
|
|
78
|
-
if (injectedWalletsList.length !== 1) {
|
|
79
|
-
return [2 /*return*/, null];
|
|
80
|
-
}
|
|
81
|
-
if (!injected_provider_1.InjectedProvider.isInsideWalletBrowser(injectedWalletsList[0].jsBridgeKey)) {
|
|
82
|
-
return [2 /*return*/, null];
|
|
83
|
-
}
|
|
84
|
-
return [2 /*return*/, injectedWalletsList[0]];
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
70
|
+
TonConnect.prototype.getWallets = function () {
|
|
71
|
+
return this.walletsList.getWallets();
|
|
88
72
|
};
|
|
89
73
|
/**
|
|
90
74
|
* Allows to subscribe to connection status changes and handle connection errors.
|
|
@@ -119,15 +103,15 @@ var TonConnect = /** @class */ (function () {
|
|
|
119
103
|
*/
|
|
120
104
|
TonConnect.prototype.restoreConnection = function () {
|
|
121
105
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
122
|
-
var _a, bridgeConnectionType,
|
|
106
|
+
var _a, bridgeConnectionType, embeddedWallet, _b, _c, _d, _e;
|
|
123
107
|
return tslib_1.__generator(this, function (_f) {
|
|
124
108
|
switch (_f.label) {
|
|
125
109
|
case 0: return [4 /*yield*/, Promise.all([
|
|
126
110
|
this.bridgeConnectionStorage.storedConnectionType(),
|
|
127
|
-
this.walletsList.
|
|
111
|
+
this.walletsList.getEmbeddedWallet()
|
|
128
112
|
])];
|
|
129
113
|
case 1:
|
|
130
|
-
_a = _f.sent(), bridgeConnectionType = _a[0],
|
|
114
|
+
_a = _f.sent(), bridgeConnectionType = _a[0], embeddedWallet = _a[1];
|
|
131
115
|
_b = bridgeConnectionType;
|
|
132
116
|
switch (_b) {
|
|
133
117
|
case 'http': return [3 /*break*/, 2];
|
|
@@ -147,12 +131,10 @@ var TonConnect = /** @class */ (function () {
|
|
|
147
131
|
_d.provider = _f.sent();
|
|
148
132
|
return [3 /*break*/, 9];
|
|
149
133
|
case 6:
|
|
150
|
-
if (!
|
|
151
|
-
// DApp probably opened in the wallet's browser. Should try smart auto connect
|
|
134
|
+
if (!embeddedWallet) return [3 /*break*/, 8];
|
|
152
135
|
_e = this;
|
|
153
|
-
return [4 /*yield*/, this.createProvider(
|
|
136
|
+
return [4 /*yield*/, this.createProvider(embeddedWallet)];
|
|
154
137
|
case 7:
|
|
155
|
-
// DApp probably opened in the wallet's browser. Should try smart auto connect
|
|
156
138
|
_e.provider = _f.sent();
|
|
157
139
|
return [3 /*break*/, 9];
|
|
158
140
|
case 8: return [2 /*return*/];
|
|
@@ -246,7 +228,7 @@ var TonConnect = /** @class */ (function () {
|
|
|
246
228
|
};
|
|
247
229
|
if (tonProofItem) {
|
|
248
230
|
wallet.connectItems = {
|
|
249
|
-
tonProof: tonProofItem.
|
|
231
|
+
tonProof: tonProofItem.proof
|
|
250
232
|
};
|
|
251
233
|
}
|
|
252
234
|
this.wallet = wallet;
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WalletInfoInjected, WalletInfo } from "./models/wallet/wallet-info";
|
|
2
2
|
export declare class WalletsListManager {
|
|
3
3
|
private walletsListCache;
|
|
4
4
|
private readonly walletsListSource;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
getWalletsConfig(): Promise<{
|
|
9
|
-
allWalletsList: WalletConfig[];
|
|
10
|
-
injectedWalletsList: JSBridgeWalletConfig[];
|
|
11
|
-
remoteConnectionWalletsList: HTTPBridgeWalletConfig[];
|
|
12
|
-
}>;
|
|
5
|
+
getWallets(): Promise<WalletInfo[]>;
|
|
6
|
+
getEmbeddedWallet(): Promise<WalletInfoInjected | null>;
|
|
7
|
+
private fetchWalletsList;
|
|
13
8
|
private walletConfigDTOListToWalletConfigList;
|
|
14
9
|
private isCorrectWalletConfigDTO;
|
|
15
|
-
private isInjectedWallet;
|
|
16
|
-
private isRemoteConnectionWallet;
|
|
17
10
|
}
|
|
@@ -3,87 +3,65 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WalletsListManager = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var fetch_wallets_error_1 = require("./errors/wallets-manager/fetch-wallets.error");
|
|
6
|
+
var wallet_info_1 = require("./models/wallet/wallet-info");
|
|
6
7
|
var injected_provider_1 = require("./provider/injected/injected-provider");
|
|
7
8
|
var WalletsListManager = /** @class */ (function () {
|
|
8
9
|
function WalletsListManager() {
|
|
9
10
|
this.walletsListCache = null;
|
|
10
11
|
this.walletsListSource = 'https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json';
|
|
11
12
|
}
|
|
12
|
-
WalletsListManager.prototype.
|
|
13
|
+
WalletsListManager.prototype.getWallets = function () {
|
|
13
14
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
14
|
-
var walletsResponse, walletsList, e_1;
|
|
15
15
|
var _this = this;
|
|
16
16
|
return tslib_1.__generator(this, function (_a) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return [2 /*return*/, this.walletsListCache];
|
|
21
|
-
}
|
|
22
|
-
_a.label = 1;
|
|
23
|
-
case 1:
|
|
24
|
-
_a.trys.push([1, 4, , 5]);
|
|
25
|
-
return [4 /*yield*/, fetch(this.walletsListSource)];
|
|
26
|
-
case 2:
|
|
27
|
-
walletsResponse = _a.sent();
|
|
28
|
-
return [4 /*yield*/, walletsResponse.json()];
|
|
29
|
-
case 3:
|
|
30
|
-
walletsList = _a.sent();
|
|
31
|
-
if (!Array.isArray(walletsList) ||
|
|
32
|
-
!walletsList.every(function (wallet) { return _this.isCorrectWalletConfigDTO(wallet); })) {
|
|
33
|
-
throw new fetch_wallets_error_1.FetchWalletsError('Wrong wallets list format');
|
|
34
|
-
}
|
|
35
|
-
this.walletsListCache = this.walletConfigDTOListToWalletConfigList(walletsList);
|
|
36
|
-
return [2 /*return*/, this.walletsListCache];
|
|
37
|
-
case 4:
|
|
38
|
-
e_1 = _a.sent();
|
|
39
|
-
throw new fetch_wallets_error_1.FetchWalletsError(e_1);
|
|
40
|
-
case 5: return [2 /*return*/];
|
|
17
|
+
if (!this.walletsListCache) {
|
|
18
|
+
this.walletsListCache = this.fetchWalletsList();
|
|
19
|
+
this.walletsListCache.catch(function () { return (_this.walletsListCache = null); });
|
|
41
20
|
}
|
|
21
|
+
return [2 /*return*/, this.walletsListCache];
|
|
42
22
|
});
|
|
43
23
|
});
|
|
44
24
|
};
|
|
45
|
-
WalletsListManager.prototype.
|
|
25
|
+
WalletsListManager.prototype.getEmbeddedWallet = function () {
|
|
46
26
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var walletsList;
|
|
27
|
+
var walletsList, injectedWallets;
|
|
48
28
|
return tslib_1.__generator(this, function (_a) {
|
|
49
29
|
switch (_a.label) {
|
|
50
|
-
case 0: return [4 /*yield*/, this.
|
|
30
|
+
case 0: return [4 /*yield*/, this.getWallets()];
|
|
51
31
|
case 1:
|
|
52
|
-
walletsList =
|
|
53
|
-
|
|
32
|
+
walletsList = _a.sent();
|
|
33
|
+
injectedWallets = walletsList.filter(wallet_info_1.isWalletInfoInjected);
|
|
34
|
+
if (injectedWallets.length !== 1) {
|
|
35
|
+
return [2 /*return*/, null];
|
|
36
|
+
}
|
|
37
|
+
return [2 /*return*/, injectedWallets[0]];
|
|
54
38
|
}
|
|
55
39
|
});
|
|
56
40
|
});
|
|
57
41
|
};
|
|
58
|
-
WalletsListManager.prototype.
|
|
42
|
+
WalletsListManager.prototype.fetchWalletsList = function () {
|
|
59
43
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
44
|
+
var walletsResponse, walletsList, e_1;
|
|
45
|
+
var _this = this;
|
|
60
46
|
return tslib_1.__generator(this, function (_a) {
|
|
61
47
|
switch (_a.label) {
|
|
62
|
-
case 0:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
WalletsListManager.prototype.getWalletsConfig = function () {
|
|
69
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
70
|
-
var allWalletsList, _a, injectedWalletsList, remoteConnectionWalletsList;
|
|
71
|
-
return tslib_1.__generator(this, function (_b) {
|
|
72
|
-
switch (_b.label) {
|
|
73
|
-
case 0: return [4 /*yield*/, this.getWalletsList()];
|
|
48
|
+
case 0:
|
|
49
|
+
_a.trys.push([0, 3, , 4]);
|
|
50
|
+
return [4 /*yield*/, fetch(this.walletsListSource)];
|
|
74
51
|
case 1:
|
|
75
|
-
|
|
76
|
-
return [4 /*yield*/,
|
|
77
|
-
this.getInjectedWalletsList(),
|
|
78
|
-
this.getRemoteConnectionWalletsList()
|
|
79
|
-
])];
|
|
52
|
+
walletsResponse = _a.sent();
|
|
53
|
+
return [4 /*yield*/, walletsResponse.json()];
|
|
80
54
|
case 2:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
55
|
+
walletsList = _a.sent();
|
|
56
|
+
if (!Array.isArray(walletsList) ||
|
|
57
|
+
!walletsList.every(function (wallet) { return _this.isCorrectWalletConfigDTO(wallet); })) {
|
|
58
|
+
throw new fetch_wallets_error_1.FetchWalletsError('Wrong wallets list format');
|
|
59
|
+
}
|
|
60
|
+
return [2 /*return*/, this.walletConfigDTOListToWalletConfigList(walletsList)];
|
|
61
|
+
case 3:
|
|
62
|
+
e_1 = _a.sent();
|
|
63
|
+
throw new fetch_wallets_error_1.FetchWalletsError(e_1);
|
|
64
|
+
case 4: return [2 /*return*/];
|
|
87
65
|
}
|
|
88
66
|
});
|
|
89
67
|
});
|
|
@@ -98,11 +76,15 @@ var WalletsListManager = /** @class */ (function () {
|
|
|
98
76
|
};
|
|
99
77
|
if ('bridge_url' in walletConfigDTO) {
|
|
100
78
|
walletConfig.bridgeUrl = walletConfigDTO.bridge_url;
|
|
101
|
-
walletConfig.
|
|
102
|
-
walletConfigDTO.universal_url;
|
|
79
|
+
walletConfig.universalLink = walletConfigDTO.universal_url;
|
|
103
80
|
}
|
|
104
81
|
if ('js_bridge_key' in walletConfigDTO) {
|
|
105
|
-
|
|
82
|
+
var jsBridgeKey = walletConfigDTO.js_bridge_key;
|
|
83
|
+
walletConfig.jsBridgeKey = jsBridgeKey;
|
|
84
|
+
walletConfig.injected =
|
|
85
|
+
injected_provider_1.InjectedProvider.isWalletInjected(jsBridgeKey);
|
|
86
|
+
walletConfig.embedded =
|
|
87
|
+
injected_provider_1.InjectedProvider.isInsideWalletBrowser(jsBridgeKey);
|
|
106
88
|
}
|
|
107
89
|
return walletConfig;
|
|
108
90
|
});
|
|
@@ -120,16 +102,7 @@ var WalletsListManager = /** @class */ (function () {
|
|
|
120
102
|
var containsUniversalUrl = 'universal_url' in value;
|
|
121
103
|
var containsHttpBridge = 'bridge_url' in value;
|
|
122
104
|
var containsJsBridge = 'js_bridge_key' in value;
|
|
123
|
-
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
return true;
|
|
127
|
-
};
|
|
128
|
-
WalletsListManager.prototype.isInjectedWallet = function (wallet) {
|
|
129
|
-
return 'jsBridgeKey' in wallet;
|
|
130
|
-
};
|
|
131
|
-
WalletsListManager.prototype.isRemoteConnectionWallet = function (wallet) {
|
|
132
|
-
return 'bridgeUrl' in wallet;
|
|
105
|
+
return (containsHttpBridge && containsUniversalUrl) || containsJsBridge;
|
|
133
106
|
};
|
|
134
107
|
return WalletsListManager;
|
|
135
108
|
}());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tonconnect/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
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.8"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"lib"
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export interface WalletConfigBase {
|
|
2
|
-
name: string;
|
|
3
|
-
imageUrl: string;
|
|
4
|
-
tondns?: string;
|
|
5
|
-
aboutUrl: string;
|
|
6
|
-
}
|
|
7
|
-
export interface HTTPBridgeWalletConfig extends WalletConfigBase {
|
|
8
|
-
universalLinkBase: string;
|
|
9
|
-
bridgeUrl: string;
|
|
10
|
-
}
|
|
11
|
-
export interface JSBridgeWalletConfig extends WalletConfigBase {
|
|
12
|
-
jsBridgeKey: string;
|
|
13
|
-
}
|
|
14
|
-
export declare type WalletConfig = HTTPBridgeWalletConfig | JSBridgeWalletConfig | (HTTPBridgeWalletConfig & JSBridgeWalletConfig);
|
|
15
|
-
export interface WalletConfigDTOBase {
|
|
16
|
-
name: string;
|
|
17
|
-
image: string;
|
|
18
|
-
tondns?: string;
|
|
19
|
-
about_url: string;
|
|
20
|
-
}
|
|
21
|
-
export interface HTTPBridgeWalletConfigDTO extends WalletConfigDTOBase {
|
|
22
|
-
universal_url: string;
|
|
23
|
-
bridge_url: string;
|
|
24
|
-
}
|
|
25
|
-
export interface JSBridgeWalletConfigDTO extends WalletConfigDTOBase {
|
|
26
|
-
js_bridge_key: string;
|
|
27
|
-
}
|
|
28
|
-
export declare type WalletConfigDTO = HTTPBridgeWalletConfigDTO | JSBridgeWalletConfigDTO | (HTTPBridgeWalletConfigDTO & JSBridgeWalletConfigDTO);
|