From dc79a9bd443b0500c9704bca254f0b640b0c4232 Mon Sep 17 00:00:00 2001 From: Oluwatobi Bamidele Date: Fri, 27 Sep 2024 21:30:13 +0100 Subject: [PATCH] feat: get singed timestamp whencreating bounty --- .../CreateBountyModal/Body/index.tsx | 25 ++++++++++--------- .../CreateBountyModal/CreateBounty/index.tsx | 6 ++--- .../index.ts | 2 +- 3 files changed, 16 insertions(+), 17 deletions(-) rename src/utils/{setupAdmin => getSignedTimestamp}/index.ts (96%) diff --git a/src/components/ModalsContainer/CreateBountyModal/Body/index.tsx b/src/components/ModalsContainer/CreateBountyModal/Body/index.tsx index 86a3c85b5..dc5ae6cb3 100644 --- a/src/components/ModalsContainer/CreateBountyModal/Body/index.tsx +++ b/src/components/ModalsContainer/CreateBountyModal/Body/index.tsx @@ -4,12 +4,12 @@ import { SuccessNotify } from '~/components/common/SuccessToast' import { postBountyData } from '~/network/postBounty' import { useSelectedNode } from '~/stores/useGraphStore' import { useModal } from '~/stores/useModalStore' +import { getSignedTimestamp } from '~/utils/getSignedTimestamp' import { CreateBounty } from '../CreateBounty' export type FormData = { nodeType: string budget: string - token: string workspaceUuid: string } & Partial<{ [k: string]: string }> @@ -28,18 +28,20 @@ export const Body = () => { } const onSubmit = async (data: FormData) => { - const { budget, token, workspaceUuid } = data - - const payload = { - type: 'code_generation', - amount: Number(budget), - workspace_uuid: workspaceUuid || 'ck9drb84nncjnaefo090', - jwt_token: token, - ref_id: selectedNode?.ref_id as string, - node_data: selectedNode?.properties || {}, - } + const { budget, workspaceUuid } = data try { + const signedToken = await getSignedTimestamp() + + const payload = { + type: 'code_generation', + amount: Number(budget), + workspace_uuid: workspaceUuid || 'ck9drb84nncjnaefo090', + ref_id: selectedNode?.ref_id as string, + node_data: selectedNode?.properties || {}, + jwt_token: signedToken, + } + await postBountyData(payload) SuccessNotify('Bounty Created') // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -48,7 +50,6 @@ export const Body = () => { } finally { setValue('budget', '') setValue('nodeType', '') - setValue('token', '') setValue('workspaceUuid', '') handleClose() } diff --git a/src/components/ModalsContainer/CreateBountyModal/CreateBounty/index.tsx b/src/components/ModalsContainer/CreateBountyModal/CreateBounty/index.tsx index e67377072..1f4ca779c 100644 --- a/src/components/ModalsContainer/CreateBountyModal/CreateBounty/index.tsx +++ b/src/components/ModalsContainer/CreateBountyModal/CreateBounty/index.tsx @@ -23,7 +23,7 @@ type NameSpacesOption = { export const CreateBounty: FC = ({ errMessage, handleClose }) => { const { setValue, watch } = useFormContext() const [options, setOptions] = useState([]) - const { pubKey, signedToken } = useUserStore() + const { pubKey } = useUserStore() useEffect(() => { async function handleGetNamesspaces() { @@ -55,10 +55,8 @@ export const CreateBounty: FC = ({ errMessage, handleClose }) => { } } - setValue('token', signedToken) - handleGetNamesspaces() - }, [pubKey, signedToken, setValue]) + }, [pubKey]) const watchBudget = watch('budget', '') const watchNodeType = watch('nodeType', '') diff --git a/src/utils/setupAdmin/index.ts b/src/utils/getSignedTimestamp/index.ts similarity index 96% rename from src/utils/setupAdmin/index.ts rename to src/utils/getSignedTimestamp/index.ts index 994a0d817..24f96ef5e 100644 --- a/src/utils/setupAdmin/index.ts +++ b/src/utils/getSignedTimestamp/index.ts @@ -1,7 +1,7 @@ import { Buffer } from 'buffer' import sphinx from 'sphinx-bridge' -export async function setupAdmin(): Promise { +export async function getSignedTimestamp(): Promise { try { // get current time in seconds const currentTimeInSeconds = Math.floor(Date.now() / 1000)