Skip to content

feat: message hover and click behavior and modal #2352

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

Merged
merged 17 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 3 additions & 16 deletions src/zoid/buttons/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -697,28 +697,15 @@
type: "function",
required: false,
value: ({ props }) => {
return async ({ offerType, messageType }) => {

Check failure on line 700 in src/zoid/buttons/component.jsx

View workflow job for this annotation

GitHub Actions / main

'messageType' is defined but never used
const {
message,
clientID,
merchantID,
currency,
locale: { lang, country },
buttonSessionID,
} = props;
const { message, clientID, merchantID, currency, buttonSessionID } =
props;
const amount = message?.amount || undefined;

const modal = await getModal();
const modalInstance = modal({
account: `client-id:${clientID}`,
});
const modalInstance = await getModal(clientID, merchantID);
modalInstance.show({
amount,
offer: offerType?.join(",") || undefined,
account: `client-id:${clientID}`,
merchantId: merchantID?.join(",") || undefined,
language: `${lang}-${country}`,
buyerCountry: getBuyerCountry(),
currency,
});

Expand Down
26 changes: 22 additions & 4 deletions src/zoid/buttons/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable compat/compat */

Check failure on line 1 in src/zoid/buttons/util.js

View workflow job for this annotation

GitHub Actions / main

'compat/compat' rule is disabled but never reported

Check failure on line 1 in src/zoid/buttons/util.js

View workflow job for this annotation

GitHub Actions / main

Requires 'eslint-enable' directive for 'compat/compat'
/* eslint-disable promise/no-native */

Check failure on line 2 in src/zoid/buttons/util.js

View workflow job for this annotation

GitHub Actions / main

Requires 'eslint-enable' directive for 'promise/no-native'
/* @flow */
import {
supportsPopups as userAgentSupportsPopups,
Expand All @@ -26,6 +26,7 @@
getPlatform,
getComponents,
getEnv,
getNamespace,
} from "@paypal/sdk-client/src";
import { getRefinedFundingEligibility } from "@paypal/funding-components/src";

Expand Down Expand Up @@ -362,9 +363,18 @@
}
}

export const getModal: () => Object = memoize(() => {
if (window.paypal?.MessagesModal) {
return window.paypal.MessagesModal;
export const getModal: (
clientID: string,
merchantID: $ReadOnlyArray<string> | void
) => Object = memoize((clientID, merchantID) => {
const namespace = getNamespace();

if (window[namespace]?.MessagesModal) {
const modal = window[namespace].MessagesModal;
return modal({
account: `client-id:${clientID}`,
merchantId: merchantID?.join(",") || undefined,
});
} else {
const modalBundleUrl = () => {
let envPiece;
Expand All @@ -389,10 +399,18 @@
return new Promise((resolve) => {
const script = document.createElement("script");
script.src = modalBundleUrl();
script.setAttribute("data-namespace", namespace);
script.setAttribute("data-pp-namespace", namespace);
document.body?.appendChild(script);
script.addEventListener("load", () => {
document.body?.removeChild(script);
resolve(window.paypal.MessagesModal);
const modal = window[namespace].MessagesModal;
resolve(() =>
modal({
account: `client-id:${clientID}`,
merchantId: merchantID?.join(",") || undefined,
})
);
});
});
} catch (err) {
Expand Down
Loading