More plumbing for txns

This commit is contained in:
Austin Chen 2022-04-21 04:41:02 -07:00
parent ec45dfa311
commit 93322e894d
8 changed files with 19 additions and 5 deletions

View File

@ -5,6 +5,7 @@ export type Txn = {
createdTime: number
fromId: string
// TODO: Do we really want to denormalize name/username/avatar here?
fromName: string
fromUsername: string
fromAvatarUrl?: string
@ -27,5 +28,5 @@ export type TxnCategory = 'TO_CHARITY' // | 'TIP' | 'BET' | ...
export type TxnData = CharityData // | TipData | BetData | ...
export type CharityData = {
// TODO: Could fill this in
charityId: string
}

View File

@ -19,7 +19,7 @@ Adapted from https://firebase.google.com/docs/functions/get-started
2. `$ yarn` to install JS dependencies
3. `$ firebase login` to authenticate the CLI tools to Firebase
4. `$ firebase use dev` to choose the dev project
5. `$ firebase functions:config:get > .runtimeconfig.json` to cache secrets for local dev (TODO: maybe not for Manifold)
5. `$ firebase functions:config:get > .runtimeconfig.json` to cache secrets for local dev
## Developing locally

View File

@ -8,7 +8,8 @@
"shell": "yarn build && firebase functions:shell",
"start": "yarn shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
"logs": "firebase functions:log",
"dev": "yarn serve"
},
"main": "lib/functions/src/index.js",
"dependencies": {

View File

@ -46,6 +46,7 @@ export const backupDb = functions.pubsub
'comments',
'followers',
'answers',
'txns',
],
})
.then((responses) => {

View File

@ -3,6 +3,7 @@ import * as admin from 'firebase-admin'
admin.initializeApp()
// export * from './keep-awake'
export * from './transact'
export * from './place-bet'
export * from './resolve-market'
export * from './stripe'

View File

@ -3,8 +3,8 @@ import { Row } from '../layout/row'
// TODO: type probably belongs elsewhere
export interface Charity {
slug: string // Note, slugs double as charity IDs
name: string
slug: string
website: string
ein: string
photo?: string

View File

@ -16,6 +16,8 @@ export const createFold = cloudFunction<
{ status: 'error' | 'success'; message?: string; fold?: Fold }
>('createFold')
export const transact = cloudFunction('transact')
export const placeBet = cloudFunction('placeBet')
export const sellBet = cloudFunction('sellBet')

View File

@ -10,6 +10,7 @@ import { Spacer } from '../../../components/layout/spacer'
import { User } from '../../../../common/user'
import { useUser } from '../../../hooks/use-user'
import { Linkify } from '../../../components/linkify'
import { transact } from '../../../lib/firebase/api-call'
const manaToUSD = (mana: number) =>
(mana / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' })
@ -117,7 +118,14 @@ function DonationBox(props: { user?: User | null }) {
setIsSubmitting(true)
setError(undefined)
// TODO await sending to db
await new Promise((resolve) => setTimeout(resolve, 1000))
await transact({
amount,
toId: 'asdfsasdf', // TODO hardcode in Manifold Markets official account
category: 'TO_CHARITY',
data: {
charityId: 'fjdkslasdf', // TODO fill in
},
})
setIsSubmitting(false)
setAmount(undefined)
}