Skip to content

Commit

Permalink
Merge commit '81f78ba008c41ce631a3d0f9e4449f4bbd90baee' into release/…
Browse files Browse the repository at this point in the history
…5.4.0

# Conflicts:
#	extension/src/popup/components/mnemonicPhrase/DisplayMnemonicPhrase/index.tsx
#	extension/src/popup/views/AccountCreator/index.tsx
  • Loading branch information
piyalbasu committed Aug 28, 2023
2 parents 628dbd4 + 81f78ba commit c33e301
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 137 deletions.
4 changes: 2 additions & 2 deletions @shared/api/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,8 @@ export const signOut = async (): Promise<{

export const showBackupPhrase = async (
password: string,
): Promise<{ error: string }> => {
let response = { error: "" };
): Promise<{ mnemonicPhrase: string; error: string }> => {
let response = { mnemonicPhrase: "", error: "" };
try {
response = await sendMessageToBackground({
password,
Expand Down
2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "extension",
"version": "5.2.6",
"version": "5.3.1",
"license": "Apache-2.0",
"prettier": "@stellar/prettier-config",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions extension/public/static/manifest/v2.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Freighter",
"version": "5.2.6",
"version_name": "5.2.6",
"version": "5.3.1",
"version_name": "5.3.1",
"description": "Freighter is a non-custodial wallet extension that enables you to sign Stellar transactions via your browser.",
"browser_specific_settings": {
"gecko": {
Expand Down
4 changes: 2 additions & 2 deletions extension/public/static/manifest/v3.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Freighter",
"version": "5.2.6",
"version_name": "5.2.6",
"version": "5.3.1",
"version_name": "5.3.1",
"description": "Freighter is a non-custodial wallet extension that enables you to sign Stellar transactions via your browser.",
"background": {
"service_worker": "background.min.js"
Expand Down
25 changes: 21 additions & 4 deletions extension/src/background/messageListener/popupMessageListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,23 @@ export const popupMessageListener = (request: Request, sessionStore: Store) => {
};
};

const getMnemonicPhrase = () => ({
mnemonicPhrase: mnemonicPhraseSelector(sessionStore.getState()),
});
const getMnemonicPhrase = async () => {
const { password } = request;

const keyID = (await getIsHardwareWalletActive())
? await _getNonHwKeyID()
: (await localStore.getItem(KEY_ID)) || "";

try {
await _unlockKeystore({ keyID, password });
} catch (e) {
console.error(e);
return { error: "Incorrect password" };
}
return {
mnemonicPhrase: mnemonicPhraseSelector(sessionStore.getState()),
};
};

const confirmMnemonicPhrase = async () => {
const isCorrectPhrase =
Expand Down Expand Up @@ -698,10 +712,13 @@ export const popupMessageListener = (request: Request, sessionStore: Store) => {
keyID: (await localStore.getItem(KEY_ID)) || "",
password,
});
return {};
} catch (e) {
return { error: "Incorrect Password" };
}

return {
mnemonicPhrase: mnemonicPhraseSelector(sessionStore.getState()),
};
};

const _getLocalStorageAccounts = async (password: string) => {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/popup/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export const Router = () => {
<GrantAccess />
</PublicKeyRoute>
<PublicKeyRoute path={ROUTES.mnemonicPhrase}>
<MnemonicPhrase />
<MnemonicPhrase mnemonicPhrase="" />
</PublicKeyRoute>
<PublicKeyRoute path={ROUTES.settings} exact>
<Settings />
Expand Down
4 changes: 3 additions & 1 deletion extension/src/popup/components/Onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { BackButton } from "popup/basics/buttons/BackButton";
import "./styles.scss";

export const Onboarding = ({
customBackAction,
hasGoBackBtn,
children,
}: {
customBackAction?: () => void;
hasGoBackBtn?: boolean;
children: React.ReactNode;
}) => {
Expand All @@ -19,7 +21,7 @@ export const Onboarding = ({
<div className="Onboarding">
{hasGoBackBtn && !isNewTabSession ? (
<div className="Onboarding--back">
<BackButton hasBackCopy />
<BackButton customBackAction={customBackAction} hasBackCopy />
</div>
) : null}
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import React from "react";
import { useTranslation } from "react-i18next";
import { Button, Icon, Notification } from "@stellar/design-system";

import { ROUTES } from "popup/constants/routes";
import { navigateTo } from "popup/helpers/navigate";

import {
OnboardingScreen,
OnboardingHalfScreen,
Expand All @@ -17,8 +14,10 @@ import "./styles.scss";

export const DisplayMnemonicPhrase = ({
mnemonicPhrase,
setIsConfirmed,
}: {
mnemonicPhrase: string;
setIsConfirmed: (confirmed: boolean) => void;
}) => {
const { t } = useTranslation();

Expand Down Expand Up @@ -62,7 +61,7 @@ export const DisplayMnemonicPhrase = ({
isFullWidth
variant="primary"
onClick={() => {
navigateTo(ROUTES.mnemonicPhraseConfirm);
setIsConfirmed(true);
}}
>
{t("Next")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface generateMnemonicPhraseDisplayProps {
}

export const generateMnemonicPhraseDisplay = ({
mnemonicPhrase,
mnemonicPhrase = "",
}: generateMnemonicPhraseDisplayProps) =>
mnemonicPhrase.split(" ").map((word: string) => {
/*
Expand Down
29 changes: 0 additions & 29 deletions extension/src/popup/helpers/useMnemonicPhrase.ts

This file was deleted.

21 changes: 11 additions & 10 deletions extension/src/popup/views/AccountCreator/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, { useEffect } from "react";
import React, { useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { Input, Checkbox, Link, Button } from "@stellar/design-system";
import { Field, FieldProps, Formik, Form } from "formik";
import { object as YupObject } from "yup";
import { useTranslation } from "react-i18next";

import { ROUTES } from "popup/constants/routes";
import { navigateTo } from "popup/helpers/navigate";
import { showBackupPhrase } from "@shared/api/internal";
import {
password as passwordValidator,
confirmPassword as confirmPasswordValidator,
Expand All @@ -29,13 +28,16 @@ import {
import { Header } from "popup/components/Header";
import { PasswordRequirements } from "popup/components/PasswordRequirements";

import { MnemonicPhrase } from "popup/views/MnemonicPhrase";

import "./styles.scss";

export const AccountCreator = () => {
const publicKey = useSelector(publicKeySelector);
const dispatch = useDispatch();
const authError = useSelector(authErrorSelector);
const { t } = useTranslation();
const [mnemonicPhrase, setMnemonicPhrase] = useState("");

interface FormValues {
password: string;
Expand All @@ -51,6 +53,9 @@ export const AccountCreator = () => {

const handleSubmit = async (values: FormValues) => {
await dispatch(createAccount(values.password));
const res = await showBackupPhrase(values.password);

setMnemonicPhrase(res.mnemonicPhrase);
};

const AccountCreatorSchema = YupObject().shape({
Expand All @@ -59,13 +64,9 @@ export const AccountCreator = () => {
termsOfUse: termsofUseValidator,
});

useEffect(() => {
if (publicKey) {
navigateTo(ROUTES.mnemonicPhrase);
}
}, [publicKey]);

return (
return mnemonicPhrase && publicKey ? (
<MnemonicPhrase mnemonicPhrase={mnemonicPhrase} />
) : (
<>
<FullscreenStyle />
<Header />
Expand Down
4 changes: 2 additions & 2 deletions extension/src/popup/views/DisplayBackupPhrase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { showBackupPhrase } from "@shared/api/internal";
import { ROUTES } from "popup/constants/routes";
import { navigateTo } from "popup/helpers/navigate";
import { emitMetric } from "helpers/metrics";
import { useMnemonicPhrase } from "popup/helpers/useMnemonicPhrase";

import { METRIC_NAMES } from "popup/constants/metricsNames";

Expand All @@ -23,7 +22,7 @@ export const DisplayBackupPhrase = () => {
const { t } = useTranslation();
const [errorMessage, setErrorMessage] = useState("");
const [isPhraseUnlocked, setIsPhraseUnlocked] = useState(false);
const mnemonicPhrase = useMnemonicPhrase();
const [mnemonicPhrase, setMnemonicPhrase] = useState("");

useEffect(() => {
emitMetric(
Expand All @@ -50,6 +49,7 @@ export const DisplayBackupPhrase = () => {
error_type: res.error,
});
} else {
setMnemonicPhrase(res.mnemonicPhrase);
setIsPhraseUnlocked(true);
setErrorMessage("");
emitMetric(METRIC_NAMES.backupPhraseSuccess);
Expand Down
52 changes: 29 additions & 23 deletions extension/src/popup/views/MnemonicPhrase.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
import React from "react";
import React, { useState } from "react";
import { useSelector } from "react-redux";
import shuffle from "lodash/shuffle";
import { Switch, Redirect } from "react-router-dom";
import { Redirect } from "react-router-dom";

import { APPLICATION_STATE } from "@shared/constants/applicationState";

import { PublicKeyRoute } from "popup/Router";
import { ROUTES } from "popup/constants/routes";
import { FullscreenStyle } from "popup/components/FullscreenStyle";
import { useMnemonicPhrase } from "popup/helpers/useMnemonicPhrase";
import { Header } from "popup/components/Header";
import { Onboarding } from "popup/components/Onboarding";
import { ConfirmMnemonicPhrase } from "popup/components/mnemonicPhrase/ConfirmMnemonicPhrase";
import { DisplayMnemonicPhrase } from "popup/components/mnemonicPhrase/DisplayMnemonicPhrase";
import { applicationStateSelector } from "popup/ducks/accountServices";

export const MnemonicPhrase = () => {
const mnemonicPhrase = useMnemonicPhrase();
interface MnemonicPhraseProps {
mnemonicPhrase: string;
}

export const MnemonicPhrase = ({
mnemonicPhrase = "",
}: MnemonicPhraseProps) => {
const applicationState = useSelector(applicationStateSelector);
const [isConfirmed, setIsConfirmed] = useState(false);

if (applicationState === APPLICATION_STATE.MNEMONIC_PHRASE_CONFIRMED) {
return <Redirect to={ROUTES.pinExtension} />;
}

if (mnemonicPhrase) {
return (
<Switch>
<PublicKeyRoute exact path={ROUTES.mnemonicPhrase}>
<Header />
<FullscreenStyle />
<Onboarding>
<DisplayMnemonicPhrase mnemonicPhrase={mnemonicPhrase} />
</Onboarding>
</PublicKeyRoute>
<PublicKeyRoute exact path={ROUTES.mnemonicPhraseConfirm}>
<Header />
<FullscreenStyle />
<Onboarding hasGoBackBtn>
<ConfirmMnemonicPhrase words={shuffle(mnemonicPhrase.split(" "))} />
</Onboarding>
</PublicKeyRoute>
</Switch>
return isConfirmed ? (
<>
<Header />
<FullscreenStyle />
<Onboarding customBackAction={() => setIsConfirmed(false)} hasGoBackBtn>
<ConfirmMnemonicPhrase words={shuffle(mnemonicPhrase.split(" "))} />
</Onboarding>
</>
) : (
<>
<Header />
<FullscreenStyle />
<Onboarding>
<DisplayMnemonicPhrase
mnemonicPhrase={mnemonicPhrase}
setIsConfirmed={setIsConfirmed}
/>
</Onboarding>
</>
);
}

Expand Down
7 changes: 2 additions & 5 deletions extension/src/popup/views/__tests__/MnemonicPhrase.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ jest.mock("popup/constants/history", () => ({
},
}));

jest.mock("popup/helpers/useMnemonicPhrase", () => ({
useMnemonicPhrase: () => "dummy mnemonic",
}));
jest.mock("react-router-dom", () => {
const ReactRouter = jest.requireActual("react-router-dom");
return {
Expand Down Expand Up @@ -68,7 +65,7 @@ describe.skip("MnemonicPhrase", () => {
},
}}
>
<MnemonicPhrase />
<MnemonicPhrase mnemonicPhrase={MNEMONIC} />
</Wrapper>,
);
await waitFor(() => screen.getByTestId("display-mnemonic-phrase"));
Expand Down Expand Up @@ -96,7 +93,7 @@ describe.skip("MnemonicPhrase", () => {
},
}}
>
<MnemonicPhrase />
<MnemonicPhrase mnemonicPhrase={MNEMONIC} />
</Wrapper>,
);

Expand Down
6 changes: 5 additions & 1 deletion extension/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const { DEFAULT_STATS } = require("../config/webpack");

const BUILD_PATH = path.resolve(__dirname, "./build");

const commonConfig = (env = { EXPERIMENTAL: false }) => ({
const commonConfig = (
env = { EXPERIMENTAL: false, AMPLITUDE_KEY: "", SENTRY_KEY: "" },
) => ({
entry: {
background: path.resolve(__dirname, "./public/background.ts"),
index: ["babel-polyfill", path.resolve(__dirname, "./src/popup/index.tsx")],
Expand Down Expand Up @@ -127,6 +129,8 @@ const commonConfig = (env = { EXPERIMENTAL: false }) => ({
}),
new webpack.DefinePlugin({
EXPERIMENTAL: env.EXPERIMENTAL,
AMPLITUDE_KEY: JSON.stringify(env.AMPLITUDE_KEY),
SENTRY_KEY: JSON.stringify(env.SENTRY_KEY),
}),
new MiniCssExtractPlugin({
filename: "[name].min.css",
Expand Down
Loading

0 comments on commit c33e301

Please sign in to comment.