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 createdTime: number
fromId: string fromId: string
// TODO: Do we really want to denormalize name/username/avatar here?
fromName: string fromName: string
fromUsername: string fromUsername: string
fromAvatarUrl?: string fromAvatarUrl?: string
@ -27,5 +28,5 @@ export type TxnCategory = 'TO_CHARITY' // | 'TIP' | 'BET' | ...
export type TxnData = CharityData // | TipData | BetData | ... export type TxnData = CharityData // | TipData | BetData | ...
export type CharityData = { 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 2. `$ yarn` to install JS dependencies
3. `$ firebase login` to authenticate the CLI tools to Firebase 3. `$ firebase login` to authenticate the CLI tools to Firebase
4. `$ firebase use dev` to choose the dev project 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 ## Developing locally

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,6 +10,7 @@ import { Spacer } from '../../../components/layout/spacer'
import { User } from '../../../../common/user' import { User } from '../../../../common/user'
import { useUser } from '../../../hooks/use-user' import { useUser } from '../../../hooks/use-user'
import { Linkify } from '../../../components/linkify' import { Linkify } from '../../../components/linkify'
import { transact } from '../../../lib/firebase/api-call'
const manaToUSD = (mana: number) => const manaToUSD = (mana: number) =>
(mana / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' }) (mana / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' })
@ -117,7 +118,14 @@ function DonationBox(props: { user?: User | null }) {
setIsSubmitting(true) setIsSubmitting(true)
setError(undefined) setError(undefined)
// TODO await sending to db // 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) setIsSubmitting(false)
setAmount(undefined) setAmount(undefined)
} }