@tonconnect/sdk 0.0.21 → 0.0.22
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/errors/dapp/dapp-metadata.error.js +6 -14
- package/lib/errors/index.js +18 -5
- package/lib/errors/protocol/events/connect/user-rejects.error.js +6 -14
- package/lib/errors/protocol/events/index.js +15 -2
- package/lib/errors/protocol/index.js +16 -3
- package/lib/errors/protocol/responses/bad-request.error.js +6 -14
- package/lib/errors/protocol/responses/unknown-app.error.js +6 -14
- package/lib/errors/storage/localstorage-not-found.error.js +6 -14
- package/lib/errors/ton-connect.error.js +5 -13
- package/lib/errors/unknown.error.js +6 -14
- package/lib/errors/wallet/wallet-already-connected.error.js +6 -14
- package/lib/errors/wallet/wallet-not-connected.error.js +6 -14
- package/lib/errors/wallet/wallet-not-injected.error.js +6 -14
- package/lib/errors/wallets-manager/fetch-wallets.error.js +6 -14
- package/lib/index.js +17 -4
- package/lib/models/index.js +16 -3
- package/lib/models/methods/index.js +16 -3
- package/lib/parsers/connect-errors-parser.js +14 -18
- package/lib/parsers/rpc-parser.js +4 -7
- package/lib/parsers/send-transaction-parser.js +19 -26
- package/lib/provider/bridge/bridge-gateway.js +60 -79
- package/lib/provider/bridge/bridge-provider.js +118 -138
- package/lib/provider/injected/injected-provider.js +93 -89
- package/lib/storage/bridge-connection-storage.js +86 -112
- package/lib/storage/default-storage.js +24 -21
- package/lib/storage/http-bridge-gateway-storage.js +28 -32
- package/lib/ton-connect.js +123 -165
- package/lib/utils/options.js +5 -5
- package/lib/utils/web-api.js +10 -10
- package/lib/wallets-list-manager.js +59 -73
- package/package.json +2 -2
|
@@ -1,143 +1,147 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
2
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
35
|
exports.InjectedProvider = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function InjectedProvider(injectedWalletKey) {
|
|
36
|
+
const wallet_not_injected_error_1 = require("../../errors/wallet/wallet-not-injected.error");
|
|
37
|
+
const protocol = __importStar(require("../../resources/protocol.json"));
|
|
38
|
+
const bridge_connection_storage_1 = require("../../storage/bridge-connection-storage");
|
|
39
|
+
class InjectedProvider {
|
|
40
|
+
constructor(injectedWalletKey) {
|
|
10
41
|
this.type = 'injected';
|
|
11
42
|
this.unsubscribeCallback = null;
|
|
12
43
|
this.listenSubscriptions = false;
|
|
13
44
|
this.listeners = [];
|
|
14
|
-
|
|
45
|
+
const window = InjectedProvider.window;
|
|
15
46
|
if (!InjectedProvider.isWindowContainsWallet(window, injectedWalletKey)) {
|
|
16
47
|
throw new wallet_not_injected_error_1.WalletNotInjectedError();
|
|
17
48
|
}
|
|
18
49
|
this.injectedWallet = window[injectedWalletKey].tonconnect;
|
|
19
50
|
}
|
|
20
|
-
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
case 0:
|
|
26
|
-
bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(storage);
|
|
27
|
-
return [4 /*yield*/, bridgeConnectionStorage.getInjectedConnection()];
|
|
28
|
-
case 1:
|
|
29
|
-
connection = _a.sent();
|
|
30
|
-
return [2 /*return*/, new InjectedProvider(connection.jsBridgeKey)];
|
|
31
|
-
}
|
|
32
|
-
});
|
|
51
|
+
static fromStorage(storage) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(storage);
|
|
54
|
+
const connection = yield bridgeConnectionStorage.getInjectedConnection();
|
|
55
|
+
return new InjectedProvider(connection.jsBridgeKey);
|
|
33
56
|
});
|
|
34
|
-
}
|
|
35
|
-
|
|
57
|
+
}
|
|
58
|
+
static isWalletInjected(injectedWalletKey) {
|
|
36
59
|
return InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey);
|
|
37
|
-
}
|
|
38
|
-
|
|
60
|
+
}
|
|
61
|
+
static isInsideWalletBrowser(injectedWalletKey) {
|
|
39
62
|
if (InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey)) {
|
|
40
63
|
return this.window[injectedWalletKey].tonconnect.isWalletBrowser;
|
|
41
64
|
}
|
|
42
65
|
return false;
|
|
43
|
-
}
|
|
44
|
-
|
|
66
|
+
}
|
|
67
|
+
static isWindowContainsWallet(window, injectedWalletKey) {
|
|
45
68
|
return (window &&
|
|
46
69
|
injectedWalletKey in window &&
|
|
47
70
|
typeof window[injectedWalletKey] === 'object' &&
|
|
48
71
|
'tonconnect' in window[injectedWalletKey]);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var _this = this;
|
|
52
|
-
if (auto === void 0) { auto = false; }
|
|
72
|
+
}
|
|
73
|
+
connect(message, auto = false) {
|
|
53
74
|
this.injectedWallet
|
|
54
75
|
.connect(protocol.version, message, auto)
|
|
55
|
-
.then(
|
|
76
|
+
.then(connectEvent => {
|
|
56
77
|
if (connectEvent.event === 'connect') {
|
|
57
|
-
|
|
58
|
-
|
|
78
|
+
this.makeSubscriptions();
|
|
79
|
+
this.listenSubscriptions = true;
|
|
59
80
|
}
|
|
60
|
-
|
|
81
|
+
this.listeners.forEach(listener => listener(connectEvent));
|
|
61
82
|
})
|
|
62
|
-
.catch(
|
|
63
|
-
|
|
83
|
+
.catch(e => {
|
|
84
|
+
const connectEventError = {
|
|
64
85
|
event: 'connect_error',
|
|
65
86
|
payload: {
|
|
66
87
|
code: 0,
|
|
67
88
|
message: e === null || e === void 0 ? void 0 : e.toString()
|
|
68
89
|
}
|
|
69
90
|
};
|
|
70
|
-
|
|
91
|
+
this.listeners.forEach(listener => listener(connectEventError));
|
|
71
92
|
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
case 1:
|
|
82
|
-
connectEvent_1 = _a.sent();
|
|
83
|
-
if (connectEvent_1.event === 'connect') {
|
|
84
|
-
this.makeSubscriptions();
|
|
85
|
-
this.listenSubscriptions = true;
|
|
86
|
-
this.listeners.forEach(function (listener) { return listener(connectEvent_1); });
|
|
87
|
-
}
|
|
88
|
-
return [3 /*break*/, 3];
|
|
89
|
-
case 2:
|
|
90
|
-
e_1 = _a.sent();
|
|
91
|
-
console.error(e_1);
|
|
92
|
-
return [3 /*break*/, 3];
|
|
93
|
-
case 3: return [2 /*return*/];
|
|
93
|
+
}
|
|
94
|
+
restoreConnection() {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
try {
|
|
97
|
+
const connectEvent = yield this.injectedWallet.restoreConnection();
|
|
98
|
+
if (connectEvent.event === 'connect') {
|
|
99
|
+
this.makeSubscriptions();
|
|
100
|
+
this.listenSubscriptions = true;
|
|
101
|
+
this.listeners.forEach(listener => listener(connectEvent));
|
|
94
102
|
}
|
|
95
|
-
}
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
console.error(e);
|
|
106
|
+
}
|
|
96
107
|
});
|
|
97
|
-
}
|
|
98
|
-
|
|
108
|
+
}
|
|
109
|
+
closeConnection() {
|
|
99
110
|
if (this.listenSubscriptions) {
|
|
100
111
|
this.injectedWallet.disconnect();
|
|
101
112
|
}
|
|
102
113
|
this.closeAllListeners();
|
|
103
|
-
}
|
|
104
|
-
|
|
114
|
+
}
|
|
115
|
+
disconnect() {
|
|
105
116
|
this.closeAllListeners();
|
|
106
117
|
this.injectedWallet.disconnect();
|
|
107
118
|
return Promise.resolve();
|
|
108
|
-
}
|
|
109
|
-
|
|
119
|
+
}
|
|
120
|
+
closeAllListeners() {
|
|
110
121
|
var _a;
|
|
111
122
|
this.listenSubscriptions = false;
|
|
112
123
|
this.listeners = [];
|
|
113
124
|
(_a = this.unsubscribeCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
var _this = this;
|
|
125
|
+
}
|
|
126
|
+
listen(eventsCallback) {
|
|
117
127
|
this.listeners.push(eventsCallback);
|
|
118
|
-
return
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
124
|
-
return tslib_1.__generator(this, function (_a) {
|
|
125
|
-
return [2 /*return*/, this.injectedWallet.send(tslib_1.__assign(tslib_1.__assign({}, request), { id: '0' }))];
|
|
126
|
-
});
|
|
128
|
+
return () => (this.listeners = this.listeners.filter(listener => listener !== eventsCallback));
|
|
129
|
+
}
|
|
130
|
+
sendRequest(request) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
return this.injectedWallet.send(Object.assign(Object.assign({}, request), { id: '0' }));
|
|
127
133
|
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
_this.listeners.forEach(function (listener) { return listener(e); });
|
|
134
|
+
}
|
|
135
|
+
makeSubscriptions() {
|
|
136
|
+
this.unsubscribeCallback = this.injectedWallet.listen(e => {
|
|
137
|
+
if (this.listenSubscriptions) {
|
|
138
|
+
this.listeners.forEach(listener => listener(e));
|
|
134
139
|
}
|
|
135
140
|
if (e.event === 'disconnect') {
|
|
136
|
-
|
|
141
|
+
this.disconnect();
|
|
137
142
|
}
|
|
138
143
|
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return InjectedProvider;
|
|
142
|
-
}());
|
|
144
|
+
}
|
|
145
|
+
}
|
|
143
146
|
exports.InjectedProvider = InjectedProvider;
|
|
147
|
+
InjectedProvider.window = window;
|
|
@@ -1,126 +1,100 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.BridgeConnectionStorage = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function BridgeConnectionStorage(storage) {
|
|
13
|
+
const protocol_1 = require("@tonconnect/protocol");
|
|
14
|
+
const errors_1 = require("../errors");
|
|
15
|
+
class BridgeConnectionStorage {
|
|
16
|
+
constructor(storage) {
|
|
9
17
|
this.storage = storage;
|
|
10
18
|
this.storeKey = 'ton-connect-storage_bridge-connection';
|
|
11
19
|
}
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
return [2 /*return*/, this.storage.setItem(this.storeKey, JSON.stringify(rawConnection))];
|
|
30
|
-
});
|
|
20
|
+
storeConnection(connection) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
if (connection.type === 'injected') {
|
|
23
|
+
return this.storage.setItem(this.storeKey, JSON.stringify(connection));
|
|
24
|
+
}
|
|
25
|
+
const rawSession = {
|
|
26
|
+
sessionKeyPair: connection.session.sessionCrypto.stringifyKeypair(),
|
|
27
|
+
walletPublicKey: connection.session.walletPublicKey,
|
|
28
|
+
walletConnectionSource: connection.session.walletConnectionSource
|
|
29
|
+
};
|
|
30
|
+
const rawConnection = {
|
|
31
|
+
type: 'http',
|
|
32
|
+
connectEvent: connection.connectEvent,
|
|
33
|
+
session: rawSession
|
|
34
|
+
};
|
|
35
|
+
return this.storage.setItem(this.storeKey, JSON.stringify(rawConnection));
|
|
31
36
|
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return
|
|
35
|
-
return
|
|
36
|
-
return [2 /*return*/, this.storage.removeItem(this.storeKey)];
|
|
37
|
-
});
|
|
37
|
+
}
|
|
38
|
+
removeConnection() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
return this.storage.removeItem(this.storeKey);
|
|
38
41
|
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
connectEvent: connection.connectEvent,
|
|
59
|
-
session: {
|
|
60
|
-
sessionCrypto: sessionCrypto,
|
|
61
|
-
walletConnectionSource: connection.session.walletConnectionSource,
|
|
62
|
-
walletPublicKey: connection.session.walletPublicKey
|
|
63
|
-
}
|
|
64
|
-
}];
|
|
42
|
+
}
|
|
43
|
+
getConnection() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const stored = yield this.storage.getItem(this.storeKey);
|
|
46
|
+
if (!stored) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const connection = JSON.parse(stored);
|
|
50
|
+
if (connection.type === 'injected') {
|
|
51
|
+
return connection;
|
|
52
|
+
}
|
|
53
|
+
const sessionCrypto = new protocol_1.SessionCrypto(connection.session.sessionKeyPair);
|
|
54
|
+
return {
|
|
55
|
+
type: 'http',
|
|
56
|
+
connectEvent: connection.connectEvent,
|
|
57
|
+
session: {
|
|
58
|
+
sessionCrypto,
|
|
59
|
+
walletConnectionSource: connection.session.walletConnectionSource,
|
|
60
|
+
walletPublicKey: connection.session.walletPublicKey
|
|
65
61
|
}
|
|
66
|
-
}
|
|
62
|
+
};
|
|
67
63
|
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
if (connection.type === 'injected') {
|
|
81
|
-
throw new errors_1.TonConnectError('Trying to read HTTP connection source while injected connection is stored');
|
|
82
|
-
}
|
|
83
|
-
return [2 /*return*/, connection];
|
|
84
|
-
}
|
|
85
|
-
});
|
|
64
|
+
}
|
|
65
|
+
getHttpConnection() {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const connection = yield this.getConnection();
|
|
68
|
+
if (!connection) {
|
|
69
|
+
throw new errors_1.TonConnectError('Trying to read HTTP connection source while nothing is stored');
|
|
70
|
+
}
|
|
71
|
+
if (connection.type === 'injected') {
|
|
72
|
+
throw new errors_1.TonConnectError('Trying to read HTTP connection source while injected connection is stored');
|
|
73
|
+
}
|
|
74
|
+
return connection;
|
|
86
75
|
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
if ((connection === null || connection === void 0 ? void 0 : connection.type) === 'http') {
|
|
100
|
-
throw new errors_1.TonConnectError('Trying to read Injected bridge connection source while HTTP connection is stored');
|
|
101
|
-
}
|
|
102
|
-
return [2 /*return*/, connection];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
76
|
+
}
|
|
77
|
+
getInjectedConnection() {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const connection = yield this.getConnection();
|
|
80
|
+
if (!connection) {
|
|
81
|
+
throw new errors_1.TonConnectError('Trying to read Injected bridge connection source while nothing is stored');
|
|
82
|
+
}
|
|
83
|
+
if ((connection === null || connection === void 0 ? void 0 : connection.type) === 'http') {
|
|
84
|
+
throw new errors_1.TonConnectError('Trying to read Injected bridge connection source while HTTP connection is stored');
|
|
85
|
+
}
|
|
86
|
+
return connection;
|
|
105
87
|
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (!stored) {
|
|
116
|
-
return [2 /*return*/, null];
|
|
117
|
-
}
|
|
118
|
-
connection = JSON.parse(stored);
|
|
119
|
-
return [2 /*return*/, connection.type];
|
|
120
|
-
}
|
|
121
|
-
});
|
|
88
|
+
}
|
|
89
|
+
storedConnectionType() {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const stored = yield this.storage.getItem(this.storeKey);
|
|
92
|
+
if (!stored) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
const connection = JSON.parse(stored);
|
|
96
|
+
return connection.type;
|
|
122
97
|
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
}());
|
|
98
|
+
}
|
|
99
|
+
}
|
|
126
100
|
exports.BridgeConnectionStorage = BridgeConnectionStorage;
|
|
@@ -1,33 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.DefaultStorage = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function DefaultStorage() {
|
|
13
|
+
const localstorage_not_found_error_1 = require("../errors/storage/localstorage-not-found.error");
|
|
14
|
+
class DefaultStorage {
|
|
15
|
+
constructor() {
|
|
8
16
|
if (!(window === null || window === void 0 ? void 0 : window.localStorage)) {
|
|
9
17
|
throw new localstorage_not_found_error_1.LocalstorageNotFoundError();
|
|
10
18
|
}
|
|
11
19
|
}
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
return
|
|
15
|
-
return [2 /*return*/, Promise.resolve(window.localStorage.getItem(key))];
|
|
16
|
-
});
|
|
20
|
+
getItem(key) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
return Promise.resolve(window.localStorage.getItem(key));
|
|
17
23
|
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return [2 /*return*/, Promise.resolve()];
|
|
24
|
-
});
|
|
24
|
+
}
|
|
25
|
+
removeItem(key) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
window.localStorage.removeItem(key);
|
|
28
|
+
return Promise.resolve();
|
|
25
29
|
});
|
|
26
|
-
}
|
|
27
|
-
|
|
30
|
+
}
|
|
31
|
+
setItem(key, value) {
|
|
28
32
|
window.localStorage.setItem(key, value);
|
|
29
33
|
return Promise.resolve();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}());
|
|
34
|
+
}
|
|
35
|
+
}
|
|
33
36
|
exports.DefaultStorage = DefaultStorage;
|
|
@@ -1,42 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.HttpBridgeGatewayStorage = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function HttpBridgeGatewayStorage(storage) {
|
|
13
|
+
class HttpBridgeGatewayStorage {
|
|
14
|
+
constructor(storage) {
|
|
7
15
|
this.storage = storage;
|
|
8
16
|
this.storeKey = 'ton-connect-storage_http-bridge-gateway';
|
|
9
17
|
}
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
return
|
|
13
|
-
return [2 /*return*/, this.storage.setItem(this.storeKey, lastEventId)];
|
|
14
|
-
});
|
|
18
|
+
storeLastEventId(lastEventId) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
return this.storage.setItem(this.storeKey, lastEventId);
|
|
15
21
|
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return
|
|
19
|
-
return
|
|
20
|
-
return [2 /*return*/, this.storage.removeItem(this.storeKey)];
|
|
21
|
-
});
|
|
22
|
+
}
|
|
23
|
+
removeLastEventId() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
return this.storage.removeItem(this.storeKey);
|
|
22
26
|
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
stored = _a.sent();
|
|
32
|
-
if (!stored) {
|
|
33
|
-
return [2 /*return*/, null];
|
|
34
|
-
}
|
|
35
|
-
return [2 /*return*/, stored];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
27
|
+
}
|
|
28
|
+
getLastEventId() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const stored = yield this.storage.getItem(this.storeKey);
|
|
31
|
+
if (!stored) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return stored;
|
|
38
35
|
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}());
|
|
36
|
+
}
|
|
37
|
+
}
|
|
42
38
|
exports.HttpBridgeGatewayStorage = HttpBridgeGatewayStorage;
|