@tezos-x/octez.connect-dapp 0.9.0 → 1.0.0
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 +3 -2
- package/dist/cjs/dapp-client/DAppClient.d.ts +5 -3
- package/dist/cjs/dapp-client/DAppClient.js +201 -129
- package/dist/cjs/dapp-client/DAppClient.js.map +1 -1
- package/dist/cjs/dapp-client/DAppClientOptions.d.ts +6 -2
- package/dist/cjs/events.d.ts +12 -4
- package/dist/cjs/events.js +30 -5
- package/dist/cjs/events.js.map +1 -1
- package/dist/esm/dapp-client/DAppClient.d.ts +5 -3
- package/dist/esm/dapp-client/DAppClient.js +158 -109
- package/dist/esm/dapp-client/DAppClient.js.map +1 -1
- package/dist/esm/dapp-client/DAppClientOptions.d.ts +6 -2
- package/dist/esm/events.d.ts +12 -4
- package/dist/esm/events.js +30 -5
- package/dist/esm/events.js.map +1 -1
- package/dist/octez.connect.dapp.min.js +1 -1066
- package/package.json +11 -10
|
@@ -8,10 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.DAppClient = void 0;
|
|
13
|
-
const axios_1 = require("axios");
|
|
14
|
-
const bs58check_1 = require("bs58check");
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const bs58check_1 = __importDefault(require("bs58check"));
|
|
15
18
|
const events_1 = require("../events");
|
|
16
19
|
const octez_connect_types_1 = require("@tezos-x/octez.connect-types");
|
|
17
20
|
const octez_connect_core_1 = require("@tezos-x/octez.connect-core");
|
|
@@ -58,7 +61,6 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
58
61
|
this.beaconIDB = new octez_connect_core_1.IndexedDBStorage('beacon', ['bug_report', 'metrics']);
|
|
59
62
|
this.debounceSetActiveAccount = false;
|
|
60
63
|
this.multiTabChannel = new octez_connect_core_1.MultiTabChannel('octez.connect-sdk-channel', this.onBCMessageHandler.bind(this), this.onElectedLeaderhandler.bind(this));
|
|
61
|
-
this.blockchains = new Map();
|
|
62
64
|
this.description = config.description;
|
|
63
65
|
this.wcProjectId = ((_a = config.walletConnectOptions) === null || _a === void 0 ? void 0 : _a.projectId) || '24469fd0a06df227b6e5f7dc7de0ff4f';
|
|
64
66
|
this.wcRelayUrl = (_b = config.walletConnectOptions) === null || _b === void 0 ? void 0 : _b.relayUrl;
|
|
@@ -67,7 +69,8 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
67
69
|
this.blockExplorer = (_d = config.blockExplorer) !== null && _d !== void 0 ? _d : new tzkt_blockexplorer_1.TzktBlockExplorer();
|
|
68
70
|
this.network = (_e = config.network) !== null && _e !== void 0 ? _e : { type: (_f = config.preferredNetwork) !== null && _f !== void 0 ? _f : octez_connect_types_1.NetworkType.MAINNET };
|
|
69
71
|
(0, octez_connect_ui_1.setColorMode)((_g = config.colorMode) !== null && _g !== void 0 ? _g : octez_connect_types_1.ColorMode.LIGHT);
|
|
70
|
-
this.
|
|
72
|
+
this.termsAndConditionsUrl = config.termsAndConditionsUrl;
|
|
73
|
+
this.privacyPolicyUrl = config.privacyPolicyUrl;
|
|
71
74
|
this.errorMessages = (_h = config.errorMessages) !== null && _h !== void 0 ? _h : {};
|
|
72
75
|
this.appMetadataManager = new octez_connect_core_1.AppMetadataManager(this.storage);
|
|
73
76
|
this.storageValidator = new octez_connect_core_1.StorageValidator(this.storage);
|
|
@@ -125,13 +128,13 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
125
128
|
}));
|
|
126
129
|
this.handleResponse = (message, connectionInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
127
130
|
var _a;
|
|
128
|
-
const typedMessage = message.version
|
|
131
|
+
const typedMessage = (0, octez_connect_core_1.usesWrappedMessages)(message.version)
|
|
129
132
|
? message.message
|
|
130
133
|
: message;
|
|
131
|
-
let appMetadata = message.version
|
|
134
|
+
let appMetadata = (0, octez_connect_core_1.usesWrappedMessages)(message.version)
|
|
132
135
|
? (_a = typedMessage.blockchainData) === null || _a === void 0 ? void 0 : _a.appMetadata
|
|
133
136
|
: typedMessage.appMetadata;
|
|
134
|
-
if (!appMetadata && message.version
|
|
137
|
+
if (!appMetadata && (0, octez_connect_core_1.usesWrappedMessages)(message.version)) {
|
|
135
138
|
const storedMetadata = yield Promise.all([
|
|
136
139
|
this.storage.get(octez_connect_types_1.StorageKey.TRANSPORT_P2P_PEERS_DAPP),
|
|
137
140
|
this.storage.get(octez_connect_types_1.StorageKey.TRANSPORT_WALLETCONNECT_PEERS_DAPP),
|
|
@@ -187,6 +190,12 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
187
190
|
}
|
|
188
191
|
yield this.removeAccountsForPeerIds([message.senderId]);
|
|
189
192
|
yield this.events.emit(events_1.BeaconEvent.CHANNEL_CLOSED);
|
|
193
|
+
// Reset transport state so next requestPermissions() shows pairing modal
|
|
194
|
+
this.postMessageTransport = undefined;
|
|
195
|
+
this.p2pTransport = undefined;
|
|
196
|
+
this.walletConnectTransport = undefined;
|
|
197
|
+
yield this.setTransport(undefined);
|
|
198
|
+
yield this.setActivePeer(undefined);
|
|
190
199
|
});
|
|
191
200
|
if (openRequest && typedMessage.type === octez_connect_types_1.BeaconMessageType.Acknowledge) {
|
|
192
201
|
this.analytics.track('event', 'DAppClient', 'Acknowledge received from Wallet');
|
|
@@ -200,16 +209,34 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
200
209
|
.catch(console.error);
|
|
201
210
|
}
|
|
202
211
|
else if (openRequest) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
212
|
+
// Define valid response types that should resolve a request
|
|
213
|
+
const validResponseTypes = [
|
|
214
|
+
octez_connect_types_1.BeaconMessageType.PermissionResponse,
|
|
215
|
+
octez_connect_types_1.BeaconMessageType.OperationResponse,
|
|
216
|
+
octez_connect_types_1.BeaconMessageType.SignPayloadResponse,
|
|
217
|
+
octez_connect_types_1.BeaconMessageType.BroadcastResponse,
|
|
218
|
+
octez_connect_types_1.BeaconMessageType.ProofOfEventChallengeResponse,
|
|
219
|
+
octez_connect_types_1.BeaconMessageType.SimulatedProofOfEventChallengeResponse,
|
|
220
|
+
octez_connect_types_1.BeaconMessageType.BlockchainResponse,
|
|
221
|
+
octez_connect_types_1.BeaconMessageType.Error
|
|
222
|
+
];
|
|
223
|
+
// Only process if it's a valid response type
|
|
224
|
+
if (validResponseTypes.includes(typedMessage.type)) {
|
|
225
|
+
if (typedMessage.type === octez_connect_types_1.BeaconMessageType.PermissionResponse && appMetadata) {
|
|
226
|
+
yield this.appMetadataManager.addAppMetadata(appMetadata);
|
|
227
|
+
}
|
|
228
|
+
if (typedMessage.type === octez_connect_types_1.BeaconMessageType.Error) {
|
|
229
|
+
openRequest.reject(typedMessage);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
openRequest.resolve({ message, connectionInfo });
|
|
233
|
+
}
|
|
234
|
+
this.openRequests.delete(typedMessage.id);
|
|
208
235
|
}
|
|
209
236
|
else {
|
|
210
|
-
|
|
237
|
+
// Log unexpected message types but don't resolve the request
|
|
238
|
+
logger.warn('handleResponse', `Received unexpected message type "${typedMessage.type}" for request ${message.id}. Expected a response type, not a request type.`);
|
|
211
239
|
}
|
|
212
|
-
this.openRequests.delete(typedMessage.id);
|
|
213
240
|
}
|
|
214
241
|
else {
|
|
215
242
|
if (typedMessage.type === octez_connect_types_1.BeaconMessageType.Disconnect) {
|
|
@@ -407,7 +434,8 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
407
434
|
onRelayerError() {
|
|
408
435
|
return __awaiter(this, void 0, void 0, function* () {
|
|
409
436
|
yield this.resetInvalidState(false);
|
|
410
|
-
|
|
437
|
+
const error = new octez_connect_core_1.UnknownBeaconError();
|
|
438
|
+
yield this.emitEventWithErrorContext(events_1.BeaconEvent.RELAYER_ERROR, error, (errorContext) => __awaiter(this, void 0, void 0, function* () { return errorContext; }));
|
|
411
439
|
});
|
|
412
440
|
}
|
|
413
441
|
wcToastHandler(status) {
|
|
@@ -429,10 +457,14 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
429
457
|
});
|
|
430
458
|
}
|
|
431
459
|
else {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
460
|
+
const error = (0, octez_connect_core_1.getError)(octez_connect_types_1.BeaconErrorType.ABORTED_ERROR, undefined);
|
|
461
|
+
yield this.emitEventWithErrorContext(events_1.BeaconEvent.PERMISSION_REQUEST_ERROR, error, (errorContext) => __awaiter(this, void 0, void 0, function* () {
|
|
462
|
+
return ({
|
|
463
|
+
errorResponse: { errorType: octez_connect_types_1.BeaconErrorType.ABORTED_ERROR },
|
|
464
|
+
walletInfo,
|
|
465
|
+
errorContext
|
|
466
|
+
});
|
|
467
|
+
}));
|
|
436
468
|
}
|
|
437
469
|
});
|
|
438
470
|
}
|
|
@@ -477,7 +509,8 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
477
509
|
catch (_a) {
|
|
478
510
|
//
|
|
479
511
|
}
|
|
480
|
-
this._initPromise = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
512
|
+
this._initPromise = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
513
|
+
this._initPromiseReject = reject;
|
|
481
514
|
if (transport) {
|
|
482
515
|
yield this.addListener(transport);
|
|
483
516
|
resolve(yield _super.init.call(this, transport));
|
|
@@ -572,6 +605,7 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
572
605
|
}))
|
|
573
606
|
.catch((error) => {
|
|
574
607
|
this._initPromise = undefined;
|
|
608
|
+
this._initPromiseReject = undefined;
|
|
575
609
|
console.error(error);
|
|
576
610
|
});
|
|
577
611
|
const abortHandler = () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -584,7 +618,12 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
584
618
|
]);
|
|
585
619
|
this.postMessageTransport = this.walletConnectTransport = this.p2pTransport = undefined;
|
|
586
620
|
this._activeAccount.isResolved() && this.clearActiveAccount();
|
|
621
|
+
this.events.emit(events_1.BeaconEvent.PAIR_ABORTED).catch((emitError) => console.warn(emitError));
|
|
622
|
+
if (this._initPromiseReject) {
|
|
623
|
+
this._initPromiseReject(new octez_connect_core_1.AbortedBeaconError());
|
|
624
|
+
}
|
|
587
625
|
this._initPromise = undefined;
|
|
626
|
+
this._initPromiseReject = undefined;
|
|
588
627
|
});
|
|
589
628
|
const serializer = new octez_connect_core_1.Serializer();
|
|
590
629
|
const p2pPeerInfo = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -594,7 +633,15 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
594
633
|
catch (err) {
|
|
595
634
|
logger.error(err);
|
|
596
635
|
yield this.hideUI(['alert']); // hide pairing alert
|
|
597
|
-
|
|
636
|
+
const error = new octez_connect_core_1.UnknownBeaconError();
|
|
637
|
+
setTimeout(() => {
|
|
638
|
+
this.emitEventWithErrorContext(events_1.BeaconEvent.GENERIC_ERROR, error, (errorContext) => __awaiter(this, void 0, void 0, function* () {
|
|
639
|
+
return ({
|
|
640
|
+
message: err.message,
|
|
641
|
+
errorContext
|
|
642
|
+
});
|
|
643
|
+
})).catch((emitError) => console.warn(emitError));
|
|
644
|
+
}, 1000);
|
|
598
645
|
abortHandler();
|
|
599
646
|
resolve('');
|
|
600
647
|
return;
|
|
@@ -614,9 +661,10 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
614
661
|
walletConnectPeerInfo,
|
|
615
662
|
networkType: this.network.type,
|
|
616
663
|
abortedHandler: abortHandler.bind(this),
|
|
617
|
-
disclaimerText: this.disclaimerText,
|
|
618
664
|
analytics: this.analytics,
|
|
619
665
|
featuredWallets: this.featuredWallets,
|
|
666
|
+
termsAndConditionsUrl: this.termsAndConditionsUrl,
|
|
667
|
+
privacyPolicyUrl: this.privacyPolicyUrl,
|
|
620
668
|
substratePairing
|
|
621
669
|
})
|
|
622
670
|
.catch((emitError) => console.warn(emitError));
|
|
@@ -669,7 +717,8 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
669
717
|
return __awaiter(this, void 0, void 0, function* () {
|
|
670
718
|
var _a;
|
|
671
719
|
if (!this.isGetActiveAccountHandled) {
|
|
672
|
-
console.warn(`An active account has been received, but no active subscription was found for BeaconEvent.ACTIVE_ACCOUNT_SET
|
|
720
|
+
console.warn(`An active account has been received, but no active subscription was found for BeaconEvent.ACTIVE_ACCOUNT_SET.
|
|
721
|
+
For more information, visit: https://octez-connect.tezos.com/guides/migration-guide`);
|
|
673
722
|
}
|
|
674
723
|
if (account && this._activeAccount.isSettled() && (yield this.isInvalidState(account))) {
|
|
675
724
|
const tranport = yield this.transport;
|
|
@@ -1023,7 +1072,7 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1023
1072
|
});
|
|
1024
1073
|
}
|
|
1025
1074
|
addBlockchain(chain) {
|
|
1026
|
-
|
|
1075
|
+
super.addBlockchain(chain);
|
|
1027
1076
|
chain.getWalletLists().then((walletLists) => {
|
|
1028
1077
|
(0, octez_connect_ui_1.setDesktopList)(walletLists.desktopList);
|
|
1029
1078
|
(0, octez_connect_ui_1.setExtensionList)(walletLists.extensionList);
|
|
@@ -1031,9 +1080,6 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1031
1080
|
(0, octez_connect_ui_1.setiOSList)(walletLists.iOSList);
|
|
1032
1081
|
});
|
|
1033
1082
|
}
|
|
1034
|
-
removeBlockchain(chainIdentifier) {
|
|
1035
|
-
this.blockchains.delete(chainIdentifier);
|
|
1036
|
-
}
|
|
1037
1083
|
permissionRequest(input) {
|
|
1038
1084
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1039
1085
|
logger.log('permissionRequest', input);
|
|
@@ -1046,13 +1092,7 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1046
1092
|
this.sendMetrics('performance-metrics/save', yield this.buildPayload('connect', 'start'));
|
|
1047
1093
|
const logId = `makeRequestV3 ${Date.now()}`;
|
|
1048
1094
|
logger.time(true, logId);
|
|
1049
|
-
const { message: response, connectionInfo } = yield this.makeRequestV3(request)
|
|
1050
|
-
requestError.errorType === octez_connect_types_1.BeaconErrorType.ABORTED_ERROR
|
|
1051
|
-
? this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'abort'))
|
|
1052
|
-
: this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'error'));
|
|
1053
|
-
logger.time(false, logId);
|
|
1054
|
-
throw yield this.handleRequestError(request, requestError);
|
|
1055
|
-
}));
|
|
1095
|
+
const { message: response, connectionInfo } = yield this.requireResponse(this.makeRequestV3(request), request, logId);
|
|
1056
1096
|
logger.time(false, logId);
|
|
1057
1097
|
this.sendMetrics('performance-metrics/save', yield this.buildPayload('connect', 'start'));
|
|
1058
1098
|
logger.log('RESPONSE V3', response, connectionInfo);
|
|
@@ -1114,14 +1154,7 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1114
1154
|
const res = (yield this.checkMakeRequest())
|
|
1115
1155
|
? this.makeRequestV3(request)
|
|
1116
1156
|
: this.makeRequestBC(request);
|
|
1117
|
-
|
|
1118
|
-
requestError.errorType === octez_connect_types_1.BeaconErrorType.ABORTED_ERROR
|
|
1119
|
-
? this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'abort'))
|
|
1120
|
-
: this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'error'));
|
|
1121
|
-
logger.time(false, logId);
|
|
1122
|
-
throw yield this.handleRequestError(request, requestError);
|
|
1123
|
-
}));
|
|
1124
|
-
const { message: response, connectionInfo } = (yield res);
|
|
1157
|
+
const { message: response, connectionInfo } = yield this.requireResponse(res, request, logId);
|
|
1125
1158
|
logger.time(false, logId);
|
|
1126
1159
|
this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'success'));
|
|
1127
1160
|
yield blockchain.handleResponse({
|
|
@@ -1165,14 +1198,7 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1165
1198
|
const res = (yield this.checkMakeRequest()) || !(yield this.getActiveAccount())
|
|
1166
1199
|
? this.makeRequest(request, undefined, undefined)
|
|
1167
1200
|
: this.makeRequestBC(request);
|
|
1168
|
-
|
|
1169
|
-
requestError.errorType === octez_connect_types_1.BeaconErrorType.ABORTED_ERROR
|
|
1170
|
-
? this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'abort'))
|
|
1171
|
-
: this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'error'));
|
|
1172
|
-
logger.time(false, logId);
|
|
1173
|
-
throw yield this.handleRequestError(request, requestError);
|
|
1174
|
-
}));
|
|
1175
|
-
const { message, connectionInfo } = (yield res);
|
|
1201
|
+
const { message, connectionInfo } = yield this.requireResponse(res, request, logId);
|
|
1176
1202
|
logger.time(false, logId);
|
|
1177
1203
|
this.sendMetrics('performance-metrics/save', yield this.buildPayload('connect', 'success'));
|
|
1178
1204
|
logger.log('requestPermissions', '######## MESSAGE #######');
|
|
@@ -1222,14 +1248,7 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1222
1248
|
const res = (yield this.checkMakeRequest())
|
|
1223
1249
|
? this.makeRequest(request)
|
|
1224
1250
|
: this.makeRequestBC(request);
|
|
1225
|
-
|
|
1226
|
-
requestError.errorType === octez_connect_types_1.BeaconErrorType.ABORTED_ERROR
|
|
1227
|
-
? this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'abort'))
|
|
1228
|
-
: this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'error'));
|
|
1229
|
-
logger.time(false, logId);
|
|
1230
|
-
throw yield this.handleRequestError(request, requestError);
|
|
1231
|
-
}));
|
|
1232
|
-
const { message, connectionInfo } = (yield res);
|
|
1251
|
+
const { message, connectionInfo } = yield this.requireResponse(res, request, logId);
|
|
1233
1252
|
logger.time(false, logId);
|
|
1234
1253
|
this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'success'));
|
|
1235
1254
|
this.analytics.track('event', 'DAppClient', `Proof of event challenge ${message.isAccepted ? 'accepted' : 'refused'}`, { address: activeAccount.address });
|
|
@@ -1266,14 +1285,7 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1266
1285
|
const res = (yield this.checkMakeRequest())
|
|
1267
1286
|
? this.makeRequest(request)
|
|
1268
1287
|
: this.makeRequestBC(request);
|
|
1269
|
-
|
|
1270
|
-
requestError.errorType === octez_connect_types_1.BeaconErrorType.ABORTED_ERROR
|
|
1271
|
-
? this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'abort'))
|
|
1272
|
-
: this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'error'));
|
|
1273
|
-
logger.time(false, logId);
|
|
1274
|
-
throw yield this.handleRequestError(request, requestError);
|
|
1275
|
-
}));
|
|
1276
|
-
const { message, connectionInfo } = (yield res);
|
|
1288
|
+
const { message, connectionInfo } = yield this.requireResponse(res, request, logId);
|
|
1277
1289
|
logger.time(false, logId);
|
|
1278
1290
|
this.analytics.track('event', 'DAppClient', `Simulated proof of event challenge ${!message.errorMessage ? 'accepted' : 'refused'}`, { address: activeAccount.address });
|
|
1279
1291
|
yield this.notifySuccess(request, {
|
|
@@ -1335,14 +1347,7 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1335
1347
|
const res = (yield this.checkMakeRequest())
|
|
1336
1348
|
? this.makeRequest(request)
|
|
1337
1349
|
: this.makeRequestBC(request);
|
|
1338
|
-
|
|
1339
|
-
requestError.errorType === octez_connect_types_1.BeaconErrorType.ABORTED_ERROR
|
|
1340
|
-
? this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'abort'))
|
|
1341
|
-
: this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'error'));
|
|
1342
|
-
logger.time(false, logId);
|
|
1343
|
-
throw yield this.handleRequestError(request, requestError);
|
|
1344
|
-
}));
|
|
1345
|
-
const { message, connectionInfo } = (yield res);
|
|
1350
|
+
const { message, connectionInfo } = yield this.requireResponse(res, request, logId);
|
|
1346
1351
|
logger.time(false, logId);
|
|
1347
1352
|
this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'success'));
|
|
1348
1353
|
yield this.notifySuccess(request, {
|
|
@@ -1432,14 +1437,7 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1432
1437
|
const res = (yield this.checkMakeRequest())
|
|
1433
1438
|
? this.makeRequest(request)
|
|
1434
1439
|
: this.makeRequestBC(request);
|
|
1435
|
-
|
|
1436
|
-
requestError.errorType === octez_connect_types_1.BeaconErrorType.ABORTED_ERROR
|
|
1437
|
-
? this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'abort'))
|
|
1438
|
-
: this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'error'));
|
|
1439
|
-
logger.time(false, logId);
|
|
1440
|
-
throw yield this.handleRequestError(request, requestError);
|
|
1441
|
-
}));
|
|
1442
|
-
const { message, connectionInfo } = (yield res);
|
|
1440
|
+
const { message, connectionInfo } = yield this.requireResponse(res, request, logId);
|
|
1443
1441
|
logger.time(false, logId);
|
|
1444
1442
|
this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'success'));
|
|
1445
1443
|
yield this.notifySuccess(request, {
|
|
@@ -1482,14 +1480,7 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1482
1480
|
const res = (yield this.checkMakeRequest())
|
|
1483
1481
|
? this.makeRequest(request)
|
|
1484
1482
|
: this.makeRequestBC(request);
|
|
1485
|
-
|
|
1486
|
-
requestError.errorType === octez_connect_types_1.BeaconErrorType.ABORTED_ERROR
|
|
1487
|
-
? this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'abort'))
|
|
1488
|
-
: this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'error'));
|
|
1489
|
-
logger.time(false, logId);
|
|
1490
|
-
throw yield this.handleRequestError(request, requestError);
|
|
1491
|
-
}));
|
|
1492
|
-
const { message, connectionInfo } = (yield res);
|
|
1483
|
+
const { message, connectionInfo } = yield this.requireResponse(res, request, logId);
|
|
1493
1484
|
logger.time(false, logId);
|
|
1494
1485
|
this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'success'));
|
|
1495
1486
|
yield this.notifySuccess(request, {
|
|
@@ -1552,10 +1543,24 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1552
1543
|
*/
|
|
1553
1544
|
sendInternalError(errorMessage) {
|
|
1554
1545
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1555
|
-
|
|
1546
|
+
const error = new octez_connect_core_1.UnknownBeaconError();
|
|
1547
|
+
yield this.emitEventWithErrorContext(events_1.BeaconEvent.INTERNAL_ERROR, error, (errorContext) => __awaiter(this, void 0, void 0, function* () {
|
|
1548
|
+
return ({
|
|
1549
|
+
text: errorMessage,
|
|
1550
|
+
errorContext
|
|
1551
|
+
});
|
|
1552
|
+
}));
|
|
1556
1553
|
throw new Error(errorMessage);
|
|
1557
1554
|
});
|
|
1558
1555
|
}
|
|
1556
|
+
emitEventWithErrorContext(event, error, buildPayload, ...additionalArgs) {
|
|
1557
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1558
|
+
const transport = this._transport.isResolved() ? yield this.transport : undefined;
|
|
1559
|
+
const errorContext = yield (0, octez_connect_core_1.buildErrorContext)(error, this.storage, transport === null || transport === void 0 ? void 0 : transport.type);
|
|
1560
|
+
const payload = yield buildPayload(errorContext);
|
|
1561
|
+
yield this.events.emit(event, payload, ...additionalArgs);
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1559
1564
|
/**
|
|
1560
1565
|
* This method will remove all accounts associated with a specific peer.
|
|
1561
1566
|
*
|
|
@@ -1583,6 +1588,27 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1583
1588
|
}
|
|
1584
1589
|
});
|
|
1585
1590
|
}
|
|
1591
|
+
requireResponse(responsePromise, request, logId) {
|
|
1592
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1593
|
+
try {
|
|
1594
|
+
return (yield responsePromise);
|
|
1595
|
+
}
|
|
1596
|
+
catch (requestError) {
|
|
1597
|
+
const error = requestError;
|
|
1598
|
+
if (error instanceof octez_connect_core_1.AbortedBeaconError) {
|
|
1599
|
+
this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'abort'));
|
|
1600
|
+
logger.time(false, logId);
|
|
1601
|
+
throw error;
|
|
1602
|
+
}
|
|
1603
|
+
const errorResponse = error;
|
|
1604
|
+
errorResponse.errorType === octez_connect_types_1.BeaconErrorType.ABORTED_ERROR
|
|
1605
|
+
? this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'abort'))
|
|
1606
|
+
: this.sendMetrics('performance-metrics/save', yield this.buildPayload('message', 'error'));
|
|
1607
|
+
logger.time(false, logId);
|
|
1608
|
+
throw yield this.handleRequestError(request, errorResponse);
|
|
1609
|
+
}
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1586
1612
|
/**
|
|
1587
1613
|
* This message handles errors that we receive from the wallet.
|
|
1588
1614
|
*
|
|
@@ -1622,13 +1648,15 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1622
1648
|
yield this.setTransport();
|
|
1623
1649
|
yield this.setActivePeer();
|
|
1624
1650
|
}
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1651
|
+
const error = (0, octez_connect_core_1.getError)(beaconError.errorType, beaconError.errorData);
|
|
1652
|
+
yield this.emitEventWithErrorContext(beacon_message_events_1.messageEvents[request.type].error, error, (errorContext) => __awaiter(this, void 0, void 0, function* () {
|
|
1653
|
+
return ({
|
|
1654
|
+
errorResponse: beaconError,
|
|
1655
|
+
walletInfo: yield this.getWalletInfo(peer, activeAccount),
|
|
1656
|
+
errorMessages: this.errorMessages,
|
|
1657
|
+
errorContext
|
|
1658
|
+
});
|
|
1659
|
+
}), buttons).catch((emitError) => logger.error('handleRequestError', emitError));
|
|
1632
1660
|
throw (0, octez_connect_core_1.getError)(beaconError.errorType, beaconError.errorData);
|
|
1633
1661
|
}
|
|
1634
1662
|
throw beaconError;
|
|
@@ -1765,9 +1793,13 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1765
1793
|
}
|
|
1766
1794
|
makeRequest(requestInput, skipResponse, otherTabMessageId) {
|
|
1767
1795
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1768
|
-
var _a, _b, _c;
|
|
1796
|
+
var _a, _b, _c, _d;
|
|
1769
1797
|
const messageId = otherTabMessageId !== null && otherTabMessageId !== void 0 ? otherTabMessageId : (yield (0, octez_connect_utils_1.generateGUID)());
|
|
1770
1798
|
if (this._initPromise && this.isInitPending) {
|
|
1799
|
+
if (this._initPromiseReject) {
|
|
1800
|
+
this._initPromiseReject(new octez_connect_core_1.AbortedBeaconError());
|
|
1801
|
+
this._initPromiseReject = undefined;
|
|
1802
|
+
}
|
|
1771
1803
|
yield Promise.all([
|
|
1772
1804
|
(_a = this.postMessageTransport) === null || _a === void 0 ? void 0 : _a.disconnect(),
|
|
1773
1805
|
(_b = this.walletConnectTransport) === null || _b === void 0 ? void 0 : _b.disconnect()
|
|
@@ -1799,12 +1831,16 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1799
1831
|
exposed = new octez_connect_utils_1.ExposedPromise();
|
|
1800
1832
|
this.addOpenRequest(request.id, exposed);
|
|
1801
1833
|
}
|
|
1802
|
-
const payload = yield new octez_connect_core_1.Serializer().serialize(request);
|
|
1803
1834
|
const account = yield this.getActiveAccount();
|
|
1804
1835
|
const peer = yield this.getPeer(account);
|
|
1836
|
+
const payload = yield new octez_connect_core_1.Serializer(this.getPeerProtocolVersion(peer)).serialize(request);
|
|
1805
1837
|
const walletInfo = yield this.getWalletInfo(peer, account);
|
|
1806
1838
|
logger.log('makeRequest', 'sending message', request);
|
|
1807
1839
|
try {
|
|
1840
|
+
// Hook for performance measurement
|
|
1841
|
+
if ((_c = window.__beaconPerf) === null || _c === void 0 ? void 0 : _c.onBeforeSend) {
|
|
1842
|
+
window.__beaconPerf.onBeforeSend();
|
|
1843
|
+
}
|
|
1808
1844
|
;
|
|
1809
1845
|
(yield this.transport).send(payload, peer);
|
|
1810
1846
|
if (request.type !== octez_connect_types_1.BeaconMessageType.PermissionRequest ||
|
|
@@ -1813,24 +1849,28 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1813
1849
|
}
|
|
1814
1850
|
}
|
|
1815
1851
|
catch (sendError) {
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1852
|
+
const error = new octez_connect_core_1.UnknownBeaconError();
|
|
1853
|
+
yield this.emitEventWithErrorContext(events_1.BeaconEvent.INTERNAL_ERROR, error, (errorContext) => __awaiter(this, void 0, void 0, function* () {
|
|
1854
|
+
return ({
|
|
1855
|
+
text: 'Unable to send message. If this problem persists, please reset the connection and pair your wallet again.',
|
|
1856
|
+
errorContext,
|
|
1857
|
+
buttons: [
|
|
1858
|
+
{
|
|
1859
|
+
text: 'Reset Connection',
|
|
1860
|
+
actionCallback: () => __awaiter(this, void 0, void 0, function* () {
|
|
1861
|
+
(0, octez_connect_ui_1.closeToast)();
|
|
1862
|
+
this.disconnect();
|
|
1863
|
+
})
|
|
1864
|
+
}
|
|
1865
|
+
]
|
|
1866
|
+
});
|
|
1867
|
+
}));
|
|
1828
1868
|
throw sendError;
|
|
1829
1869
|
}
|
|
1830
1870
|
if (!otherTabMessageId) {
|
|
1831
1871
|
this.events
|
|
1832
1872
|
.emit(beacon_message_events_1.messageEvents[requestInput.type].sent, {
|
|
1833
|
-
walletInfo: Object.assign(Object.assign({}, walletInfo), { name: (
|
|
1873
|
+
walletInfo: Object.assign(Object.assign({}, walletInfo), { name: (_d = walletInfo.name) !== null && _d !== void 0 ? _d : 'Wallet' }),
|
|
1834
1874
|
extraInfo: {
|
|
1835
1875
|
resetCallback: () => __awaiter(this, void 0, void 0, function* () {
|
|
1836
1876
|
this.disconnect();
|
|
@@ -1853,8 +1893,12 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1853
1893
|
*/
|
|
1854
1894
|
makeRequestV3(requestInput, otherTabMessageId) {
|
|
1855
1895
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1856
|
-
var _a, _b, _c;
|
|
1896
|
+
var _a, _b, _c, _d;
|
|
1857
1897
|
if (this._initPromise && this.isInitPending) {
|
|
1898
|
+
if (this._initPromiseReject) {
|
|
1899
|
+
this._initPromiseReject(new octez_connect_core_1.AbortedBeaconError());
|
|
1900
|
+
this._initPromiseReject = undefined;
|
|
1901
|
+
}
|
|
1858
1902
|
yield Promise.all([
|
|
1859
1903
|
(_a = this.postMessageTransport) === null || _a === void 0 ? void 0 : _a.disconnect(),
|
|
1860
1904
|
(_b = this.walletConnectTransport) === null || _b === void 0 ? void 0 : _b.disconnect()
|
|
@@ -1885,12 +1929,16 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1885
1929
|
};
|
|
1886
1930
|
const exposed = new octez_connect_utils_1.ExposedPromise();
|
|
1887
1931
|
this.addOpenRequest(request.id, exposed);
|
|
1888
|
-
const payload = yield new octez_connect_core_1.Serializer().serialize(request);
|
|
1889
1932
|
const account = yield this.getActiveAccount();
|
|
1890
1933
|
const peer = yield this.getPeer(account);
|
|
1934
|
+
const payload = yield new octez_connect_core_1.Serializer(this.getPeerProtocolVersion(peer)).serialize(request);
|
|
1891
1935
|
const walletInfo = yield this.getWalletInfo(peer, account);
|
|
1892
1936
|
logger.log('makeRequest', 'sending message', request);
|
|
1893
1937
|
try {
|
|
1938
|
+
// Hook for performance measurement
|
|
1939
|
+
if ((_c = window.__beaconPerf) === null || _c === void 0 ? void 0 : _c.onBeforeSend) {
|
|
1940
|
+
window.__beaconPerf.onBeforeSend();
|
|
1941
|
+
}
|
|
1894
1942
|
;
|
|
1895
1943
|
(yield this.transport).send(payload, peer);
|
|
1896
1944
|
if (request.message.type !== octez_connect_types_1.BeaconMessageType.PermissionRequest ||
|
|
@@ -1899,24 +1947,28 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1899
1947
|
}
|
|
1900
1948
|
}
|
|
1901
1949
|
catch (sendError) {
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1950
|
+
const error = new octez_connect_core_1.UnknownBeaconError();
|
|
1951
|
+
yield this.emitEventWithErrorContext(events_1.BeaconEvent.INTERNAL_ERROR, error, (errorContext) => __awaiter(this, void 0, void 0, function* () {
|
|
1952
|
+
return ({
|
|
1953
|
+
text: 'Unable to send message. If this problem persists, please reset the connection and pair your wallet again.',
|
|
1954
|
+
errorContext,
|
|
1955
|
+
buttons: [
|
|
1956
|
+
{
|
|
1957
|
+
text: 'Reset Connection',
|
|
1958
|
+
actionCallback: () => __awaiter(this, void 0, void 0, function* () {
|
|
1959
|
+
(0, octez_connect_ui_1.closeToast)();
|
|
1960
|
+
this.disconnect();
|
|
1961
|
+
})
|
|
1962
|
+
}
|
|
1963
|
+
]
|
|
1964
|
+
});
|
|
1965
|
+
}));
|
|
1914
1966
|
throw sendError;
|
|
1915
1967
|
}
|
|
1916
1968
|
const index = requestInput.type;
|
|
1917
1969
|
this.events
|
|
1918
1970
|
.emit(beacon_message_events_1.messageEvents[index].sent, {
|
|
1919
|
-
walletInfo: Object.assign(Object.assign({}, walletInfo), { name: (
|
|
1971
|
+
walletInfo: Object.assign(Object.assign({}, walletInfo), { name: (_d = walletInfo.name) !== null && _d !== void 0 ? _d : 'Wallet' }),
|
|
1920
1972
|
extraInfo: {
|
|
1921
1973
|
resetCallback: () => __awaiter(this, void 0, void 0, function* () {
|
|
1922
1974
|
this.disconnect();
|
|
@@ -1977,13 +2029,33 @@ class DAppClient extends octez_connect_core_1.Client {
|
|
|
1977
2029
|
}
|
|
1978
2030
|
yield this.createStateSnapshot();
|
|
1979
2031
|
this.sendMetrics('performance-metrics/save', yield this.buildPayload('disconnect', 'start'));
|
|
2032
|
+
const peers = yield transport.getPeers();
|
|
2033
|
+
if (peers.length > 0) {
|
|
2034
|
+
const shouldNotifyPeers = !(transport instanceof octez_connect_transport_walletconnect_1.WalletConnectTransport);
|
|
2035
|
+
yield this.removeAllPeers(shouldNotifyPeers);
|
|
2036
|
+
}
|
|
1980
2037
|
yield this.clearActiveAccount();
|
|
1981
2038
|
if (!(transport instanceof octez_connect_transport_walletconnect_1.WalletConnectTransport)) {
|
|
1982
|
-
|
|
2039
|
+
try {
|
|
2040
|
+
yield transport.disconnect();
|
|
2041
|
+
}
|
|
2042
|
+
catch (disconnectError) {
|
|
2043
|
+
const message = disconnectError instanceof Error ? disconnectError.message : String(disconnectError);
|
|
2044
|
+
if (typeof message === 'string' && message.includes('Syncing stopped manually')) {
|
|
2045
|
+
logger.log('disconnect', 'Matrix sync stopped manually');
|
|
2046
|
+
}
|
|
2047
|
+
else {
|
|
2048
|
+
throw disconnectError;
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
1983
2051
|
}
|
|
1984
2052
|
this.postMessageTransport = undefined;
|
|
1985
2053
|
this.p2pTransport = undefined;
|
|
1986
2054
|
this.walletConnectTransport = undefined;
|
|
2055
|
+
yield this.setTransport();
|
|
2056
|
+
this._initPromise = undefined;
|
|
2057
|
+
this._initPromiseReject = undefined;
|
|
2058
|
+
this.isInitPending = false;
|
|
1987
2059
|
this.sendMetrics('performance-metrics/save', yield this.buildPayload('disconnect', 'success'));
|
|
1988
2060
|
});
|
|
1989
2061
|
}
|