@opexa/portal-components 0.1.6 → 0.1.8

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.
@@ -17,6 +17,14 @@ import { onMobileDevice } from '../../../utils/onMobileDevice.js';
17
17
  import { parseDecimal } from '../../../utils/parseDecimal.js';
18
18
  import { useDepositWithdrawalPropsContext } from '../DepositWithdrawalContext.js';
19
19
  import { PaymentMethods } from '../PaymentMethods.js';
20
+ /** True when identity is verified on the member account, including Sumsub flows where nested `verification` is null. */
21
+ function isMemberWithdrawalVerifiedByAccount(account) {
22
+ const nested = account.verification?.status;
23
+ return (account.verificationStatus === 'VERIFIED' ||
24
+ account.verified === true ||
25
+ nested === 'VERIFIED' ||
26
+ nested === 'APPROVED');
27
+ }
20
28
  const GCashStandardCashInWithdrawal = lazy(() => import('./GCashStandardCashInWithdrawal/GCashStandardCashInWithdrawal.js').then((m) => ({
21
29
  default: m.GCashStandardCashInWithdrawal,
22
30
  })));
@@ -145,17 +153,21 @@ export function Withdrawal() {
145
153
  if (!isMayaSessionValid) {
146
154
  return _jsx(MayaSessionSessionExpired, {});
147
155
  }
148
- if (account?.status === 'VERIFICATION_LOCKED') {
156
+ const withdrawalVerified = account != null ? isMemberWithdrawalVerifiedByAccount(account) : false;
157
+ if (account?.status === 'VERIFICATION_LOCKED' &&
158
+ !withdrawalVerified) {
149
159
  return _jsx(AccountVerificationLockRequired, {});
150
160
  }
151
161
  if (parseDecimal(wallet?.balance, 0) < 1) {
152
162
  return _jsx(InsufficientBalance, {});
153
163
  }
154
164
  if (restrictWithdrawalsToVerifiedMembers &&
165
+ !withdrawalVerified &&
155
166
  memberVerification?.status === 'PENDING') {
156
167
  return _jsx(_AccountVerificationPending, {});
157
168
  }
158
169
  if (restrictWithdrawalsToVerifiedMembers &&
170
+ !withdrawalVerified &&
159
171
  (!memberVerification ||
160
172
  (memberVerification.status !== 'APPROVED' &&
161
173
  memberVerification.status !== 'VERIFIED' &&
@@ -1 +1,6 @@
1
- export declare function UpdateMobilePhoneNumber(): import("react/jsx-runtime").JSX.Element;
1
+ import { type UpdateMobilePhoneNumberShouldOnlyShow } from './hooks/useAutoOpen';
2
+ export type { UpdateMobilePhoneNumberShouldOnlyShow };
3
+ type UpdateMobilePhoneNumberProps = {
4
+ shouldOnlyShow?: UpdateMobilePhoneNumberShouldOnlyShow;
5
+ };
6
+ export declare function UpdateMobilePhoneNumber({ shouldOnlyShow, }?: UpdateMobilePhoneNumberProps): import("react/jsx-runtime").JSX.Element;
@@ -10,10 +10,10 @@ import { Dialog } from '../../ui/Dialog/index.js';
10
10
  import { Portal } from '../../ui/Portal/index.js';
11
11
  import { Step1MobileNumberForm } from './components/Step1MobileNumberForm.js';
12
12
  import { Step2VerificationForm } from './components/Step2VerificationForm.js';
13
- import { useAutoOpenWhenUnverified } from './hooks/useAutoOpenWhenUnverified.js';
13
+ import { useAutoOpen, } from './hooks/useAutoOpen.js';
14
14
  import { useUpdateMobileFlow } from './hooks/useUpdateMobileFlow.js';
15
- export function UpdateMobilePhoneNumber() {
16
- useAutoOpenWhenUnverified();
15
+ export function UpdateMobilePhoneNumber({ shouldOnlyShow = 'MobileVerified', } = {}) {
16
+ useAutoOpen(shouldOnlyShow);
17
17
  const featureFlag = useFeatureFlag();
18
18
  const globalStore = useGlobalStore(useShallow((ctx) => ({
19
19
  updateMobilePhoneNumber: ctx.updateMobilePhoneNumber,
@@ -0,0 +1,8 @@
1
+ export type UpdateMobilePhoneNumberShouldOnlyShow = 'MobileVerified' | 'HasMobile';
2
+ /**
3
+ * Opens the UpdateMobilePhoneNumber dialog automatically (once per mount) if
4
+ * the account has finished loading and:
5
+ * - `MobileVerified` (default): the mobile number is not verified; closes if verified.
6
+ * - `HasMobile`: the user has no mobile number (`mobileNumber` is null); closes if set.
7
+ */
8
+ export declare function useAutoOpen(shouldOnlyShow?: UpdateMobilePhoneNumberShouldOnlyShow): void;
@@ -0,0 +1,48 @@
1
+ 'use client';
2
+ import { useEffect, useRef } from 'react';
3
+ import { useShallow } from 'zustand/shallow';
4
+ import { useAccountQuery } from '../../../client/hooks/useAccountQuery.js';
5
+ import { useGlobalStore } from '../../../client/hooks/useGlobalStore.js';
6
+ /**
7
+ * Opens the UpdateMobilePhoneNumber dialog automatically (once per mount) if
8
+ * the account has finished loading and:
9
+ * - `MobileVerified` (default): the mobile number is not verified; closes if verified.
10
+ * - `HasMobile`: the user has no mobile number (`mobileNumber` is null); closes if set.
11
+ */
12
+ export function useAutoOpen(shouldOnlyShow = 'MobileVerified') {
13
+ const { setOpen } = useGlobalStore(useShallow((ctx) => ({
14
+ setOpen: ctx.updateMobilePhoneNumber.setOpen,
15
+ })));
16
+ const accountQuery = useAccountQuery();
17
+ const account = accountQuery.data;
18
+ const isAccountLoading = accountQuery.isLoading;
19
+ const isMobileNumberVerified = account?.mobileNumberVerified === true;
20
+ const hasMobileNumber = account?.mobileNumber != null;
21
+ const hasExecuted = useRef(false);
22
+ useEffect(() => {
23
+ if (!isAccountLoading && !!account && !hasExecuted.current) {
24
+ if (shouldOnlyShow === 'HasMobile') {
25
+ if (!hasMobileNumber) {
26
+ setOpen(true);
27
+ }
28
+ else {
29
+ setOpen(false);
30
+ }
31
+ }
32
+ else if (!isMobileNumberVerified) {
33
+ setOpen(true);
34
+ }
35
+ else {
36
+ setOpen(false);
37
+ }
38
+ hasExecuted.current = true;
39
+ }
40
+ }, [
41
+ isAccountLoading,
42
+ account,
43
+ hasMobileNumber,
44
+ isMobileNumberVerified,
45
+ shouldOnlyShow,
46
+ setOpen,
47
+ ]);
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opexa/portal-components",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "exports": {
5
5
  "./ui/*": {
6
6
  "types": "./dist/ui/*/index.d.ts",