@akinon/pz-masterpass 1.19.1 → 1.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @akinon/pz-masterpass
2
2
 
3
+ ## 1.19.3
4
+
5
+ ### Patch Changes
6
+
7
+ - ZERO-2427: Fix translation and check script load states
8
+
9
+ ## 1.19.2
10
+
11
+ ### Patch Changes
12
+
13
+ - ZERO-2287: Add optional masterpassJsUrl to Settings
14
+
3
15
  ## 1.19.1
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/pz-masterpass",
3
- "version": "1.19.1",
3
+ "version": "1.19.3",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.d.ts",
@@ -3,7 +3,7 @@
3
3
  import { useLocalization } from '@akinon/next/hooks';
4
4
  import { useAppDispatch, useAppSelector } from '@akinon/next/redux/hooks';
5
5
  import Script from 'next/script';
6
- import { useEffect } from 'react';
6
+ import { useEffect, useState } from 'react';
7
7
  import { checkMasterpass } from './utils/check-masterpass';
8
8
  import { init } from './utils/init';
9
9
  import {
@@ -46,6 +46,11 @@ export const MasterpassProvider = (props: MasterpassProviderProps) => {
46
46
  const { locale } = useLocalization();
47
47
  const dispatch = useAppDispatch();
48
48
 
49
+ const [scriptLoadState, setScriptLoadState] = useState({
50
+ zepto: false,
51
+ mfs: false
52
+ });
53
+
49
54
  const prepareState = async () => {
50
55
  dispatch(setLanguage(getLanguage(locale)));
51
56
 
@@ -86,12 +91,16 @@ export const MasterpassProvider = (props: MasterpassProviderProps) => {
86
91
  };
87
92
 
88
93
  useEffect(() => {
89
- if (preOrder?.payment_option?.payment_type !== 'masterpass') {
94
+ if (
95
+ preOrder?.payment_option?.payment_type !== 'masterpass' ||
96
+ !scriptLoadState.zepto ||
97
+ !scriptLoadState.mfs
98
+ ) {
90
99
  return;
91
100
  }
92
101
 
93
102
  prepareState();
94
- }, [preOrder?.payment_option?.payment_type]);
103
+ }, [scriptLoadState, preOrder?.payment_option?.payment_type]);
95
104
 
96
105
  useEffect(() => {
97
106
  if (!otp.response) {
@@ -116,8 +125,26 @@ export const MasterpassProvider = (props: MasterpassProviderProps) => {
116
125
 
117
126
  return (
118
127
  <>
119
- <Script src="/mfs-client.min.js" strategy="afterInteractive" />
120
- <Script src="/zepto.min.js" strategy="afterInteractive" />
128
+ <Script
129
+ src="/mfs-client.min.js"
130
+ strategy="afterInteractive"
131
+ onLoad={() => {
132
+ setScriptLoadState((prevState) => ({
133
+ ...prevState,
134
+ mfs: true
135
+ }));
136
+ }}
137
+ />
138
+ <Script
139
+ src="/zepto.min.js"
140
+ strategy="afterInteractive"
141
+ onLoad={() => {
142
+ setScriptLoadState((prevState) => ({
143
+ ...prevState,
144
+ zepto: true
145
+ }));
146
+ }}
147
+ />
121
148
 
122
149
  <Modal
123
150
  portalId="masterpass-error-modal"
package/src/utils/init.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  import { buildClientRequestUrl } from '@akinon/next/utils';
2
2
  import { MasterpassCredentials } from '../types';
3
+ import settings from 'settings';
3
4
 
4
5
  export const init = () =>
5
6
  new Promise<MasterpassCredentials>(async (resolve) => {
6
7
  try {
7
- const response = await fetch(buildClientRequestUrl('/masterpass-js'));
8
+ const response = await fetch(
9
+ settings.checkout?.masterpassJsUrl ??
10
+ buildClientRequestUrl('/masterpass-js')
11
+ );
8
12
  const data: MasterpassCredentials = await response.json();
9
13
 
10
14
  window.MFS.setClientId(data.client_id);
@@ -1,21 +1,14 @@
1
1
  import React from 'react';
2
2
  import { Button, LoaderSpinner } from 'components';
3
- import { useTranslation } from '@akinon/next/hooks';
4
3
  import { useCountdown } from '../../hooks/use-countdown';
5
4
 
6
- const SendSms = ({ resendSms, resendSmsFetching }) => {
7
- const { t } = useTranslation('checkout');
8
-
5
+ const SendSms = ({ resendSms, resendSmsFetching, resendSmsTranslation }) => {
9
6
  return (
10
7
  <Button
11
8
  onClick={() => resendSms()}
12
9
  className="mt-2 w-full text-primary bg-[#cccccc] border-0 hover:border"
13
10
  >
14
- {!resendSmsFetching ? (
15
- t('payment.masterpass.add.send_sms_again')
16
- ) : (
17
- <LoaderSpinner />
18
- )}
11
+ {!resendSmsFetching ? resendSmsTranslation : <LoaderSpinner />}
19
12
  </Button>
20
13
  );
21
14
  };
@@ -28,12 +21,21 @@ const ShowCounter = ({ minutes, seconds }) => {
28
21
  );
29
22
  };
30
23
 
31
- const CountdownTimer = ({ targetDate, resendSms, resendSmsFetching }) => {
24
+ const CountdownTimer = ({
25
+ targetDate,
26
+ resendSms,
27
+ resendSmsFetching,
28
+ resendSmsTranslation
29
+ }) => {
32
30
  const [minutes, seconds] = useCountdown(targetDate);
33
31
 
34
32
  if (minutes + seconds <= 0) {
35
33
  return (
36
- <SendSms resendSms={resendSms} resendSmsFetching={resendSmsFetching} />
34
+ <SendSms
35
+ resendSms={resendSms}
36
+ resendSmsFetching={resendSmsFetching}
37
+ resendSmsTranslation={resendSmsTranslation}
38
+ />
37
39
  );
38
40
  } else {
39
41
  return <ShowCounter minutes={minutes} seconds={seconds} />;
@@ -8,7 +8,7 @@ import { useCallback, useEffect, useState } from 'react';
8
8
  import { formCreator } from '../../utils';
9
9
 
10
10
  import CountdownTimer from '../countdown-timer/countdown-timer';
11
- import { OtpForm, OtpFormProps } from './otp-form';
11
+ import { OtpForm, OtpFormProps, defaultTranslations } from './otp-form';
12
12
  import { useAppDispatch, useAppSelector } from '@akinon/next/redux/hooks';
13
13
  import { setOtpResponse } from '../../redux/reducer';
14
14
  import { Image } from '@akinon/next/components/image';
@@ -140,6 +140,9 @@ export const MasterpassOtpModal = ({
140
140
  resendSmsFetching={isBusy}
141
141
  targetDate={otpTime}
142
142
  resendSms={resendSms}
143
+ resendSmsTranslation={
144
+ translations?.resend_sms ?? defaultTranslations.resend_sms
145
+ }
143
146
  />
144
147
  </div>
145
148
  </div>
@@ -4,10 +4,11 @@ import { useEffect } from 'react';
4
4
  import { useForm } from 'react-hook-form';
5
5
  import * as yup from 'yup';
6
6
 
7
- const defaultTranslations = {
7
+ export const defaultTranslations = {
8
8
  enter_the_verification_code: 'Enter the verification code',
9
9
  sms_code: 'SMS Code',
10
- verify: 'Verify'
10
+ verify: 'Verify',
11
+ resend_sms: 'Resend SMS'
11
12
  };
12
13
 
13
14
  export interface OtpFormProps {