forked from cerc-io/laconic-wallet
* 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
50 lines
1.2 KiB
TypeScript
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 };
|