@@ -685,77 +685,55 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
685685 onMessageHover : {
686686 type : "function" ,
687687 required : false ,
688- value : ( { props, state } ) => {
689- return async ( { offerType } ) => {
690- if ( ! window . paypal . MessagesModal . show && ! state . isModalFetching ) {
691- state . isModalFetching = true ;
692- await getModal ( ) ;
693- state . isModalFetching = false ;
694-
695- if ( state . isAwaitingShow === true ) {
696- const { message, clientID, merchantID } = props ;
697- const amount = message ?. amount ;
698-
699- window . paypal
700- . MessagesModal ( {
701- onReady : ( { show } ) => {
702- show ( {
703- amount,
704- offer : offerType ,
705- account : clientID ,
706- merchantId : merchantID ,
707- } ) ;
708- } ,
709- } )
710- . render ( "body" ) ;
711-
712- state . isAwaitingShow = false ;
713- }
714- }
688+ value : ( ) => {
689+ return ( ) => {
690+ // lazy loads the modal, to be memoized and executed onMessageClick
691+ getModal ( ) ;
715692 } ;
716693 } ,
717694 } ,
718695
719696 onMessageClick : {
720697 type : "function" ,
721698 required : false ,
722- value : ( { props, state } ) => {
699+ value : ( { props } ) => {
723700 return async ( { offerType, messageType } ) => {
724- if ( window . paypal . MessagesModal ) {
725- const { message, clientID, merchantID, buttonSessionID } = props ;
726- const amount = message ?. amount || undefined ;
727-
728- window . paypal
729- . MessagesModal ( {
730- onReady : ( { show } ) => {
731- show ( {
732- amount,
733- offer : offerType ,
734- account : clientID ,
735- merchantId : merchantID ,
736- } ) ;
737- } ,
738- } )
739- . render ( "body" ) ;
740-
741- getLogger ( )
742- . info ( "button_message_clicked" )
743- . track ( {
744- [ FPTI_KEY . MESSAGE_TYPE ] : messageType ,
745- [ FPTI_KEY . MESSAGE_STYLE_POSITION ] : message . position ,
746- [ FPTI_KEY . MESSAGE_STYLE_TEXT_ALIGN ] : message . align ,
747- [ FPTI_KEY . MESSAGE_STYLE_COLOR ] : message . color ,
748- [ FPTI_KEY . MESSAGE_OFFER ] : offerType ,
749- [ FPTI_KEY . AMOUNT ] : amount ,
750- [ FPTI_KEY . BUTTON_MESSAGE_ID ] : buttonSessionID ,
751- } ) ;
752- } else if ( ! state . isModalFetching ) {
753- state . isModalFetching = true ;
754- await getModal ( ) ;
755- state . isModalFetching = false ;
756- } else {
757- state . isAwaitingShow = true ;
758- }
701+ const {
702+ message,
703+ clientID,
704+ merchantID,
705+ currency,
706+ locale : { lang, country } ,
707+ buttonSessionID,
708+ } = props ;
709+ const amount = message ?. amount || undefined ;
710+
711+ const modal = await getModal ( ) ;
712+ const modalInstance = modal ( {
713+ account : `client-id:${ clientID } ` ,
714+ } ) ;
715+ modalInstance . show ( {
716+ amount,
717+ offer : offerType ?. join ( "," ) || undefined ,
718+ account : `client-id:${ clientID } ` ,
719+ merchantId : merchantID ?. join ( "," ) || undefined ,
720+ language : `${ lang } -${ country } ` ,
721+ buyerCountry : getBuyerCountry ( ) ,
722+ currency,
723+ } ) ;
724+
725+ getLogger ( )
726+ . info ( "button_message_clicked" )
727+ . track ( {
728+ [ FPTI_KEY . EVENT_NAME ] : "message_click" ,
729+ // [FPTI_KEY.BUTTON_MESSAGE_OFFER_TYPE]: offerType,
730+ // [FPTI_KEY.BUTTON_MESSAGE_TYPE]: messageType,
731+ // [FPTI_KEY.BUTTON_MESSAGE_POSITION]: message.position,
732+ // [FPTI_KEY.BUTTON_MESSAGE_ALIGN]: message.align,
733+ // [FPTI_KEY.BUTTON_MESSAGE_COLOR]: message.color,
734+ // [FPTI_KEY.AMOUNT]: amount,
735+ [ FPTI_KEY . BUTTON_SESSION_UID ] : buttonSessionID ,
736+ } ) ;
759737 } ;
760738 } ,
761739 } ,
0 commit comments