55c91dfcdd
* start on script
* Revert "Remove category filters"
This reverts commit d6e808e1a3
.
* Convert categories to official default groups
* Add new users to default groups
* Rework group cards
* Cleanup
* Add unique bettors to contract and sort by them
* Most bettors to most popular
* Unused vars
* Track unique bettor ids on contracts
* Add followed users' bets to personal markets
* Add new users to welcome, bugs, and updates groups
* Add users to fewer default cats
83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
import { auth } from './users'
|
|
import { APIError, getFunctionUrl } from 'common/api'
|
|
export { APIError } from 'common/api'
|
|
|
|
export async function call(url: string, method: string, params: any) {
|
|
const user = auth.currentUser
|
|
if (user == null) {
|
|
throw new Error('Must be signed in to make API calls.')
|
|
}
|
|
const token = await user.getIdToken()
|
|
const req = new Request(url, {
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
method: method,
|
|
body: JSON.stringify(params),
|
|
})
|
|
return await fetch(req).then(async (resp) => {
|
|
const json = (await resp.json()) as { [k: string]: any }
|
|
if (!resp.ok) {
|
|
throw new APIError(resp.status, json?.message, json?.details)
|
|
}
|
|
return json
|
|
})
|
|
}
|
|
|
|
export function createAnswer(params: any) {
|
|
return call(getFunctionUrl('createanswer'), 'POST', params)
|
|
}
|
|
|
|
export function transact(params: any) {
|
|
return call(getFunctionUrl('transact'), 'POST', params)
|
|
}
|
|
|
|
export function createUser(params: any) {
|
|
return call(getFunctionUrl('createuser'), 'POST', params)
|
|
}
|
|
|
|
export function changeUserInfo(params: any) {
|
|
return call(getFunctionUrl('changeuserinfo'), 'POST', params)
|
|
}
|
|
|
|
export function addLiquidity(params: any) {
|
|
return call(getFunctionUrl('addliquidity'), 'POST', params)
|
|
}
|
|
|
|
export function withdrawLiquidity(params: any) {
|
|
return call(getFunctionUrl('withdrawliquidity'), 'POST', params)
|
|
}
|
|
|
|
export function createMarket(params: any) {
|
|
return call(getFunctionUrl('createmarket'), 'POST', params)
|
|
}
|
|
|
|
export function resolveMarket(params: any) {
|
|
return call(getFunctionUrl('resolvemarket'), 'POST', params)
|
|
}
|
|
|
|
export function placeBet(params: any) {
|
|
return call(getFunctionUrl('placebet'), 'POST', params)
|
|
}
|
|
|
|
export function cancelBet(params: { betId: string }) {
|
|
return call(getFunctionUrl('cancelbet'), 'POST', params)
|
|
}
|
|
|
|
export function sellShares(params: any) {
|
|
return call(getFunctionUrl('sellshares'), 'POST', params)
|
|
}
|
|
|
|
export function sellBet(params: any) {
|
|
return call(getFunctionUrl('sellbet'), 'POST', params)
|
|
}
|
|
|
|
export function claimManalink(params: any) {
|
|
return call(getFunctionUrl('claimmanalink'), 'POST', params)
|
|
}
|
|
|
|
export function createGroup(params: any) {
|
|
return call(getFunctionUrl('creategroup'), 'POST', params)
|
|
}
|