diff --git a/jslib b/jslib index 2045e7047a6..41ab22a82fb 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 2045e7047a66599b2c8a92b88cd0d1b8bfc5186f +Subproject commit 41ab22a82fb5fafcce2e8d1abe86789e152ef1fa diff --git a/src/app/vault/add-edit.component.ts b/src/app/vault/add-edit.component.ts index 3e97de7b2f4..7d8167bffb4 100644 --- a/src/app/vault/add-edit.component.ts +++ b/src/app/vault/add-edit.component.ts @@ -59,10 +59,11 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit { if (this.cipher.type === CipherType.Login && this.cipher.login.totp && (this.cipher.organizationUseTotp || this.isPremium)) { await this.totpUpdateCode(); - await this.totpTick(); + const interval = this.totpService.getTimeInterval(this.cipher.login.totp); + await this.totpTick(interval); this.totpInterval = window.setInterval(async () => { - await this.totpTick(); + await this.totpTick(interval); }, 1000); } } @@ -132,7 +133,12 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit { this.totpCode = await this.totpService.getCode(this.cipher.login.totp); if (this.totpCode != null) { - this.totpCodeFormatted = this.totpCode.substring(0, 3) + ' ' + this.totpCode.substring(3); + if (this.totpCode.length > 4) { + const half = Math.floor(this.totpCode.length / 2); + this.totpCodeFormatted = this.totpCode.substring(0, half) + ' ' + this.totpCode.substring(half); + } else { + this.totpCodeFormatted = this.totpCode; + } } else { this.totpCodeFormatted = null; if (this.totpInterval) { @@ -141,15 +147,16 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit { } } - protected async totpTick() { + private async totpTick(intervalSeconds: number) { const epoch = Math.round(new Date().getTime() / 1000.0); - const mod = epoch % 30; + const mod = epoch % intervalSeconds; - this.totpSec = 30 - mod; - this.totpDash = +(Math.round(((2.62 * mod) + 'e+2') as any) + 'e-2'); + this.totpSec = intervalSeconds - mod; + this.totpDash = +(Math.round((((78.6 / intervalSeconds) * mod) + 'e+2') as any) + 'e-2'); this.totpLow = this.totpSec <= 7; if (mod === 0) { await this.totpUpdateCode(); } } + }