@block-auth.io/angular 0.7.6 → 0.8.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.
@@ -172,9 +172,15 @@ class BlockAuthRuntimeDirective {
172
172
  onError: () => this.errored.emit(),
173
173
  onLogout: () => this.loggedOut.emit(),
174
174
  });
175
+ this.client.registerRuntime({
176
+ switchAccount: this.runtime.switchAccount,
177
+ resumeSession: this.runtime.resumeSession,
178
+ });
175
179
  void this.runtime.start();
176
180
  }
177
181
  ngOnDestroy() {
182
+ if (this.runtime)
183
+ this.client.registerRuntime(null);
178
184
  this.runtime?.stop();
179
185
  this.runtime = null;
180
186
  this.wasReady = false;
@@ -4455,7 +4461,7 @@ class TxnComponent {
4455
4461
  (click)="closeLifetime()"
4456
4462
  ></div>
4457
4463
  <div
4458
- class="bal-ba-glass-popup-slot bas-absolute bas-inset-x-0 bas-top-44 bas-z-40 bas-box-border bas-px-4"
4464
+ class="bal-ba-glass-popup-slot bas-absolute bas-inset-0 bas-z-40 bas-box-border bas-items-center bas-px-4"
4459
4465
  >
4460
4466
  <div
4461
4467
  role="dialog"
@@ -4699,7 +4705,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImpo
4699
4705
  (click)="closeLifetime()"
4700
4706
  ></div>
4701
4707
  <div
4702
- class="bal-ba-glass-popup-slot bas-absolute bas-inset-x-0 bas-top-44 bas-z-40 bas-box-border bas-px-4"
4708
+ class="bal-ba-glass-popup-slot bas-absolute bas-inset-0 bas-z-40 bas-box-border bas-items-center bas-px-4"
4703
4709
  >
4704
4710
  <div
4705
4711
  role="dialog"
@@ -10148,11 +10154,16 @@ class FlowBlockAuthComponent {
10148
10154
  effect((onCleanup) => {
10149
10155
  if (!this.isReconnectingRemembered() || !this.ui().isServiceConnected)
10150
10156
  return;
10151
- const timer = setTimeout(() => {
10152
- this.isReconnectingRemembered.set(false);
10153
- untracked(() => this.requestReturningSignin());
10157
+ let cancelled = false;
10158
+ const timer = setTimeout(async () => {
10159
+ await untracked(() => this.resumeOrRequestSignin(() => cancelled));
10160
+ if (!cancelled)
10161
+ this.isReconnectingRemembered.set(false);
10154
10162
  }, REMEMBERED_SIGNIN_SETTLE_MS);
10155
- onCleanup(() => clearTimeout(timer));
10163
+ onCleanup(() => {
10164
+ cancelled = true;
10165
+ clearTimeout(timer);
10166
+ });
10156
10167
  });
10157
10168
  effect(() => {
10158
10169
  if (!this.ui().isSigning)
@@ -10160,9 +10171,25 @@ class FlowBlockAuthComponent {
10160
10171
  });
10161
10172
  }
10162
10173
  ngOnInit() {
10163
- if (!this.isHosted || this.user() !== undefined || !this.client.usesAuthEndpoint(Boolean(this.onAuthCode())))
10174
+ if (!this.isHosted)
10164
10175
  return;
10165
- this.client.restoreHostedLogin().catch(() => this.errored.emit());
10176
+ const authCode = this.onAuthCode();
10177
+ const ownsAuthCode = Boolean(authCode);
10178
+ const restoresSession = this.user() === undefined &&
10179
+ (this.client.hasAuthEndpoint ? this.client.usesAuthEndpoint(ownsAuthCode) : !ownsAuthCode);
10180
+ const redirectLogin = authCode
10181
+ ? this.client.completeRedirectAuthCode(authCode)
10182
+ : this.client.handleRedirectCallback();
10183
+ redirectLogin
10184
+ .then(async (redirectUser) => {
10185
+ if (redirectUser) {
10186
+ this.success.emit(redirectUser.address);
10187
+ return;
10188
+ }
10189
+ if (restoresSession)
10190
+ await this.client.restoreHostedLogin();
10191
+ })
10192
+ .catch(() => this.errored.emit());
10166
10193
  }
10167
10194
  onHostedLoginClicked() {
10168
10195
  if (this.isPopupOpen())
@@ -10214,9 +10241,20 @@ class FlowBlockAuthComponent {
10214
10241
  if (this.isRequestingSignin() || this.ui().isSigning)
10215
10242
  return;
10216
10243
  this.isRequestingSignin.set(true);
10217
- this.requestReturningSignin();
10244
+ void this.resumeOrRequestSignin();
10218
10245
  }
10219
10246
  }
10247
+ async resumeOrRequestSignin(isCancelled = () => false) {
10248
+ const resumed = await this.client.resumeSession();
10249
+ if (isCancelled())
10250
+ return;
10251
+ if (resumed) {
10252
+ this.isRequestingSignin.set(false);
10253
+ setIsSigningLoader(false);
10254
+ return;
10255
+ }
10256
+ this.requestReturningSignin();
10257
+ }
10220
10258
  requestReturningSignin() {
10221
10259
  // LOG-IN branch: emit the signin transaction, then open the signin modal
10222
10260
  // and flag the signing loader. The runtime clears the loader once
@@ -10511,7 +10549,17 @@ class LinkBlockAuthComponent {
10511
10549
  this.linkLabel = computed(() => this.linkDefault[this.locale()] ?? this.linkDefault['en'], ...(ngDevMode ? [{ debugName: "linkLabel" }] : []));
10512
10550
  }
10513
10551
  ngOnInit() {
10514
- void this.refreshStatus();
10552
+ this.client
10553
+ .completeRedirectLink()
10554
+ .then((linked) => {
10555
+ if (linked)
10556
+ this.linked.emit();
10557
+ return this.refreshStatus();
10558
+ })
10559
+ .catch((error) => {
10560
+ this.errored.emit(error instanceof AccountLinkError ? error.reason : 'failed');
10561
+ return this.refreshStatus();
10562
+ });
10515
10563
  }
10516
10564
  onLinkClicked() {
10517
10565
  if (this.isPopupOpen())