Skip to content

Commit

Permalink
fix: opt code
Browse files Browse the repository at this point in the history
Signed-off-by: 王山栋 <[email protected]>
  • Loading branch information
ezailWang committed Dec 27, 2024
1 parent a8a9262 commit e26465d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
3 changes: 3 additions & 0 deletions packages/components/src/forms/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ type IFieldProps = Omit<GetProps<typeof Controller>, 'render'> &
horizontal?: boolean;
optional?: boolean;
labelAddon?: string | ReactElement;
errorMessageAlign?: 'left' | 'center' | 'right';
}>;

function Field({
name,
label,
optional,
display,
errorMessageAlign,
description,
rules,
children,
Expand Down Expand Up @@ -201,6 +203,7 @@ function Field({
<SizableText
color="$textCritical"
size="$bodyMd"
textAlign={errorMessageAlign}
key={error?.message}
testID={`${testID}-message`}
>
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/forms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ export * from './Select';
export * from './Slider';
export * from './Switch';
export * from './TextArea';
export * from './PinCodeValidator';
export * from './types';
35 changes: 13 additions & 22 deletions packages/kit/src/components/Password/components/PassCodeInput.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';

import { StyleSheet, Text } from 'react-native';
import {
CodeField,
useBlurOnFulfill,
useClearByFocusCell,
} from 'react-native-confirmation-code-field';

import { YStack } from '@onekeyhq/components';

import type { TextInput } from 'react-native';

export const PIN_CELL_COUNT = 6;

const PassCodeInput = ({
Expand All @@ -17,29 +18,28 @@ const PassCodeInput = ({
disabledComplete,
pinCodeFocus,
enableAutoFocus,
showMask,
editable,
// showMask,
testId,
}: {
onPinCodeChange?: (pin: string) => void;
onComplete?: () => void;
disabledComplete?: boolean;
pinCodeFocus?: boolean;
enableAutoFocus?: boolean;
editable?: boolean;
testId?: string;
showMask?: boolean;
// showMask?: boolean;
}) => {
const [pinValue, setPinValue] = useState('');

const pinInputRef = useBlurOnFulfill({
value: pinValue,
cellCount: PIN_CELL_COUNT,
});
const pinInputRef = useRef<TextInput>(null);
const [props, getCellOnLayoutHandler] = useClearByFocusCell({
value: pinValue,
setValue: setPinValue,
});
const [enableMask, setEnableMask] = useState(true);
const toggleMask = () => setEnableMask((f) => !f);
// const [enableMask, setEnableMask] = useState(true);
// const toggleMask = () => setEnableMask((f) => !f);

const cellStyles = StyleSheet.create({
cell: {
Expand All @@ -51,27 +51,17 @@ const PassCodeInput = ({
const renderCell = ({
index,
symbol,
isFocused,
}: {
}: // isFocused,
{
index: number;
symbol: string;
isFocused: boolean;
}) => (
// let textChild = null;
// if (symbol) {
// textChild = enableMask ? '•' : symbol;
// }

<Text
key={index}
style={[...[cellStyles.cell]]}
onLayout={getCellOnLayoutHandler(index)}
>
{/* {symbol ? (
<YStack w="$4" h="$4" borderRadius="$full" bg="$borderActive" />
) : (
''
)} */}
<YStack
animation="50ms"
w="$4"
Expand Down Expand Up @@ -113,6 +103,7 @@ const PassCodeInput = ({
textContentType="oneTimeCode"
renderCell={renderCell}
{...props}
editable={editable}
/>

// <YStack gap="$4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ const PasswordSetup = ({
<Form.Field
name="passCode"
display={passCodeFirstStep ? 'flex' : 'none'}
errorMessageAlign="center"
rules={{
validate: {
required: (v) =>
Expand Down Expand Up @@ -238,12 +239,12 @@ const PasswordSetup = ({
}}
enableAutoFocus
testId="pass-code"
showMask
/>
</Form.Field>
<Form.Field
display={passCodeFirstStep ? 'none' : 'flex'}
name="confirmPassCode"
errorMessageAlign="center"
rules={{
validate: {
equal: (v, values) => {
Expand Down Expand Up @@ -274,7 +275,6 @@ const PasswordSetup = ({
enableAutoFocus={false}
pinCodeFocus={passCodeConfirm}
testId="confirm-pass-code"
showMask
/>
<Divider />
</Form.Field>
Expand Down
17 changes: 15 additions & 2 deletions packages/kit/src/components/Password/components/PasswordVerify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import PassCodeInput from './PassCodeInput';
interface IPasswordVerifyProps {
authType: AuthenticationType[];
isEnable: boolean;
disableInput?: boolean;
passwordMode: EPasswordMode;
onPasswordChange: (e: any) => void;
onBiologyAuth: () => void;
Expand All @@ -57,6 +58,7 @@ const PasswordVerify = ({
isEnable,
alertText,
confirmBtnDisabled,
disableInput,
status,
passwordMode,
onBiologyAuth,
Expand Down Expand Up @@ -156,6 +158,9 @@ const PasswordVerify = ({
const fieldName =
passwordMode === EPasswordMode.PASSWORD ? 'password' : 'passCode';
if (status.value === EPasswordVerifyStatus.ERROR) {
if (passwordMode === EPasswordMode.PASSCODE) {
form.setValue(fieldName, '');
}
form.setError(fieldName, { message: status.message });
form.setFocus(fieldName);
} else {
Expand Down Expand Up @@ -212,7 +217,10 @@ const PasswordVerify = ({
<Input
selectTextOnFocus
size="large"
editable={status.value !== EPasswordVerifyStatus.VERIFYING}
editable={Boolean(
status.value !== EPasswordVerifyStatus.VERIFYING &&
!disableInput,
)}
placeholder={intl.formatMessage({
id: ETranslations.auth_enter_your_passcode,
})}
Expand Down Expand Up @@ -241,6 +249,7 @@ const PasswordVerify = ({
<>
<Form.Field
name="passCode"
errorMessageAlign="center"
rules={{
validate: {
required: (v) =>
Expand All @@ -258,13 +267,17 @@ const PasswordVerify = ({
form.setValue('passCode', pin);
form.clearErrors('passCode');
}}
editable={Boolean(
status.value !== EPasswordVerifyStatus.VERIFYING &&
!disableInput,
)}
onComplete={form.handleSubmit(onInputPasswordAuth)}
disabledComplete={confirmBtnDisabled}
enableAutoFocus
testId="pass-code-input"
/>
</Form.Field>
{isEnable && !passwordInput ? (
{isEnable ? (
<YStack alignSelf="center" pt="$6" scale={1.5}>
<IconButton
size="large"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const usePasswordProtection = (isLock: boolean) => {
id: ETranslations.auth_passcode_cooldown,
},
{
cooldowntime: Math.floor(passwordErrorProtectionTimeMinutesSurplus),
cooldowntime: `${Math.floor(
passwordErrorProtectionTimeMinutesSurplus,
)} Min`,
},
);
}
Expand Down

0 comments on commit e26465d

Please sign in to comment.