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: Comrads Worker #44

Merged
merged 33 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5039297
feat: basic community validator page, slug and backend structure
EdSDR Jul 6, 2024
cf70044
chore: update development scripts
EdSDR Jul 7, 2024
da17b89
feat: add delegate module percentage state functionality
EdSDR Jul 8, 2024
e2f8351
feat: update ModuleCard component to fetch and display custom metadata
EdSDR Jul 8, 2024
7406a6a
chore: Add markdown-view component for rendering Markdown content
EdSDR Jul 9, 2024
fa2f4d9
feat: update delegateModuleWeight component
EdSDR Jul 9, 2024
58ce11f
chore: checkpoint
gabrielcipriano Jul 9, 2024
7f5a77a
feat: Update schema and moduleRouter to include allModuleWeight funct…
EdSDR Jul 9, 2024
fef8241
draft: calc weights
gabrielcipriano Jul 9, 2024
9629ccc
feat: update schema and add post methos for userModuleData and Module…
EdSDR Jul 10, 2024
ad7a441
Merge remote-tracking branch 'origin/feat/community-validator' into f…
gabrielcipriano Jul 10, 2024
f9c451b
feat: basic zustand store for module percentage delegations
EdSDR Jul 10, 2024
56b4aa9
Merge remote-tracking branch 'origin/feat/community-validator' into f…
gabrielcipriano Jul 10, 2024
bcc773f
feat: Update module_data schema and add primary key for id
EdSDR Jul 10, 2024
a6e49f1
feat: Add form submission functionality to DelegatedModulesList compo…
EdSDR Jul 10, 2024
6bc1376
fix: build
EdSDR Jul 10, 2024
3881136
Merge remote-tracking branch 'origin/feat/community-validator' into f…
gabrielcipriano Jul 11, 2024
59ecf77
feat: assert or throw
gabrielcipriano Jul 14, 2024
af21eeb
feat: subspace module zod schema
gabrielcipriano Jul 14, 2024
3584f0e
feat: add module queries
gabrielcipriano Jul 14, 2024
7144ef2
feat: update db schema
gabrielcipriano Jul 14, 2024
d968e02
chore: update exports
gabrielcipriano Jul 14, 2024
c800f4f
feat: retrieve/insert flow
gabrielcipriano Jul 14, 2024
0d61dd0
chore: module config
gabrielcipriano Jul 14, 2024
7990832
chore: dev stuff
gabrielcipriano Jul 14, 2024
cea733d
feat: worker loop
gabrielcipriano Jul 14, 2024
1776512
chore: rename to comrads
gabrielcipriano Jul 14, 2024
4f2ddc2
chore: Add warning message for unresolved module in enrichSubspaceMod…
gabrielcipriano Jul 15, 2024
cf24bf4
Merge branch 'main' into feat/app-comrads-worker
EdSDR Jul 15, 2024
3b89912
fix: eslint / tsconfig on worker
EdSDR Jul 15, 2024
f6d68da
chore: Update package dependencies and scripts
EdSDR Jul 16, 2024
a3ccc70
chore: Update package dependencies and scripts
EdSDR Jul 16, 2024
3a9dbbb
Merge branch 'main' into feat/app-comrads-worker
EdSDR Jul 16, 2024
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
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/hydrogen
3 changes: 1 addition & 2 deletions apps/commune-governance/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { cairo } from "@commune-ts/ui/fonts";
import { Footer } from "@commune-ts/ui/footer";
import { Header } from "@commune-ts/ui/header";

import { applicationsList } from "../utils/applications-list";
import { FooterDivider } from "./components/footer-divider";

// TODO this could come from the ui lib since the only thing that changes between apps is the title
Expand Down Expand Up @@ -41,7 +40,7 @@ export default function RootLayout({
/>
{children}
<FooterDivider />
<Footer applicationsList={applicationsList} />
<Footer />
</Providers>
</body>
</html>
Expand Down
3 changes: 1 addition & 2 deletions apps/commune-page/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Suspense } from "react";
import { Footer } from "@commune-ts/ui/footer";
import { Loading } from "@commune-ts/ui/loading";

import { applicationsList } from "../utils/applications-list";
import { sections } from "../utils/mocks/sections-mock";
import { FrequentQuestions } from "./components/sections/frequent-questions";
import { GenericSection } from "./components/sections/generic-section";
Expand Down Expand Up @@ -37,7 +36,7 @@ export default function Page(): JSX.Element {
);
})}
<FrequentQuestions />
<Footer applicationsList={applicationsList} />
<Footer />
</Suspense>
);
}
25 changes: 13 additions & 12 deletions apps/commune-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,35 @@
"type-check": "tsc --noEmit"
},
"dependencies": {
"next": "^14.2.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"@commune-ts/api": "workspace:*",
"@commune-ts/providers": "workspace:*",
"@commune-ts/ui": "workspace:*",
"@heroicons/react": "^2.1.3",
"superjson": "2.2.1",
"zod": "^3.23.8",
"@t3-oss/env-nextjs": "^0.10.1",
"@tanstack/react-query": "^5.45.0",
"@trpc/client": "11.0.0-rc.364",
"@trpc/react-query": "11.0.0-rc.364",
"@trpc/server": "11.0.0-rc.364",
"@commune-ts/ui": "workspace:*",
"@commune-ts/api": "workspace:*",
"@commune-ts/providers": "workspace:*"
"next": "^14.2.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"superjson": "2.2.1",
"zod": "^3.23.8",
"zustand": "^4.5.4"
},
"devDependencies": {
"jiti": "^1.21.0",
"@commune-ts/eslint-config": "workspace:*",
"@commune-ts/tailwind-config": "workspace:*",
"@commune-ts/tsconfig": "workspace:*",
"@next/eslint-plugin-next": "^14.2.3",
"@tailwindcss/typography": "^0.5.10",
"@types/node": "^20.11.24",
"@types/react": "^18.2.61",
"@types/react-dom": "^18.2.19",
"autoprefixer": "^10.4.18",
"@commune-ts/eslint-config": "workspace:*",
"jiti": "^1.21.0",
"postcss": "^8.4.38",
"@commune-ts/tailwind-config": "workspace:*",
"tailwindcss": "^3.4.3",
"@commune-ts/tsconfig": "workspace:*",
"typescript": "^5.4.5"
}
}
11 changes: 11 additions & 0 deletions apps/commune-validator/public/receive-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions apps/commune-validator/public/send-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions apps/commune-validator/public/stake-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions apps/commune-validator/public/transfer-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions apps/commune-validator/public/unstake-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions apps/commune-validator/src/app/components/copy-square-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use client";

import { Square2StackIcon } from "@heroicons/react/24/outline";

import { toast } from "@commune-ts/providers/use-toast";
import { copyToClipboard } from "@commune-ts/providers/utils";

interface CopySquareButtonProps {
address: string;
}

export function CopySquareButton(props: CopySquareButtonProps) {
function handleCopy() {
copyToClipboard(props.address);
toast.success("Copied to clipboard");
}
return (
<button
className="border border-white/20 bg-[#898989]/5 p-2 backdrop-blur-md transition duration-200 hover:border-green-500 hover:bg-green-500/10"
onClick={handleCopy}
>
<Square2StackIcon className="h-6 w-6 text-gray-400 transition duration-200 hover:text-green-500" />
</button>
);
}
43 changes: 0 additions & 43 deletions apps/commune-validator/src/app/components/create-module-test.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use client";

import { ChartPieIcon } from "@heroicons/react/24/outline";

import { useDelegateStore } from "~/stores/delegateStore";

interface DelegateModuleWeightProps {
id: number;
title: string;
moduleKey: string;
}

export function DelegateModuleWeight(props: DelegateModuleWeightProps) {
const { delegatedModules, addModule, removeModule } = useDelegateStore();
const isModuleDelegated = delegatedModules.some((m) => m.id === props.id);

const handleDelegateClick = () => {
if (isModuleDelegated) {
removeModule(props.id);
} else {
addModule({ id: props.id, address: props.moduleKey, title: props.title });
}
};

return (
<button
onClick={handleDelegateClick}
className={`flex w-fit items-center gap-2 border border-white/20 bg-[#898989]/5 p-2 text-white backdrop-blur-md transition duration-200 ${
isModuleDelegated
? "border-red-500 bg-red-500/10 hover:bg-red-500/20"
: "hover:border-green-500 hover:bg-green-500/10"
}`}
>
<ChartPieIcon
className={`h-6 w-6 ${isModuleDelegated ? "text-red-500" : "text-green-500"}`}
/>
{isModuleDelegated ? "Remove" : "Delegate"}
</button>
);
}
113 changes: 113 additions & 0 deletions apps/commune-validator/src/app/components/delegated-modules-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"use client";

import { useState } from "react";
import { useRouter } from "next/navigation";

import { useCommune } from "@commune-ts/providers/use-commune";

import { useDelegateStore } from "~/stores/delegateStore";
import { api } from "~/trpc/react";

export function DelegatedModulesList() {
const {
delegatedModules,
updatePercentage,
removeModule,
getTotalPercentage,
} = useDelegateStore();
const totalPercentage = getTotalPercentage();
const { selectedAccount } = useCommune();
const router = useRouter();
const [isSubmitting, setIsSubmitting] = useState(false);

const handlePercentageChange = (id: number, percentage: number) => {
if (percentage >= 0 && percentage <= 100) {
updatePercentage(id, percentage);
}
};

const createUserModuleData = api.module.createUserModuleData.useMutation({
onSuccess: () => {
router.refresh();
setIsSubmitting(false);
},
onError: (error) => {
console.error("Error submitting data:", error);
setIsSubmitting(false);
},
});

const handleSubmit = async () => {
if (!selectedAccount?.address || totalPercentage !== 100) {
return;
}

setIsSubmitting(true);

try {
for (const delegatedModule of delegatedModules) {
await createUserModuleData.mutateAsync({
userKey: selectedAccount.address,
moduleKey: delegatedModule.address,
weight: delegatedModule.percentage,
});
}
} catch (error) {
console.error("Error submitting data:", error);
} finally {
setIsSubmitting(false);
}
};

return (
<div className="absolute bottom-0 right-0 mb-24 mr-4 mt-8 border border-white/20 bg-[#898989]/5 p-2 backdrop-blur-md">
<h2 className="mb-4 text-xl font-semibold text-white">
Delegated Modules
</h2>
{delegatedModules.map((module) => (
<div
key={module.id}
className="mb-2 flex items-center justify-between border border-white/20 bg-[#898989]/5 p-2"
>
<span className="text-white">{module.title}</span>
<div className="flex items-center">
<input
type="number"
value={module.percentage}
onChange={(e) =>
handlePercentageChange(module.id, Number(e.target.value))
}
className="mr-2 w-16 bg-[#898989]/10 p-1 text-white"
min="0"
max="100"
/>
<span className="mr-2 text-white">%</span>
<button
onClick={() => removeModule(module.id)}
className="text-red-500 hover:text-red-400"
>
Remove
</button>
</div>
</div>
))}
<div className="mt-4 text-white">
Total Percentage: {totalPercentage}%
{totalPercentage !== 100 && (
<span className="ml-2 text-red-500">
{totalPercentage > 100 ? "Exceeds" : "Does not equal"} 100%
</span>
)}
</div>
<button
onClick={handleSubmit}
className="mt-4 bg-white/10 px-10 py-3 font-semibold transition hover:bg-white/20 disabled:opacity-50"
disabled={
isSubmitting || totalPercentage !== 100 || !selectedAccount?.address
}
>
{isSubmitting ? "Submitting..." : "Submit"}
</button>
</div>
);
}
Loading