From 5dad6ce14a0005e45aa2ed9cd5b5b7241c420681 Mon Sep 17 00:00:00 2001 From: guilhermer Date: Tue, 27 Feb 2024 11:52:20 +0100 Subject: [PATCH 1/2] feat: removing onValid and adjusting isAvailable --- .../src/components/GooglePay/GooglePay.tsx | 4 +-- .../lib/src/components/GooglePay/types.ts | 2 +- .../IssuerListContainer.tsx | 1 - .../internal/UIElement/UIElement.test.ts | 26 ------------------- .../internal/UIElement/UIElement.tsx | 12 ++------- .../components/internal/UIElement/types.ts | 3 --- 6 files changed, 5 insertions(+), 43 deletions(-) diff --git a/packages/lib/src/components/GooglePay/GooglePay.tsx b/packages/lib/src/components/GooglePay/GooglePay.tsx index 0910fc90f9..da61b096ce 100644 --- a/packages/lib/src/components/GooglePay/GooglePay.tsx +++ b/packages/lib/src/components/GooglePay/GooglePay.tsx @@ -183,11 +183,11 @@ class GooglePay extends UIElement { return this.isReadyToPay() .then(response => { if (!response.result) { - throw new Error('Google Pay is not available'); + throw new AdyenCheckoutError('ERROR', 'GooglePay is not available'); } if (response.paymentMethodPresent === false) { - throw new Error('Google Pay - No paymentMethodPresent'); + throw new AdyenCheckoutError('ERROR', 'GooglePay - No paymentMethodPresent'); } return Promise.resolve(); diff --git a/packages/lib/src/components/GooglePay/types.ts b/packages/lib/src/components/GooglePay/types.ts index 33d8be26cb..23043da12c 100644 --- a/packages/lib/src/components/GooglePay/types.ts +++ b/packages/lib/src/components/GooglePay/types.ts @@ -40,7 +40,7 @@ export interface GooglePayConfiguration extends UIElementProps { /** * @see https://developers.google.com/pay/api/web/reference/request-objects#IsReadyToPayRequest - * @defaultValue true + * @defaultValue false */ existingPaymentMethodRequired?: boolean; diff --git a/packages/lib/src/components/helpers/IssuerListContainer/IssuerListContainer.tsx b/packages/lib/src/components/helpers/IssuerListContainer/IssuerListContainer.tsx index afe250cf9a..784b27f5dd 100644 --- a/packages/lib/src/components/helpers/IssuerListContainer/IssuerListContainer.tsx +++ b/packages/lib/src/components/helpers/IssuerListContainer/IssuerListContainer.tsx @@ -12,7 +12,6 @@ import type { ICore } from '../../../core/types'; class IssuerListContainer extends UIElement { protected static defaultProps = { showImage: true, - onValid: () => {}, issuers: [], highlightedIssuers: [], loadingContext: FALLBACK_CONTEXT, diff --git a/packages/lib/src/components/internal/UIElement/UIElement.test.ts b/packages/lib/src/components/internal/UIElement/UIElement.test.ts index 9a68ca304f..5beb7ed658 100644 --- a/packages/lib/src/components/internal/UIElement/UIElement.test.ts +++ b/packages/lib/src/components/internal/UIElement/UIElement.test.ts @@ -72,32 +72,6 @@ describe('UIElement', () => { expect(onChange.mock.calls.length).toBe(1); }); - - test('should not trigger onValid method if the component is not valid', () => { - const onValid = jest.fn(); - const element = new MyElement(core, { onValid }); - - element.callOnChange(); - - expect(onValid.mock.calls.length).toBe(0); - }); - - test('should trigger the onValid method if the component is valid', () => { - class MyValidElement extends UIElement { - get isValid() { - return true; - } - onChange(): object { - return super.onChange(); - } - } - - const onValid = jest.fn(); - const element = new MyValidElement(core, { onValid }); - element.onChange(); - - expect(onValid.mock.calls.length).toBe(1); - }); }); describe('isValid()', () => { diff --git a/packages/lib/src/components/internal/UIElement/UIElement.tsx b/packages/lib/src/components/internal/UIElement/UIElement.tsx index b9eaaaf37a..8815fffe8e 100644 --- a/packages/lib/src/components/internal/UIElement/UIElement.tsx +++ b/packages/lib/src/components/internal/UIElement/UIElement.tsx @@ -50,8 +50,6 @@ export abstract class UIElement

exten this.submit = this.submit.bind(this); this.setState = this.setState.bind(this); - this.onValid = this.onValid.bind(this); - this.onComplete = this.onComplete.bind(this); this.handleAction = this.handleAction.bind(this); this.handleOrder = this.handleOrder.bind(this); this.handleAdditionalDetails = this.handleAdditionalDetails.bind(this); @@ -127,8 +125,8 @@ export abstract class UIElement

exten protected onChange(): object { const isValid = this.isValid; const state = { data: this.data, errors: this.state.errors, valid: this.state.valid, isValid }; - if (this.props.onChange) this.props.onChange(state, this.elementRef); - if (isValid) this.onValid(); + + this.props.onChange?.(state, this.elementRef); return state; } @@ -245,12 +243,6 @@ export abstract class UIElement

exten // }; } - private onValid() { - const state = { data: this.data }; - if (this.props.onValid) this.props.onValid(state, this.elementRef); - return state; - } - protected onComplete(state): void { if (this.props.onComplete) this.props.onComplete(state, this.elementRef); } diff --git a/packages/lib/src/components/internal/UIElement/types.ts b/packages/lib/src/components/internal/UIElement/types.ts index 03166407f8..b70b8a230b 100644 --- a/packages/lib/src/components/internal/UIElement/types.ts +++ b/packages/lib/src/components/internal/UIElement/types.ts @@ -28,14 +28,11 @@ export type UIElementProps = BaseElementProps & CoreCallbacks & { environment?: string; session?: Session; - onValid?: (state: any, element: UIElement) => void; onComplete?: (state, element: UIElement) => void; isInstantPayment?: boolean; - // brand?: string; // TODO confirm it this is needed - /** * Flags if the element is Stored payment method * @internal From 861c7bae968e0506c40983ffe408692cebf7352a Mon Sep 17 00:00:00 2001 From: guilhermer Date: Tue, 27 Feb 2024 13:54:03 +0100 Subject: [PATCH 2/2] fix: reverting line removal --- packages/lib/src/components/internal/UIElement/UIElement.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/lib/src/components/internal/UIElement/UIElement.tsx b/packages/lib/src/components/internal/UIElement/UIElement.tsx index 8815fffe8e..9aeabc71fb 100644 --- a/packages/lib/src/components/internal/UIElement/UIElement.tsx +++ b/packages/lib/src/components/internal/UIElement/UIElement.tsx @@ -50,6 +50,7 @@ export abstract class UIElement

exten this.submit = this.submit.bind(this); this.setState = this.setState.bind(this); + this.onComplete = this.onComplete.bind(this); this.handleAction = this.handleAction.bind(this); this.handleOrder = this.handleOrder.bind(this); this.handleAdditionalDetails = this.handleAdditionalDetails.bind(this);