Skip to content

hasReturned uses app switch state #2489

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
56 changes: 34 additions & 22 deletions src/zoid/buttons/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ export type ButtonsComponent = ZoidComponent<
ButtonExtensions
>;

// $FlowIssue
export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
const queriedEligibleFunding = [];

// $FlowIssue
return create({
tag: "paypal-buttons",
url: () => `${getPayPalDomain()}${__PAYPAL_CHECKOUT__.__URI__.__BUTTONS__}`,
Expand All @@ -125,7 +123,10 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
getExtensions: (parent) => {
return {
hasReturned: () => {
return isAppSwitchResumeFlow();
return (
isAppSwitchResumeFlow() &&
!parent.getHelpers()?.state?.appSwitchState
);
},
resume: () => {
const resumeFlowParams = getAppSwitchResumeParams();
Expand Down Expand Up @@ -356,22 +357,28 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
type: "function",
sendToChild: false,
queryParam: false,
value: () => (event) => {
sendPostRobotMessageToButtonIframe({
eventName: "paypal-hashchange",
payload: {
url: event.newURL,
},
});
},
value:
({ state }) =>
(event) => {
state.appSwitchState = "returned";

sendPostRobotMessageToButtonIframe({
eventName: "paypal-hashchange",
payload: {
url: event.newURL,
},
});
},
},

listenForHashChanges: {
type: "function",
queryParam: false,
value:
({ props }) =>
({ props, state }) =>
() => {
state.appSwitchState = "pending";

window.addEventListener("hashchange", props.hashChangeHandler);
},
},
Expand All @@ -390,24 +397,29 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
type: "function",
sendToChild: false,
queryParam: false,
value: () => () => {
sendPostRobotMessageToButtonIframe({
eventName: "paypal-visibilitychange",
payload: {
url: window.location.href,
value:
({ state }) =>
() => {
state.appSwitchState = "returned";

visibilityState: document.visibilityState,
},
});
},
sendPostRobotMessageToButtonIframe({
eventName: "paypal-visibilitychange",
payload: {
url: window.location.href,
visibilityState: document.visibilityState,
},
});
},
},

listenForVisibilityChange: {
type: "function",
queryParam: false,
value:
({ props }) =>
({ props, state }) =>
() => {
state.appSwitchState = "pending";

window.addEventListener(
"visibilitychange",
props.visibilityChangeHandler
Expand Down