Extract actions to separate files
This commit is contained in:
28
state/actions/importAccount.ts
Normal file
28
state/actions/importAccount.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import toast from "react-hot-toast";
|
||||
import { derive } from "xrpl-accountlib";
|
||||
|
||||
import state from '../index';
|
||||
import { names } from './addFaucetAccount';
|
||||
|
||||
export const importAccount = (secret: string) => {
|
||||
if (!secret) {
|
||||
return toast.error("You need to add secret!");
|
||||
}
|
||||
if (state.accounts.find((acc) => acc.secret === secret)) {
|
||||
return toast.error("Account already added!");
|
||||
}
|
||||
const account = derive.familySeed(secret);
|
||||
if (!account.secret.familySeed) {
|
||||
return toast.error(`Couldn't create account!`);
|
||||
}
|
||||
state.accounts.push({
|
||||
name: names[state.accounts.length],
|
||||
address: account.address || "",
|
||||
secret: account.secret.familySeed || "",
|
||||
xrp: "0",
|
||||
sequence: 1,
|
||||
hooks: [],
|
||||
isLoading: false,
|
||||
});
|
||||
return toast.success("Account imported successfully!");
|
||||
};
|
||||
Reference in New Issue
Block a user