Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3498093
D11768.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
D11768.diff
View Options
diff --git a/lib/hooks/login-hooks.js b/lib/hooks/login-hooks.js
--- a/lib/hooks/login-hooks.js
+++ b/lib/hooks/login-hooks.js
@@ -5,6 +5,7 @@
import {
identityLogInActionTypes,
useIdentityPasswordLogIn,
+ useIdentityWalletLogIn,
} from '../actions/user-actions.js';
import { useKeyserverAuth } from '../keyserver-conn/keyserver-auth.js';
import { logInActionSources } from '../types/account-types.js';
@@ -27,24 +28,45 @@
const inactiveStep = { step: 'inactive' };
-function usePasswordLogIn(): (
- username: string,
- password: string,
-) => Promise<void> {
+type LogInInputs =
+ | {
+ +accountType: 'username',
+ +username: string,
+ +password: string,
+ }
+ | {
+ +accountType: 'ethereum',
+ +walletAddress: string,
+ +siweMessage: string,
+ +siweSignature: string,
+ };
+
+function useLogIn(): LogInInputs => Promise<void> {
const [currentStep, setCurrentStep] =
React.useState<CurrentStep>(inactiveStep);
const identityPasswordLogIn = useIdentityPasswordLogIn();
+ const identityWalletLogIn = useIdentityWalletLogIn();
const dispatchActionPromise = useDispatchActionPromise();
const returnedFunc = React.useCallback(
- (username: string, password: string) =>
+ (logInInputs: LogInInputs) =>
new Promise<void>(
// eslint-disable-next-line no-async-promise-executor
async (resolve, reject) => {
if (currentStep.step !== 'inactive') {
return;
}
- const action = identityPasswordLogIn(username, password);
+ const action =
+ logInInputs.accountType === 'username'
+ ? identityPasswordLogIn(
+ logInInputs.username,
+ logInInputs.password,
+ )
+ : identityWalletLogIn(
+ logInInputs.walletAddress,
+ logInInputs.siweMessage,
+ logInInputs.siweSignature,
+ );
void dispatchActionPromise(identityLogInActionTypes, action);
try {
await action;
@@ -58,7 +80,12 @@
}
},
),
- [currentStep, dispatchActionPromise, identityPasswordLogIn],
+ [
+ currentStep,
+ dispatchActionPromise,
+ identityPasswordLogIn,
+ identityWalletLogIn,
+ ],
);
const keyserverAuth = useKeyserverAuth(authoritativeKeyserverID());
@@ -104,4 +131,38 @@
return returnedFunc;
}
-export { usePasswordLogIn };
+function usePasswordLogIn(): (
+ username: string,
+ password: string,
+) => Promise<void> {
+ const logIn = useLogIn();
+ return React.useCallback(
+ (username: string, password: string) =>
+ logIn({
+ accountType: 'username',
+ username,
+ password,
+ }),
+ [logIn],
+ );
+}
+
+function useWalletLogIn(): (
+ walletAddress: string,
+ siweMessage: string,
+ siweSignature: string,
+) => Promise<void> {
+ const logIn = useLogIn();
+ return React.useCallback(
+ (walletAddress: string, siweMessage: string, siweSignature: string) =>
+ logIn({
+ accountType: 'ethereum',
+ walletAddress,
+ siweMessage,
+ siweSignature,
+ }),
+ [logIn],
+ );
+}
+
+export { usePasswordLogIn, useWalletLogIn };
diff --git a/native/account/fullscreen-siwe-panel.react.js b/native/account/fullscreen-siwe-panel.react.js
--- a/native/account/fullscreen-siwe-panel.react.js
+++ b/native/account/fullscreen-siwe-panel.react.js
@@ -6,6 +6,7 @@
import { ActivityIndicator, View } from 'react-native';
import { setDataLoadedActionType } from 'lib/actions/client-db-store-actions.js';
+import { useWalletLogIn } from 'lib/hooks/login-hooks.js';
import { type SIWEResult, SIWEMessageTypes } from 'lib/types/siwe-types.js';
import { ServerError } from 'lib/utils/errors.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
@@ -14,10 +15,7 @@
import { useGetEthereumAccountFromSIWEResult } from './registration/ethereum-utils.js';
import { RegistrationContext } from './registration/registration-context.js';
import { enableNewRegistrationMode } from './registration/registration-types.js';
-import {
- useLegacySIWEServerCall,
- useIdentityWalletLogInCall,
-} from './siwe-hooks.js';
+import { useLegacySIWEServerCall } from './siwe-hooks.js';
import SIWEPanel from './siwe-panel.react.js';
import { commRustModule } from '../native-modules.js';
import {
@@ -71,7 +69,7 @@
);
const legacySiweServerCall = useLegacySIWEServerCall();
- const identityWalletLogInCall = useIdentityWalletLogInCall();
+ const walletLogIn = useWalletLogIn();
const successRef = React.useRef(false);
const dispatch = useDispatch();
const onSuccess = React.useCallback(
@@ -82,7 +80,7 @@
const findUserIDResponse =
await commRustModule.findUserIDForWalletAddress(result.address);
if (JSON.parse(findUserIDResponse).userID) {
- await identityWalletLogInCall(result);
+ await walletLogIn(result.address, result.message, result.signature);
} else if (enableNewRegistrationMode) {
await onAccountDoesNotExist(result);
} else {
@@ -139,7 +137,7 @@
}
},
[
- identityWalletLogInCall,
+ walletLogIn,
registrationServerCall,
goBackToPrompt,
dispatch,
diff --git a/native/account/registration/existing-ethereum-account.react.js b/native/account/registration/existing-ethereum-account.react.js
--- a/native/account/registration/existing-ethereum-account.react.js
+++ b/native/account/registration/existing-ethereum-account.react.js
@@ -6,6 +6,7 @@
import { setDataLoadedActionType } from 'lib/actions/client-db-store-actions.js';
import { siweAuthActionTypes } from 'lib/actions/siwe-actions.js';
import { useENSName } from 'lib/hooks/ens-cache.js';
+import { useWalletLogIn } from 'lib/hooks/login-hooks.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
import type { SIWEResult } from 'lib/types/siwe-types.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
@@ -21,10 +22,7 @@
import { useStyles } from '../../themes/colors.js';
import { UnknownErrorAlertDetails } from '../../utils/alert-messages.js';
import Alert from '../../utils/alert.js';
-import {
- useIdentityWalletLogInCall,
- useLegacySIWEServerCall,
-} from '../siwe-hooks.js';
+import { useLegacySIWEServerCall } from '../siwe-hooks.js';
const siweAuthLoadingStatusSelector =
createLoadingStatusSelector(siweAuthActionTypes);
@@ -37,14 +35,14 @@
};
function ExistingEthereumAccount(props: Props): React.Node {
const legacySiweServerCall = useLegacySIWEServerCall();
- const identityWalletLogInCall = useIdentityWalletLogInCall();
+ const walletLogIn = useWalletLogIn();
const { params } = props.route;
const dispatch = useDispatch();
const onProceedToLogIn = React.useCallback(async () => {
if (usingCommServicesAccessToken) {
try {
- await identityWalletLogInCall(params);
+ await walletLogIn(params.address, params.message, params.signature);
} catch (e) {
Alert.alert(
UnknownErrorAlertDetails.title,
@@ -77,7 +75,7 @@
},
});
}
- }, [legacySiweServerCall, identityWalletLogInCall, params, dispatch]);
+ }, [legacySiweServerCall, walletLogIn, params, dispatch]);
const siweAuthCallLoading = useSelector(
state => siweAuthLoadingStatusSelector(state) === 'loading',
diff --git a/native/account/siwe-hooks.js b/native/account/siwe-hooks.js
--- a/native/account/siwe-hooks.js
+++ b/native/account/siwe-hooks.js
@@ -4,8 +4,6 @@
import { siweAuth, siweAuthActionTypes } from 'lib/actions/siwe-actions.js';
import {
- identityLogInActionTypes,
- useIdentityWalletLogIn,
identityRegisterActionTypes,
useIdentityWalletRegister,
} from 'lib/actions/user-actions.js';
@@ -16,10 +14,7 @@
LogInStartingPayload,
LogInExtraInfo,
} from 'lib/types/account-types.js';
-import type {
- SIWEResult,
- IdentityWalletRegisterInput,
-} from 'lib/types/siwe-types.js';
+import type { IdentityWalletRegisterInput } from 'lib/types/siwe-types.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
import { authoritativeKeyserverID } from '../authoritative-keyserver.js';
@@ -102,20 +97,6 @@
);
}
-function useIdentityWalletLogInCall(): SIWEResult => Promise<void> {
- const identityWalletLogIn = useIdentityWalletLogIn();
- const dispatchActionPromise = useDispatchActionPromise();
- return React.useCallback(
- async ({ address, message, signature }) => {
- const siwePromise = identityWalletLogIn(address, message, signature);
- void dispatchActionPromise(identityLogInActionTypes, siwePromise);
-
- await siwePromise;
- },
- [dispatchActionPromise, identityWalletLogIn],
- );
-}
-
function useIdentityWalletRegisterCall(): IdentityWalletRegisterInput => Promise<void> {
const identityWalletRegister = useIdentityWalletRegister();
const dispatchActionPromise = useDispatchActionPromise();
@@ -135,8 +116,4 @@
);
}
-export {
- useLegacySIWEServerCall,
- useIdentityWalletLogInCall,
- useIdentityWalletRegisterCall,
-};
+export { useLegacySIWEServerCall, useIdentityWalletRegisterCall };
diff --git a/web/account/siwe-login-form.react.js b/web/account/siwe-login-form.react.js
--- a/web/account/siwe-login-form.react.js
+++ b/web/account/siwe-login-form.react.js
@@ -16,12 +16,11 @@
import {
identityGenerateNonceActionTypes,
useIdentityGenerateNonce,
- identityLogInActionTypes,
- useIdentityWalletLogIn,
} from 'lib/actions/user-actions.js';
import ConnectedWalletInfo from 'lib/components/connected-wallet-info.react.js';
import SWMansionIcon from 'lib/components/swmansion-icon.react.js';
import stores from 'lib/facts/stores.js';
+import { useWalletLogIn } from 'lib/hooks/login-hooks.js';
import { useLegacyAshoatKeyserverCall } from 'lib/keyserver-conn/legacy-keyserver-call.js';
import { logInExtraInfoSelector } from 'lib/selectors/account-selectors.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
@@ -79,7 +78,7 @@
const legacySiweAuthCall = useLegacyAshoatKeyserverCall(siweAuth);
const logInExtraInfo = useSelector(logInExtraInfoSelector);
- const identityWalletLogIn = useIdentityWalletLogIn();
+ const walletLogIn = useWalletLogIn();
const [siweNonce, setSIWENonce] = React.useState<?string>(null);
@@ -156,27 +155,22 @@
[callLegacySIWEAuthEndpoint, dispatchActionPromise, logInExtraInfo],
);
- const attemptIdentityWalletLogIn = React.useCallback(
- (walletAddress: string, siweMessage: string, siweSignature: string) => {
- return dispatchActionPromise(
- identityLogInActionTypes,
- (async () => {
- try {
- return await identityWalletLogIn(
- walletAddress,
- siweMessage,
- siweSignature,
- );
- } catch (e) {
- if (getMessageForException(e) === 'user not found') {
- setError('account_does_not_exist');
- }
- throw e;
- }
- })(),
- );
+ const attemptWalletLogIn = React.useCallback(
+ async (
+ walletAddress: string,
+ siweMessage: string,
+ siweSignature: string,
+ ) => {
+ try {
+ return await walletLogIn(walletAddress, siweMessage, siweSignature);
+ } catch (e) {
+ if (getMessageForException(e) === 'user not found') {
+ setError('account_does_not_exist');
+ }
+ throw e;
+ }
},
- [dispatchActionPromise, identityWalletLogIn],
+ [walletLogIn],
);
const dispatch = useDispatch();
@@ -191,7 +185,7 @@
const message = createSIWEMessage(address, statement, siweNonce);
const signature = await signer.signMessage({ message });
if (usingCommServicesAccessToken) {
- await attemptIdentityWalletLogIn(address, message, signature);
+ await attemptWalletLogIn(address, message, signature);
} else {
await attemptLegacySIWEAuth(message, signature);
dispatch({
@@ -204,7 +198,7 @@
}, [
address,
attemptLegacySIWEAuth,
- attemptIdentityWalletLogIn,
+ attemptWalletLogIn,
signer,
siweNonce,
dispatch,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 8:36 PM (18 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2682886
Default Alt Text
D11768.diff (12 KB)
Attached To
Mode
D11768: [lib][native][web] Introduce useWalletLogIn hook
Attached
Detach File
Event Timeline
Log In to Comment