-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3405446
commit ee38b79
Showing
22 changed files
with
808 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5344,3 +5344,7 @@ h4 { | |
margin-bottom: 0.5em; | ||
margin-top: 0.5em; | ||
} | ||
|
||
.is-open-add-account-modal { | ||
opacity: 0.4; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { netSlice } from "./netSlice" | ||
export { themeSlice } from "./themeSlice" | ||
export { themeSlice } from "./themeSlice" | ||
export { accountSlice } from "./accountsSlice" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { INetSlice, IThemeSlice } from "@/shared/types/store/slices"; | ||
import { IAccountsSlice, INetSlice, IThemeSlice } from "@/shared/types/store/slices"; | ||
|
||
interface Store extends INetSlice, IThemeSlice {} | ||
interface Store extends INetSlice, IThemeSlice, IAccountsSlice {} | ||
|
||
export default Store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export type IAccount = { | ||
id: string | ||
accountID: string | ||
isMultiSig: boolean | ||
isCurrent: boolean | ||
net: string | ||
} | ||
|
||
export interface AccountState { | ||
accounts: IAccount[] | ||
isOpenAddAccountModal: boolean | ||
isAuth: boolean | ||
currentAccount: IAccount | null | ||
} | ||
|
||
export interface AccountActions { | ||
setAccounts: (Accounts: IAccount[]) => void | ||
setIsOpenAddAccountModal: (isOpenAddAccountModal: boolean) => void | ||
setIsAuth: (isAuth: boolean) => void | ||
} | ||
|
||
interface IAccountsSlice extends AccountState, AccountActions {} | ||
|
||
export default IAccountsSlice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export {type default as INetSlice} from "./netSlice" | ||
export {type default as IThemeSlice} from "./themeSlice" | ||
export {type default as IThemeSlice} from "./themeSlice" | ||
export {type default as IAccountsSlice, type IAccount} from "./accountsSlice" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {default} from "./ui" |
70 changes: 70 additions & 0 deletions
70
src/widgets/shared/layouts/Header/ui/AccountItem/ui/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { FC } from "react"; | ||
import Link from "next/link"; | ||
import { useStore } from "@/features/store"; | ||
import { useShallow } from "zustand/react/shallow"; | ||
import { collapseAccount } from "@/pages/public/account/publicnet"; | ||
import { IAccount } from "@/shared/types"; | ||
|
||
interface Props { | ||
id: string; | ||
isOpenAccount: boolean; | ||
setIsOpenAccount: (isOpenAccount: boolean) => void; | ||
isMain?: boolean; | ||
account: IAccount; | ||
} | ||
|
||
const AccountItem: FC<Props> = ({ | ||
id, | ||
isOpenAccount, | ||
setIsOpenAccount, | ||
isMain = true, | ||
account, | ||
}) => { | ||
const { net, theme, accounts, setAccounts } = useStore( | ||
useShallow((state) => ({ | ||
net: state.net, | ||
theme: state.theme, | ||
accounts: state.accounts, | ||
setAccounts: state.setAccounts, | ||
})) | ||
); | ||
|
||
const handleAccount = () => { | ||
setIsOpenAccount(!isOpenAccount); | ||
|
||
// Обновляем аккаунты только если они находятся на одном и том же 'net' | ||
const updatedAccounts = accounts.map( | ||
(account) => | ||
account.net === net | ||
? account.accountID === id | ||
? { ...account, isCurrent: true } | ||
: { ...account, isCurrent: false } | ||
: account // Не трогаем аккаунты с другим 'net' | ||
); | ||
|
||
setAccounts(updatedAccounts); | ||
}; | ||
|
||
return ( | ||
<Link href={`/${net}/account?id=${id}`}> | ||
<li | ||
className={ | ||
theme === "night" | ||
? `dropdown-item ${isMain && "selected"}` | ||
: `dropdown-item-light ${isMain && "selected"}` | ||
} | ||
style={{ textAlign: "center" }} | ||
onClick={handleAccount} | ||
> | ||
{account?.isMultiSig ? ( | ||
<i className="fa-solid fa-users"></i> | ||
) : ( | ||
<i className="fa-solid fa-user"></i> | ||
)}{" "} | ||
{collapseAccount(id)} | ||
</li> | ||
</Link> | ||
); | ||
}; | ||
|
||
export default AccountItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {default} from "./ui" |
Oops, something went wrong.