2022-05-19 22:04:34 +00:00
|
|
|
import { auth } from './users'
|
2022-07-10 22:03:15 +00:00
|
|
|
import { APIError, getFunctionUrl } from 'common/api'
|
2022-08-29 15:06:17 +00:00
|
|
|
import { JSONContent } from '@tiptap/core'
|
2022-07-10 22:03:15 +00:00
|
|
|
export { APIError } from 'common/api'
|
2022-01-05 18:23:58 +00:00
|
|
|
|
2022-05-23 21:16:56 +00:00
|
|
|
export async function call(url: string, method: string, params: any) {
|
2022-05-19 22:04:34 +00:00
|
|
|
const user = auth.currentUser
|
|
|
|
if (user == null) {
|
|
|
|
throw new Error('Must be signed in to make API calls.')
|
2022-01-19 03:36:46 +00:00
|
|
|
}
|
2022-05-19 22:04:34 +00:00
|
|
|
const token = await user.getIdToken()
|
|
|
|
const req = new Request(url, {
|
|
|
|
headers: {
|
|
|
|
Authorization: `Bearer ${token}`,
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
method: method,
|
2022-05-20 21:58:14 +00:00
|
|
|
body: JSON.stringify(params),
|
2022-05-19 22:04:34 +00:00
|
|
|
})
|
|
|
|
return await fetch(req).then(async (resp) => {
|
|
|
|
const json = (await resp.json()) as { [k: string]: any }
|
2022-05-20 21:58:14 +00:00
|
|
|
if (!resp.ok) {
|
2022-06-22 16:35:50 +00:00
|
|
|
throw new APIError(resp.status, json?.message, json?.details)
|
2022-05-19 22:04:34 +00:00
|
|
|
}
|
2022-05-20 21:58:14 +00:00
|
|
|
return json
|
2022-05-19 22:04:34 +00:00
|
|
|
})
|
2022-01-19 03:36:46 +00:00
|
|
|
}
|
2022-02-04 03:04:56 +00:00
|
|
|
|
2022-07-09 07:26:56 +00:00
|
|
|
export function createAnswer(params: any) {
|
|
|
|
return call(getFunctionUrl('createanswer'), 'POST', params)
|
|
|
|
}
|
2022-07-09 20:43:18 +00:00
|
|
|
|
2022-07-09 20:54:15 +00:00
|
|
|
export function transact(params: any) {
|
|
|
|
return call(getFunctionUrl('transact'), 'POST', params)
|
|
|
|
}
|
|
|
|
|
2022-07-10 21:02:32 +00:00
|
|
|
export function createUser(params: any) {
|
|
|
|
return call(getFunctionUrl('createuser'), 'POST', params)
|
|
|
|
}
|
|
|
|
|
2022-07-08 22:00:03 +00:00
|
|
|
export function changeUserInfo(params: any) {
|
|
|
|
return call(getFunctionUrl('changeuserinfo'), 'POST', params)
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:56:16 +00:00
|
|
|
export function addSubsidy(params: any) {
|
|
|
|
return call(getFunctionUrl('addsubsidy'), 'POST', params)
|
2022-07-08 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
2022-09-30 15:27:42 +00:00
|
|
|
export function addCommentBounty(params: any) {
|
|
|
|
return call(getFunctionUrl('addcommentbounty'), 'POST', params)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function awardCommentBounty(params: any) {
|
|
|
|
return call(getFunctionUrl('awardcommentbounty'), 'POST', params)
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:46:06 +00:00
|
|
|
export function createMarket(params: any) {
|
|
|
|
return call(getFunctionUrl('createmarket'), 'POST', params)
|
2022-02-04 03:04:56 +00:00
|
|
|
}
|
2022-04-21 17:58:12 +00:00
|
|
|
|
2022-06-29 23:47:06 +00:00
|
|
|
export function resolveMarket(params: any) {
|
|
|
|
return call(getFunctionUrl('resolvemarket'), 'POST', params)
|
|
|
|
}
|
|
|
|
|
2022-05-19 22:04:34 +00:00
|
|
|
export function placeBet(params: any) {
|
2022-06-06 19:46:06 +00:00
|
|
|
return call(getFunctionUrl('placebet'), 'POST', params)
|
2022-04-21 17:58:12 +00:00
|
|
|
}
|
2022-06-07 20:54:58 +00:00
|
|
|
|
2022-07-10 18:05:44 +00:00
|
|
|
export function cancelBet(params: { betId: string }) {
|
|
|
|
return call(getFunctionUrl('cancelbet'), 'POST', params)
|
|
|
|
}
|
|
|
|
|
2022-06-07 20:54:58 +00:00
|
|
|
export function sellShares(params: any) {
|
|
|
|
return call(getFunctionUrl('sellshares'), 'POST', params)
|
|
|
|
}
|
2022-06-07 21:08:56 +00:00
|
|
|
|
|
|
|
export function sellBet(params: any) {
|
|
|
|
return call(getFunctionUrl('sellbet'), 'POST', params)
|
|
|
|
}
|
2022-06-22 16:35:50 +00:00
|
|
|
|
2022-07-08 22:28:04 +00:00
|
|
|
export function claimManalink(params: any) {
|
|
|
|
return call(getFunctionUrl('claimmanalink'), 'POST', params)
|
|
|
|
}
|
|
|
|
|
2022-06-22 16:35:50 +00:00
|
|
|
export function createGroup(params: any) {
|
|
|
|
return call(getFunctionUrl('creategroup'), 'POST', params)
|
|
|
|
}
|
2022-08-02 07:06:23 +00:00
|
|
|
|
2022-08-04 21:27:02 +00:00
|
|
|
export function acceptChallenge(params: any) {
|
|
|
|
return call(getFunctionUrl('acceptchallenge'), 'POST', params)
|
|
|
|
}
|
|
|
|
|
2022-08-02 07:06:23 +00:00
|
|
|
export function getCurrentUser(params: any) {
|
|
|
|
return call(getFunctionUrl('getcurrentuser'), 'GET', params)
|
|
|
|
}
|
2022-08-29 15:06:17 +00:00
|
|
|
|
2022-09-23 19:11:50 +00:00
|
|
|
export function createPost(params: {
|
|
|
|
title: string
|
|
|
|
content: JSONContent
|
|
|
|
groupId?: string
|
|
|
|
}) {
|
2022-08-29 15:06:17 +00:00
|
|
|
return call(getFunctionUrl('createpost'), 'POST', params)
|
|
|
|
}
|