Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recent activity #105

Open
wants to merge 5 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ const Admin = () => {
console.log(data);
};

const setRecentActivity = async () => {
const res = await fetch(
`/api/vercel/set-recent-activity?key=${setterKey}&value=${setterValue}`
);
const data = await res.json();
console.log(data);
};

const getAllRecentActivity = async () => {
const res = await fetch(
`/api/vercel/get-all-recent-activity?key=${inputValue}`
);
const data = await res.json();
console.log(data);
};

const buttons = [
{
name: "flushall",
Expand Down Expand Up @@ -109,6 +125,15 @@ const Admin = () => {
name: "setData",
method: () => setData(),
},
{
name: "setRecentActivity",
method: () => setRecentActivity(),
},

{
name: "getAllRecentActivity - by parent wallet",
method: () => getAllRecentActivity(),
},
];

if (!isUnlocked) {
Expand Down
56 changes: 21 additions & 35 deletions app/parent-dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use client";
/* eslint-disable react/no-children-prop */

import {
Box,
Expand Down Expand Up @@ -40,8 +39,8 @@ const Parent: React.FC = () => {
//=============================================================================

const [childKey, setChildKey] = useState<number>(0);
const [childrenLoading, setChildrenLoading] = useState(false);
const [children, setChildren] = useState([]);
const [membersLoading, setMembersLoading] = useState(false);
const [members, setMembers] = useState<User[]>([]);
// const [stakeContract, setStakeContract] = useState<StakeContract>();
const [familyDetails, setFamilyDetails] = useState({} as User);

Expand Down Expand Up @@ -84,12 +83,6 @@ const Parent: React.FC = () => {
onClose: onCloseEtherScan,
} = useDisclosure();

const {
isOpen: isOpenChildDetails,
onOpen: onOpenChildDetails,
onClose: onCloseChildDetails,
} = useDisclosure();

const {
isOpen: isChangeUsernameOpen,
onOpen: onChangeUsernameOpen,
Expand Down Expand Up @@ -134,16 +127,9 @@ const Parent: React.FC = () => {

useEffect(() => {
fetchFamilyDetails();
fetchChildren();
fetchMembers();
}, []);

// useEffect(() => {
// if (!stakeContract || !children.length) {
// setChildrenStakes({});
// return;
// }
// }, [stakeContract, children]);

//=============================================================================
// FUNCTIONS
//=============================================================================
Expand All @@ -159,30 +145,30 @@ const Parent: React.FC = () => {
setFamilyDetails(user);
}, [userDetails?.wallet]);

const fetchChildren = useCallback(async () => {
const getChildren = async () => {
const fetchMembers = useCallback(async () => {
const getMembers = async () => {
if (!userDetails?.wallet) return;

const children = [] as User[];
const members = [] as User[];

familyDetails.children?.forEach(async (walletAddress) => {
const { data } = await axios.get(
`/api/vercel/get-json?key=${walletAddress}`
);

children.push(data as User);
members.push(data as User);
});

if (children.length) {
const childrenWalletBalances = await axios.post(
if (members.length) {
const membersWalletBalances = await axios.post(
`/api/etherscan/balancemulti`,
{
addresses: children.map((c) => c.wallet),
addresses: members.map((c) => c.wallet),
}
);

const childrenWithBalances = children.map((c) => {
const balance = childrenWalletBalances.data.find(
const membersWithBalances = members.map((c) => {
const balance = membersWalletBalances.data.find(
(b) => b.account === c.wallet
);
return {
Expand All @@ -191,17 +177,17 @@ const Parent: React.FC = () => {
};
});

// setChildren(childrenWithBalances);
setMembers(membersWithBalances);
} else {
// setChildren(children);
setMembers(members);
}

setChildrenLoading(false);
setMembersLoading(false);
};

await getChildren();
await getMembers();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [children.length, userDetails?.wallet]);
}, [members.length, userDetails?.wallet]);

const closeTab = () => {
setSelectedTab(ParentDashboardTabs.DASHBOARD);
Expand All @@ -213,7 +199,7 @@ const Parent: React.FC = () => {
<Box zIndex={1}>
<ExpandedDashboardMenu
familyDetails={familyDetails}
children={children}
members={members}
onAddChildOpen={onAddChildOpen}
setSelectedTab={setSelectedTab}
onToggleCollapsedMenu={onToggleCollapsedMenu}
Expand Down Expand Up @@ -302,7 +288,7 @@ const Parent: React.FC = () => {
bg={useColorModeValue("gray.100", "gray.900")}
borderRadius={isMobileSize ? "0" : "10px"}
>
<RecentMemberActivity />
<RecentMemberActivity members={members} />
</GridItem>

<GridItem
Expand All @@ -322,9 +308,9 @@ const Parent: React.FC = () => {
isOpen={isChangeUsernameOpen}
onClose={onChangeUsernameClose}
childKey={childKey}
children={children}
members={members}
familyId={familyDetails.familyId}
fetchChildren={fetchChildren}
fetchChildren={fetchMembers}
fetchFamilyDetails={fetchFamilyDetails}
/>

Expand Down
16 changes: 16 additions & 0 deletions pages/api/vercel/get-all-recent-activity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { kv } from "@vercel/kv";
import { NextApiRequest, NextApiResponse } from "next";

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
try {
const { key } = req.query as { key: string };
const data = await kv.hgetall(`activity::${key}`);
return res.status(200).json(data);
} catch (error) {
console.error("Error:", error);
return res.status(500).json({ error: "An error occurred" });
}
}
27 changes: 27 additions & 0 deletions pages/api/vercel/set-recent-activity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { kv } from "@vercel/kv";
import { NextApiRequest, NextApiResponse } from "next";

//https://redis.io/commands/hset/

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
try {
const { key, value } = req.query as unknown as {
key: string;
value: string;
};

// value = "<walletAddress>::<eventDescription>"

const data = await kv.hset(`activity::${key}`, {
[Math.floor(Date.now() / 1000)]: value,
});

return res.status(200).json(data);
} catch (error) {
console.error("Error:", error);
return res.status(500).json({ error: "An error occurred" });
}
}
2 changes: 1 addition & 1 deletion src/components/AvatarSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const AvatarSelection = ({
<Avatar
size="2xl"
name={familyDetails?.username ? familyDetails?.username : "Avatar"}
src={avatar ? avatar : "/images/placeholder-avatar.jpeg"}
src={avatar && avatar}
_hover={{ cursor: "pointer", transform: "scale(1.1)" }}
onClick={openFileInput}
/>
Expand Down
5 changes: 1 addition & 4 deletions src/components/CollapsedDashboardMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@ export const CollapsedDashboardMenu = ({
name={userDetails?.username}
sx={{
fontFamily: "Slackey",
bgColor: `${
userDetails?.avatarURI ? "transparent" : "purple.500"
}`,
}}
src={userDetails?.avatarURI || "/images/placeholder-avatar.jpeg"}
src={userDetails?.avatarURI}
/>
<Flex direction="column" ml={3}>
<Heading fontSize="lg">{userDetails?.username}</Heading>
Expand Down
6 changes: 3 additions & 3 deletions src/components/ExpandedDashboardMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { useNetwork } from "wagmi";

export const ExpandedDashboardMenu = ({
familyDetails,
children,
members,
onAddChildOpen,
setSelectedTab,
onToggleCollapsedMenu,
Expand All @@ -44,7 +44,7 @@ export const ExpandedDashboardMenu = ({
onOpenMembersTableModal,
}: {
familyDetails: User;
children: User[];
members: User[];
onAddChildOpen: () => void;
setSelectedTab: (tab: ParentDashboardTabs) => void;
onToggleCollapsedMenu: () => void;
Expand Down Expand Up @@ -133,7 +133,7 @@ export const ExpandedDashboardMenu = ({
onOpenSendFundsModal={onOpenSendFundsModal}
onOpenNetworkModal={onOpenNetworkModal}
onOpenMembersTableModal={onOpenMembersTableModal}
children={children}
members={members}
/>
</Box>

Expand Down
6 changes: 1 addition & 5 deletions src/components/LoggedInNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ export default function LoggedInNavBar() {
<Avatar
size="md"
name={userDetails?.username}
src={
userDetails?.avatarURI
? userDetails?.avatarURI
: "/images/placeholder-avatar.jpeg"
}
src={userDetails?.avatarURI && userDetails?.avatarURI}
onClick={() => {
setMobileMenuOpen(!mobileMenuOpen);
}}
Expand Down
7 changes: 7 additions & 0 deletions src/components/forms/RegisterParentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import shallow from "zustand/shallow";
import { useRouter } from "next/navigation";
import { useAccount } from "wagmi";
import { TestnetNetworks, NetworkType } from "@/data-schema/enums";
import { registerActivityEvent } from "@/utils/recentActivity";

export const RegisterParentForm = ({ onClose }: { onClose: () => void }) => {
//=============================================================================
Expand Down Expand Up @@ -144,6 +145,12 @@ export const RegisterParentForm = ({ onClose }: { onClose: () => void }) => {
setUserDetails(body);
setIsLoggedIn(true);

registerActivityEvent(
String(address),
String(address),
"Registered as parent"
);

const emailSent = await sendEmailConfirmation();
if (!emailSent) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/components/modals/UsernameModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const UsernameModal = ({
isOpen,
onClose,
childKey,
children,
members,
familyId,
fetchChildren,
fetchFamilyDetails,
Expand All @@ -43,7 +43,7 @@ export const UsernameModal = ({
isOpen: boolean;
onClose: () => void;
childKey?: number;
children?: any;
members?: any;
familyId?: string;
fetchChildren?: () => void;
fetchFamilyDetails?: () => void;
Expand Down
2 changes: 1 addition & 1 deletion src/components/parentDashboard/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ParentAvatar = () => {
sx={{
bgColor: `${!userDetails?.avatarURI && "purple.500"}`,
}}
src={userDetails?.avatarURI || "/images/placeholder-avatar.jpeg"}
src={userDetails?.avatarURI}
/>
</Flex>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/parentDashboard/ButtonMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ButtonMenu = ({
onOpenSendFundsModal,
onOpenNetworkModal,
onOpenMembersTableModal,
children,
members,
}: {
onAddChildOpen: () => void;
setSelectedTab: (tab: ParentDashboardTabs) => void;
Expand All @@ -26,7 +26,7 @@ const ButtonMenu = ({
onOpenSendFundsModal: () => void;
onOpenNetworkModal: () => void;
onOpenMembersTableModal: () => void;
children?: User[];
members?: User[];
}) => {
const { userDetails } = useAuthStore(
(state) => ({
Expand Down
Loading