Skip to content

Commit dd623e4

Browse files
limichangelimichange
authored andcommitted
feat: watch state
1 parent 61d5ec4 commit dd623e4

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

packages/kit/src/views/Prime/components/PrimeLoginEmailCodeDialogV2/PrimeLoginEmailCodeDialogV2.tsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ import {
1414
} from '@onekeyhq/components';
1515
import { ETranslations } from '@onekeyhq/shared/src/locale';
1616

17+
import type { IPrivyState } from '../../hooks/usePrivyUniversalV2/usePrivyUniversalV2Types';
18+
1719
const COUNTDOWN_TIME = 60;
1820

1921
export function PrimeLoginEmailCodeDialogV2(props: {
2022
email: string;
23+
state: IPrivyState;
2124
loginWithCode: (args: { code: string; email?: string }) => Promise<void>;
2225
sendCode: (args: { email: string }) => void;
2326
onLoginSuccess: () => void;
2427
}) {
25-
const { email, loginWithCode, sendCode, onLoginSuccess } = props;
28+
const { email, loginWithCode, sendCode, onLoginSuccess, state } = props;
2629
const [countdown, setCountdown] = useState(COUNTDOWN_TIME);
2730
const [isResending, setIsResending] = useState(false);
2831
const [verificationCode, setVerificationCode] = useState('');
@@ -128,13 +131,25 @@ export function PrimeLoginEmailCodeDialogV2(props: {
128131
email,
129132
});
130133

131-
onLoginSuccess?.();
132-
133-
Toast.success({
134-
title: intl.formatMessage({
135-
id: ETranslations.login_welcome_message,
136-
}),
137-
});
134+
if (state.status === 'done') {
135+
Toast.success({
136+
title: intl.formatMessage({
137+
id: ETranslations.login_welcome_message,
138+
}),
139+
});
140+
141+
onLoginSuccess?.();
142+
}
143+
144+
if (state.status === 'error') {
145+
Toast.error({
146+
title: intl.formatMessage({
147+
id: ETranslations.auth_error_passcode_incorrect,
148+
}),
149+
});
150+
151+
preventClose();
152+
}
138153
} catch (error) {
139154
console.log('error', error);
140155

packages/kit/src/views/Prime/hooks/usePrimeAuthV2.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,16 @@ export function usePrimeAuthV2() {
3333
useEffect(() => {
3434
if (state.status === 'sending-code') {
3535
Toast.success({
36-
title: '🔑 ✅ send code',
36+
title: 'send code',
3737
});
3838
} else if (state.status === 'awaiting-code-input') {
3939
Toast.success({
40-
title: '🔑 ✅ awaiting code input',
41-
});
42-
} else if (state.status === 'submitting-code') {
43-
Toast.success({
44-
title: '🔑 ✅ submitting code',
45-
});
46-
} else if (state.status === 'error') {
47-
Toast.error({
48-
title: '🔑 ❌ User failed to log in with email',
40+
title: 'awaiting code input',
4941
});
42+
// } else if (state.status === 'submitting-code') {
43+
// Toast.success({
44+
// title: 'submitting code',
45+
// });
5046
}
5147
}, [state.status]);
5248

@@ -63,6 +59,7 @@ export function usePrimeAuthV2() {
6359
renderContent: (
6460
// 4. input code
6561
<PrimeLoginEmailCodeDialogV2
62+
state={state}
6663
sendCode={sendCode}
6764
loginWithCode={loginWithCode}
6865
email={email}

packages/kit/src/views/Prime/hooks/usePrivyUniversalV2/usePrivyUniversalV2Types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type IState =
1+
export type IPrivyState =
22
| { status: 'initial' }
33
| {
44
status: 'error';
@@ -17,7 +17,7 @@ export interface IUsePrivyUniversalV2 {
1717
onComplete?: () => void;
1818
onError?: (error: any) => void;
1919
}) => {
20-
state: IState;
20+
state: IPrivyState;
2121
sendCode: (args: { email: string }) => Promise<void>;
2222
loginWithCode: (args: { code: string; email?: string }) => Promise<void>;
2323
};

0 commit comments

Comments
 (0)