forked from anoma/namada
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplifying code with Context API (anoma#440)
* feat(extension): using React context to manage state * refactor(extension): removing unused component * refactor(extension, app): refactoring route management * New pages: Rename key, View Mnemonic, and fixing bugs (anoma#441) * feat(extension, app): adding Vault context * feat(extension): creating view mnemonic page * feat(extension, setup): reflecting changes on SeedPhraseInstructions and reusing a few components * feat(extension): fixing inital loading state * feat(extension): adding rename page * feat(extension): adding navigation menu * feat(extension): handling passwords with session storage * feat(extension): storing hashed password in session storage * feat(extension,app): adding back some global styles * refactor(extension, app): making ViewAccount code clearer * fix(extension,app): fixing 404 route
- Loading branch information
1 parent
c890c2d
commit 95022f6
Showing
60 changed files
with
1,346 additions
and
591 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
73 changes: 73 additions & 0 deletions
73
apps/extension/src/App/Accounts/RenameAccount/RenameAccount.tsx
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,73 @@ | ||
import { | ||
Input, | ||
GapPatterns, | ||
Heading, | ||
Stack, | ||
ActionButton, | ||
} from "@namada/components"; | ||
import routes from "App/routes"; | ||
import { useEffect, useState } from "react"; | ||
import { useNavigate, useParams } from "react-router-dom"; | ||
import { DerivedAccount } from "@namada/types"; | ||
import { useAccountContext } from "context"; | ||
|
||
type RenameAccountParamsType = { | ||
accountId: string; | ||
}; | ||
|
||
export const RenameAccount = (): JSX.Element => { | ||
const { accountId } = useParams<RenameAccountParamsType>(); | ||
const { getById, rename } = useAccountContext(); | ||
const [account, setAccount] = useState<DerivedAccount | undefined>(); | ||
const [error, setError] = useState(""); | ||
const [alias, setAlias] = useState(""); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const handleSubmit = async (e: React.FormEvent): Promise<void> => { | ||
e.preventDefault(); | ||
|
||
try { | ||
if (!accountId) { | ||
throw new Error("Invalid account id"); | ||
} | ||
await rename(accountId, alias); | ||
} catch (err) { | ||
setError(`${err}`); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (!accountId) { | ||
navigate(routes.viewAccountList()); | ||
return; | ||
} | ||
|
||
const account = getById(accountId); | ||
if (!account) { | ||
throw new Error("Invalid account provided"); | ||
} | ||
|
||
setAccount(account); | ||
}, [accountId]); | ||
|
||
return ( | ||
<Stack gap={GapPatterns.TitleContent}> | ||
<Heading>Rename Key</Heading> | ||
{account && ( | ||
<Stack as="form" gap={GapPatterns.FormFields} onSubmit={handleSubmit}> | ||
<Input readOnly label="Current name" value={account.alias} /> | ||
<Input | ||
autoFocus | ||
label="New name" | ||
placeholder="Ex: Special Account" | ||
value={alias} | ||
onChange={(e) => setAlias(e.target.value)} | ||
error={error} | ||
/> | ||
<ActionButton>Rename</ActionButton> | ||
</Stack> | ||
)} | ||
</Stack> | ||
); | ||
}; |
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 @@ | ||
export * from "./RenameAccount"; |
Oops, something went wrong.