diff --git a/components/Accounts.tsx b/components/Accounts.tsx index a979c62..301d173 100644 --- a/components/Accounts.tsx +++ b/components/Accounts.tsx @@ -31,7 +31,7 @@ import transactionsData from "../content/transactions.json"; import { SetHookDialog } from "./SetHookDialog"; import { addFunds } from "../state/actions/addFaucetAccount"; import { deleteHook } from "../state/actions/deployHook"; -import { capitalize } from '../utils/helpers'; +import { capitalize } from "../utils/helpers"; export const AccountDialog = ({ activeAccountAddress, @@ -523,28 +523,23 @@ const ImportAccountDialog = ({ }: { type?: "import" | "create"; }) => { - const [value, setValue] = useState(""); + const [secret, setSecret] = useState(""); + const [name, setName] = useState(""); const btnText = type === "import" ? "Import" : "Create"; const title = type === "import" ? "Import Account" : "Create Account"; - const labelText = type === "import" ? "Account secret" : "Account Name"; - const cancelText = type === "import" ? "Cancel" : "Skip"; const handleSubmit = async () => { if (type === "create") { - const name = capitalize(value); - await addFaucetAccount(name, true); - setValue(""); + const value = capitalize(name); + await addFaucetAccount(value, true); + setName(""); + setSecret(""); return; } - importAccount(value); - setValue(""); - }; - const handleCancel = () => { - setValue(""); - if (type === "create") { - addFaucetAccount(undefined, true); - } + importAccount(secret, name); + setName(""); + setSecret(""); }; return ( @@ -556,24 +551,29 @@ const ImportAccountDialog = ({ {title} - - {type === "import" ? ( - setValue(e.target.value)} - /> - ) : ( + + setValue(e.target.value)} + value={name} + onChange={e => setName(e.target.value)} /> + + {type === "import" && ( + + + setSecret(e.target.value)} + /> + )} @@ -585,12 +585,10 @@ const ImportAccountDialog = ({ }} > - + - diff --git a/state/actions/importAccount.ts b/state/actions/importAccount.ts index 2223e97..f0525b5 100644 --- a/state/actions/importAccount.ts +++ b/state/actions/importAccount.ts @@ -5,7 +5,7 @@ import state from '../index'; import { names } from './addFaucetAccount'; // Adds test account to global state with secret key -export const importAccount = (secret: string) => { +export const importAccount = (secret: string, name?: string) => { if (!secret) { return toast.error("You need to add secret!"); } @@ -27,7 +27,7 @@ export const importAccount = (secret: string) => { return toast.error(`Couldn't create account!`); } state.accounts.push({ - name: names[state.accounts.length], + name: name || names[state.accounts.length], address: account.address || "", secret: account.secret.familySeed || "", xrp: "0",