Skip to content

Commit 17fdf95

Browse files
committed
Add Member Withdraws Component
1 parent fd5775b commit 17fdf95

File tree

13 files changed

+119
-27
lines changed

13 files changed

+119
-27
lines changed

app/member-dashboard/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
Grid,
1111
} from "@chakra-ui/react";
1212
import React, { useEffect, useState } from "react";
13-
import { shallow } from "zustand/shallow";
13+
import shallow from "zustand/shallow";
1414
import { useAuthStore } from "@/store/auth/authStore";
1515
import { useContractStore } from "@/store/contract/contractStore";
1616
import { SettingsModal } from "@/components/modals/SettingsModal";
@@ -133,6 +133,7 @@ const MemberDashboard: React.FC = () => {
133133
onOpenSettingsModal={onOpenSettingsModal}
134134
onOpenInfoModal={onOpenInfoModal}
135135
onOpenWithdrawDefiDollarsModal={onOpenWithdrawDefiDollarsModal}
136+
stableTokenBalance={tokenBalance}
136137
/>
137138
</Box>
138139
{!isMobileSize && (

app/parent-dashboard/page.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import { RecentMemberActivity } from "@/components/dashboards/parentDashboard/Re
2121
import StakingContracts from "@/components/dashboards/parentDashboard/StakingContracts";
2222
import FamilyStatistics from "@/components/dashboards/parentDashboard/FamilyStatistics";
2323
import { DefiKidsHeading } from "@/components/DefiKidsHeading";
24-
import { USDC } from "@/components/dashboards/parentDashboard/USDC";
24+
import { StableToken } from "@/components/dashboards/parentDashboard/StableToken";
25+
import { MemberWithdrawRequest } from "@/components/dashboards/parentDashboard/MemberWithdrawRequest";
2526

2627
// Modals
2728
import { SettingsModal } from "@/components/modals/SettingsModal";
@@ -31,7 +32,6 @@ import { SendAllowanceModal } from "@/components/modals/SendAllowanceModal";
3132
import { MembersTableModal } from "@/components/modals/MembersTableModal";
3233
import { DepositDefiDollarsModal } from "@/components/modals/DepositDefiDollarsModal";
3334
import { WithdrawDefiDollarsModal } from "@/components/modals/WithdrawDefiDollarsModal";
34-
import { IActivity } from "@/models/Activity";
3535

3636
const Parent: React.FC = () => {
3737
//=============================================================================
@@ -247,11 +247,22 @@ const Parent: React.FC = () => {
247247
rowStart={1}
248248
rowEnd={isMobileSize ? 2 : 1}
249249
colStart={isMobileSize ? 1 : 1}
250+
colEnd={isMobileSize ? 1 : 5}
251+
h={isMobileSize ? "auto" : "105"}
252+
mt={isMobileSize ? "1.2rem" : "12rem"}
253+
>
254+
<StableToken stableTokenBalance={stableTokenBalance} />
255+
</GridItem>
256+
257+
<GridItem
258+
rowStart={1}
259+
rowEnd={isMobileSize ? 2 : 1}
260+
colStart={isMobileSize ? 1 : 5}
250261
colEnd={isMobileSize ? 1 : 9}
251262
h={isMobileSize ? "auto" : "105"}
252263
mt={isMobileSize ? "1.2rem" : "12rem"}
253264
>
254-
<USDC stableTokenBalance={stableTokenBalance} />
265+
<MemberWithdrawRequest />
255266
</GridItem>
256267

257268
<GridItem

app/withdraw-requests/page.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Center } from "@chakra-ui/react";
2+
import Navbar from "@/components/LandingNavbar";
3+
4+
const HowTo = () => {
5+
return (
6+
<>
7+
<Navbar />
8+
<Center mt="10rem">
9+
<h1>Withdraw Requests</h1>
10+
</Center>
11+
</>
12+
);
13+
};
14+
15+
export default HowTo;

config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import { ChainId } from "@/data-schema/enums";
22

33
export const validChainId = ChainId.GOERLI;
4+
export const stable_coin_symbol = "DK-USDC";

pages/api/etherscan/balancemulti.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default async function uploadToIpfsRoute(
3030

3131
const normalizedData = data.result.map((item: any) => {
3232
return {
33-
balance: Number(ethers.formatEther(item.balance)).toFixed(4),
33+
balance: Number(ethers.formatEther(item.balance)).toFixed(2),
3434
account: item.account,
3535
};
3636
});

src/components/DepositAndMint.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { createActivity } from "@/services/mongo/routes/activity";
3737
import { convertTimestampToSeconds } from "@/utils/dateTime";
3838
import { IActivity } from "@/models/Activity";
3939
import { useAuthStore } from "@/store/auth/authStore";
40+
import { stable_coin_symbol } from "@/config";
4041

4142
type PermitResult = {
4243
data?: SignatureLike;
@@ -178,7 +179,9 @@ export const DepositAndMint = ({
178179
accountId,
179180
wallet: address,
180181
date: convertTimestampToSeconds(Date.now()),
181-
type: `Sent allowance. ${amount.trim()} USDC to ${user.username}`,
182+
type: `Sent allowance. ${amount.trim()} ${stable_coin_symbol} to ${
183+
user.username
184+
}`,
182185
});
183186
newActivities.push(newActivity);
184187
})
@@ -234,10 +237,10 @@ export const DepositAndMint = ({
234237
<UsdcTokenIcon width={40} height={40} />
235238
<Flex direction="row" alignItems="baseline" justify="center" my={5}>
236239
<Heading size="xl" display="flex" alignItems="baseline" ml={3}>
237-
{`${Number(stableTokenBalance).toFixed(4)}`}
240+
{`${Number(stableTokenBalance).toFixed(2)}`}
238241
</Heading>
239242
<Text fontSize="sm" ml={2}>
240-
USDC
243+
{stable_coin_symbol}
241244
</Text>
242245
</Flex>
243246
</Flex>

src/components/dashboards/DashboardAccountBalance.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
useToast,
1212
Tooltip,
1313
} from "@chakra-ui/react";
14-
import { useBalance } from "wagmi";
1514
import { shallow } from "zustand/shallow";
15+
import { stable_coin_symbol } from "@/config";
1616

1717
const AccountBalance = ({
1818
walletAddress,
@@ -21,11 +21,6 @@ const AccountBalance = ({
2121
walletAddress: string;
2222
tokenBalance: number;
2323
}) => {
24-
const { data } = useBalance({
25-
address: walletAddress as `0x${string}`,
26-
watch: true,
27-
});
28-
2924
const { userDetails } = useAuthStore(
3025
(state) => ({
3126
userDetails: state.userDetails,
@@ -49,10 +44,12 @@ const AccountBalance = ({
4944
display="flex"
5045
alignItems="baseline"
5146
>
52-
{Number(tokenBalance).toFixed(4)}
47+
{Number(tokenBalance).toFixed(2)}
5348
</Heading>
5449
<Text fontSize="sm" ml={2}>
55-
{userDetails?.userType === UserType.PARENT ? "USDC" : "DFD"}
50+
{userDetails?.userType === UserType.PARENT
51+
? stable_coin_symbol
52+
: "DFD"}
5653
</Text>
5754
</Flex>
5855

src/components/dashboards/parentDashboard/DefiDollars.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const DefiDollars = ({
7171
alignItems="center"
7272
>
7373
<Heading size="2xl" display="flex">
74-
{`${Number(tokenBalance).toFixed(4)}`}
74+
{`${Number(tokenBalance).toFixed(2)}`}
7575
</Heading>
7676

7777
{/* Actions */}

src/components/dashboards/parentDashboard/FamilyStatistics.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Grid,
99
GridItem,
1010
} from "@chakra-ui/react";
11+
import { stable_coin_symbol } from "@/config";
1112

1213
interface Notification {
1314
title: string;
@@ -16,16 +17,27 @@ interface Notification {
1617
}
1718

1819
const FamilyStatistics = ({ members }: { members: User[] }) => {
20+
const totalActiveAllowances: number = members.reduce(
21+
(acc: number, member: User) => {
22+
const balanceAsNumber =
23+
typeof member.balance === "number"
24+
? member.balance
25+
: parseFloat(member.balance!) || 0;
26+
return acc + balanceAsNumber;
27+
},
28+
0
29+
);
30+
1931
const stats: Notification[] = [
2032
{
2133
title: "Members",
2234
value: members.length.toString(),
2335
unit: "",
2436
},
2537
{
26-
title: "Currently Staked",
27-
value: "31,573",
28-
unit: "ETH",
38+
title: "Total Active Allowances",
39+
value: totalActiveAllowances.toString(),
40+
unit: stable_coin_symbol,
2941
},
3042
{
3143
title: "Rewards Earned",
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"use client";
2+
3+
import {
4+
Flex,
5+
useColorModeValue,
6+
Heading,
7+
Button,
8+
Box,
9+
} from "@chakra-ui/react";
10+
import { useRouter } from "next/navigation";
11+
12+
export const MemberWithdrawRequest = () => {
13+
const router = useRouter();
14+
15+
return (
16+
<Box p={5} bg={useColorModeValue("gray.100", "gray.900")} rounded="lg">
17+
<Flex justifyContent="space-between" alignItems="center" pb={2}>
18+
<Heading as="h3" size="sm" color="white">
19+
Withdraw Requests
20+
</Heading>
21+
<Button
22+
size="xs"
23+
colorScheme="blue"
24+
variant="outline"
25+
cursor="pointer"
26+
onClick={() => {
27+
router.push("/withdraw-requests");
28+
}}
29+
>
30+
Manage
31+
</Button>
32+
</Flex>
33+
34+
<Flex
35+
rounded="md"
36+
overflow="hidden"
37+
justifyContent="space-between"
38+
alignItems="center"
39+
>
40+
<Heading size="2xl" display="flex">
41+
0
42+
</Heading>
43+
</Flex>
44+
</Box>
45+
);
46+
};

src/components/dashboards/parentDashboard/USDC.tsx renamed to src/components/dashboards/parentDashboard/StableToken.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import {
1212
} from "@chakra-ui/react";
1313
import { AddUSDCTokenToWallet } from "@/services/metamask/addToken";
1414
import { useRouter } from "next/navigation";
15+
import { stable_coin_symbol } from "@/config";
1516

16-
export const USDC = ({
17+
export const StableToken = ({
1718
stableTokenBalance,
1819
}: {
1920
stableTokenBalance: number;
@@ -40,7 +41,7 @@ export const USDC = ({
4041
<Box p={5} bg={useColorModeValue("gray.100", "gray.900")} rounded="lg">
4142
<Flex justifyContent="space-between" alignItems="center" pb={2}>
4243
<Heading as="h3" size="sm" color="white">
43-
USDC
44+
{stable_coin_symbol}
4445
</Heading>
4546
<Tooltip label="Add to Metamask" hasArrow placement="top">
4647
<Image
@@ -69,7 +70,7 @@ export const USDC = ({
6970
alignItems="center"
7071
>
7172
<Heading size="2xl" display="flex">
72-
{stableTokenBalance.toFixed(4)}
73+
{stableTokenBalance.toFixed(2)}
7374
</Heading>
7475

7576
{/* Actions */}

src/data/explainations/allowance.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { stable_coin_symbol } from "@/config";
2+
13
export const data = {
24
title: "Allowance",
35
paragraphs: [
46
{
5-
text: "When sending an allowance you are exchanging the underlying asset (USDC) for a sandbox version of the asset. This sandbox token is called Defi Dollars and is only usable within the sandbox. The Defi Dollars are pegged to the underlying asset at a 1:1 ratio. This means that 1 Defi Dollar is always worth 1 USDC.",
7+
text: `When sending an allowance you are exchanging the underlying asset (${stable_coin_symbol}) for a sandbox version of the asset. This sandbox token is called Defi Dollars and is only usable within the sandbox. The Defi Dollars are pegged to the underlying asset at a 1:1 ratio. This means that 1 Defi Dollar is always worth 1 ${stable_coin_symbol}.`,
68
},
79
{
810
text: "The Defi Dollars are used to pay the allowance. The members are able to use these tokens to interact with the features of the sandbox. When a member would like to withdraw the Defi Dollars for fiat the Parent will recieve a notification of the withdraw request via email.",

src/services/metamask/addToken.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { GOERLI_DK_STABLETOKEN_ADDRESS } from "@/blockchain/contract-addresses";
2+
import { stable_coin_symbol } from "@/config";
3+
14
interface CustomWindow extends Window {
25
ethereum?: any;
36
}
@@ -7,7 +10,7 @@ export const AddUSDCTokenToWallet = async () => {
710
const ethereum = customWindow.ethereum;
811

912
const response = {
10-
message: "USDC Token",
13+
message: `${stable_coin_symbol} Token`,
1114
error: "Something went wrong.",
1215
};
1316

@@ -18,8 +21,8 @@ export const AddUSDCTokenToWallet = async () => {
1821
params: {
1922
type: "ERC20",
2023
options: {
21-
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
22-
symbol: "USDC",
24+
address: GOERLI_DK_STABLETOKEN_ADDRESS,
25+
symbol: stable_coin_symbol,
2326
decimals: 18,
2427
image:
2528
"https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",

0 commit comments

Comments
 (0)