Skip to content

Commit b8c6328

Browse files
authored
Merge branch 'x' into fix-friends-2
2 parents 104809e + 1a7e5d6 commit b8c6328

File tree

7 files changed

+209
-81
lines changed

7 files changed

+209
-81
lines changed

packages/components/src/forms/Input/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export type IInputProps = {
9292
containerProps?: IGroupProps;
9393
onPaste?: (event: IPasteEventParams) => void;
9494
onChangeText?: ((text: string) => string | void) | undefined;
95+
onSecureTextEntryChange?: (secureTextEntry: boolean) => void;
9596
} & Omit<ITMInputProps, 'size' | 'onChangeText' | 'onPaste' | 'readOnly'> & {
9697
/** Web only */
9798
onCompositionStart?: CompositionEventHandler<any>;
@@ -271,6 +272,7 @@ function BaseInput(
271272
autoFocusDelayMs,
272273
autoScrollTopDelayMs,
273274
secureTextEntry,
275+
onSecureTextEntryChange,
274276
...props
275277
} = useProps(inputProps) as IInputProps;
276278
const { paddingLeftWithIcon, height, iconLeftPosition } = SIZE_MAPPINGS[size];
@@ -360,6 +362,7 @@ function BaseInput(
360362
allAddOns.push({
361363
iconName: secureEntryState ? 'EyeOffOutline' : 'EyeOutline',
362364
onPress: () => {
365+
onSecureTextEntryChange?.(!secureEntryState);
363366
setSecureEntryState(!secureEntryState);
364367
},
365368
});
@@ -379,6 +382,7 @@ function BaseInput(
379382
clearClipboardOnPaste,
380383
clearText,
381384
secureEntryState,
385+
onSecureTextEntryChange,
382386
]);
383387

384388
useOnWebPaste(inputRef, onPaste);

packages/kit/src/views/Onboardingv2/hooks/useDeviceConnect.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,11 @@ export function useDeviceConnect() {
706706
console.log('Current hardware wallet State', deviceState, strategy);
707707
if (!strategy) {
708708
await closeDialogAndReturn(device, { skipDelayClose: true });
709-
throw new OneKeyLocalError('No wallet creation strategy');
709+
throw new OneKeyLocalError({
710+
message: intl.formatMessage({
711+
id: ETranslations.hardware_user_cancel_error,
712+
}),
713+
});
710714
}
711715

712716
await createHwWallet(
@@ -724,6 +728,7 @@ export function useDeviceConnect() {
724728
determineWalletCreationStrategy,
725729
createHwWallet,
726730
closeDialogAndReturn,
731+
intl,
727732
],
728733
);
729734
return useMemo(

packages/kit/src/views/Onboardingv2/pages/CheckAndUpdate.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function CheckAndUpdatePage({
7272
console.log('deviceData', deviceData);
7373
const themeVariant = useThemeVariant();
7474
const navigation = useAppNavigation();
75+
const isFirmwareVerifiedRef = useRef<boolean | undefined>(undefined);
7576

7677
const deviceLabel = useMemo(() => {
7778
if ((deviceData.device as KnownDevice)?.label) {
@@ -269,7 +270,7 @@ function CheckAndUpdatePage({
269270
...deviceData,
270271
device: (deviceForFinalize ?? deviceData.device) as SearchDevice,
271272
},
272-
isFirmwareVerified: true,
273+
isFirmwareVerified: isFirmwareVerifiedRef.current,
273274
});
274275
}, 1200);
275276
}, [
@@ -451,6 +452,7 @@ function CheckAndUpdatePage({
451452
void checkFirmwareUpdate();
452453
}, 150);
453454
}
455+
isFirmwareVerifiedRef.current = !!result.verified;
454456
} catch (error) {
455457
setSteps((prev) => {
456458
const newSteps = [...prev];
@@ -988,11 +990,13 @@ function CheckAndUpdatePage({
988990
id: ETranslations.global_retry,
989991
})}
990992
</Button>
991-
<Button onPress={handleSkipCurrentStep}>
992-
{intl.formatMessage({
993-
id: ETranslations.global_skip,
994-
})}
995-
</Button>
993+
{step.id !== ECheckAndUpdateStepId.GenuineCheck ? (
994+
<Button onPress={handleSkipCurrentStep}>
995+
{intl.formatMessage({
996+
id: ETranslations.global_skip,
997+
})}
998+
</Button>
999+
) : null}
9961000
</XStack>
9971001
</XStack>
9981002
) : null}

packages/kit/src/views/Onboardingv2/pages/FinalizeWalletSetup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ function FinalizeWalletSetupPage({
303303
},
304304
});
305305
created.current = true;
306-
} else if (deviceData && isFirmwareVerified) {
306+
} else if (deviceData && isFirmwareVerified !== undefined) {
307307
await connectDevice(deviceData.device as SearchDevice);
308308
await createHWWallet({
309309
device: deviceData.device as SearchDevice,

packages/kit/src/views/Onboardingv2/pages/ImportPhraseOrPrivateKey.tsx

Lines changed: 124 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ReactNode, RefObject } from 'react';
2-
import { useCallback, useRef, useState } from 'react';
2+
import { useCallback, useMemo, useRef, useState } from 'react';
33

44
import { useRoute } from '@react-navigation/core';
55
import { noop } from 'lodash';
@@ -10,6 +10,7 @@ import Animated, {
1010
useSharedValue,
1111
} from 'react-native-reanimated';
1212

13+
import type { IInputRef, ITextAreaInputProps } from '@onekeyhq/components';
1314
import {
1415
Button,
1516
HeightTransition,
@@ -35,14 +36,134 @@ import {
3536

3637
import backgroundApiProxy from '../../../background/instance/backgroundApiProxy';
3738
import useAppNavigation from '../../../hooks/useAppNavigation';
38-
import { useAppRoute } from '../../../hooks/useAppRoute';
3939
import { fixInputImportSingleChain } from '../../Onboarding/pages/ImportWallet/ImportSingleChainBase';
4040
import useScanQrCode from '../../ScanQrCode/hooks/useScanQrCode';
4141
import { OnboardingLayout } from '../components/OnboardingLayout';
4242
import { PhaseInputArea } from '../components/PhaseInputArea';
4343

4444
import type { IPhaseInputAreaInstance } from '../components/PhaseInputArea';
4545
import type { RouteProp } from '@react-navigation/core';
46+
import type {
47+
NativeSyntheticEvent,
48+
TextInput,
49+
TextInputSelectionChangeEventData,
50+
} from 'react-native';
51+
52+
function PrivateKeyInput({ value = '', onChangeText }: ITextAreaInputProps) {
53+
const intl = useIntl();
54+
const [privateKey, setPrivateKey] = useState(value);
55+
const { start: startScanQrCode } = useScanQrCode();
56+
const [encrypted, setEncrypted] = useState(true);
57+
const inputRef = useRef<IInputRef>(null);
58+
59+
const privateKeyRef = useRef(privateKey);
60+
privateKeyRef.current = privateKey;
61+
const selectionRef = useRef({ start: 0, end: 0 });
62+
63+
const handleSelectionChange = useCallback(
64+
(e: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => {
65+
const selection = e.nativeEvent.selection;
66+
console.log('handleSelectionChange', selection);
67+
selectionRef.current = selection;
68+
},
69+
[],
70+
);
71+
72+
const formattedValue = useMemo(() => {
73+
if (encrypted) {
74+
return '•'.repeat(privateKey.length);
75+
}
76+
return privateKey;
77+
}, [encrypted, privateKey]);
78+
79+
const updatePrivateKey = useCallback(
80+
(text: string) => {
81+
setPrivateKey(text);
82+
onChangeText?.(text);
83+
},
84+
[onChangeText],
85+
);
86+
87+
const handleChangeText = useCallback(
88+
(text: string) => {
89+
if (encrypted) {
90+
// Find non-asterisk characters in text and merge with actual privateKey
91+
const selection = selectionRef.current;
92+
let newPrivateKey = privateKeyRef.current;
93+
94+
// Calculate the difference between old and new text
95+
const oldLength = privateKeyRef.current.length;
96+
const newLength = text.length;
97+
98+
const selectionRange = selection.end - selection.start;
99+
100+
if (selectionRange > 0) {
101+
// Text was selected and replaced - replace selected characters with new text
102+
const selectedText = text
103+
.slice(selection.start, selection.end)
104+
.replace(//g, '');
105+
newPrivateKey =
106+
privateKeyRef.current.slice(0, selection.start) +
107+
selectedText +
108+
privateKeyRef.current.slice(selection.end);
109+
} else if (newLength > oldLength) {
110+
// Text was added - insert new characters at selection position
111+
const addedText = text.slice(
112+
selection.start,
113+
selection.start + (newLength - oldLength),
114+
);
115+
newPrivateKey =
116+
privateKeyRef.current.slice(0, selection.start) +
117+
addedText +
118+
privateKeyRef.current.slice(selection.start);
119+
} else if (newLength < oldLength) {
120+
// Text was removed - remove characters from selection position
121+
const removedCount = oldLength - newLength;
122+
const selectionStart = selection.start - 1;
123+
newPrivateKey =
124+
privateKeyRef.current.slice(0, selectionStart) +
125+
privateKeyRef.current.slice(selectionStart + removedCount);
126+
} else {
127+
// Text was replaced - replace characters at selection position
128+
const replacedText = text.slice(selection.start, selection.end);
129+
newPrivateKey =
130+
privateKeyRef.current.slice(0, selection.start) +
131+
replacedText +
132+
privateKeyRef.current.slice(selection.end);
133+
}
134+
135+
updatePrivateKey(newPrivateKey);
136+
} else {
137+
updatePrivateKey(text);
138+
}
139+
},
140+
[encrypted, updatePrivateKey],
141+
);
142+
143+
return (
144+
<TextAreaInput
145+
ref={inputRef as RefObject<TextInput>}
146+
allowPaste
147+
allowClear
148+
allowScan
149+
allowSecureTextEye // TextAreaInput not support allowSecureTextEye
150+
onSelectionChange={handleSelectionChange}
151+
clearClipboardOnPaste
152+
onSecureTextEntryChange={setEncrypted}
153+
startScanQrCode={startScanQrCode}
154+
size="large"
155+
numberOfLines={5}
156+
value={formattedValue}
157+
onChangeText={handleChangeText}
158+
$platform-native={{
159+
minHeight: 160,
160+
}}
161+
placeholder={intl.formatMessage({
162+
id: ETranslations.form_enter_private_key_placeholder,
163+
})}
164+
/>
165+
);
166+
}
46167

47168
export default function ImportPhraseOrPrivateKey() {
48169
const navigation = useAppNavigation();
@@ -221,23 +342,9 @@ export default function ImportPhraseOrPrivateKey() {
221342
}}
222343
gap="$5"
223344
>
224-
<Input
225-
allowPaste
226-
allowClear
227-
allowScan
228-
allowSecureTextEye // TextAreaInput not support allowSecureTextEye
229-
clearClipboardOnPaste
230-
startScanQrCode={startScanQrCode}
231-
size="large"
232-
numberOfLines={5}
345+
<PrivateKeyInput
233346
value={privateKey}
234347
onChangeText={setPrivateKey}
235-
$platform-native={{
236-
minHeight: 160,
237-
}}
238-
placeholder={intl.formatMessage({
239-
id: ETranslations.form_enter_private_key_placeholder,
240-
})}
241348
/>
242349
</YStack>
243350
)}

0 commit comments

Comments
 (0)