798253f887
* Challenge bets * Store avatar url * Fix before and after probs * Check balance before creation * Calculate winning shares * pretty * Change winning value * Set shares to equal each other * Fix share challenge link * pretty * remove lib refs * Probability of bet is set to market * Remove peer pill * Cleanup * Button on contract page * don't show challenge if not binary or if resolved * challenge button (WIP) * fix accept challenge: don't change pool/probability * Opengraph preview [WIP] * elim lib * Edit og card props * Change challenge text * New card gen attempt * Get challenge on server * challenge button styling * Use env domain * Remove other window ref * Use challenge creator as avatar * Remove user name * Remove s from property, replace prob with outcome * challenge form * share text * Add in challenge parts to template and url * Challenge url params optional * Add challenge params to parse request * Parse please * Don't remove prob * Challenge card styling * Challenge card styling * Challenge card styling * Challenge card styling * Challenge card styling * Challenge card styling * Challenge card styling * Challenge card styling * Add to readme about how to dev og-image * Add emojis * button: gradient background, 2xl size * beautify accept bet screen * update question button * Add separate challenge template * Accepted challenge sharing card, fix accept bet call * accept challenge button * challenge winner page * create challenge screen * Your outcome/cost=> acceptorOutcome/cost * New create challenge panel * Fix main merge * Add challenge slug to bet and filter by it * Center title * Add helper text * Add FAQ section * Lint * Columnize the user areas in preview link too * Absolutely position * Spacing * Orientation * Restyle challenges list, cache contract name * Make copying easy on mobile * Link spacing * Fix spacing * qr codes! * put your challenges first * eslint * Changes to contract buttons and create challenge modal * Change titles around for current bet * Add back in contract title after winning * Cleanup * Add challenge enabled flag * Spacing of switch button * Put sharing qr code in modal Co-authored-by: mantikoros <sgrugett@gmail.com>
91 lines
2.5 KiB
TypeScript
91 lines
2.5 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)
|
|
}
|
|
|
|
export function acceptChallenge(params: any) {
|
|
return call(getFunctionUrl('acceptchallenge'), 'POST', params)
|
|
}
|
|
|
|
export function getCurrentUser(params: any) {
|
|
return call(getFunctionUrl('getcurrentuser'), 'GET', params)
|
|
}
|