2021-12-24 21:06:01 +00:00
|
|
|
import { getFunctions, httpsCallable } from 'firebase/functions'
|
2022-01-18 07:18:38 +00:00
|
|
|
import { User } from '../../../common/user'
|
2022-01-19 03:36:46 +00:00
|
|
|
import { randomString } from '../../../common/util/random'
|
2021-12-24 21:06:01 +00:00
|
|
|
|
|
|
|
const functions = getFunctions()
|
|
|
|
|
|
|
|
export const cloudFunction = (name: string) => httpsCallable(functions, name)
|
|
|
|
|
2022-01-05 18:23:58 +00:00
|
|
|
export const createContract = cloudFunction('createContract')
|
|
|
|
|
|
|
|
export const placeBet = cloudFunction('placeBet')
|
|
|
|
|
|
|
|
export const resolveMarket = cloudFunction('resolveMarket')
|
|
|
|
|
|
|
|
export const sellBet = cloudFunction('sellBet')
|
2022-01-18 07:18:38 +00:00
|
|
|
|
2022-01-19 03:36:46 +00:00
|
|
|
export const createUser: () => Promise<User | null> = () => {
|
|
|
|
let deviceToken = window.localStorage.getItem('device-token')
|
|
|
|
if (!deviceToken) {
|
|
|
|
deviceToken = randomString()
|
|
|
|
window.localStorage.setItem('device-token', deviceToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cloudFunction('createUser')({ deviceToken })
|
2022-01-18 07:18:38 +00:00
|
|
|
.then((r) => (r.data as any)?.user || null)
|
|
|
|
.catch(() => null)
|
2022-01-19 03:36:46 +00:00
|
|
|
}
|