mars-v2-frontend/stores/useWalletStore.tsx
Gustavo Mauricio 28c53b1e59
Wallets integration (#3)
* keplr/metamask integration initial commit

* chains settings and type definitions. notifications prototype

* fix: dom nested buttons

* address copied toast

* react-toastify colors

* wallet store and initial queries setup. zustand and react query dependencies added

* _app code cleanup

* remove obsolete WalletContext

* unused import

* walletStore initial commit

* leftover component reference removed

* fix: react hydration mismatch wallet component

* metamask conditional click handler

* connect modal minor tweaks and wallet installation urls added
2022-09-14 12:28:18 +01:00

53 lines
1.2 KiB
TypeScript

import create from "zustand";
import { persist } from "zustand/middleware";
import { Wallet } from "types";
const dummyStorageApi = {
getItem: () => null,
removeItem: () => undefined,
setItem: () => undefined,
};
interface WalletStore {
address: string;
injectiveAddress: string;
addresses: string[];
metamaskInstalled: boolean;
wallet: Wallet;
actions: {
setAddress: (address: string) => void;
setMetamaskInstalledStatus: (value: boolean) => void;
};
}
const useWalletStore = create<WalletStore>()(
persist(
(set, get) => ({
address: "",
injectiveAddress: "",
addresses: [],
metamaskInstalled: false,
wallet: Wallet.Metamask,
actions: {
setAddress: (address: string) => set(() => ({ address })),
setMetamaskInstalledStatus: (value: boolean) =>
set(() => ({ metamaskInstalled: value })),
},
}),
{
name: "wallet",
partialize: (state) =>
Object.fromEntries(
Object.entries(state).filter(
([key]) => !["metamaskInstalled", "actions"].includes(key)
)
),
// getStorage: () =>
// typeof window !== "undefined" ? localStorage : dummyStorageApi,
}
)
);
export default useWalletStore;