Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v6 - Removing onValid and adjusting isAvailable #2578

Merged
merged 2 commits into from
Feb 28, 2024
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
4 changes: 2 additions & 2 deletions packages/lib/src/components/GooglePay/GooglePay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ class GooglePay extends UIElement<GooglePayConfiguration> {
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();
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/components/GooglePay/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type { ICore } from '../../../core/types';
class IssuerListContainer extends UIElement<IssuerListConfiguration> {
protected static defaultProps = {
showImage: true,
onValid: () => {},
issuers: [],
highlightedIssuers: [],
loadingContext: FALLBACK_CONTEXT,
Expand Down
26 changes: 0 additions & 26 deletions packages/lib/src/components/internal/UIElement/UIElement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down
11 changes: 2 additions & 9 deletions packages/lib/src/components/internal/UIElement/UIElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export abstract class UIElement<P extends UIElementProps = UIElementProps> 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);
Expand Down Expand Up @@ -127,8 +126,8 @@ export abstract class UIElement<P extends UIElementProps = UIElementProps> 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;
}
Expand Down Expand Up @@ -245,12 +244,6 @@ export abstract class UIElement<P extends UIElementProps = UIElementProps> 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);
}
Expand Down
3 changes: 0 additions & 3 deletions packages/lib/src/components/internal/UIElement/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading