Skip to content

Commit

Permalink
feat(fux): workstream on fux creation
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbeckers committed Dec 5, 2022
1 parent 1be7dac commit 21de212
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
66 changes: 65 additions & 1 deletion app/components/FUX/WorkstreamModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UserDocument } from "../../../.graphclient";
import { useMintWorkstream } from "../../../hooks/workstream";
import { useConstants } from "../../../utils/constants";
import { AddIcon } from "@chakra-ui/icons";
Expand Down Expand Up @@ -31,11 +32,13 @@ import { BigNumber, ethers } from "ethers";
import { DateTime } from "luxon";
import { useState, useEffect } from "react";
import { Controller, useForm } from "react-hook-form";
import { useQuery } from "urql";

type FormData = {
name: string;
duration: string;
funding: number;
fuxGiven: number;
};

const WorkstreamModal: React.FC<{ onCloseAction: () => void }> = ({
Expand All @@ -46,6 +49,19 @@ const WorkstreamModal: React.FC<{ onCloseAction: () => void }> = ({
const addWorkstream = useMintWorkstream();
const { nativeToken } = useConstants();

const [result, reexecuteQuery] = useQuery({
query: UserDocument,
variables: {
address: user?.toLowerCase() || "",
},
});

const { data, fetching, error } = result;

const fuxBalance = data?.user?.balances?.find(
(balance) => balance.token.name === "FUX"
)?.balance;

const [ethBalance, setEthBalance] = useState(BigNumber.from(0));

useEffect(() => {
Expand All @@ -71,6 +87,7 @@ const WorkstreamModal: React.FC<{ onCloseAction: () => void }> = ({
name: "",
duration: "7",
funding: 0,
fuxGiven: fuxBalance,
},
});

Expand All @@ -85,8 +102,16 @@ const WorkstreamModal: React.FC<{ onCloseAction: () => void }> = ({
const deadline = Number(
DateTime.fromISO(form.duration).endOf("day").toSeconds().toFixed()
);

const _fuxGiven = form.fuxGiven;
if (user) {
addWorkstream(form.name, [user], deadline, funding).then(handleOnClose);
addWorkstream(
form.name,
[user],
_fuxGiven,
deadline,
funding
).then(handleOnClose);
}
};

Expand Down Expand Up @@ -167,6 +192,45 @@ const WorkstreamModal: React.FC<{ onCloseAction: () => void }> = ({
</>
)}
/>
<Controller
name={`fuxGiven`}
control={control}
rules={{ required: true }}
key={`fuxGiven`}
render={({ field: { ref, onChange, ...restField } }) => (
<>
<FormHelperText textColor={"white"} w={"100%"}>
How many FUX do you give?
</FormHelperText>
<InputGroup>
<NumberInput
precision={0}
step={1}
onChange={onChange}
min={0}
max={fuxBalance}
{...restField}
>
<NumberInputField
ref={ref}
name={restField.name}
borderRightRadius={0}
/>
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</NumberInput>
<InputRightAddon bg={"#8E4EC6"} fontWeight={"bold"}>
<Text>FUX</Text>
</InputRightAddon>
</InputGroup>
<FormHelperText textColor={"white"} w={"100%"}>
{`${fuxBalance} FUX to give`}
</FormHelperText>
</>
)}
/>
</VStack>
</HStack>
</FormControl>
Expand Down
3 changes: 2 additions & 1 deletion app/hooks/workstream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ export const useMintWorkstream = () => {
return async (
name: string,
contributors: string[],
fux: number,
deadline: number,
value?: string
) => mutate(name, contributors, deadline, { value });
) => mutate(name, contributors, fux, deadline, { value });
};

export const useCommitToWorkstream = () => {
Expand Down

0 comments on commit 21de212

Please sign in to comment.