diff --git a/native/account/siwe-panel.react.js b/native/account/siwe-panel.react.js --- a/native/account/siwe-panel.react.js +++ b/native/account/siwe-panel.react.js @@ -1,9 +1,15 @@ // @flow import * as React from 'react'; +import { ActivityIndicator, Text } from 'react-native'; import WebView from 'react-native-webview'; +import { + getSIWENonce, + getSIWENonceActionTypes, +} from 'lib/actions/siwe-actions'; import { registerActionTypes, register } from 'lib/actions/user-actions'; +import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors'; import type { LogInStartingPayload } from 'lib/types/account-types'; import { useServerCall, @@ -18,10 +24,15 @@ const commSIWE = `${defaultLandingURLPrefix}/siwe`; +const getSIWENonceLoadingStatusSelector = createLoadingStatusSelector( + getSIWENonceActionTypes, +); + function SIWEPanel(): React.Node { const navContext = React.useContext(NavContext); const dispatchActionPromise = useDispatchActionPromise(); const registerAction = useServerCall(register); + const getSIWENonceCall = useServerCall(getSIWENonce); const logInExtraInfo = useSelector(state => nativeLogInExtraInfoSelector({ @@ -30,6 +41,24 @@ }), ); + const getSIWENonceCallFailed = useSelector( + state => getSIWENonceLoadingStatusSelector(state) === 'error', + ); + + const [nonce, setNonce] = React.useState(null); + + React.useEffect(() => { + (async () => { + dispatchActionPromise( + getSIWENonceActionTypes, + (async () => { + const response = await getSIWENonceCall(); + setNonce(response); + })(), + ); + })(); + }, [dispatchActionPromise, getSIWENonceCall]); + const handleSIWE = React.useCallback( ({ address, signature }) => { // this is all mocked from register-panel @@ -61,8 +90,23 @@ [handleSIWE], ); - const source = React.useMemo(() => ({ uri: commSIWE }), []); - return ; + const source = React.useMemo( + () => ({ + uri: commSIWE, + headers: { + 'siwe-nonce': nonce, + }, + }), + [nonce], + ); + + if (nonce) { + return ; + } else if (getSIWENonceCallFailed) { + return Oops, try again later!; + } else { + return ; + } } export default SIWEPanel;