feat: convert privKeyBytes to hex

redux doesnt like uint8Array, rename shouldQuit to shouldQuitOnClick
pull/3083/head
yougotwill 9 months ago
parent 9a4356a6b7
commit cbf0a5b877

@ -28,13 +28,13 @@ export const BackButtonWithinContainer = ({
children,
margin,
callback,
shouldQuit,
shouldQuitOnClick,
quitMessage,
}: {
children: ReactNode;
margin?: string;
callback?: () => void;
shouldQuit?: boolean;
shouldQuitOnClick?: boolean;
quitMessage?: string;
}) => {
return (
@ -46,7 +46,11 @@ export const BackButtonWithinContainer = ({
alignItems="flex-start"
>
<div style={{ margin }}>
<BackButton callback={callback} shouldQuit={shouldQuit} quitMessage={quitMessage} />
<BackButton
callback={callback}
shouldQuitOnClick={shouldQuitOnClick}
quitMessage={quitMessage}
/>
</div>
{children}
</StyledBackButtonContainer>
@ -55,11 +59,11 @@ export const BackButtonWithinContainer = ({
export const BackButton = ({
callback,
shouldQuit,
shouldQuitOnClick,
quitMessage,
}: {
callback?: () => void;
shouldQuit?: boolean;
shouldQuitOnClick?: boolean;
quitMessage?: string;
}) => {
const step = useOnboardStep();
@ -76,7 +80,7 @@ export const BackButton = ({
iconRotation={90}
padding={'0'}
onClick={() => {
if (shouldQuit && quitMessage) {
if (shouldQuitOnClick && quitMessage) {
dispatch(
updateQuitModal({
title: window.i18n('warning'),

@ -3,8 +3,9 @@ import { useDispatch } from 'react-redux';
import useMount from 'react-use/lib/useMount';
import { SettingsKey } from '../../../data/settings-key';
import { mnDecode } from '../../../session/crypto/mnemonic';
import { ProfileManager } from '../../../session/profile_manager/ProfileManager';
import { StringUtils } from '../../../session/utils';
import { fromHex } from '../../../session/utils/String';
import { fromHex, toHex } from '../../../session/utils/String';
import LIBSESSION_CONSTANTS from '../../../session/utils/libsession/libsession_constants';
import { trigger } from '../../../shims/events';
import {
@ -13,13 +14,13 @@ import {
setDisplayName,
setDisplayNameError,
setHexGeneratedPubKey,
setPrivateKeyBytes,
setPrivateKeyBytesHex,
setRecoveryPassword,
} from '../../../state/onboarding/ducks/registration';
import {
useDisplayName,
useDisplayNameError,
useOnboardPrivateKeyBytes,
useOnboardPrivateKeyBytesHex,
useRecoveryPassword,
} from '../../../state/onboarding/selectors/registration';
import {
@ -35,7 +36,6 @@ import { resetRegistration } from '../RegistrationStages';
import { ContinueButton, OnboardDescription, OnboardHeading } from '../components';
import { BackButtonWithinContainer } from '../components/BackButton';
import { displayNameIsValid, sanitizeDisplayNameOrToast } from '../utils';
import { ProfileManager } from '../../../session/profile_manager/ProfileManager';
export type AccountDetails = {
recoveryPassword: string;
@ -59,7 +59,7 @@ async function signUp(signUpDetails: AccountDetails) {
}
export const CreateAccount = () => {
const privateKeyBytes = useOnboardPrivateKeyBytes();
const privateKeyBytesHex = useOnboardPrivateKeyBytesHex();
const recoveryPassword = useRecoveryPassword();
const displayName = useDisplayName();
const displayNameError = useDisplayNameError();
@ -82,7 +82,7 @@ export const CreateAccount = () => {
const newHexPubKey = StringUtils.decode(keyPair.pubKey, 'hex');
dispatch(setRecoveryPassword(mnemonic));
dispatch(setPrivateKeyBytes(keyPair.ed25519KeyPair.privateKey));
dispatch(setPrivateKeyBytesHex(toHex(keyPair.ed25519KeyPair.privateKey)));
dispatch(setHexGeneratedPubKey(newHexPubKey)); // our 'frontend' account ID
}
};
@ -97,7 +97,7 @@ export const CreateAccount = () => {
}
try {
if (!privateKeyBytes) {
if (!privateKeyBytesHex) {
throw new Error('Private key not found');
}
@ -122,7 +122,7 @@ export const CreateAccount = () => {
return (
<BackButtonWithinContainer
margin={'2px 0 0 -36px'}
shouldQuit={true}
shouldQuitOnClick={true}
quitMessage={window.i18n('onboardingBackAccountCreation')}
callback={() => {
dispatch(setDisplayName(''));

@ -197,7 +197,7 @@ export const RestoreAccount = () => {
return (
<BackButtonWithinContainer
margin={'2px 0 0 -36px'}
shouldQuit={step !== AccountRestoration.RecoveryPassword}
shouldQuitOnClick={step !== AccountRestoration.RecoveryPassword}
quitMessage={window.i18n('onboardingBackLoadAccount')}
callback={() => {
dispatch(setRecoveryPassword(''));

@ -41,7 +41,7 @@ export type OnboardingState = {
progress: number;
recoveryPassword: string;
recoveryPasswordError: string | undefined;
privateKeyBytes: Uint8Array | undefined;
privateKeyBytesHex: string | undefined;
hexGeneratedPubKey: string;
displayName: string;
displayNameError: string | undefined;
@ -55,7 +55,7 @@ const initialState: OnboardingState = {
progress: 0,
recoveryPassword: '',
recoveryPasswordError: undefined,
privateKeyBytes: undefined,
privateKeyBytesHex: undefined,
hexGeneratedPubKey: '',
displayName: '',
displayNameError: undefined,
@ -92,8 +92,8 @@ export const registrationSlice = createSlice({
setHexGeneratedPubKey(state, action: PayloadAction<string>) {
return { ...state, hexGeneratedPubKey: action.payload };
},
setPrivateKeyBytes(state, action: PayloadAction<Uint8Array>) {
return { ...state, privateKeyBytes: action.payload };
setPrivateKeyBytesHex(state, action: PayloadAction<string>) {
return { ...state, privateKeyBytesHex: action.payload };
},
setDisplayName(state, action: PayloadAction<string>) {
return { ...state, displayName: action.payload };
@ -114,7 +114,7 @@ export const {
setRecoveryPassword,
setRecoveryPasswordError,
setHexGeneratedPubKey,
setPrivateKeyBytes,
setPrivateKeyBytesHex,
setDisplayName,
setDisplayNameError,
} = registrationSlice.actions;

@ -54,9 +54,9 @@ const getHexGeneratedPubKey = createSelector(
(state: OnboardingState): string => state.hexGeneratedPubKey
);
const getPrivateKeyBytes = createSelector(
const getPrivateKeyBytesHex = createSelector(
getRegistration,
(state: OnboardingState): Uint8Array | undefined => state.privateKeyBytes
(state: OnboardingState): string | undefined => state.privateKeyBytesHex
);
const getDisplayName = createSelector(
@ -103,8 +103,8 @@ export const useOnboardHexGeneratedPubKey = () => {
return useSelector(getHexGeneratedPubKey);
};
export const useOnboardPrivateKeyBytes = () => {
return useSelector(getPrivateKeyBytes);
export const useOnboardPrivateKeyBytesHex = () => {
return useSelector(getPrivateKeyBytesHex);
};
export const useDisplayName = () => {

Loading…
Cancel
Save