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

add attestation link #80

Merged
merged 4 commits into from
Oct 30, 2024
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
63 changes: 48 additions & 15 deletions app/allocation/[category]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ const RankingPage = () => {
const category = categorySlugIdMap.get((params?.category as string) || '');

// const [search, setSearch] = useState<string>("");
const [attestationState, setAttestationState] = useState(AttestationState.Initial);
const [attestationState, setAttestationState] = useState(
AttestationState.Initial
);
const [attestationLink, setAttestationLink] = useState<string>();
const [checkedItems, setCheckedItems] = useState<number[]>([]);
const [projects, setProjects] = useState<IProjectRanking[] | null>(null);
Expand All @@ -68,6 +70,7 @@ const RankingPage = () => {
const [isLocked, setIsLocked] = useState(false);
const [isUnlocked, setIsUnlocked] = useState(false);
const [allocationBudget, setAllocationBudget] = useState<number>(0);
const [isSubmitting, setIsSubmitting] = useState(false);

const { data: categoryRankings, isLoading: rankingLoading }
= useCategoryRankings();
Expand Down Expand Up @@ -120,8 +123,8 @@ const RankingPage = () => {
projects.map(project => ({
...project,
share:
(newRanking.find(el => el.id === project.projectId)
?.percentage || 0) / 100,
(newRanking.find(el => el.id === project.projectId)
?.percentage || 0) / 100,
}))
);

Expand Down Expand Up @@ -201,7 +204,8 @@ const RankingPage = () => {
};

const submitVotes = async () => {
console.log('Projects,', projects);
setIsSubmitting(true);

if (!projects) return;

const rankingArray = projects.map(project => ({
Expand All @@ -215,12 +219,26 @@ const RankingPage = () => {

if (!wallet || !ranking || !signer) {
console.error('Requirements not met for attestations');
setIsSubmitting(false);
return;
}

await attest({ ranking: { id: ranking.id, name: ranking.name,
ranking: projects.map(el => ({ RF6Id: el.project.RF6Id, share: el.share })) },
setAttestationLink, setAttestationState, signer, wallet });
await attest({
ranking: {
id: ranking.id,
name: ranking.name,
ranking: projects.map(el => ({
RF6Id: el.project.RF6Id,
share: el.share,
})),
},
setAttestationLink,
setAttestationState,
signer,
wallet,
});

setIsSubmitting(false);
};

const handleAttestationModalClose = () => {
Expand Down Expand Up @@ -296,9 +314,7 @@ const RankingPage = () => {
return (
<div>
<Modal
isOpen={
attestationState !== AttestationState.Initial
}
isOpen={attestationState !== AttestationState.Initial}
onClose={handleAttestationModalClose}
showCloseButton={true}
>
Expand All @@ -308,8 +324,12 @@ const RankingPage = () => {
onClose={() => setAttestationState(AttestationState.Initial)}
/>
)}
{attestationState === AttestationState.Loading && <AttestationLoading />}
{attestationState === AttestationState.Error && <AttestationError onClick={submitVotes} />}
{attestationState === AttestationState.Loading && (
<AttestationLoading />
)}
{attestationState === AttestationState.Error && (
<AttestationError onClick={submitVotes} />
)}
</Modal>
<HeaderRF6 />
<div className="flex flex-col justify-between gap-4 px-6 py-16 lg:px-20 xl:px-52 2xl:px-72">
Expand Down Expand Up @@ -441,12 +461,25 @@ const RankingPage = () => {
Back to Categories
</button>
<button
className="flex items-center justify-center gap-3 rounded-lg bg-primary px-10 py-2 font-semibold text-white"
className={`font-semibold" flex items-center justify-center gap-3 rounded-lg px-10 py-2
${
totalShareError
? 'bg-gray-200 text-gray-400'
: 'bg-primary text-white'
}`}
onClick={submitVotes}
disabled={!!totalShareError}
>
Submit Vote
<ArrowRightIcon size={20} />
{isSubmitting
? (
'Submitting votes...'
)
: (
<>
Submit votes
<ArrowRightIcon />
</>
)}
</button>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion app/allocation/components/CategoryAllocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const CategoryAllocation: FC<CategoryAllocationProps> = ({
allocationPercentage,
allocationBudget,
locked,
attestationLink,
delegations,
loading,
username,
Expand Down Expand Up @@ -97,14 +98,15 @@ const CategoryAllocation: FC<CategoryAllocationProps> = ({
return (
<DelegatedCategory
id={id}

isAutoConnecting={isAutoConnecting}
username={username}
/>
);
case CollectionProgressStatusEnum.Finished:
return <VotedCategory id={id} isAutoConnecting={isAutoConnecting} />;
case CollectionProgressStatusEnum.Attested:
return <VotedCategory id={id} isAutoConnecting={isAutoConnecting} />;
return <VotedCategory id={id} isAutoConnecting={isAutoConnecting} attestationLink={attestationLink || ''} />;
case CollectionProgressStatusEnum.Pending:
default:
return (
Expand Down
28 changes: 17 additions & 11 deletions app/allocation/components/ProgressCards/VotedCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { CheckIcon } from '@/public/assets/icon-components/Check';
type TVotedCategoryProps = {
id: number
isAutoConnecting: boolean
attestationLink?: string | null
};

const VotedCategory = ({
id,
isAutoConnecting,
attestationLink,
}: TVotedCategoryProps) => {
const router = useRouter();

Expand All @@ -21,17 +23,21 @@ const VotedCategory = ({
>
Edit
</button>
<div className="flex w-full justify-center gap-2 rounded-xl border border-[#17B26A] bg-[#ECFDF3] py-1">
<p className="text-xs font-medium text-[#17B26A]">Voted</p>
<CheckIcon size={15} />
</div>
<button
onClick={() => {}}
className="whitespace-nowrap text-xs text-gray-600 underline"
disabled={isAutoConnecting}
>
View attestation
</button>
{attestationLink != null && (
<div className="flex w-full justify-center gap-2 rounded-xl border border-[#17B26A] bg-[#ECFDF3] py-1">
<p className="text-xs font-medium text-[#17B26A]">Voted</p>
<CheckIcon size={15} />
</div>
)}
{attestationLink && (
<button
onClick={() => window.open(attestationLink, '_blank')}
className="whitespace-nowrap text-xs text-gray-600 underline"
disabled={isAutoConnecting}
>
View attestation
</button>
)}
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions app/comparison/utils/data-fetching/categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type TCategory = {
image: string
projectCount: number
progress: CollectionProgressStatus
attestationLink: string | null
};

export const getCategories = async (): Promise<TCategory[]> => {
Expand Down