diff --git a/app/globals.css b/app/globals.css index 6f6b26d..a80ecfc 100644 --- a/app/globals.css +++ b/app/globals.css @@ -5344,3 +5344,7 @@ h4 { margin-bottom: 0.5em; margin-top: 0.5em; } + +.is-open-add-account-modal { + opacity: 0.4; +} \ No newline at end of file diff --git a/app/testnet/account/testnet.tsx b/app/testnet/account/testnet.tsx index 2899acc..2142f75 100644 --- a/app/testnet/account/testnet.tsx +++ b/app/testnet/account/testnet.tsx @@ -40,20 +40,16 @@ const PublicNet: FC = ({ id }) => { try { await server.loadAccount(account); setExists(true); - console.log('valid') // Navigate to the account page if the account exists } catch (e) { if (e instanceof StellarSdk.NotFoundError) { setExists(false); setErrorvalid('Error: Account does not exist on the network. Make sure that you copied account address correctly and there was at least one payment to this address.') - } else { - console.error(e); } } }; if (StellarSdk.StrKey.isValidEd25519PublicKey(account)) { - console.log('true') checkAccount(); } else { diff --git a/package.json b/package.json index 4941525..f8e7779 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "mtl-stellar-multisig", "version": "0.1.0", "private": true, - "homepage": "https://stellar-multisig.montelibero.org", + "homepage": "https://monobladegg.github.io/stellar-multisig-stanging", "scripts": { "dev": "next dev", "build": "next build", diff --git a/src/features/store/index.ts b/src/features/store/index.ts index 163c25a..d815cad 100644 --- a/src/features/store/index.ts +++ b/src/features/store/index.ts @@ -2,7 +2,7 @@ import { create } from "zustand"; import { devtools, subscribeWithSelector } from "zustand/middleware"; import { immer } from "zustand/middleware/immer"; -import { netSlice, themeSlice } from "./slices"; +import { netSlice, themeSlice, accountSlice } from "./slices"; import { Store } from "@/shared/types" export const useStore = create()( @@ -10,7 +10,8 @@ export const useStore = create()( subscribeWithSelector( immer((...a) => ({ ...netSlice(...a), - ...themeSlice(...a) + ...themeSlice(...a), + ...accountSlice(...a) })) ) ) diff --git a/src/features/store/slices/accountsSlice/index.ts b/src/features/store/slices/accountsSlice/index.ts new file mode 100644 index 0000000..362b866 --- /dev/null +++ b/src/features/store/slices/accountsSlice/index.ts @@ -0,0 +1,38 @@ +import { IAccountsSlice, IAccount } from "@/shared/types"; +import { StateCreator } from "zustand"; + +export const accountSlice: StateCreator< + IAccountsSlice, + [["zustand/immer", never]], + [], + IAccountsSlice +> = (set/*, get*/) => { + const accounts: IAccount[] = []; + const isOpenAddAccountModal = false; + const currentAccount = null + const isAuth = false + + const setIsAuth = (isAuth: boolean) => { + set({ isAuth: isAuth }); + }; + + const setAccounts = (accounts: IAccount[]) => { + set({ accounts: accounts }); + localStorage.setItem("accounts", JSON.stringify(accounts)); + }; + + const setIsOpenAddAccountModal = (isOpenAddAccountModal: boolean) => { + set({ isOpenAddAccountModal: isOpenAddAccountModal }); + }; + + + return { + accounts, + setAccounts, + isOpenAddAccountModal, + setIsOpenAddAccountModal, + isAuth, + currentAccount, + setIsAuth + }; +}; diff --git a/src/features/store/slices/index.ts b/src/features/store/slices/index.ts index 9ae2306..1f899b3 100644 --- a/src/features/store/slices/index.ts +++ b/src/features/store/slices/index.ts @@ -1,2 +1,3 @@ export { netSlice } from "./netSlice" -export { themeSlice } from "./themeSlice" \ No newline at end of file +export { themeSlice } from "./themeSlice" +export { accountSlice } from "./accountsSlice" \ No newline at end of file diff --git a/src/pages/Layout/layout.tsx b/src/pages/Layout/layout.tsx index 1f41ca9..61040b3 100644 --- a/src/pages/Layout/layout.tsx +++ b/src/pages/Layout/layout.tsx @@ -4,6 +4,9 @@ import { FC, useEffect, useState } from "react"; import { useStore } from "@/features/store"; import { Footer, Header } from "@/widgets"; import { useShallow } from "zustand/react/shallow"; +import AddAccountModal from "@/widgets/shared/layouts/Header/ui/AddAccountModal"; +import Script from "next/script"; +import Head from "next/head"; type Props = { children: React.ReactNode; @@ -12,22 +15,41 @@ type Props = { const PageLayout: FC = ({ children }) => { const [isWindowDefined, setIsWindowDefined] = useState(false); - const { theme, setTheme, setNet } = useStore( - useShallow((state) => ({ - theme: state.theme, - setTheme: state.setTheme, - setNet: state.setNet, - })) - ); + const { + theme, + setTheme, + setNet, + setAccounts, + accounts, + isOpenAddAccountModal, + setIsAuth, + net, + } = useStore(useShallow((state) => state)); useEffect(() => { setIsWindowDefined(typeof window !== "undefined"); if (isWindowDefined) { - if (localStorage.getItem("theme")) + if (localStorage.getItem("theme")) { setTheme(localStorage.getItem("theme")!); - if (localStorage.getItem("net")) setNet(localStorage.getItem("net")!); + } + + if (localStorage.getItem("net")) { + setNet(localStorage.getItem("net")!); + } + + if (localStorage.getItem("accounts")) { + setAccounts(JSON.parse(localStorage.getItem("accounts")!)); + } } - }, [setTheme, setNet, isWindowDefined]); + }, [isWindowDefined, setTheme, setNet, setAccounts]); + + useEffect(() => { + setIsAuth( + accounts + .filter((account) => account.net === net) + .filter((account) => account.isCurrent).length > 0 + ); + }, [accounts, net, setIsAuth]); const themeLS: string | undefined | null = isWindowDefined ? window.localStorage.getItem("theme") @@ -38,7 +60,7 @@ const PageLayout: FC = ({ children }) => { if (!isWindowDefined) { return ( - + = ({ children }) => { content={process.env.NEXT_PUBLIC_COMMIT_HASH || ""} /> Stellar Multisig - + ); @@ -56,21 +78,30 @@ const PageLayout: FC = ({ children }) => { return ( - + Stellar Multisig - + -
+

{children}
+ {isOpenAddAccountModal && } +