Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unchain unlock call from enable screen #3143

Merged
merged 7 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/app/router/Prompt/Prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ function Prompt() {
<Providers>
<HashRouter>
<Routes>
<Route
index
pavanjoshi914 marked this conversation as resolved.
Show resolved Hide resolved
element={
<Navigate
to={`/${navigationState.action}`}
replace
state={navigationState}
/>
}
/>
<Route
path="/"
element={
Expand All @@ -68,16 +78,6 @@ function Prompt() {
</RequireAuth>
}
>
<Route
index
element={
<Navigate
to={`/${navigationState.action}`}
replace
state={navigationState}
/>
}
/>
<Route
path="public/alby/enable"
element={
Expand Down
3 changes: 3 additions & 0 deletions src/app/screens/Unlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useLocation, useNavigate } from "react-router-dom";
import Hyperlink from "~/app/components/Hyperlink";
import PasswordViewAdornment from "~/app/components/PasswordViewAdornment";
import { useAccount } from "~/app/context/AccountContext";
import { useNavigationState } from "~/app/hooks/useNavigationState";
import msg from "~/common/lib/msg";
import utils from "~/common/lib/utils";

Expand All @@ -17,6 +18,7 @@ function Unlock() {
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const navigate = useNavigate();
const navState = useNavigationState();
const location = useLocation() as {
state: { from?: { pathname?: string } };
};
Expand Down Expand Up @@ -45,6 +47,7 @@ function Unlock() {
setLoading(true);
auth
.unlock(password, () => {
if (navState.action === "unlock") msg.reply({ unlocked: true });
pavanjoshi914 marked this conversation as resolved.
Show resolved Hide resolved
navigate(from, { replace: true });
setLoading(false);
})
Expand Down
16 changes: 15 additions & 1 deletion src/extension/background-script/actions/nostr/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,22 @@ const enable = async (message: MessageAllowanceEnable, sender: Sender) => {

const enabledFor = new Set(allowance?.enabledFor);

if (!isUnlocked) {
pavanjoshi914 marked this conversation as resolved.
Show resolved Hide resolved
try {
await utils.openPrompt<{ unlocked: boolean }>({
args: {},
origin: { internal: true },
action: "unlock",
});
} catch (e) {
console.error(e);
if (e instanceof Error) {
return { error: e.message };
}
}
}

if (
isUnlocked &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we still need the unlock check? because if your new check fails for whatever reason then it's not unlocked and this action should not run.

allowance &&
allowance.enabled &&
account?.nostrPrivateKey &&
Expand Down
Loading