-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/1349 - Require unlocked keychain for all access (#1352)
* feat: extension must be unlocked to connect * feat: wrap approve connection with auth component * feat: wrap all top-level approvals with auth * fix: clean up naming conventions * feat: validate origin & chain Id to see if already approved * fix: fix failing tests * feat: subscribe to unlock event
- Loading branch information
Showing
27 changed files
with
356 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Login } from "App/Login"; | ||
import { UnlockVaultMsg } from "background/vault"; | ||
import { useRequester } from "hooks/useRequester"; | ||
import { useContext } from "react"; | ||
import { Ports } from "router"; | ||
import { ExtensionLockContext } from "./Approvals"; | ||
|
||
type Props = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
export const WithAuth: React.FC<Props> = ({ children }) => { | ||
const requester = useRequester(); | ||
const { isUnlocked, setIsUnlocked } = useContext(ExtensionLockContext); | ||
|
||
const handleOnLogin = async (password: string): Promise<boolean> => { | ||
try { | ||
const isUnlocked = await requester.sendMessage( | ||
Ports.Background, | ||
new UnlockVaultMsg(password) | ||
); | ||
setIsUnlocked!(isUnlocked); | ||
return isUnlocked; | ||
} catch (_) { | ||
setIsUnlocked!(false); | ||
} | ||
return false; | ||
}; | ||
|
||
return ( | ||
<> | ||
{isUnlocked ? | ||
<>{children}</> | ||
: <Login onLogin={handleOnLogin} />} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
231d0a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://namada-interface-dev.netlify.app as production
🚀 Deployed on https://674dbce4e6d0f62c186be065--namada-interface-dev.netlify.app