Skip to content

Commit

Permalink
Clarified function name and purpose (via comments)
Browse files Browse the repository at this point in the history
  • Loading branch information
sponglord committed Dec 5, 2023
1 parent c31de29 commit 0b6c5fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/lib/src/components/Redirect/Redirect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Redirect from './Redirect';
import RedirectShopper from './components/RedirectShopper';
import RedirectElement from './Redirect';

jest.mock('../../utils/detectInIframeInAccessibleDomain', () => {
jest.mock('../../utils/detectInIframeInSameOrigin', () => {
return jest.fn().mockImplementation(() => {
return true;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, h } from 'preact';
import detectInIframeInAccessibleDomain from '../../../../utils/detectInIframeInAccessibleDomain';
import detectInIframeInSameOrigin from '../../../../utils/detectInIframeInSameOrigin';

interface RedirectShopperProps {
beforeRedirect: (resolve, reject, url) => Promise<void>;
Expand All @@ -21,7 +21,7 @@ class RedirectShopper extends Component<RedirectShopperProps> {
if (this.postForm) {
this.postForm.submit();
} else {
if (this.props.redirectFromTopWhenInIframe && detectInIframeInAccessibleDomain()) {
if (this.props.redirectFromTopWhenInIframe && detectInIframeInSameOrigin()) {
// if in an iframe and the config prop allows it - try to redirect from the top level window
window.top.location.assign?.(this.props.url);
} else {
Expand Down Expand Up @@ -51,7 +51,7 @@ class RedirectShopper extends Component<RedirectShopperProps> {
ref={ref => {
this.postForm = ref;
}}
{...(this.props.redirectFromTopWhenInIframe && detectInIframeInAccessibleDomain() && { target: '_top' })}
{...(this.props.redirectFromTopWhenInIframe && detectInIframeInSameOrigin() && { target: '_top' })}
>
{Object.keys(data).map(key => (
<input type="hidden" name={key} key={key} value={data[key]} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Returns true if the page is being run in an iframe (in a domain we have access to)
/**
* Returns true if the page is being run in an iframe with the same origin as the parent.
* In this scenario, if the merchant has set redirectFromTopWhenInIframe: true, then we can perform the redirect on the top level, parent, window;
* rather than on the iframe's window
*/
export default () => {
try {
if (window.parent.location.href) {
Expand Down

0 comments on commit 0b6c5fb

Please sign in to comment.