Skip to content

Commit

Permalink
feat(solo): solo review form frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbeckers committed Dec 5, 2022
1 parent fe13c94 commit 1be7dac
Show file tree
Hide file tree
Showing 8 changed files with 718 additions and 18 deletions.
90 changes: 90 additions & 0 deletions app/components/FUX/SoloResolutionForm/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { WorkstreamFragmentFragment } from "../../../.graphclient";
import { useResolveSoloWorkstream } from "../../../hooks/resolution";
import { ContributorRow } from "../ContributorRow";
import {
Button,
FormControl,
Grid,
GridItem,
Text,
VStack,
useToast,
} from "@chakra-ui/react";
import { useWallet } from "@raidguild/quiver";
import _ from "lodash";
import React, { Fragment } from "react";
import { useForm } from "react-hook-form";

const SoloResolutionForm: React.FC<{
workstream?: WorkstreamFragmentFragment;
}> = ({ workstream }) => {
if (!workstream) {
<Text>Loading...</Text>;
}

const toast = useToast();
const { address: user } = useWallet();

const resolveSolo = useResolveSoloWorkstream();

const {
handleSubmit,
formState: { isSubmitting },
} = useForm({});

const onSubmit = () => {
if (
workstream?.contributors?.length === 1 &&
workstream.contributors[0].user.id.toLowerCase() ===
user?.toLowerCase() &&
workstream?.id
) {
resolveSolo(Number(workstream.id));
}
};

const contributors = workstream?.contributors;

const reviewForm =
contributors && contributors?.length > 0 && user ? (
<form onSubmit={handleSubmit(onSubmit)}>
<FormControl>
<Grid gap={2} templateColumns="repeat(10, 1fr)">
<Fragment>
<GridItem
display={"flex"}
alignItems={"center"}
bg="#301A3A"
colSpan={6}
borderLeftRadius="3xl"
>
<ContributorRow address={contributors[0].user.id} />
</GridItem>
<GridItem
display={"flex"}
alignItems={"center"}
justifyContent={"center"}
colSpan={3}
>
<Button h={"100%"} isLoading={isSubmitting} type="submit">
Close workstream
</Button>
</GridItem>
</Fragment>
</Grid>
</FormControl>

<VStack w={"100%"} pt={4}>
<Text paddingBottom={"2em"} paddingTop={"2em"} textAlign={"center"}>
You are the sole contributor.
</Text>
</VStack>
</form>
) : (
<Text>No contributors found</Text>
);

return reviewForm;
};

export { SoloResolutionForm };
6 changes: 4 additions & 2 deletions app/components/FUX/ValueResolutionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {
useMintVFux,
useVFuxBalanceForWorkstreamEvaluation,
} from "../../../hooks/fux";
import { useResolveValueEvaluation } from "../../../hooks/resolution";
import {
useResolveValueEvaluation,
} from "../../../hooks/resolution";
import { ContributorRow } from "../ContributorRow";
import {
Button,
Expand Down Expand Up @@ -102,7 +104,7 @@ const ValueResolutionForm: React.FC<{
.map((rating) => (rating ? +rating : 0))
.reduce((_total, value) => _total + value, 0);

if(totalVFux) setTotal(totalVFux);
if (totalVFux) setTotal(totalVFux);
}, [formData]);

const onSubmit = (data: FormData) => {
Expand Down
31 changes: 31 additions & 0 deletions app/hooks/resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,34 @@ export const useResolveValueEvaluation = () => {
return (workstreamID: number, contributors: string[], ratings: BigNumberish[]) =>
mutate(workstreamID, contributors, ratings);
};

export const useResolveSoloWorkstream = () => {
const toast = useToast();
const contract = useFuxContract();

const { mutate } = useWriteContract(contract, "resolveSoloWorkstream", {
onError: (e) => {
toast({
title: `Couldn't resolve workstream: ${parseTxErrorMessage(e)}`,
status: "error",
});
throw new Error(e.message);
},
onResponse: () => {
toast({
title: `Submitting resolution`,
status: "info",
duration: 30000,
});
},
onConfirmation: () => {
toast({
title: "Resolution submitted",
status: "success",
});
},
});

return (workstreamID: number) =>
mutate(workstreamID);
};
26 changes: 20 additions & 6 deletions app/pages/resolve/[workstreamID].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { WorkstreamEvaluationsDocument } from "../../.graphclient";
import { ContributorRow } from "../../components/FUX/ContributorRow";
import { SoloResolutionForm } from "../../components/FUX/SoloResolutionForm";
import ValueHeader from "../../components/FUX/ValueHeader";
import { ValueResolutionForm } from "../../components/FUX/ValueResolutionForm";
import { ValueReviewForm } from "../../components/FUX/ValueReviewForm";
Expand Down Expand Up @@ -46,12 +47,25 @@ const Resolve: NextPage = () => {
return undefined;
}

return user?.toLowerCase() ===
_workstream?.coordinator?.id.toLowerCase() ? (
<ValueResolutionForm workstream={_workstream} />
) : (
<ValueReviewForm workstream={_workstream} />
);
const _user = user?.toLowerCase();
const _coordinator = _workstream?.coordinator?.id.toLowerCase();
const _contributors = _workstream?.contributors;

let form = <></>;

if (
_user === _coordinator &&
_contributors?.length === 1 &&
_contributors[0].user.id.toLowerCase() === _user
) {
form = <SoloResolutionForm workstream={_workstream} />;
} else if (_user === _coordinator) {
form = <ValueResolutionForm workstream={_workstream} />;
} else {
form = <ValueReviewForm workstream={_workstream} />;
}

return form;
};

const form = generateContent();
Expand Down
40 changes: 37 additions & 3 deletions graph/generated/FUX/FUX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1277,8 +1277,8 @@ export class CommitToWorkstreamCall__Inputs {
return this._call.inputValues[0].value.toBigInt();
}

get fuxGiven(): i32 {
return this._call.inputValues[1].value.toI32();
get fuxGiven(): BigInt {
return this._call.inputValues[1].value.toBigInt();
}
}

Expand Down Expand Up @@ -1431,9 +1431,13 @@ export class MintWorkstreamCall__Inputs {
return this._call.inputValues[1].value.toAddressArray();
}

get deadline(): BigInt {
get selfFux(): BigInt {
return this._call.inputValues[2].value.toBigInt();
}

get deadline(): BigInt {
return this._call.inputValues[3].value.toBigInt();
}
}

export class MintWorkstreamCall__Outputs {
Expand Down Expand Up @@ -1478,6 +1482,36 @@ export class RenounceRoleCall__Outputs {
}
}

export class ResolveSoloWorkstreamCall extends ethereum.Call {
get inputs(): ResolveSoloWorkstreamCall__Inputs {
return new ResolveSoloWorkstreamCall__Inputs(this);
}

get outputs(): ResolveSoloWorkstreamCall__Outputs {
return new ResolveSoloWorkstreamCall__Outputs(this);
}
}

export class ResolveSoloWorkstreamCall__Inputs {
_call: ResolveSoloWorkstreamCall;

constructor(call: ResolveSoloWorkstreamCall) {
this._call = call;
}

get workstreamID(): BigInt {
return this._call.inputValues[0].value.toBigInt();
}
}

export class ResolveSoloWorkstreamCall__Outputs {
_call: ResolveSoloWorkstreamCall;

constructor(call: ResolveSoloWorkstreamCall) {
this._call = call;
}
}

export class ResolveValueEvaluationCall extends ethereum.Call {
get inputs(): ResolveValueEvaluationCall__Inputs {
return new ResolveValueEvaluationCall__Inputs(this);
Expand Down
Loading

0 comments on commit 1be7dac

Please sign in to comment.