diff --git a/packages/mobile/src/components/pincode/pincode-component.tsx b/packages/mobile/src/components/pincode/pincode-component.tsx index c020a3dfc6..f3d78b7c34 100644 --- a/packages/mobile/src/components/pincode/pincode-component.tsx +++ b/packages/mobile/src/components/pincode/pincode-component.tsx @@ -1,4 +1,10 @@ -import React, { FunctionComponent, useEffect, useRef, useState } from "react"; +import React, { + FunctionComponent, + useCallback, + useEffect, + useRef, + useState, +} from "react"; import { View, StyleSheet, @@ -82,22 +88,25 @@ export const Pincode: FunctionComponent<{ setPrevPad("alphabet"); appInitStore.updateKeyboardType("alphabet"); - if (password.length >= 6) { - if (needConfirmation) { - if (!confirmCode) { - setConfirmCode(password); - setPassword(""); - } else { - handleCheckConfirm(password); - } - } else { - onVerifyPincode(password); - } - } else { + const isPasswordValid = password.length >= 6; + const shouldSetConfirmCode = needConfirmation && !confirmCode; + const shouldCheckConfirm = needConfirmation && confirmCode; + const shouldVerifyPincode = !needConfirmation; + + if (!isPasswordValid) { showToast({ message: "*The password must be at least 6 characters", type: "danger", }); + return; + } + if (shouldSetConfirmCode) { + setConfirmCode(password); + setPassword(""); + } else if (shouldCheckConfirm) { + handleCheckConfirm(password); + } else if (shouldVerifyPincode) { + onVerifyPincode(password); } }; @@ -153,23 +162,22 @@ export const Pincode: FunctionComponent<{ } }; - useEffect(() => { - if (needConfirmation) { - if (code.length >= 6) { - if (confirmCode) { - handleConfirm(); - } else { - handleSetPassword(); - } - } - } else { - if (code.length >= 6) { - numpadRef?.current?.clearAll(); - onVerifyPincode(code); - } + const handleLogicAfterCodeChange = useCallback(() => { + if (code.length <= 6) return; + const needHandleConfirm = needConfirmation && confirmCode; + const needResetPassword = needConfirmation && !confirmCode; + needHandleConfirm && handleConfirm(); + needResetPassword && handleSetPassword(); + if (!needConfirmation) { + numpadRef?.current?.clearAll(); + onVerifyPincode(code); } }, [code]); + useEffect(() => { + handleLogicAfterCodeChange(); + }, [handleLogicAfterCodeChange]); + const renderPassword = ({ field: {} }) => { return ( { + if (isTablet) { + return (height / baseHeight) * size; + } else { + return (width / baseWidth) * size; + } +}; + +/** + * Apply scale to numeric values ​​in style + * @param {Record} style - The style object needs to have scale applied + * @param {boolean} [isScale=true] - Flag to determine whether scaling is applied or not (optional), default is true + * @returns {Record | undefined} - The style object has scale applied or undefined if the style is undefined + * ex: + * + */ +export const styleWithScale = ( + style: Record, + isScale = true +) => { + if (style === undefined) { + return undefined; + } + const flattenedStyle = StyleSheet.flatten(style); + const scaledEntries = Object.entries(flattenedStyle).map(([key, value]) => { + if (typeof value === "number" && !["flex", "opacity"].includes(key)) { + return [key, isScale ? scale(value) : value]; + } + return [key, value]; + }); + + return Object.fromEntries(scaledEntries); +}; + export function getPlatformFontWeight( fontWeight: FontWeightTypes | FontWeightNumbers ): {