Make type definitions for Txn more precise (#551)

* Make type definitions for Txn more precise

* Changes in response to feedback
This commit is contained in:
Marshall Polaris 2022-06-22 01:13:25 -07:00 committed by GitHub
parent 402f80b420
commit 0df4ca8f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -1,6 +1,9 @@
// A txn (pronounced "texan") respresents a payment between two ids on Manifold // A txn (pronounced "texan") respresents a payment between two ids on Manifold
// Shortened from "transaction" to distinguish from Firebase transactions (and save chars) // Shortened from "transaction" to distinguish from Firebase transactions (and save chars)
export type Txn = { type AnyTxnType = Donation | Tip
type SourceType = 'USER' | 'CONTRACT' | 'CHARITY' | 'BANK'
export type Txn<T extends AnyTxnType = AnyTxnType> = {
id: string id: string
createdTime: number createdTime: number
@ -13,22 +16,20 @@ export type Txn = {
amount: number amount: number
token: 'M$' // | 'USD' | MarketOutcome token: 'M$' // | 'USD' | MarketOutcome
category: 'CHARITY' | 'TIP' // | 'BET'
// Any extra data // Any extra data
data?: { [key: string]: any } data?: { [key: string]: any }
// Human-readable description // Human-readable description
description?: string description?: string
} } & T
export type SourceType = 'USER' | 'CONTRACT' | 'CHARITY' | 'BANK' type Donation = {
export type DonationTxn = Omit<Txn, 'data'> & {
fromType: 'USER' fromType: 'USER'
toType: 'CHARITY' toType: 'CHARITY'
category: 'CHARITY' category: 'CHARITY'
} }
export type TipTxn = Txn & { type Tip = {
fromType: 'USER' fromType: 'USER'
toType: 'USER' toType: 'USER'
category: 'TIP' category: 'TIP'
@ -37,3 +38,6 @@ export type TipTxn = Txn & {
commentId: string commentId: string
} }
} }
export type DonationTxn = Txn & Donation
export type TipTxn = Txn & Tip

View File

@ -78,7 +78,7 @@ export const transact = functions
const newTxnDoc = firestore.collection(`txns/`).doc() const newTxnDoc = firestore.collection(`txns/`).doc()
const txn: Txn = removeUndefinedProps({ const txn = removeUndefinedProps({
id: newTxnDoc.id, id: newTxnDoc.id,
createdTime: Date.now(), createdTime: Date.now(),