Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3558608
D11005.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D11005.diff
View Options
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
@@ -9,12 +9,18 @@
import type { SIWEResult } from 'lib/types/siwe-types.js';
import { ServerError } from 'lib/utils/errors.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
+import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js';
import { useGetEthereumAccountFromSIWEResult } from './registration/ethereum-utils.js';
import { RegistrationContext } from './registration/registration-context.js';
import { enableNewRegistrationMode } from './registration/registration-types.js';
-import { useLegacySIWEServerCall } from './siwe-hooks.js';
+import {
+ useLegacySIWEServerCall,
+ useIdentityWalletLogInCall,
+ useIdentityWalletRegisterCall,
+} from './siwe-hooks.js';
import SIWEPanel from './siwe-panel.react.js';
+import { commRustModule } from '../native-modules.js';
import {
AccountDoesNotExistRouteName,
RegistrationRouteName,
@@ -64,40 +70,71 @@
);
const legacySiweServerCall = useLegacySIWEServerCall();
+ const identityWalletLogInCall = useIdentityWalletLogInCall();
+ const identityWalletRegisterCall = useIdentityWalletRegisterCall();
const successRef = React.useRef(false);
const dispatch = useDispatch();
const onSuccess = React.useCallback(
async (result: SIWEResult) => {
successRef.current = true;
- try {
- await legacySiweServerCall({
- ...result,
- doNotRegister: enableNewRegistrationMode,
- });
- } catch (e) {
- if (
- e instanceof ServerError &&
- e.message === 'account_does_not_exist'
- ) {
- await onAccountDoesNotExist(result);
- return;
+ if (usingCommServicesAccessToken) {
+ try {
+ const findUserIDResponse =
+ await commRustModule.findUserIDForWalletAddress(result.address);
+ if (JSON.parse(findUserIDResponse).userID) {
+ await identityWalletLogInCall(result);
+ } else if (enableNewRegistrationMode) {
+ await onAccountDoesNotExist(result);
+ } else {
+ await identityWalletRegisterCall(result);
+ }
+ } catch (e) {
+ Alert.alert(
+ UnknownErrorAlertDetails.title,
+ UnknownErrorAlertDetails.message,
+ [{ text: 'OK', onPress: goBackToPrompt }],
+ { cancelable: false },
+ );
+ throw e;
}
- Alert.alert(
- UnknownErrorAlertDetails.title,
- UnknownErrorAlertDetails.message,
- [{ text: 'OK', onPress: goBackToPrompt }],
- { cancelable: false },
- );
- throw e;
+ } else {
+ try {
+ await legacySiweServerCall({
+ ...result,
+ doNotRegister: enableNewRegistrationMode,
+ });
+ } catch (e) {
+ if (
+ e instanceof ServerError &&
+ e.message === 'account_does_not_exist'
+ ) {
+ await onAccountDoesNotExist(result);
+ return;
+ }
+ Alert.alert(
+ UnknownErrorAlertDetails.title,
+ UnknownErrorAlertDetails.message,
+ [{ text: 'OK', onPress: goBackToPrompt }],
+ { cancelable: false },
+ );
+ throw e;
+ }
+ dispatch({
+ type: setDataLoadedActionType,
+ payload: {
+ dataLoaded: true,
+ },
+ });
}
- dispatch({
- type: setDataLoadedActionType,
- payload: {
- dataLoaded: true,
- },
- });
},
- [legacySiweServerCall, dispatch, goBackToPrompt, onAccountDoesNotExist],
+ [
+ identityWalletLogInCall,
+ identityWalletRegisterCall,
+ goBackToPrompt,
+ dispatch,
+ legacySiweServerCall,
+ onAccountDoesNotExist,
+ ],
);
const ifBeforeSuccessGoBackToPrompt = React.useCallback(() => {
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
@@ -3,11 +3,18 @@
import * as React from 'react';
import { siweAuth, siweAuthActionTypes } from 'lib/actions/siwe-actions.js';
+import {
+ identityLogInActionTypes,
+ useIdentityWalletLogIn,
+ identityRegisterActionTypes,
+ useIdentityWalletRegister,
+} from 'lib/actions/user-actions.js';
import { useInitialNotificationsEncryptedMessage } from 'lib/shared/crypto-utils.js';
import type {
LogInStartingPayload,
LogInExtraInfo,
} from 'lib/types/account-types.js';
+import type { SIWEResult } from 'lib/types/siwe-types.js';
import { useLegacyAshoatKeyserverCall } from 'lib/utils/action-utils.js';
import type { CallSingleKeyserverEndpointOptions } from 'lib/utils/call-single-keyserver-endpoint.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
@@ -93,4 +100,36 @@
);
}
-export { useLegacySIWEServerCall };
+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(): SIWEResult => Promise<void> {
+ const identityWalletRegister = useIdentityWalletRegister();
+ const dispatchActionPromise = useDispatchActionPromise();
+ return React.useCallback(
+ async ({ address, message, signature }) => {
+ const siwePromise = identityWalletRegister(address, message, signature);
+ void dispatchActionPromise(identityRegisterActionTypes, siwePromise);
+
+ await siwePromise;
+ },
+ [dispatchActionPromise, identityWalletRegister],
+ );
+}
+
+export {
+ useLegacySIWEServerCall,
+ useIdentityWalletLogInCall,
+ useIdentityWalletRegisterCall,
+};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 28, 4:26 AM (6 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2723674
Default Alt Text
D11005.diff (6 KB)
Attached To
Mode
D11005: [native] use identity wallet login in fullscreen-siwe-panel
Attached
Detach File
Event Timeline
Log In to Comment