Part of [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675) Co-authored-by: IshaVenikar <ishavenikar7@gmail.com> Reviewed-on: cerc-io/laconic-wallet-web#10 Co-authored-by: Nabarun <nabarun@deepstacksoft.com> Co-committed-by: Nabarun <nabarun@deepstacksoft.com>
40 lines
969 B
TypeScript
40 lines
969 B
TypeScript
import React, { createContext, useContext, useState } from 'react';
|
|
|
|
import { Account } from '../types';
|
|
|
|
const AccountsContext = createContext<{
|
|
accounts: Account[];
|
|
setAccounts: (account: Account[]) => void;
|
|
currentIndex: number;
|
|
setCurrentIndex: (index: number) => void;
|
|
}>({
|
|
accounts: [],
|
|
setAccounts: () => {},
|
|
currentIndex: 0,
|
|
setCurrentIndex: () => {},
|
|
});
|
|
|
|
const useAccounts = () => {
|
|
const accountsContext = useContext(AccountsContext);
|
|
return accountsContext;
|
|
};
|
|
|
|
const AccountsProvider = ({ children }: { children: React.ReactNode }) => {
|
|
const [accounts, setAccounts] = useState<Account[]>([]);
|
|
const [currentIndex, setCurrentIndex] = useState<number>(0);
|
|
|
|
return (
|
|
<AccountsContext.Provider
|
|
value={{
|
|
accounts,
|
|
setAccounts,
|
|
currentIndex,
|
|
setCurrentIndex,
|
|
}}>
|
|
{children}
|
|
</AccountsContext.Provider>
|
|
);
|
|
};
|
|
|
|
export { useAccounts, AccountsProvider };
|