@tonconnect/sdk 0.0.21 → 0.0.23
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 +71 -79
- package/lib/provider/bridge/bridge-provider.js +118 -138
- package/lib/provider/injected/injected-provider.js +95 -90
- package/lib/storage/bridge-connection-storage.js +86 -112
- package/lib/storage/default-storage.d.ts +1 -0
- package/lib/storage/default-storage.js +28 -22
- 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.d.ts +3 -0
- package/lib/utils/web-api.js +36 -13
- package/lib/wallets-list-manager.js +59 -73
- package/package.json +4 -2
|
@@ -1,143 +1,148 @@
|
|
|
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
|
-
|
|
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
|
+
const web_api_1 = require("../../utils/web-api");
|
|
40
|
+
class InjectedProvider {
|
|
41
|
+
constructor(injectedWalletKey) {
|
|
10
42
|
this.type = 'injected';
|
|
11
43
|
this.unsubscribeCallback = null;
|
|
12
44
|
this.listenSubscriptions = false;
|
|
13
45
|
this.listeners = [];
|
|
14
|
-
|
|
46
|
+
const window = InjectedProvider.window;
|
|
15
47
|
if (!InjectedProvider.isWindowContainsWallet(window, injectedWalletKey)) {
|
|
16
48
|
throw new wallet_not_injected_error_1.WalletNotInjectedError();
|
|
17
49
|
}
|
|
18
50
|
this.injectedWallet = window[injectedWalletKey].tonconnect;
|
|
19
51
|
}
|
|
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
|
-
});
|
|
52
|
+
static fromStorage(storage) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const bridgeConnectionStorage = new bridge_connection_storage_1.BridgeConnectionStorage(storage);
|
|
55
|
+
const connection = yield bridgeConnectionStorage.getInjectedConnection();
|
|
56
|
+
return new InjectedProvider(connection.jsBridgeKey);
|
|
33
57
|
});
|
|
34
|
-
}
|
|
35
|
-
|
|
58
|
+
}
|
|
59
|
+
static isWalletInjected(injectedWalletKey) {
|
|
36
60
|
return InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey);
|
|
37
|
-
}
|
|
38
|
-
|
|
61
|
+
}
|
|
62
|
+
static isInsideWalletBrowser(injectedWalletKey) {
|
|
39
63
|
if (InjectedProvider.isWindowContainsWallet(this.window, injectedWalletKey)) {
|
|
40
64
|
return this.window[injectedWalletKey].tonconnect.isWalletBrowser;
|
|
41
65
|
}
|
|
42
66
|
return false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return (window &&
|
|
67
|
+
}
|
|
68
|
+
static isWindowContainsWallet(window, injectedWalletKey) {
|
|
69
|
+
return (!!window &&
|
|
46
70
|
injectedWalletKey in window &&
|
|
47
71
|
typeof window[injectedWalletKey] === 'object' &&
|
|
48
72
|
'tonconnect' in window[injectedWalletKey]);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var _this = this;
|
|
52
|
-
if (auto === void 0) { auto = false; }
|
|
73
|
+
}
|
|
74
|
+
connect(message, auto = false) {
|
|
53
75
|
this.injectedWallet
|
|
54
76
|
.connect(protocol.version, message, auto)
|
|
55
|
-
.then(
|
|
77
|
+
.then(connectEvent => {
|
|
56
78
|
if (connectEvent.event === 'connect') {
|
|
57
|
-
|
|
58
|
-
|
|
79
|
+
this.makeSubscriptions();
|
|
80
|
+
this.listenSubscriptions = true;
|
|
59
81
|
}
|
|
60
|
-
|
|
82
|
+
this.listeners.forEach(listener => listener(connectEvent));
|
|
61
83
|
})
|
|
62
|
-
.catch(
|
|
63
|
-
|
|
84
|
+
.catch(e => {
|
|
85
|
+
const connectEventError = {
|
|
64
86
|
event: 'connect_error',
|
|
65
87
|
payload: {
|
|
66
88
|
code: 0,
|
|
67
89
|
message: e === null || e === void 0 ? void 0 : e.toString()
|
|
68
90
|
}
|
|
69
91
|
};
|
|
70
|
-
|
|
92
|
+
this.listeners.forEach(listener => listener(connectEventError));
|
|
71
93
|
});
|
|
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*/];
|
|
94
|
+
}
|
|
95
|
+
restoreConnection() {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
try {
|
|
98
|
+
const connectEvent = yield this.injectedWallet.restoreConnection();
|
|
99
|
+
if (connectEvent.event === 'connect') {
|
|
100
|
+
this.makeSubscriptions();
|
|
101
|
+
this.listenSubscriptions = true;
|
|
102
|
+
this.listeners.forEach(listener => listener(connectEvent));
|
|
94
103
|
}
|
|
95
|
-
}
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
console.error(e);
|
|
107
|
+
}
|
|
96
108
|
});
|
|
97
|
-
}
|
|
98
|
-
|
|
109
|
+
}
|
|
110
|
+
closeConnection() {
|
|
99
111
|
if (this.listenSubscriptions) {
|
|
100
112
|
this.injectedWallet.disconnect();
|
|
101
113
|
}
|
|
102
114
|
this.closeAllListeners();
|
|
103
|
-
}
|
|
104
|
-
|
|
115
|
+
}
|
|
116
|
+
disconnect() {
|
|
105
117
|
this.closeAllListeners();
|
|
106
118
|
this.injectedWallet.disconnect();
|
|
107
119
|
return Promise.resolve();
|
|
108
|
-
}
|
|
109
|
-
|
|
120
|
+
}
|
|
121
|
+
closeAllListeners() {
|
|
110
122
|
var _a;
|
|
111
123
|
this.listenSubscriptions = false;
|
|
112
124
|
this.listeners = [];
|
|
113
125
|
(_a = this.unsubscribeCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
var _this = this;
|
|
126
|
+
}
|
|
127
|
+
listen(eventsCallback) {
|
|
117
128
|
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
|
-
});
|
|
129
|
+
return () => (this.listeners = this.listeners.filter(listener => listener !== eventsCallback));
|
|
130
|
+
}
|
|
131
|
+
sendRequest(request) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
return this.injectedWallet.send(Object.assign(Object.assign({}, request), { id: '0' }));
|
|
127
134
|
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
_this.listeners.forEach(function (listener) { return listener(e); });
|
|
135
|
+
}
|
|
136
|
+
makeSubscriptions() {
|
|
137
|
+
this.unsubscribeCallback = this.injectedWallet.listen(e => {
|
|
138
|
+
if (this.listenSubscriptions) {
|
|
139
|
+
this.listeners.forEach(listener => listener(e));
|
|
134
140
|
}
|
|
135
141
|
if (e.event === 'disconnect') {
|
|
136
|
-
|
|
142
|
+
this.disconnect();
|
|
137
143
|
}
|
|
138
144
|
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return InjectedProvider;
|
|
142
|
-
}());
|
|
145
|
+
}
|
|
146
|
+
}
|
|
143
147
|
exports.InjectedProvider = InjectedProvider;
|
|
148
|
+
InjectedProvider.window = (0, web_api_1.getWindow)();
|
|
@@ -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,39 @@
|
|
|
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
|
-
|
|
13
|
+
const localstorage_not_found_error_1 = require("../errors/storage/localstorage-not-found.error");
|
|
14
|
+
const web_api_1 = require("../utils/web-api");
|
|
15
|
+
class DefaultStorage {
|
|
16
|
+
constructor() {
|
|
17
|
+
const window = (0, web_api_1.getWindow)();
|
|
8
18
|
if (!(window === null || window === void 0 ? void 0 : window.localStorage)) {
|
|
9
19
|
throw new localstorage_not_found_error_1.LocalstorageNotFoundError();
|
|
10
20
|
}
|
|
21
|
+
this.window = window;
|
|
11
22
|
}
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
return
|
|
15
|
-
return [2 /*return*/, Promise.resolve(window.localStorage.getItem(key))];
|
|
16
|
-
});
|
|
23
|
+
getItem(key) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
return Promise.resolve(this.window.localStorage.getItem(key));
|
|
17
26
|
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return [2 /*return*/, Promise.resolve()];
|
|
24
|
-
});
|
|
27
|
+
}
|
|
28
|
+
removeItem(key) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
this.window.localStorage.removeItem(key);
|
|
31
|
+
return Promise.resolve();
|
|
25
32
|
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
window.localStorage.setItem(key, value);
|
|
33
|
+
}
|
|
34
|
+
setItem(key, value) {
|
|
35
|
+
this.window.localStorage.setItem(key, value);
|
|
29
36
|
return Promise.resolve();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
33
39
|
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;
|