Changeset View
Changeset View
Standalone View
Standalone View
native/account/siwe-hooks.js
// @flow | // @flow | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import { siweAuth, siweAuthActionTypes } from 'lib/actions/siwe-actions.js'; | import { siweAuth, siweAuthActionTypes } from 'lib/actions/siwe-actions.js'; | ||||
import type { LogInStartingPayload } from 'lib/types/account-types.js'; | import type { LogInStartingPayload } from 'lib/types/account-types.js'; | ||||
import { | import { | ||||
useServerCall, | useServerCall, | ||||
useDispatchActionPromise, | useDispatchActionPromise, | ||||
} from 'lib/utils/action-utils.js'; | } from 'lib/utils/action-utils.js'; | ||||
import { NavContext } from '../navigation/navigation-context.js'; | import { NavContext } from '../navigation/navigation-context.js'; | ||||
import { useSelector } from '../redux/redux-utils.js'; | import { useSelector } from '../redux/redux-utils.js'; | ||||
import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js'; | import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js'; | ||||
import { useInitialNotificationsEncryptedMessage } from '../utils/crypto-utils.js'; | |||||
type SIWEServerCallParams = { | type SIWEServerCallParams = { | ||||
+message: string, | +message: string, | ||||
+signature: string, | +signature: string, | ||||
... | ... | ||||
}; | }; | ||||
type UseSIWEServerCallParams = { | type UseSIWEServerCallParams = { | ||||
+onFailure: () => mixed, | +onFailure: () => mixed, | ||||
Show All 24 Lines | ): SIWEServerCallParams => Promise<void> { | ||||
const navContext = React.useContext(NavContext); | const navContext = React.useContext(NavContext); | ||||
const logInExtraInfo = useSelector(state => | const logInExtraInfo = useSelector(state => | ||||
nativeLogInExtraInfoSelector({ | nativeLogInExtraInfoSelector({ | ||||
redux: state, | redux: state, | ||||
navContext, | navContext, | ||||
}), | }), | ||||
); | ); | ||||
const getInitialNotificationsEncryptedMessage = | |||||
useInitialNotificationsEncryptedMessage(); | |||||
const dispatchActionPromise = useDispatchActionPromise(); | const dispatchActionPromise = useDispatchActionPromise(); | ||||
return React.useCallback( | return React.useCallback( | ||||
async ({ message, signature }) => { | async ({ message, signature }) => { | ||||
const extraInfo = await logInExtraInfo(); | const extraInfo = await logInExtraInfo(); | ||||
const initialNotificationsEncryptedMessage = | |||||
await getInitialNotificationsEncryptedMessage(); | |||||
dispatchActionPromise( | dispatchActionPromise( | ||||
siweAuthActionTypes, | siweAuthActionTypes, | ||||
callSIWE(message, signature, extraInfo), | callSIWE(message, signature, { | ||||
...extraInfo, | |||||
initialNotificationsEncryptedMessage, | |||||
}), | |||||
undefined, | undefined, | ||||
({ calendarQuery: extraInfo.calendarQuery }: LogInStartingPayload), | ({ calendarQuery: extraInfo.calendarQuery }: LogInStartingPayload), | ||||
); | ); | ||||
}, | }, | ||||
[logInExtraInfo, dispatchActionPromise, callSIWE], | [ | ||||
logInExtraInfo, | |||||
dispatchActionPromise, | |||||
callSIWE, | |||||
getInitialNotificationsEncryptedMessage, | |||||
], | |||||
); | ); | ||||
} | } | ||||
export { useSIWEServerCall }; | export { useSIWEServerCall }; |