Skip to content

Commit 5b405c7

Browse files
committed
chore: optimise imports
1 parent d6a9468 commit 5b405c7

24 files changed

+91
-147
lines changed

src/components/AdyenCheckout.tsx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,33 @@ import React, {
77
useMemo,
88
} from 'react';
99
import { type EmitterSubscription, NativeEventEmitter } from 'react-native';
10-
import { Event } from '../core/constants';
11-
import type { AdyenComponent } from '../core/AdyenNativeModules';
12-
import {
13-
SessionHelper,
14-
type SessionContext,
15-
} from '../modules/session/SessionHelperModule';
1610
import type {
11+
AddressLookup,
12+
AddressLookupItem,
13+
AdyenActionComponent,
14+
AdyenComponent,
1715
AdyenError,
16+
Configuration,
17+
Order,
18+
PartialPaymentComponent,
19+
PaymentDetailsData,
20+
PaymentMethodData,
1821
PaymentMethodsResponse,
22+
RemovesStoredPayment,
1923
SessionConfiguration,
20-
PaymentMethodData,
21-
PaymentDetailsData,
24+
SessionsResult,
2225
StoredPaymentMethod,
2326
SubmitModel,
24-
Order,
25-
SessionsResult,
26-
RemovesStoredPayment,
27-
} from '../core/types';
28-
import type { Configuration } from '../core/configurations/Configuration';
29-
import { checkPaymentMethodsResponse, checkConfiguration } from '../core/utils';
30-
import type { AdyenActionComponent } from '../core/AdyenNativeModules';
31-
import type {
32-
AddressLookup,
33-
AddressLookupItem,
34-
} from '../core/configurations/AddressLookup';
27+
} from '../core';
28+
import { Event } from '../core';
3529
import { AdyenCheckoutContext } from '../hooks/useAdyenCheckout';
36-
import type { PartialPaymentComponent } from '../core/configurations/PartialPaymentConfiguration';
3730
import { getWrapper } from '../modules/base/getWrapper';
3831
import type { EventListenerWrapper } from '../modules/base/EventListenerWrapper';
32+
import {
33+
SessionHelper,
34+
type SessionContext,
35+
} from '../modules/session/SessionHelperModule';
36+
import { checkConfiguration, checkPaymentMethodsResponse } from './utils';
3937

4038
/**
4139
* Props for AdyenCheckout
@@ -135,7 +133,7 @@ export const AdyenCheckout: React.FC<AdyenCheckoutProps> = ({
135133
}, [session, sessionContext, config, onError, setSessionContext]);
136134

137135
const startEventListeners = useCallback(
138-
(nativeComponent: EventListenerWrapper) => {
136+
(nativeComponent: EventListenerWrapper & AdyenComponent) => {
139137
removeEventListeners();
140138
const eventEmitter = new NativeEventEmitter(nativeComponent);
141139

@@ -156,14 +154,14 @@ export const AdyenCheckout: React.FC<AdyenCheckoutProps> = ({
156154
submitPayment(response.paymentData, response.extra)
157155
),
158156
eventEmitter.addListener(Event.onError, (error: AdyenError) =>
159-
onError?.(error, nativeComponent as unknown as AdyenComponent)
157+
onError?.(error, nativeComponent)
160158
),
161159
];
162160

163161
if (nativeComponent.isSupported(Event.onComplete)) {
164162
subscriptions.current.push(
165163
eventEmitter.addListener(Event.onComplete, (data: any) =>
166-
onComplete?.(data, nativeComponent as unknown as AdyenComponent)
164+
onComplete?.(data, nativeComponent)
167165
)
168166
);
169167
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Platform } from 'react-native';
2-
import type { Configuration } from './configurations/Configuration';
3-
import type { PaymentMethodsResponse } from './types';
2+
import type { Configuration, PaymentMethodsResponse } from '../core';
43

54
export const checkPaymentMethodsResponse = (
65
paymentMethodsResponse: PaymentMethodsResponse | undefined

src/core/AdyenNativeModules.tsx

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/core/configurations/PartialPaymentConfiguration.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import type { AdyenComponent } from '../AdyenNativeModules';
2-
import type { Balance, Order, PaymentMethodData } from '../types';
1+
import type {
2+
AdyenComponent,
3+
Balance,
4+
Order,
5+
PaymentMethodData,
6+
} from '../types';
37

48
export interface PartialPaymentConfiguration {
59
/**

src/core/constants.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
export const MISSING_CONTEXT_ERROR =
2-
'useAdyenCheckout must be used within an AdyenCheckout';
3-
41
/** Collection of events that components can trigger. */
52
export enum Event {
63
/** Event handler, called when the shopper selects the Pay button and payment details are valid. */

src/hooks/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { useAdyenCheckout } from './useAdyenCheckout';
2-
export type { AdyenCheckoutContextValue } from './useAdyenCheckout';
2+
export type { AdyenCheckoutContextType } from './useAdyenCheckout';

src/hooks/useAdyenCheckout.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { createContext, useContext } from 'react';
2-
import type { PaymentMethodsResponse } from '../core/types';
3-
import type { Configuration } from '../core/configurations';
4-
import { MISSING_CONTEXT_ERROR } from '../core/constants';
2+
import type { PaymentMethodsResponse, Configuration } from '../core';
53

64
/**
75
* Shape of the AdyenCheckout context value.
86
*/
9-
export interface AdyenCheckoutContextValue {
7+
export interface AdyenCheckoutContextType {
108
/** Start payment with Drop-in or any payment method available in `paymentMethods` collection. */
119
start: (typeName: string) => void;
1210

@@ -21,15 +19,18 @@ export interface AdyenCheckoutContextValue {
2119
}
2220

2321
export const AdyenCheckoutContext =
24-
createContext<AdyenCheckoutContextValue | null>(null);
22+
createContext<AdyenCheckoutContextType | null>(null);
2523

2624
/**
2725
* Returns AdyenCheckout context. This context allows you to initiate payment with Drop-in or any payment method available in `paymentMethods` collection.
2826
*/
29-
export const useAdyenCheckout = (): AdyenCheckoutContextValue => {
27+
export const useAdyenCheckout = (): AdyenCheckoutContextType => {
3028
const context = useContext(AdyenCheckoutContext);
3129
if (context !== null) {
3230
return context;
3331
}
3432
throw new Error(MISSING_CONTEXT_ERROR);
3533
};
34+
35+
const MISSING_CONTEXT_ERROR =
36+
'useAdyenCheckout must be used within an AdyenCheckout';

src/modules/action/ActionModuleWrapper.tsx renamed to src/modules/action/ActionModuleWrapper.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { NativeModule } from 'react-native';
2-
import type { BaseConfiguration } from '../../core/configurations';
3-
import type { PaymentAction, PaymentDetailsData } from '../../core/types';
2+
import type {
3+
BaseConfiguration,
4+
PaymentAction,
5+
PaymentDetailsData,
6+
} from '../../core';
47
import type { ActionModule } from './AdyenAction';
58

69
/** Native module interface specific to Action */

src/modules/action/AdyenAction.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { NativeModules } from 'react-native';
2-
import type { PaymentAction, PaymentDetailsData } from '../../core/types';
3-
import type { BaseConfiguration } from '../../core/configurations';
4-
import { ActionModuleWrapper } from './ActionModuleWrapper';
2+
import type {
3+
BaseConfiguration,
4+
PaymentAction,
5+
PaymentDetailsData,
6+
} from '../../core';
57
import { ModuleMock } from '../base/ModuleMock';
8+
import { ActionModuleWrapper } from './ActionModuleWrapper';
69

710
/** Describes a native module capable of handling actions standalone. */
811
export interface ActionModule {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NativeModules } from 'react-native';
2-
import type { ConditionalPaymentComponent } from '../../core/types';
2+
import type { ConditionalPaymentComponent } from '../../core';
33
import { ModuleMock } from '../base/ModuleMock';
44
import { ApplePayWrapper } from './ApplePayWrapper';
55

0 commit comments

Comments
 (0)