From 8e41d51632f87129cd5501ad993f25436472c35f Mon Sep 17 00:00:00 2001 From: William Grant Date: Tue, 26 Mar 2024 17:18:17 +1100 Subject: [PATCH] feat: restoring an account from seed and fetching seems to work --- ts/components/registration/SessionRegistrationView.tsx | 6 +++--- ts/components/registration/stages/RestoreAccount.tsx | 2 +- ts/session/apis/snode_api/swarmPolling.ts | 10 ---------- ts/util/accountManager.ts | 3 ++- ts/util/storage.ts | 1 + 5 files changed, 7 insertions(+), 15 deletions(-) diff --git a/ts/components/registration/SessionRegistrationView.tsx b/ts/components/registration/SessionRegistrationView.tsx index f29edc2a4..cea12f50c 100644 --- a/ts/components/registration/SessionRegistrationView.tsx +++ b/ts/components/registration/SessionRegistrationView.tsx @@ -1,7 +1,7 @@ -import { useEffect } from 'react'; import { Provider } from 'react-redux'; import styled from 'styled-components'; +import { useMount } from 'react-use'; import { onboardingStore } from '../../state/onboarding/store'; import { SessionTheme } from '../../themes/SessionTheme'; import { setSignInByLinking } from '../../util/storage'; @@ -56,9 +56,9 @@ const StyledSessionContent = styled(Flex)` `; export const SessionRegistrationView = () => { - useEffect(() => { + useMount(() => { void setSignInByLinking(false); - }, []); + }); return ( diff --git a/ts/components/registration/stages/RestoreAccount.tsx b/ts/components/registration/stages/RestoreAccount.tsx index e38efa3f2..e667476c6 100644 --- a/ts/components/registration/stages/RestoreAccount.tsx +++ b/ts/components/registration/stages/RestoreAccount.tsx @@ -89,7 +89,7 @@ async function signInAndFetchDisplayName( 'configurationMessageReceived', async (ourPubkey: string, displayName: string) => { window.Whisper.events.off('configurationMessageReceived'); - await setSignInByLinking(true); + await setSignInByLinking(false); await setSignWithRecoveryPhrase(false); dispatch(setHexGeneratedPubKey(ourPubkey)); dispatch(setDisplayName(displayName)); diff --git a/ts/session/apis/snode_api/swarmPolling.ts b/ts/session/apis/snode_api/swarmPolling.ts index fde14f2e8..65529a3f7 100644 --- a/ts/session/apis/snode_api/swarmPolling.ts +++ b/ts/session/apis/snode_api/swarmPolling.ts @@ -409,9 +409,6 @@ export class SwarmPolling { // we take the lastest config message to create the wrapper in memory const incomingConfigMessage = allDecryptedConfigMessages.at(-1); - window.log.debug( - `WIP: [SwarmPolling] configMessage: ${JSON.stringify(incomingConfigMessage)}` - ); if (!incomingConfigMessage) { throw new Error('incomingConfigMessage not found'); } @@ -681,9 +678,6 @@ export class SwarmPolling { toPollFrom, UserUtils.getOurPubKeyStrFromCache() ); - window.log.debug( - `WIP: [resultsFromUserProfile] resultsFromUserProfile: ${JSON.stringify(resultsFromUserProfile)}` - ); } catch (e) { if (e.message === ERROR_CODE_NO_CONNECT) { if (window.inboxStore?.getState().onionPaths.isOnline) { @@ -709,10 +703,6 @@ export class SwarmPolling { const userConfigMessagesMerged = flatten(compact(userConfigMessages)); if (userConfigMessagesMerged.length) { - window.log.info( - `[pollOnceForDisplayName] received userConfigMessages count: ${userConfigMessagesMerged.length} for key ${pubkey.key}` - ); - const displayName = await this.handleSharedConfigMessages(userConfigMessagesMerged, true); return displayName; } diff --git a/ts/util/accountManager.ts b/ts/util/accountManager.ts index 679fa15e2..162fe1b33 100644 --- a/ts/util/accountManager.ts +++ b/ts/util/accountManager.ts @@ -14,7 +14,7 @@ import { NotFoundError } from '../session/utils/errors'; import { LibSessionUtil } from '../session/utils/libsession/libsession_utils'; import { actions as userActions } from '../state/ducks/user'; import { Registration } from './registration'; -import { Storage, saveRecoveryPhrase, setLocalPubKey } from './storage'; +import { Storage, saveRecoveryPhrase, setLocalPubKey, setSignInByLinking } from './storage'; /** * Might throw @@ -78,6 +78,7 @@ export async function signInByLinkingDevice( const identityKeyPair = await generateKeypair(mnemonic, mnemonicLanguage); + await setSignInByLinking(true); loadingAnimationCallback(); await createAccount(identityKeyPair); await saveRecoveryPhrase(mnemonic); diff --git a/ts/util/storage.ts b/ts/util/storage.ts index dbf0e2507..89916f960 100644 --- a/ts/util/storage.ts +++ b/ts/util/storage.ts @@ -113,6 +113,7 @@ export function isSignInByLinking() { 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) { await put('is_sign_in_by_linking', isLinking); }