Files
desktop/app/providers/AccountProvider/useAccount.ts
rosetta 83f38dc63f 'init'
2026-01-30 05:01:05 +02:00

28 lines
987 B
TypeScript

import { useContext } from "react";
import { Account, AccountContext, AccountContextValue } from "./AccountProvider";
import { useDatabase } from "@/app/providers/DatabaseProvider/useDatabase";
export function useAccount() : [
Account, () => void
] {
const {runQuery} = useDatabase();
const context : AccountContextValue = useContext(AccountContext);
if(!context){
throw new Error("useAccount must be used within a AccountProvider");
}
const deleteAccount = () => {
runQuery("DELETE FROM `accounts` WHERE `public_key` = ?", [context.loginedAccount.publicKey])
context.removeAccountsFromArrayOfAccounts(context.loginedAccount);
context.loginAccount({
privateHash: "",
privatePlain: "",
publicKey: "",
privateKey: "",
seedPhraseEncrypted: ""
});
localStorage.removeItem("last_logined_account");
}
return [context.loginedAccount, deleteAccount];
}