Store bonus txn data in data field
This commit is contained in:
parent
e5428ce525
commit
4a5c6a42f6
|
@ -1,6 +1,12 @@
|
|||
// 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 | Manalink | Referral | Bonus
|
||||
type AnyTxnType =
|
||||
| Donation
|
||||
| Tip
|
||||
| Manalink
|
||||
| Referral
|
||||
| UniqueBettorBonus
|
||||
| BettingStreakBonus
|
||||
type SourceType = 'USER' | 'CONTRACT' | 'CHARITY' | 'BANK'
|
||||
|
||||
export type Txn<T extends AnyTxnType = AnyTxnType> = {
|
||||
|
@ -60,10 +66,27 @@ type Referral = {
|
|||
category: 'REFERRAL'
|
||||
}
|
||||
|
||||
type Bonus = {
|
||||
type UniqueBettorBonus = {
|
||||
fromType: 'BANK'
|
||||
toType: 'USER'
|
||||
category: 'UNIQUE_BETTOR_BONUS' | 'BETTING_STREAK_BONUS'
|
||||
category: 'UNIQUE_BETTOR_BONUS'
|
||||
// This data was mistakenly stored as a stringified JSON object in description previously
|
||||
data: {
|
||||
contractId: string
|
||||
uniqueNewBettorId?: string
|
||||
// Previously stored all unique bettor ids in description
|
||||
uniqueBettorIds?: string[]
|
||||
}
|
||||
}
|
||||
|
||||
type BettingStreakBonus = {
|
||||
fromType: 'BANK'
|
||||
toType: 'USER'
|
||||
category: 'BETTING_STREAK_BONUS'
|
||||
// This data was mistakenly stored as a stringified JSON object in description previously
|
||||
data: {
|
||||
currentBettingStreak?: number
|
||||
}
|
||||
}
|
||||
|
||||
export type DonationTxn = Txn & Donation
|
||||
|
|
|
@ -119,6 +119,7 @@ const updateBettingStreak = async (
|
|||
token: 'M$',
|
||||
category: 'BETTING_STREAK_BONUS',
|
||||
description: JSON.stringify(bonusTxnDetails),
|
||||
data: bonusTxnDetails,
|
||||
}
|
||||
return await runTxn(trans, bonusTxn)
|
||||
})
|
||||
|
@ -186,7 +187,7 @@ const updateUniqueBettorsAndGiveCreatorBonus = async (
|
|||
// Create combined txn for all new unique bettors
|
||||
const bonusTxnDetails = {
|
||||
contractId: contract.id,
|
||||
uniqueBettorIds: newUniqueBettorIds,
|
||||
uniqueNewBettorId: bettor.id,
|
||||
}
|
||||
const fromUserId = isProd()
|
||||
? HOUSE_LIQUIDITY_PROVIDER_ID
|
||||
|
@ -204,6 +205,7 @@ const updateUniqueBettorsAndGiveCreatorBonus = async (
|
|||
token: 'M$',
|
||||
category: 'UNIQUE_BETTOR_BONUS',
|
||||
description: JSON.stringify(bonusTxnDetails),
|
||||
data: bonusTxnDetails,
|
||||
}
|
||||
return await runTxn(trans, bonusTxn)
|
||||
})
|
||||
|
|
34
functions/src/scripts/update-bonus-txn-data-fields.ts
Normal file
34
functions/src/scripts/update-bonus-txn-data-fields.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import * as admin from 'firebase-admin'
|
||||
|
||||
import { initAdmin } from './script-init'
|
||||
import { Txn } from 'common/txn'
|
||||
import { getValues } from 'functions/src/utils'
|
||||
|
||||
initAdmin()
|
||||
|
||||
const firestore = admin.firestore()
|
||||
|
||||
async function main() {
|
||||
// get all txns
|
||||
const bonusTxns = await getValues<Txn>(
|
||||
firestore
|
||||
.collection('txns')
|
||||
.where('category', 'in', ['UNIQUE_BETTOR_BONUS', 'BETTING_STREAK_BONUS'])
|
||||
)
|
||||
// JSON parse description field and add to data field
|
||||
const updatedTxns = bonusTxns.map((txn) => {
|
||||
txn.data = txn.description && JSON.parse(txn.description)
|
||||
return txn
|
||||
})
|
||||
console.log('updatedTxns', updatedTxns[0])
|
||||
// update txns
|
||||
await Promise.all(
|
||||
updatedTxns.map((txn) => {
|
||||
return firestore.collection('txns').doc(txn.id).update({
|
||||
data: txn.data,
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
if (require.main === module) main().then(() => process.exit())
|
Loading…
Reference in New Issue
Block a user