@sumaris-net/ngx-components 1.9.5 → 1.9.6

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.
@@ -15432,7 +15432,7 @@
15432
15432
  };
15433
15433
  var AccountService = /** @class */ (function (_super) {
15434
15434
  __extends(AccountService, _super);
15435
- function AccountService(cryptoService, network, graphql, settings, storage, file, environment) {
15435
+ function AccountService(cryptoService, network, graphql, settings, storage, file, translate, toastController, environment) {
15436
15436
  var _this = _super.call(this, graphql, environment) || this;
15437
15437
  _this.cryptoService = cryptoService;
15438
15438
  _this.network = network;
@@ -15440,6 +15440,8 @@
15440
15440
  _this.settings = settings;
15441
15441
  _this.storage = storage;
15442
15442
  _this.file = file;
15443
+ _this.translate = translate;
15444
+ _this.toastController = toastController;
15443
15445
  _this.environment = environment;
15444
15446
  _this.onLogin = new rxjs.Subject();
15445
15447
  _this.onLogout = new rxjs.Subject();
@@ -15869,7 +15871,7 @@
15869
15871
  };
15870
15872
  AccountService.prototype.reload = function () {
15871
15873
  return __awaiter(this, void 0, void 0, function () {
15872
- var now;
15874
+ var now, wasLogin, error_6;
15873
15875
  return __generator(this, function (_b) {
15874
15876
  switch (_b.label) {
15875
15877
  case 0:
@@ -15879,17 +15881,32 @@
15879
15881
  throw new Error('Cannot check account in offline mode');
15880
15882
  now = Date.now();
15881
15883
  console.debug("[account] Reloading account...");
15882
- return [4 /*yield*/, this.loadData()];
15884
+ wasLogin = this.isLogin();
15885
+ _b.label = 1;
15883
15886
  case 1:
15887
+ _b.trys.push([1, 4, , 8]);
15888
+ return [4 /*yield*/, this.loadData()];
15889
+ case 2:
15884
15890
  _b.sent();
15885
15891
  return [4 /*yield*/, this.saveLocally()];
15886
- case 2:
15892
+ case 3:
15887
15893
  _b.sent();
15888
15894
  console.debug("[account] Reloading account [OK] in " + (Date.now() - now) + "ms");
15889
15895
  // Emit login event to subscribers
15890
15896
  this.onLogin.next(this._data);
15891
15897
  this.onChange.next(this._data);
15892
15898
  return [2 /*return*/, this._data];
15899
+ case 4:
15900
+ error_6 = _b.sent();
15901
+ if (!(wasLogin && !this.isLogin())) return [3 /*break*/, 6];
15902
+ console.error("[account] Reloading account failed. Will force logout...", error_6);
15903
+ return [4 /*yield*/, this.logout()];
15904
+ case 5:
15905
+ _b.sent();
15906
+ return [3 /*break*/, 7];
15907
+ case 6: throw error_6;
15908
+ case 7: return [3 /*break*/, 8];
15909
+ case 8: return [2 /*return*/];
15893
15910
  }
15894
15911
  });
15895
15912
  });
@@ -16188,7 +16205,7 @@
16188
16205
  };
16189
16206
  AccountService.prototype.loadData = function (opts) {
16190
16207
  return __awaiter(this, void 0, void 0, function () {
16191
- var account, settings, error_6;
16208
+ var account, settings, error_7;
16192
16209
  return __generator(this, function (_b) {
16193
16210
  switch (_b.label) {
16194
16211
  case 0:
@@ -16225,11 +16242,11 @@
16225
16242
  _b.label = 4;
16226
16243
  case 4: return [2 /*return*/, this._data];
16227
16244
  case 5:
16228
- error_6 = _b.sent();
16245
+ error_7 = _b.sent();
16229
16246
  this.resetData();
16230
- if (error_6.code && error_6.message)
16231
- throw error_6;
16232
- console.error(error_6);
16247
+ if (error_7.code && error_7.message)
16248
+ throw error_7;
16249
+ console.error(error_7);
16233
16250
  throw {
16234
16251
  code: ErrorCodes$2.LOAD_ACCOUNT_ERROR,
16235
16252
  message: 'ERROR.LOAD_ACCOUNT_ERROR'
@@ -16253,7 +16270,7 @@
16253
16270
  };
16254
16271
  AccountService.prototype.restoreLocally = function () {
16255
16272
  return __awaiter(this, void 0, void 0, function () {
16256
- var values, pubkey, token, seckey, canRemoteAuth, error_7, jsonAccount, accountStr, account;
16273
+ var values, pubkey, token, seckey, canRemoteAuth, error_8, jsonAccount, accountStr, account;
16257
16274
  return __generator(this, function (_b) {
16258
16275
  switch (_b.label) {
16259
16276
  case 0: return [4 /*yield*/, Promise.all([
@@ -16291,7 +16308,7 @@
16291
16308
  throw new Error('Authentication failed');
16292
16309
  return [3 /*break*/, 5];
16293
16310
  case 4:
16294
- error_7 = _b.sent();
16311
+ error_8 = _b.sent();
16295
16312
  // Offline feature are enable: continue in offline mode
16296
16313
  if (this.settings.hasOfflineFeature()) {
16297
16314
  console.warn('[account] Unable to authenticate on pod: forcing offline mode');
@@ -16300,7 +16317,7 @@
16300
16317
  }
16301
16318
  // No offline features enable (=offline mode not allowed)
16302
16319
  else {
16303
- console.error(error_7);
16320
+ console.error(error_8);
16304
16321
  this.logout();
16305
16322
  return [2 /*return*/];
16306
16323
  }
@@ -16663,9 +16680,12 @@
16663
16680
  target.id = source.id || target.id;
16664
16681
  target.updateDate = source.updateDate || target.updateDate;
16665
16682
  };
16683
+ AccountService.prototype.showToast = function (opts) {
16684
+ return Toasts.show(this.toastController, this.translate, opts);
16685
+ };
16666
16686
  return AccountService;
16667
16687
  }(BaseGraphqlService));
16668
- AccountService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function AccountService_Factory() { return new AccountService(i0__namespace.ɵɵinject(CryptoService), i0__namespace.ɵɵinject(NetworkService), i0__namespace.ɵɵinject(GraphqlService), i0__namespace.ɵɵinject(LocalSettingsService), i0__namespace.ɵɵinject(i3__namespace$1.Storage), i0__namespace.ɵɵinject(FileService), i0__namespace.ɵɵinject(ENVIRONMENT)); }, token: AccountService, providedIn: "root" });
16688
+ AccountService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function AccountService_Factory() { return new AccountService(i0__namespace.ɵɵinject(CryptoService), i0__namespace.ɵɵinject(NetworkService), i0__namespace.ɵɵinject(GraphqlService), i0__namespace.ɵɵinject(LocalSettingsService), i0__namespace.ɵɵinject(i3__namespace$1.Storage), i0__namespace.ɵɵinject(FileService), i0__namespace.ɵɵinject(i1__namespace$1.TranslateService, 8), i0__namespace.ɵɵinject(i1__namespace$4.ToastController, 8), i0__namespace.ɵɵinject(ENVIRONMENT)); }, token: AccountService, providedIn: "root" });
16669
16689
  AccountService.decorators = [
16670
16690
  { type: i0.Injectable, args: [{ providedIn: 'root' },] }
16671
16691
  ];
@@ -16676,6 +16696,8 @@
16676
16696
  { type: LocalSettingsService },
16677
16697
  { type: i3$2.Storage },
16678
16698
  { type: FileService },
16699
+ { type: i1$2.TranslateService, decorators: [{ type: i0.Optional }] },
16700
+ { type: i1$5.ToastController, decorators: [{ type: i0.Optional }] },
16679
16701
  { type: undefined, decorators: [{ type: i0.Inject, args: [ENVIRONMENT,] }] }
16680
16702
  ]; };
16681
16703
  var templateObject_1$4, templateObject_2$4, templateObject_3$3, templateObject_4$3, templateObject_5$2, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12;