laconic-wallet/src/context/AccountsContext.tsx
IshaVenikar 94bd8b6480 Persist network data (#84)
* Store new network data

* Store default networks in keystore (#86)

* Add default nws in keystore

* Fix duplicate networks

* Display correct currency symbols for eth and cosmos tx

* Fix currency display

* Use wei for eth
2024-04-25 17:08:27 +05:30

50 lines
1.2 KiB
TypeScript

import React, { createContext, useContext, useState } from 'react';
import { AccountsState } from '../types';
const AccountsContext = createContext<{
accounts: AccountsState;
setAccounts: (account: AccountsState) => void;
currentIndex: number;
setCurrentIndex: (index: number) => void;
networkType: string;
setNetworkType: (networkType: string) => void;
}>({
accounts: { ethAccounts: [], cosmosAccounts: [] },
setAccounts: () => {},
currentIndex: 0,
setCurrentIndex: () => {},
networkType: '',
setNetworkType: () => {},
});
const useAccounts = () => {
const accountsContext = useContext(AccountsContext);
return accountsContext;
};
const AccountsProvider = ({ children }: { children: any }) => {
const [accounts, setAccounts] = useState<AccountsState>({
ethAccounts: [],
cosmosAccounts: [],
});
const [currentIndex, setCurrentIndex] = useState<number>(0);
const [networkType, setNetworkType] = useState<string>('eth');
return (
<AccountsContext.Provider
value={{
accounts,
setAccounts,
currentIndex,
setCurrentIndex,
networkType,
setNetworkType,
}}>
{children}
</AccountsContext.Provider>
);
};
export { useAccounts, AccountsProvider };