Skip to content
Draft
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
1 change: 0 additions & 1 deletion platforms/android/lib/api/lib.api
Original file line number Diff line number Diff line change
Expand Up @@ -3933,7 +3933,6 @@ public final class com/shopify/checkoutkit/ShopifyCheckoutKit {
public static final fun configure (Lcom/shopify/checkoutkit/ConfigurationUpdater;)V
public static final fun getConfiguration ()Lcom/shopify/checkoutkit/Configuration;
public static final fun invalidate ()V
public static final fun preload (Ljava/lang/String;Landroidx/activity/ComponentActivity;)V
public static final fun present (Ljava/lang/String;Landroidx/activity/ComponentActivity;Lcom/shopify/checkoutkit/DefaultCheckoutEventProcessor;)Lcom/shopify/checkoutkit/CheckoutKitDialog;
public static final fun present (Ljava/lang/String;Landroidx/activity/ComponentActivity;Lcom/shopify/checkoutkit/DefaultCheckoutEventProcessor;Lcom/shopify/checkoutkit/CheckoutCommunicationClient;)Lcom/shopify/checkoutkit/CheckoutKitDialog;
public static synthetic fun present$default (Ljava/lang/String;Landroidx/activity/ComponentActivity;Lcom/shopify/checkoutkit/DefaultCheckoutEventProcessor;Lcom/shopify/checkoutkit/CheckoutCommunicationClient;ILjava/lang/Object;)Lcom/shopify/checkoutkit/CheckoutKitDialog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ public object ShopifyCheckoutKit {
*
* @param checkoutUrl The URL of the checkout to be loaded, this can be obtained via the Storefront API
* @param context The context the checkout is being presented from
*
* Public preload support is coming soon.
*/
@JvmStatic
public fun preload(checkoutUrl: String, context: ComponentActivity) {
internal fun preload(checkoutUrl: String, context: ComponentActivity) {
log.d("ShopifyCheckoutKit", "Preload called. Preloading enabled ${configuration.preloading.enabled}.")
if (!configuration.preloading.enabled) return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ class CartViewModel(
fun preloadCheckout(
activity: ComponentActivity,
) {
val state = _cartState.value
if (state is CartState.Cart) {
Timber.i("Preloading checkout with url ${state.checkoutUrl}")
ShopifyCheckoutKit.preload(state.checkoutUrl, activity)
} else {
Timber.i("Skipping checkout preload, cart is empty")
}
// val state = _cartState.value
// if (state is CartState.Cart) {
// Timber.i("Preloading checkout with url ${state.checkoutUrl}")
// ShopifyCheckoutKit.preload(state.checkoutUrl, activity)
// } else {
// Timber.i("Skipping checkout preload, cart is empty")
// }
}

fun continueShopping(navController: NavController) {
Expand Down
1 change: 0 additions & 1 deletion platforms/react-native/__mocks__/react-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const exampleConfig = {preloading: true};
const ShopifyCheckoutKit = {
version: '0.7.0',
getConstants: jest.fn(() => ({version: '0.7.0'})),
preload: jest.fn(),
present: jest.fn(),
dismiss: jest.fn(),
invalidateCache: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ public void dismiss() {
}
}

@ReactMethod
public void preload(String checkoutURL) {
Activity currentActivity = getCurrentActivity();

if (currentActivity instanceof ComponentActivity) {
ShopifyCheckoutSheetKit.preload(checkoutURL, (ComponentActivity) currentActivity);
}
}

@ReactMethod
public void invalidateCache() {
ShopifyCheckoutSheetKit.invalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,6 @@ class RCTShopifyCheckoutKit: RCTEventEmitter, CheckoutDelegate {
}
}

@objc func preload(_ checkoutURL: String) {
DispatchQueue.main.async {
if let url = URL(string: checkoutURL) {
ShopifyCheckoutSheetKit.preload(checkout: url)
}
}
}

private func getColorScheme(_ colorScheme: String) -> ShopifyCheckoutSheetKit.Configuration.ColorScheme {
switch colorScheme {
case "web_default":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ interface Context {
getConfig: () => Configuration | undefined;
setConfig: (config: Configuration) => void;
removeEventListeners: RemoveEventListeners;
preload: (checkoutUrl: string) => void;
present: (checkoutUrl: string) => void;
dismiss: () => void;
invalidate: () => void;
Expand Down Expand Up @@ -80,8 +79,8 @@ export function ShopifyCheckoutProvider({
// eslint-disable-next-line no-console
console.warn(
'[ShopifyCheckoutKit] Providing accessToken with contactFields (email / phoneNumber) is deprecated and will become an error in v4.' +
'When the user is authenticated with Customer Accounts, provide accessToken' +
'When the user is otherwise authenticated, provide email/phoneNumber.',
'When the user is authenticated with Customer Accounts, provide accessToken' +
'When the user is otherwise authenticated, provide email/phoneNumber.',
);
}

Expand All @@ -108,12 +107,6 @@ export function ShopifyCheckoutProvider({
}
}, []);

const preload = useCallback((checkoutUrl: string) => {
if (checkoutUrl) {
instance.current?.preload(checkoutUrl);
}
}, []);

const invalidate = useCallback(() => {
instance.current?.invalidate();
}, []);
Expand All @@ -137,7 +130,6 @@ export function ShopifyCheckoutProvider({
dismiss,
setConfig,
getConfig,
preload,
present,
invalidate,
removeEventListeners,
Expand All @@ -150,7 +142,6 @@ export function ShopifyCheckoutProvider({
removeEventListeners,
getConfig,
setConfig,
preload,
present,
invalidate,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,6 @@ export interface ShopifyCheckoutKit {
* The version number of the Shopify Checkout SDK.
*/
readonly version: string;
/**
* Preload the checkout for faster presentation.
*/
preload(checkoutURL: string): void;

/**
* Invalidate preload cache.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ import {
import {CheckoutErrorCode} from './errors.d';
import type {CheckoutCompletedEvent} from './events.d';
import type {CustomEvent, PixelEvent, StandardEvent} from './pixels.d';
import {ApplePayLabel, ApplePayStyle} from './components/AcceleratedCheckoutButtons';
import {
ApplePayLabel,
ApplePayStyle,
} from './components/AcceleratedCheckoutButtons';
import type {
AcceleratedCheckoutButtonsProps,
RenderStateChangeEvent,
Expand Down Expand Up @@ -133,14 +136,6 @@ class ShopifyCheckout implements ShopifyCheckoutKit {
RNShopifyCheckoutKit.invalidateCache();
}

/**
* Preloads checkout for a given URL to improve performance
* @param checkoutUrl The URL of the checkout to preload
*/
public preload(checkoutUrl: string): void {
RNShopifyCheckoutKit.preload(checkoutUrl);
}

/**
* Presents the checkout sheet for a given checkout URL
* @param checkoutUrl The URL of the checkout to display
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ type ConfigurationResultSpec = {

export interface Spec extends TurboModule {
present(checkoutUrl: string): void;
preload(checkoutUrl: string): void;
dismiss(): void;
invalidateCache(): void;
setConfig(configuration: ConfigurationSpec): void;
Expand All @@ -96,6 +95,4 @@ export interface Spec extends TurboModule {
getConstants(): {version: string};
}

export default TurboModuleRegistry.getEnforcing<Spec>(
'ShopifyCheckoutKit',
);
export default TurboModuleRegistry.getEnforcing<Spec>('ShopifyCheckoutKit');
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React from 'react';
import {render, act} from '@testing-library/react-native';
import {NativeModules, Platform} from 'react-native';
import {
ShopifyCheckoutProvider,
useShopifyCheckout,
} from '../src/context';
import {ShopifyCheckoutProvider, useShopifyCheckout} from '../src/context';
import {ApplePayContactField, ColorScheme, type Configuration} from '../src';

const checkoutUrl = 'https://shopify.com/checkout';
Expand Down Expand Up @@ -54,9 +51,9 @@ describe('ShopifyCheckoutProvider', () => {
</TestComponent>,
);

expect(
NativeModules.ShopifyCheckoutKit.setConfig,
).toHaveBeenCalledWith(config);
expect(NativeModules.ShopifyCheckoutKit.setConfig).toHaveBeenCalledWith(
config,
);
});

it('skips configuration when no configuration is provided', () => {
Expand All @@ -66,9 +63,7 @@ describe('ShopifyCheckoutProvider', () => {
</ShopifyCheckoutProvider>,
);

expect(
NativeModules.ShopifyCheckoutKit.setConfig,
).not.toHaveBeenCalled();
expect(NativeModules.ShopifyCheckoutKit.setConfig).not.toHaveBeenCalled();
expect(
NativeModules.ShopifyCheckoutKit.configureAcceleratedCheckouts,
).not.toHaveBeenCalled();
Expand Down Expand Up @@ -137,9 +132,9 @@ describe('ShopifyCheckoutProvider', () => {
</TestComponent>,
);

expect(
NativeModules.ShopifyCheckoutKit.setConfig.mock.calls,
).toHaveLength(2);
expect(NativeModules.ShopifyCheckoutKit.setConfig.mock.calls).toHaveLength(
2,
);
});
});

Expand Down Expand Up @@ -226,51 +221,7 @@ describe('useShopifyCheckout', () => {
hookValue.present('');
});

expect(
NativeModules.ShopifyCheckoutKit.present,
).not.toHaveBeenCalled();
});

it('provides preload function and calls it with checkoutUrl', () => {
let hookValue: any;
const onHookValue = (value: any) => {
hookValue = value;
};

render(
<Wrapper>
<HookTestComponent onHookValue={onHookValue} />
</Wrapper>,
);

act(() => {
hookValue.preload(checkoutUrl);
});

expect(NativeModules.ShopifyCheckoutKit.preload).toHaveBeenCalledWith(
checkoutUrl,
);
});

it('does not call preload with empty checkoutUrl', () => {
let hookValue: any;
const onHookValue = (value: any) => {
hookValue = value;
};

render(
<Wrapper>
<HookTestComponent onHookValue={onHookValue} />
</Wrapper>,
);

act(() => {
hookValue.preload('');
});

expect(
NativeModules.ShopifyCheckoutKit.preload,
).not.toHaveBeenCalled();
expect(NativeModules.ShopifyCheckoutKit.present).not.toHaveBeenCalled();
});

it('provides invalidate function', () => {
Expand All @@ -289,9 +240,7 @@ describe('useShopifyCheckout', () => {
hookValue.invalidate();
});

expect(
NativeModules.ShopifyCheckoutKit.invalidateCache,
).toHaveBeenCalled();
expect(NativeModules.ShopifyCheckoutKit.invalidateCache).toHaveBeenCalled();
});

it('provides dismiss function', () => {
Expand Down Expand Up @@ -331,9 +280,9 @@ describe('useShopifyCheckout', () => {
hookValue.setConfig(newConfig);
});

expect(
NativeModules.ShopifyCheckoutKit.setConfig,
).toHaveBeenCalledWith(newConfig);
expect(NativeModules.ShopifyCheckoutKit.setConfig).toHaveBeenCalledWith(
newConfig,
);
});

it('provides getConfig function', async () => {
Expand Down
Loading
Loading