Skip to content

Commit

Permalink
Revert "add cw metadata and project order"
Browse files Browse the repository at this point in the history
This reverts commit 93ecbf3.
  • Loading branch information
subject026 committed Sep 1, 2024
1 parent dbfeba3 commit 83ba1bf
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 99 deletions.
Binary file removed public/project/citizen_wallet.png
Binary file not shown.
64 changes: 6 additions & 58 deletions src/app/governance/GovernancePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,12 @@ import { useMinRequiredVotingPower } from "./useMinRequiredVotingPower";
import { InfoCallout } from "./components/InfoCallout";
import { useDistributions } from "./useDistributions";
import { useModal } from "../core/context/ModalContext";
import { ProjectMeta, projectsMeta } from "../projectsMeta";

export type Project = {
address: Hex;
points: number;
};

type ProjectWithMeta = Prettify<
ProjectMeta & { account: Hex; currentDistribution: number }
>;

type Prettify<T> = {
[K in keyof T]: T[K];
} & {};

export type CurrentProjectsLoading = { status: "LOADING"; data: null };
export type CurrentProjectsSuccess = {
status: "SUCCESS";
data: ProjectWithMeta[];
};
export type CurrentProjectsError = { status: "ERROR"; data: null };
export type CurrentProjectsState =
| CurrentProjectsLoading
| CurrentProjectsSuccess
| CurrentProjectsError;

export function GovernancePage() {
const { user, isSafe } = useConnectedUser();
const { currentVotingDistribution } = useCurrentVotingDistribution();
Expand Down Expand Up @@ -81,38 +61,6 @@ export function GovernancePage() {
}
}, [currentVotingDistribution, projects]);

const currentProjects = useMemo<CurrentProjectsState>(() => {
if (currentVotingDistribution.status === "LOADING")
return { status: "LOADING", data: null };

if (currentVotingDistribution.status === "ERROR")
return { status: "ERROR", data: null };
let data;
try {
data = currentVotingDistribution.data[0]
.map((account, i): ProjectWithMeta => {
if (!projectsMeta[account])
throw new Error("no metadata found for project!");
return {
account,
...projectsMeta[account],
currentDistribution: currentVotingDistribution.data[1][i],
};
})
.sort((a, b) => a.order - b.order);
} catch (err) {
console.log(err);
return {
status: "ERROR",
data: null,
};
}
return {
status: "SUCCESS",
data,
};
}, [currentVotingDistribution]);

function updateValue(value: number, address: Hex) {
const updatedProjects = projects.map((project) => {
if (project.address === address) {
Expand Down Expand Up @@ -158,7 +106,7 @@ export function GovernancePage() {
: false;

if (
currentProjects.status === "ERROR" ||
currentVotingDistribution.status === "ERROR" ||
cycleDates.status === "ERROR" ||
cycleLength.status === "ERROR"
)
Expand All @@ -169,7 +117,7 @@ export function GovernancePage() {
);

if (
currentProjects.status === "LOADING" ||
!projects.length ||
currentVotingDistribution.status === "LOADING" ||
cycleDates.status === "LOADING" ||
cycleLength.status === "LOADING"
Expand Down Expand Up @@ -203,7 +151,7 @@ export function GovernancePage() {
/>

<div className="max-w-md m-auto col-span-12 row-start-3 row-span-1 lg:row-start-3 lg:col-start-9 lg:col-span-4 h-full flex flex-col gap-4">
<ResultsPanel projects={currentProjects} />
<ResultsPanel distribution={currentVotingDistribution} />
<InfoCallout />
</div>

Expand All @@ -221,9 +169,9 @@ export function GovernancePage() {
/>
</div>
<div className="col-span-12 row-start-5 lg:col-start-1 lg:col-span-8 lg:row-start-3 grid grid-cols-1 gap-3">
{currentProjects.data.map((project, i) => {
{currentVotingDistribution.data[0].map((address, i) => {
return (
<ProjectRow key={project.account} address={project.account}>
<ProjectRow key={address} address={address}>
{!isRecasting && castVote && castVote.length > 0 ? (
<VoteDisplay
points={castVote[i]}
Expand All @@ -233,7 +181,7 @@ export function GovernancePage() {
<VoteForm
value={projects[i].points}
updateValue={updateValue}
address={project.account}
address={address}
totalPoints={totalPoints}
user={user}
userCanVote={userCanVote}
Expand Down
1 change: 1 addition & 0 deletions src/app/governance/components/DistributionOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function DistributionOverview({
const estimateTotal = useMemo(() => {
if (cycleDates.status === "SUCCESS" && claimableYield && yieldPerHour) {
const difference = differenceInHours(cycleDates.end, new Date());
console.log({ yieldPerHour });
return difference * yieldPerHour + claimableYield;
}
}, [yieldPerHour, claimableYield, cycleDates]);
Expand Down
30 changes: 15 additions & 15 deletions src/app/governance/components/ResultsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import { projectsMeta } from "@/app/projectsMeta";
import { formatVotePercentage } from "@/app/core/util/formatter";
import { CurrentVotingDistributionState } from "../useCurrentVotingDistribution";
import { CardBox } from "@/app/core/components/CardBox";
import { CurrentProjectsSuccess } from "../GovernancePage";

export function ResultsPanel({
projects,
distribution,
}: {
projects: CurrentProjectsSuccess;
distribution: CurrentVotingDistributionState;
}) {
const totalPoints = projects.data.reduce(
(acc, points) => acc + points.currentDistribution,
0
);
const totalPoints =
distribution.status === "SUCCESS"
? distribution.data[1].reduce((acc, points) => acc + points, 0)
: 0;

return (
<section className="grid grid-cols-1 gap-4">
Expand All @@ -25,14 +24,15 @@ export function ResultsPanel({
results
</h3>
<div className="grid grid-cols-1 gap-4">
{projects.data.map((project, i) => (
<ResultsProject
key={`project_result_${project.account}`}
address={project.account}
projectPoints={projects.data[i].currentDistribution}
totalPoints={totalPoints}
/>
))}
{distribution.status === "SUCCESS" &&
distribution.data[0].map((account, i) => (
<ResultsProject
key={`project_result_${account}`}
address={account}
projectPoints={distribution.data[1][i]}
totalPoints={totalPoints}
/>
))}
</div>
</div>
</div>
Expand Down
9 changes: 3 additions & 6 deletions src/app/governance/useCycleDates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,13 @@ export function useCycleDates(cycleLength: CycleLengthState) {
cycleLength.data -
Number(currentBlockNumberData);
const cycleSecondsRemaining = cycleBlocksRemaining * 5;
const cycleDates = {
status: "SUCCESS" as const,
setCycleDates({
status: "SUCCESS",
start: sub(new Date(), { seconds: secondsSinceStart }),
end: add(new Date(), {
seconds: cycleSecondsRemaining,
}),
};
console.log("cycle start: ", cycleDates.start);
console.log("cycle end: ", cycleDates.end);
setCycleDates(cycleDates);
});
}
}, [
lastClaimedBlockNumberData,
Expand Down
22 changes: 2 additions & 20 deletions src/app/projectsMeta.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Hex } from "viem";

export type ProjectMeta = {
type ProjectMeta = {
name: string;
order: number;
description: string;
logoSrc: string;
links: {
Expand All @@ -11,11 +8,10 @@ export type ProjectMeta = {
};

export const projectsMeta: {
[key: Hex]: ProjectMeta;
[key: string]: ProjectMeta;
} = {
"0x7E1367998e1fe8Fab8f0bbF41e97cD6E0C891B64": {
name: "Labour DAO",
order: 1,
description:
"A DAO supporting workers who want to organize in web3 and out.",
logoSrc: "project/labor_dao.png",
Expand All @@ -26,7 +22,6 @@ export const projectsMeta: {
},
"0x5405e2D4D12AAdB57579E780458c9a1151b560F1": {
name: "Symbiota",
order: 2,
description:
"Event-focused organisations devoted to new forms of culture and enquiry.",
logoSrc: "project/symbiota.png",
Expand All @@ -37,7 +32,6 @@ export const projectsMeta: {
},
"0x5c22B3F03b3d8FFf56C9B2e90151512Cb3F3dE0F": {
name: "Crypto Commons",
order: 3,
description:
"Creating research and events on decentralized tech and the commons.",
logoSrc: "project/cca.png",
Expand All @@ -46,19 +40,8 @@ export const projectsMeta: {
"https://breadchain.notion.site/Crypto-Commons-Association-77818c4f425942479835e8bfec0b951b",
},
},
"0x9c8C8513974d22E8eA9F74f2860833Db107111E6": {
name: "Citizen Wallet",
order: 4,
description: "Open source tool stack to support Web3 community currencies.",
logoSrc: "project/citizen_wallet.png",
links: {
notion:
"https://breadchain.notion.site/Citizen-Wallet-0139bb3030f7442a8804459d717adb52?pvs=74",
},
},
"0x918dEf5d593F46735f74F9E2B280Fe51AF3A99ad": {
name: "Breadchain Core",
order: 5,
description:
"The core team developing the tech and design used by Breadchain.",
logoSrc: "project/core.png",
Expand All @@ -69,7 +52,6 @@ export const projectsMeta: {
},
"0x6A148b997e6651237F2fCfc9E30330a6480519f0": {
name: "Breadchain Treasury",
order: 6,
description:
"A co-owned treasury in Breadchain used for grants and sponsorships.",
logoSrc: "project/treasury.png",
Expand Down

0 comments on commit 83ba1bf

Please sign in to comment.