'init'
This commit is contained in:
28
app/providers/AccountProvider/useAccount.ts
Normal file
28
app/providers/AccountProvider/useAccount.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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];
|
||||
}
|
||||
Reference in New Issue
Block a user