0df4ca8f1e
* Make type definitions for Txn more precise * Changes in response to feedback
44 lines
890 B
TypeScript
44 lines
890 B
TypeScript
// A txn (pronounced "texan") respresents a payment between two ids on Manifold
|
|
// Shortened from "transaction" to distinguish from Firebase transactions (and save chars)
|
|
type AnyTxnType = Donation | Tip
|
|
type SourceType = 'USER' | 'CONTRACT' | 'CHARITY' | 'BANK'
|
|
|
|
export type Txn<T extends AnyTxnType = AnyTxnType> = {
|
|
id: string
|
|
createdTime: number
|
|
|
|
fromId: string
|
|
fromType: SourceType
|
|
|
|
toId: string
|
|
toType: SourceType
|
|
|
|
amount: number
|
|
token: 'M$' // | 'USD' | MarketOutcome
|
|
|
|
// Any extra data
|
|
data?: { [key: string]: any }
|
|
|
|
// Human-readable description
|
|
description?: string
|
|
} & T
|
|
|
|
type Donation = {
|
|
fromType: 'USER'
|
|
toType: 'CHARITY'
|
|
category: 'CHARITY'
|
|
}
|
|
|
|
type Tip = {
|
|
fromType: 'USER'
|
|
toType: 'USER'
|
|
category: 'TIP'
|
|
data: {
|
|
contractId: string
|
|
commentId: string
|
|
}
|
|
}
|
|
|
|
export type DonationTxn = Txn & Donation
|
|
export type TipTxn = Txn & Tip
|