Skip to content

Commit

Permalink
feat: get singed timestamp whencreating bounty
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi-bams committed Sep 27, 2024
1 parent 7d673f7 commit dc79a9b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
25 changes: 13 additions & 12 deletions src/components/ModalsContainer/CreateBountyModal/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>

Expand All @@ -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
Expand All @@ -48,7 +50,6 @@ export const Body = () => {
} finally {
setValue('budget', '')
setValue('nodeType', '')
setValue('token', '')
setValue('workspaceUuid', '')
handleClose()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type NameSpacesOption = {
export const CreateBounty: FC<Props> = ({ errMessage, handleClose }) => {
const { setValue, watch } = useFormContext()
const [options, setOptions] = useState<NameSpacesOption[]>([])
const { pubKey, signedToken } = useUserStore()
const { pubKey } = useUserStore()

useEffect(() => {
async function handleGetNamesspaces() {
Expand Down Expand Up @@ -55,10 +55,8 @@ export const CreateBounty: FC<Props> = ({ errMessage, handleClose }) => {
}
}

setValue('token', signedToken)

handleGetNamesspaces()
}, [pubKey, signedToken, setValue])
}, [pubKey])

const watchBudget = watch('budget', '')
const watchNodeType = watch('nodeType', '')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Buffer } from 'buffer'
import sphinx from 'sphinx-bridge'

export async function setupAdmin(): Promise<string> {
export async function getSignedTimestamp(): Promise<string> {
try {
// get current time in seconds
const currentTimeInSeconds = Math.floor(Date.now() / 1000)
Expand Down

0 comments on commit dc79a9b

Please sign in to comment.