mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 21:33:27 +00:00
PM-17187 Autofill new card information in the popout (#13688)
This commit is contained in:
@@ -25,6 +25,11 @@ export type OptionalInitialValues = {
|
||||
username?: string;
|
||||
password?: string;
|
||||
name?: string;
|
||||
cardholderName?: string;
|
||||
number?: string;
|
||||
expMonth?: string;
|
||||
expYear?: string;
|
||||
code?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,6 +65,8 @@ describe("CardDetailsSectionComponent", () => {
|
||||
cardView.cardholderName = "Ron Burgundy";
|
||||
cardView.number = "4242 4242 4242 4242";
|
||||
cardView.brand = "Visa";
|
||||
cardView.expMonth = "";
|
||||
cardView.code = "";
|
||||
|
||||
expect(patchCipherSpy).toHaveBeenCalled();
|
||||
const patchFn = patchCipherSpy.mock.lastCall[0];
|
||||
@@ -79,6 +81,10 @@ describe("CardDetailsSectionComponent", () => {
|
||||
});
|
||||
|
||||
const cardView = new CardView();
|
||||
cardView.cardholderName = "";
|
||||
cardView.number = "";
|
||||
cardView.expMonth = "";
|
||||
cardView.code = "";
|
||||
cardView.expYear = "2022";
|
||||
|
||||
expect(patchCipherSpy).toHaveBeenCalled();
|
||||
|
||||
@@ -97,6 +97,10 @@ export class CardDetailsSectionComponent implements OnInit {
|
||||
|
||||
EventType = EventType;
|
||||
|
||||
get initialValues() {
|
||||
return this.cipherFormContainer.config.initialValues;
|
||||
}
|
||||
|
||||
constructor(
|
||||
private cipherFormContainer: CipherFormContainer,
|
||||
private formBuilder: FormBuilder,
|
||||
@@ -139,7 +143,9 @@ export class CardDetailsSectionComponent implements OnInit {
|
||||
const prefillCipher = this.cipherFormContainer.getInitialCipherView();
|
||||
|
||||
if (prefillCipher) {
|
||||
this.setInitialValues(prefillCipher);
|
||||
this.initFromExistingCipher(prefillCipher.card);
|
||||
} else {
|
||||
this.initNewCipher();
|
||||
}
|
||||
|
||||
if (this.disabled) {
|
||||
@@ -147,6 +153,26 @@ export class CardDetailsSectionComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
private initFromExistingCipher(existingCard: CardView) {
|
||||
this.cardDetailsForm.patchValue({
|
||||
cardholderName: this.initialValues?.cardholderName ?? existingCard.cardholderName,
|
||||
number: this.initialValues?.number ?? existingCard.number,
|
||||
expMonth: this.initialValues?.expMonth ?? existingCard.expMonth,
|
||||
expYear: this.initialValues?.expYear ?? existingCard.expYear,
|
||||
code: this.initialValues?.code ?? existingCard.code,
|
||||
});
|
||||
}
|
||||
|
||||
private initNewCipher() {
|
||||
this.cardDetailsForm.patchValue({
|
||||
cardholderName: this.initialValues?.cardholderName || "",
|
||||
number: this.initialValues?.number || "",
|
||||
expMonth: this.initialValues?.expMonth || "",
|
||||
expYear: this.initialValues?.expYear || "",
|
||||
code: this.initialValues?.code || "",
|
||||
});
|
||||
}
|
||||
|
||||
/** Get the section heading based on the card brand */
|
||||
getSectionHeading(): string {
|
||||
const { brand } = this.cardDetailsForm.value;
|
||||
|
||||
Reference in New Issue
Block a user