feat: restoring an account from seed and fetching seems to work

pull/3056/head
William Grant 2 years ago
parent e0ca888e85
commit 8e41d51632

@ -1,7 +1,7 @@
import { useEffect } from 'react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import styled from 'styled-components'; import styled from 'styled-components';
import { useMount } from 'react-use';
import { onboardingStore } from '../../state/onboarding/store'; import { onboardingStore } from '../../state/onboarding/store';
import { SessionTheme } from '../../themes/SessionTheme'; import { SessionTheme } from '../../themes/SessionTheme';
import { setSignInByLinking } from '../../util/storage'; import { setSignInByLinking } from '../../util/storage';
@ -56,9 +56,9 @@ const StyledSessionContent = styled(Flex)`
`; `;
export const SessionRegistrationView = () => { export const SessionRegistrationView = () => {
useEffect(() => { useMount(() => {
void setSignInByLinking(false); void setSignInByLinking(false);
}, []); });
return ( return (
<Provider store={onboardingStore}> <Provider store={onboardingStore}>

@ -89,7 +89,7 @@ async function signInAndFetchDisplayName(
'configurationMessageReceived', 'configurationMessageReceived',
async (ourPubkey: string, displayName: string) => { async (ourPubkey: string, displayName: string) => {
window.Whisper.events.off('configurationMessageReceived'); window.Whisper.events.off('configurationMessageReceived');
await setSignInByLinking(true); await setSignInByLinking(false);
await setSignWithRecoveryPhrase(false); await setSignWithRecoveryPhrase(false);
dispatch(setHexGeneratedPubKey(ourPubkey)); dispatch(setHexGeneratedPubKey(ourPubkey));
dispatch(setDisplayName(displayName)); dispatch(setDisplayName(displayName));

@ -409,9 +409,6 @@ export class SwarmPolling {
// we take the lastest config message to create the wrapper in memory // we take the lastest config message to create the wrapper in memory
const incomingConfigMessage = allDecryptedConfigMessages.at(-1); const incomingConfigMessage = allDecryptedConfigMessages.at(-1);
window.log.debug(
`WIP: [SwarmPolling] configMessage: ${JSON.stringify(incomingConfigMessage)}`
);
if (!incomingConfigMessage) { if (!incomingConfigMessage) {
throw new Error('incomingConfigMessage not found'); throw new Error('incomingConfigMessage not found');
} }
@ -681,9 +678,6 @@ export class SwarmPolling {
toPollFrom, toPollFrom,
UserUtils.getOurPubKeyStrFromCache() UserUtils.getOurPubKeyStrFromCache()
); );
window.log.debug(
`WIP: [resultsFromUserProfile] resultsFromUserProfile: ${JSON.stringify(resultsFromUserProfile)}`
);
} catch (e) { } catch (e) {
if (e.message === ERROR_CODE_NO_CONNECT) { if (e.message === ERROR_CODE_NO_CONNECT) {
if (window.inboxStore?.getState().onionPaths.isOnline) { if (window.inboxStore?.getState().onionPaths.isOnline) {
@ -709,10 +703,6 @@ export class SwarmPolling {
const userConfigMessagesMerged = flatten(compact(userConfigMessages)); const userConfigMessagesMerged = flatten(compact(userConfigMessages));
if (userConfigMessagesMerged.length) { if (userConfigMessagesMerged.length) {
window.log.info(
`[pollOnceForDisplayName] received userConfigMessages count: ${userConfigMessagesMerged.length} for key ${pubkey.key}`
);
const displayName = await this.handleSharedConfigMessages(userConfigMessagesMerged, true); const displayName = await this.handleSharedConfigMessages(userConfigMessagesMerged, true);
return displayName; return displayName;
} }

@ -14,7 +14,7 @@ import { NotFoundError } from '../session/utils/errors';
import { LibSessionUtil } from '../session/utils/libsession/libsession_utils'; import { LibSessionUtil } from '../session/utils/libsession/libsession_utils';
import { actions as userActions } from '../state/ducks/user'; import { actions as userActions } from '../state/ducks/user';
import { Registration } from './registration'; import { Registration } from './registration';
import { Storage, saveRecoveryPhrase, setLocalPubKey } from './storage'; import { Storage, saveRecoveryPhrase, setLocalPubKey, setSignInByLinking } from './storage';
/** /**
* Might throw * Might throw
@ -78,6 +78,7 @@ export async function signInByLinkingDevice(
const identityKeyPair = await generateKeypair(mnemonic, mnemonicLanguage); const identityKeyPair = await generateKeypair(mnemonic, mnemonicLanguage);
await setSignInByLinking(true);
loadingAnimationCallback(); loadingAnimationCallback();
await createAccount(identityKeyPair); await createAccount(identityKeyPair);
await saveRecoveryPhrase(mnemonic); await saveRecoveryPhrase(mnemonic);

@ -113,6 +113,7 @@ export function isSignInByLinking() {
return isByLinking; return isByLinking;
} }
/** this is a loading state to prevent config sync jobs while we are trying to sign in through link a device. It should be set to false after the linking is complete */
export async function setSignInByLinking(isLinking: boolean) { export async function setSignInByLinking(isLinking: boolean) {
await put('is_sign_in_by_linking', isLinking); await put('is_sign_in_by_linking', isLinking);
} }

Loading…
Cancel
Save