Skip to content

Commit

Permalink
Merge branch 'develop' into hotfix/safari-modal-focus
Browse files Browse the repository at this point in the history
  • Loading branch information
jadutter committed Oct 17, 2023
2 parents cdcbad7 + fe91522 commit 560d92f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
5 changes: 5 additions & 0 deletions src/components/modal/v2/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ const { userAgent } = window.navigator;
export const isIframe = window.top !== window || isIosWebview(userAgent) || isAndroidWebview(userAgent);

export function setupTabTrap() {
// Disable tab trap functionality for modal lander
if (isLander) {
return;
}

const focusableElementsString =
"a[href], button, input, textarea, select, details, [tabindex]:not([tabindex='-1'])";

Expand Down
4 changes: 2 additions & 2 deletions src/library/zoid/message/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
getSessionID,
getGlobalState,
getCurrentTime,
writeToLocalStorage,
updateStorage,
getOrCreateDeviceID,
getStageTag,
getFeatures,
Expand Down Expand Up @@ -212,7 +212,7 @@ export default createGlobalVariableGetter('__paypal_credit_message__', () =>
// We still want to write it here to handle the scenario where the SDK has never been loaded
// and thus the inner iframe has no value for deviceID until after the first message render
const tsCookie = typeof ts !== 'undefined' ? ts : getTsCookieFromStorage();
writeToLocalStorage({ ts: tsCookie });
updateStorage({ ts: tsCookie });

logger.addMetaBuilder(existingMeta => {
// Remove potential existing meta info
Expand Down
10 changes: 5 additions & 5 deletions src/library/zoid/treatments/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
getEnv,
getLibraryVersion,
getStageTag,
getNamespace,
writeToLocalStorage,
updateStorage,
getDisableSetCookie,
getFeatures
getFeatures,
getDefaultNamespace
} from '../../../utils/sdk';
import { getGlobalUrl, createGlobalVariableGetter, globalEvent } from '../../../utils/global';
import { ppDebug } from '../../../utils/debug';
Expand Down Expand Up @@ -61,7 +61,7 @@ export default createGlobalVariableGetter('__paypal_credit_treatments__', () =>
namespace: {
type: 'string',
queryParam: false,
value: getNamespace
value: getDefaultNamespace
},

onReady: {
Expand All @@ -72,7 +72,7 @@ export default createGlobalVariableGetter('__paypal_credit_treatments__', () =>
const TREATMENTS_MAX_AGE = 1000 * 60 * 15;

return ({ treatmentsHash, deviceID }) => {
writeToLocalStorage({
updateStorage({
experiments: {
treatmentsHash,
// Experiments can only be maintained for 15 minutes
Expand Down
37 changes: 18 additions & 19 deletions src/utils/sdk.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable eslint-comments/disable-enable-pair, no-else-return */
import arrayFrom from 'core-js-pure/stable/array/from';

import { isLocalStorageEnabled, getStorage as getBelterStorage } from '@krakenjs/belter/src';
import { getStorage as getBelterStorage } from '@krakenjs/belter/src';
import { SDK_QUERY_KEYS, SDK_SETTINGS } from '@paypal/sdk-constants/src';
import {
getClientID,
Expand All @@ -14,8 +14,10 @@ import {
getSDKQueryParam,
getCSPNonce,
getNamespace as getSDKNamespace,
getDefaultNamespace as getDefaultSDKNamespace,
getSessionID as getSDKSessionID,
getStorageID as getSDKStorageID,
getStorageState as getSDKStorageState,
getPayPalDomain as getSDKPayPalDomain,
getDisableSetCookie as getSDKDisableCookie
} from '@paypal/sdk-client/src';
Expand Down Expand Up @@ -116,11 +118,19 @@ export function getScriptAttributes() {
}
}

export function getDefaultNamespace() {
if (__MESSAGES__.__TARGET__ === 'SDK') {
return getDefaultSDKNamespace();
} else {
return 'paypal';
}
}

export function getNamespace() {
if (__MESSAGES__.__TARGET__ === 'SDK') {
return getSDKNamespace();
} else {
return getScript()?.getAttribute('data-pp-namespace') || 'paypal';
return getScript()?.getAttribute('data-pp-namespace') || getDefaultNamespace();
}
}

Expand Down Expand Up @@ -157,23 +167,12 @@ export function getOrCreateDeviceID() {
}
}

// Retrieve namespaced localStorage directly
function getRawStorage() {
return isLocalStorageEnabled()
? JSON.parse(window.localStorage?.getItem(`__${getNamespace()}_storage__`) ?? '{}')
: {};
}

export function writeToLocalStorage(values) {
return isLocalStorageEnabled()
? window.localStorage?.setItem(
`__${getNamespace()}_storage__`,
JSON.stringify({
...getRawStorage(),
...values
}) ?? '{}'
)
: {};
export function updateStorage(values) {
if (__MESSAGES__.__TARGET__ === 'SDK') {
return getSDKStorageState(storage => Object.assign(storage, values));
} else {
return getStorage().getState(storage => Object.assign(storage, values));
}
}

// Check if the current script is in the process of being destroyed since
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/spec/src/utils/experiments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ jest.mock('@paypal/sdk-client/src', () => ({
getPayPalDomain: () => 'localhost.paypal.com',
getSDKMeta: () => 'meta',
getEnv: () => 'local',
getDisableSetCookie: () => 'true'
getDisableSetCookie: () => 'true',
getDefaultNamespace: () => 'paypal'
}));

describe('experiments utils', () => {
Expand Down

0 comments on commit 560d92f

Please sign in to comment.