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

feat: getting the user score, adding an interface card to the settings page #96

Merged
Merged
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
23 changes: 22 additions & 1 deletion src/content/applications/Tasks/settings/AdminOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Stack, TextField, Typography } from '@mui/material';
import { Button, Card, CardContent, Stack, TextField, Typography } from '@mui/material';
import { Box } from '@mui/system';
import { useState } from 'react';
import { useTaskService } from 'src/services/tasks-service';
Expand Down Expand Up @@ -140,6 +140,27 @@ const AdminOptions = () => {
<TextField label={'Bool'} sx={{ mr: 2 }} onChange={(event) => (handleInputChange('operator', event))} name='isAuthorized' />
<Button variant='contained' onClick={(event) => (handleSubmit('setOperator', event))}>Enviar</Button>
</Box>
<Box>
<Card sx={{ width: 250 }}>
<CardContent>
<Typography variant='h4'>
Interface ID
</Typography>
<Typography>
createTask - 0xe610a2dd
</Typography>
<Typography>
startTask - 0xf3ae70f0
</Typography>
<Typography>
reviewTask - 0xc66e9543
</Typography>
<Typography>
CompleteTask - 0xc66e9543
</Typography>
</CardContent>
</Card>
</Box>
<Box m={2}>
<Typography sx={{ alignItems: 'left' }} fontWeight={'bold'} fontSize={'24px'} mb={2}>setQuorum</Typography>
<TextField label={'Value'} sx={{ mr: 2 }} onChange={(event) => (handleInputChange('quorum', event))} name='Value' />
Expand Down
6 changes: 4 additions & 2 deletions src/content/applications/Tasks/settings/CreateTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import SuspenseLoader from 'src/components/SuspenseLoader';
import CoverCreateTask from '../../../../components/Cover/CoverCreateTask';
import { useSnackBar } from 'src/contexts/SnackBarContext';
import { Helmet } from 'react-helmet-async';
import { BigNumber, ethers } from 'ethers';

let newTask: Task = {
status: 0,
title: '',
description: '',
reward: BigInt(''),
reward: BigNumber.from("0"),
endDate: BigInt(''),
authorizedRoles: [BigInt('')],
creatorRole: BigInt(''),
Expand Down Expand Up @@ -124,7 +125,8 @@ const CreateTask = ({ data }) => {
let authorizedRoles: string[] = (authorizedRolesStr).split(',');
const splittedRoles: readonly bigint[] = authorizedRoles.map(str => BigInt(str));
task.authorizedRoles = splittedRoles;
task.reward = BigInt(valueReward);
task.reward = ethers.utils.parseEther(valueReward);
console.log('task.reward = ', task.reward);
let expireTimestamp = expireDate.unix();
task.endDate = BigInt(expireTimestamp);
console.log("task.endDate: ", task.endDate);
Expand Down
14 changes: 8 additions & 6 deletions src/content/applications/Users/profile/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { styled } from '@mui/material/styles';
import { Helmet } from 'react-helmet-async';
import { useTaskService } from "src/services/tasks-service";
import { useTaskServiceHook } from "src/hooks/TaskServiceHook";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import CardMultiTasks from "src/components/Task/CardMultiTasks";
import { useWeb3Utils } from "src/hooks/Web3UtilsHook";
import usePagination from "src/components/Pagination";
Expand All @@ -28,10 +28,11 @@ const BoxCoverAction = styled(Box)(
);

const UserProfile = () => {
const { shortenAddressFromUser } = useWeb3Utils();
const { shortenAddressFromUser, userAddress } = useWeb3Utils();
const taskService = useTaskService();
const [userScore, setUserScore] = useState<number>();

const { handleMultiTask, multiTasksData, loading, error } = useTaskServiceHook(taskService);
const { handleMultiTask, multiTasksData, loading, handleUserScore, error } = useTaskServiceHook(taskService);

const tasksPerPage = 20;
const { currentPage, Pagination, setPage } = usePagination();
Expand All @@ -42,6 +43,7 @@ const UserProfile = () => {

const fetchData = async () => {
try {
await handleUserScore(userAddress()).then(score => { setUserScore(parseInt(score)); console.log('score', parseInt(score)) });
await handleMultiTask(minimumTasks, maxTasks, true);
} catch (error) {
console.error('Error fetching tasks:', error);
Expand All @@ -51,6 +53,8 @@ const UserProfile = () => {
fetchData();
}, [currentPage]);



return (
<>
<Helmet>
Expand Down Expand Up @@ -163,15 +167,13 @@ const UserProfile = () => {
<Typography gutterBottom variant="h5" component="div" textAlign="center">
{shortenAddressFromUser()}
</Typography>
User Task Score {userScore}
</BoxCoverAction>

</BoxCover>
<Box mt={'7%'}>
<Box>
<Box display={'flex'} justifyContent={'center'} alignItems={'center'} height={'max-content'} >
<Box>

</Box>

<CardMultiTasks multiTasksData={multiTasksData} loading={loading} page={currentPage} />
</Box >
Expand Down
14 changes: 12 additions & 2 deletions src/hooks/TaskServiceHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface TaskService {
setOperator: (interfaceId: any, roleId: any, isAuthorized: boolean) => Promise<any>
setMinQuorum: (quorum: any) => Promise<any>
deposit: (roleId: any, amount: any) => Promise<any>
getScore: (address: any) => Promise<any>
}

/**
Expand Down Expand Up @@ -107,7 +108,7 @@ export const useTaskServiceHook = (task: TaskService) => {
setTaskData(nft);
} catch (error) {
setError('Erro ao buscar tarefa');
handleSnackbar('Error Searching Task: '+error, 'error')
handleSnackbar('Error Searching Task: ' + error, 'error')
} finally {
setLoading(false);
}
Expand Down Expand Up @@ -207,6 +208,14 @@ export const useTaskServiceHook = (task: TaskService) => {
}
};

const handleUserScore = async (address: any) => {
try {
return await task.getScore(address);
} catch (error) {
handleSnackbar('Error getting Score', 'error')
}
};

return {
taskData,
multiTasksData,
Expand All @@ -217,6 +226,7 @@ export const useTaskServiceHook = (task: TaskService) => {
handleRole,
handleOperator,
handleQuorum,
handleDeposit
handleDeposit,
handleUserScore
};
};
4 changes: 3 additions & 1 deletion src/models/task.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BigNumber } from "ethers";

export enum TaskStatus {
Created = 0,
Progress = 1,
Expand All @@ -11,7 +13,7 @@ export interface Task {
status: TaskStatus;
title: string;
description: string;
reward: bigint;
reward: BigNumber;
endDate: bigint;
authorizedRoles: readonly bigint[];
creatorRole: bigint;
Expand Down
11 changes: 10 additions & 1 deletion src/services/tasks-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ export function useTaskService() {
}
}

async function getScore(address: any) {
try {
return await tasksManagerContract.getScore(address)
} catch (error) {
handleSnackbar('Error getting Score', 'error')
}
}

async function hasLeaderRole(address: any) {
return await tasksManagerContract.hasRole(UserRole.Leader, address);
}
Expand All @@ -217,7 +225,8 @@ export function useTaskService() {
hasLeaderRole,
hasMemberRole,
setMinQuorum,
deposit
deposit,
getScore
};

}
Loading