From bec5d24c6b6ac36647bc91158934ac75e16f8e13 Mon Sep 17 00:00:00 2001 From: 0xMazout Date: Thu, 4 Jul 2024 15:58:37 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8Add=20=20Env=20Update=20Project=20?= =?UTF-8?q?Name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- motivator/.env.example | 5 ++++- motivator/src/app/assessor/slot/[id]/page.tsx | 3 +-- .../core/server/actions/randomize/randomizeAssessorSlot.ts | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/motivator/.env.example b/motivator/.env.example index 33a6bd00..6d5a21ae 100644 --- a/motivator/.env.example +++ b/motivator/.env.example @@ -23,4 +23,7 @@ DOMAIN_URL="http://localhost:3000" ## SERVER ## Replace with correct values INFURA_SECRET= -INFURA_PROJECT_ID= \ No newline at end of file +INFURA_PROJECT_ID= + +## Project Name implementation +NEXT_PUBLIC_PROJECT_NAME="hyperdrive" \ No newline at end of file diff --git a/motivator/src/app/assessor/slot/[id]/page.tsx b/motivator/src/app/assessor/slot/[id]/page.tsx index 0634a86d..52fe92f3 100644 --- a/motivator/src/app/assessor/slot/[id]/page.tsx +++ b/motivator/src/app/assessor/slot/[id]/page.tsx @@ -6,10 +6,9 @@ type Props = {} import DatatableProxyAssessor from '@/components/datatables/DatatableProxyAssessor' const HomeAssessor = (props: Props) => { - const protocol = 'hyperdrive' + const protocol = process.env.NEXT_PUBLIC_PROJECT_NAME as string return (
- {/* Update the hyperdrive value with Global Variable Env or a Selector of Protocol if Multiprotocol on same App */}
) diff --git a/motivator/src/core/server/actions/randomize/randomizeAssessorSlot.ts b/motivator/src/core/server/actions/randomize/randomizeAssessorSlot.ts index 8d4421a2..f7f83fba 100644 --- a/motivator/src/core/server/actions/randomize/randomizeAssessorSlot.ts +++ b/motivator/src/core/server/actions/randomize/randomizeAssessorSlot.ts @@ -23,8 +23,8 @@ export async function randomizeAssessorSlot({ score: number address: string } - /* Update the hyperdrive value with Global Variable Env or a Selector of Protocol if Multiprotocol on same App */ - const protocol = 'hyperdrive' + + const protocol = process.env.NEXT_PUBLIC_PROJECT_NAME as string const generalPool: ScoreAndAddress[] = [] // append the pool to general pool foreach frequency From fa85b6d892925efb1b7c2897e003e4d6cdeb7532 Mon Sep 17 00:00:00 2001 From: 0xMazout Date: Thu, 4 Jul 2024 17:00:22 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9A=A1=20Improve=20Datatable=20Proxy=20?= =?UTF-8?q?=F0=9F=93=96=20Add=20new=20types=20to=20=20add=20genericity=20?= =?UTF-8?q?=E2=9A=A1=20Improve=20Hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../container/DataTableAuditContainer.tsx | 4 +- .../datatables/DatatableProxyAssessor.tsx | 51 ++++++++++++++++++- .../hooks/assessorSlot/useGetAssessorSlot.ts | 12 ++++- .../actions/assessor/getAssessorSlot.ts | 4 +- .../globals/getAllAssessorSlotsAudit.ts | 4 +- .../core/types/data/assessorSlotsProtocols.ts | 7 +++ .../container/DataTableContainerAssessor.tsx | 47 ++++++----------- .../hyperdrive/types/data/assessorSlot.ts | 6 ++- 8 files changed, 93 insertions(+), 42 deletions(-) create mode 100644 motivator/src/core/types/data/assessorSlotsProtocols.ts diff --git a/motivator/src/core/components/container/DataTableAuditContainer.tsx b/motivator/src/core/components/container/DataTableAuditContainer.tsx index 05f35da5..650cd4c1 100644 --- a/motivator/src/core/components/container/DataTableAuditContainer.tsx +++ b/motivator/src/core/components/container/DataTableAuditContainer.tsx @@ -1,7 +1,7 @@ 'use client' import React, { useEffect } from 'react' import { DataTableAuditAssessorSlot } from '@/components/datatables/DataTableAuditAssessorSlot' -import { AssessorSlot } from '@protocols/hyperdrive/types/data/assessorSlot' +import { AssessorSlotHyperdrive } from '@protocols/hyperdrive/types/data/assessorSlot' import { useAccount } from 'wagmi' import { RoundSpinner } from '@/components/ui/spinner' import { AuditAssessorsSlotsDatatable } from '@/components/datatables/DataTableAuditAssessorSlot' @@ -21,7 +21,7 @@ const DataTableAuditContainer = () => { if (statusAccount === 'connected' && refetch) refetch() }, [refetch, statusAccount]) - const prepareDataForTable = (assessorSlots: AssessorSlot[]) => { + const prepareDataForTable = (assessorSlots: AssessorSlotHyperdrive[]) => { const res: AuditAssessorsSlotsDatatable[] = [] if ( assessorSlots === undefined || diff --git a/motivator/src/core/components/datatables/DatatableProxyAssessor.tsx b/motivator/src/core/components/datatables/DatatableProxyAssessor.tsx index 7eefc13f..00d38a4d 100644 --- a/motivator/src/core/components/datatables/DatatableProxyAssessor.tsx +++ b/motivator/src/core/components/datatables/DatatableProxyAssessor.tsx @@ -1,6 +1,14 @@ 'use client' import { DataTableContainerAssessor } from '@protocols/hyperdrive/components/datatables/container/DataTableContainerAssessor' +import { useGetAssessorSlot } from '@/hooks/assessorSlot/useGetAssessorSlot' +import { useAccount } from 'wagmi' +import { usePathname } from 'next/navigation' +import { RoundSpinner } from '../ui/spinner' +import { useEffect } from 'react' +import { AssessorSlotHyperdrive } from '../../../protocols/hyperdrive/types/data/assessorSlot' +import { AssessorSlotProtocols } from '@/types/data/assessorSlotsProtocols' + type Props = { protocol: string } @@ -12,12 +20,51 @@ type Props = { * @returns DataTableContainer component */ const DatatableProxyAssessor = ({ protocol }: Props) => { + const { address, status: statusAccount } = useAccount() + const pathname = usePathname() + // Extract id from the pathname + // http://localhost:3000/assessor/slot/7677e331-29eb-4c54-8e7a-d44a816fe423 + const slotID = pathname.split('/').slice(2)[1] + + const { data, error, status, refetch } = useGetAssessorSlot({ + assessorSlotID: slotID as string, + }) + + // Refresh the data when the account is connected + useEffect(() => { + if (statusAccount === 'connected' && refetch) refetch() + }, [refetch, statusAccount]) + + // Implement Skeletton + if ( + status != 'success' || + (data.res as AssessorSlotProtocols) === undefined + ) { + return ( +
+ +
+ ) + } + /** + * Load Datatable Container for each protocol + * @param protocol + * @returns Container for the Datatable + */ const loadDatatableProtocol = (protocol: string) => { switch (protocol) { case 'hyperdrive': - return + return ( + + ) default: - return + return ( + + ) } } diff --git a/motivator/src/core/hooks/assessorSlot/useGetAssessorSlot.ts b/motivator/src/core/hooks/assessorSlot/useGetAssessorSlot.ts index 51de0736..c80836e1 100644 --- a/motivator/src/core/hooks/assessorSlot/useGetAssessorSlot.ts +++ b/motivator/src/core/hooks/assessorSlot/useGetAssessorSlot.ts @@ -13,10 +13,20 @@ type Props = { * */ const useGetAssessorSlot = ({ assessorSlotID }: Props) => { + const protocol = process.env.NEXT_PUBLIC_PROJECT_NAME as string + + /** + * When implementing a new protocol, add a case in the switch statement with the name of the protocol and the new function to get the assessor slot + */ const { data, refetch, status, error } = useQuery({ queryKey: ['useGetAssessorSlot'], queryFn: async () => { - return await getAssessorSlot({ assessorSlotID }) + switch (protocol) { + case 'hyperdrive': + return await getAssessorSlot({ assessorSlotID }) + default: + return await getAssessorSlot({ assessorSlotID }) + } }, // staleTime: 1000 * 6, retry: true, diff --git a/motivator/src/core/server/actions/assessor/getAssessorSlot.ts b/motivator/src/core/server/actions/assessor/getAssessorSlot.ts index 96a7f9eb..8d5de615 100644 --- a/motivator/src/core/server/actions/assessor/getAssessorSlot.ts +++ b/motivator/src/core/server/actions/assessor/getAssessorSlot.ts @@ -3,7 +3,7 @@ import { and, eq, ne } from 'drizzle-orm' import { db } from '@db/dbRouter' import { assessor_slot, assessor_slot_user, reward } from '@db/schema' import { - AssessorSlot, + AssessorSlotHyperdrive, Statistics, Totals, } from '@protocols/hyperdrive/types/data/assessorSlot' @@ -94,7 +94,7 @@ export async function getAssessorSlot({ const statistics = await statisticsPromised() //build the response - const assessorSlot: AssessorSlot = { + const assessorSlot: AssessorSlotHyperdrive = { assessorSlotCore: { id: assessorSlotOfAssessor.id, assessorID: assessorSlotOfAssessor.assessor_ID as string, diff --git a/motivator/src/core/server/actions/globals/getAllAssessorSlotsAudit.ts b/motivator/src/core/server/actions/globals/getAllAssessorSlotsAudit.ts index 1edcff67..c48a9409 100644 --- a/motivator/src/core/server/actions/globals/getAllAssessorSlotsAudit.ts +++ b/motivator/src/core/server/actions/globals/getAllAssessorSlotsAudit.ts @@ -2,7 +2,7 @@ import { and, eq, ne } from 'drizzle-orm' import { db } from '@db/dbRouter' import { assessor_slot, audit, reward } from '@db/schema' -import { AssessorSlot } from '@protocols/hyperdrive/types/data/assessorSlot' +import { AssessorSlotHyperdrive } from '@protocols/hyperdrive/types/data/assessorSlot' import { Grade } from '@/types/enums/grade' import { Address } from 'viem' // Send Rewards to specifics users based on their actions @@ -33,7 +33,7 @@ export async function getAllAssessorSlotsAudit() { const getAudit = await db.query.audit.findFirst({ where: eq(audit.assessor_slot_id, assessorSlot.id), }) - const assessor: AssessorSlot = { + const assessor: AssessorSlotHyperdrive = { assessorSlotCore: { id: assessorSlot.id, assessorID: assessorSlot.assessor_ID as string, diff --git a/motivator/src/core/types/data/assessorSlotsProtocols.ts b/motivator/src/core/types/data/assessorSlotsProtocols.ts new file mode 100644 index 00000000..d5872529 --- /dev/null +++ b/motivator/src/core/types/data/assessorSlotsProtocols.ts @@ -0,0 +1,7 @@ +import { AssessorSlotHyperdrive } from '@protocols/hyperdrive/types/data/assessorSlot' + +/** + * This type is a multiple type of Assessor Slots + * When implementing a new protocol, add a new type in the union + */ +export type AssessorSlotProtocols = AssessorSlotHyperdrive | any diff --git a/motivator/src/protocols/hyperdrive/components/datatables/container/DataTableContainerAssessor.tsx b/motivator/src/protocols/hyperdrive/components/datatables/container/DataTableContainerAssessor.tsx index a391fa6c..96f96d57 100644 --- a/motivator/src/protocols/hyperdrive/components/datatables/container/DataTableContainerAssessor.tsx +++ b/motivator/src/protocols/hyperdrive/components/datatables/container/DataTableContainerAssessor.tsx @@ -5,7 +5,7 @@ import { UserDatatable, } from '@protocols/hyperdrive/components/datatables/table/DataTableAssessor' import { - AssessorSlot, + AssessorSlotHyperdrive, Statistics, Totals, } from '@protocols/hyperdrive/types/data/assessorSlot' @@ -14,8 +14,19 @@ import { Status } from '@protocols/hyperdrive/types/enums/status' import { RoundSpinner } from '@/components/ui/spinner' import { usePathname } from 'next/navigation' import { useGetAssessorSlot } from '@/hooks/assessorSlot/useGetAssessorSlot' -export const DataTableContainerAssessor = () => { - const prepareDataForTable = (assessorSlot: AssessorSlot) => { + +type Props = { + data: AssessorSlotHyperdrive +} + +export const DataTableContainerAssessor = ({ data }: Props) => { + /** + * This function is used to prepare the data for the table + * Grab the data in the Assessor Slot and prepare it for the table + * @param assessorSlot The Assessor Slot + * @returns The UserDatatable array + */ + const prepareDataForTable = (assessorSlot: AssessorSlotHyperdrive) => { const res: UserDatatable[] = [] assessorSlot?.users.forEach((element, index) => { const reward = assessorSlot.rewards.find( @@ -63,33 +74,5 @@ export const DataTableContainerAssessor = () => { }) } - const { address, status: statusAccount } = useAccount() - const pathname = usePathname() - // Extract id from the pathname - // http://localhost:3000/assessor/slot/7677e331-29eb-4c54-8e7a-d44a816fe423 - const slotID = pathname.split('/').slice(2)[1] - - const { data, error, status, refetch } = useGetAssessorSlot({ - assessorSlotID: slotID as string, - }) - - // Refresh the data when the account is connected - useEffect(() => { - if (statusAccount === 'connected' && refetch) refetch() - }, [refetch, statusAccount]) - - // Implement Skeletton - if (status != 'success' || (data.res as AssessorSlot) === undefined) { - return ( -
- -
- ) - } - - return ( - - ) + return } diff --git a/motivator/src/protocols/hyperdrive/types/data/assessorSlot.ts b/motivator/src/protocols/hyperdrive/types/data/assessorSlot.ts index 334ddd1c..c320191c 100644 --- a/motivator/src/protocols/hyperdrive/types/data/assessorSlot.ts +++ b/motivator/src/protocols/hyperdrive/types/data/assessorSlot.ts @@ -2,7 +2,11 @@ import { Address } from 'viem' import { Grade } from '@/types/enums/grade' import { AssessorSlotCore } from '@/types/data/assessorSlotCore' -export type AssessorSlot = { +/** + * This type is the Assessor Slot for the Hyperdrive protocol + * When implementing a new protocol, Add AssessorSlotCore and add the new parameters + */ +export type AssessorSlotHyperdrive = { assessorSlotCore: AssessorSlotCore week: number users: string[]