Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jslib
5 changes: 5 additions & 0 deletions src/popup/components/action-buttons.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
[ngClass]="{disabled: (!cipher.login.password || !cipher.viewPassword)}">
<i class="fa fa-lg fa-key" aria-hidden="true"></i>
</span>
<span class="row-btn" appStopClick appStopProp appA11yTitle="{{'copyVerificationCode' | i18n}}"
(click)="copy(cipher, cipher.login.totp, 'verificationCodeTotp', 'TOTP')"
[ngClass]="{disabled: (!displayTotpCopyButton(cipher))}">
<i class="fa fa-lg fa-clock-o" aria-hidden="true"></i>
</span>
</ng-container>
<ng-container *ngIf="cipher.type === cipherType.Card">
<span class="row-btn" appStopClick appStopProp appA11yTitle="{{'copyNumber' | i18n}}"
Expand Down
23 changes: 19 additions & 4 deletions src/popup/components/action-buttons.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { CipherView } from 'jslib/models/view/cipherView';
import { EventService } from 'jslib/abstractions/event.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { TotpService } from 'jslib/abstractions/totp.service';
import { UserService } from 'jslib/abstractions/user.service';

import { PopupUtilsService } from '../services/popup-utils.service';

Expand All @@ -31,11 +33,17 @@ export class ActionButtonsComponent {
@Input() showView = false;

cipherType = CipherType;
userHasPremiumAccess = false;

constructor(private analytics: Angulartics2, private toasterService: ToasterService,
private i18nService: I18nService, private platformUtilsService: PlatformUtilsService,
private popupUtilsService: PopupUtilsService, private eventService: EventService) { }
private popupUtilsService: PopupUtilsService, private eventService: EventService,
private totpService: TotpService, private userService: UserService) { }

async ngOnInit() {
this.userHasPremiumAccess = await this.userService.canAccessPremium();
}

launch() {
if (this.cipher.type !== CipherType.Login || !this.cipher.login.canLaunch) {
return;
Expand All @@ -48,9 +56,11 @@ export class ActionButtonsComponent {
}
}

copy(cipher: CipherView, value: string, typeI18nKey: string, aType: string) {
if (value == null) {
async copy(cipher: CipherView, value: string, typeI18nKey: string, aType: string) {
if (value == null || !this.displayTotpCopyButton(cipher)) {
return;
} else if (value === cipher.login.totp) {
value = await this.totpService.getCode(value);
}

if (!cipher.viewPassword) {
Expand All @@ -62,13 +72,18 @@ export class ActionButtonsComponent {
this.toasterService.popAsync('info', null,
this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey)));

if (typeI18nKey === 'password') {
if (typeI18nKey === 'password' || typeI18nKey === 'verificationCodeTotp') {
this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, cipher.id);
} else if (typeI18nKey === 'securityCode') {
this.eventService.collect(EventType.Cipher_ClientCopiedCardCode, cipher.id);
}
}

displayTotpCopyButton(cipher: CipherView) {
return (cipher?.login?.hasTotp ?? false) &&
(cipher.organizationUseTotp || this.userHasPremiumAccess);
}

view() {
this.onView.emit(this.cipher);
}
Expand Down