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
|
// 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)
|
||||||
type AnyTxnType = Donation | Tip | Manalink | Referral | Bonus
|
type AnyTxnType =
|
||||||
|
| Donation
|
||||||
|
| Tip
|
||||||
|
| Manalink
|
||||||
|
| Referral
|
||||||
|
| UniqueBettorBonus
|
||||||
|
| BettingStreakBonus
|
||||||
type SourceType = 'USER' | 'CONTRACT' | 'CHARITY' | 'BANK'
|
type SourceType = 'USER' | 'CONTRACT' | 'CHARITY' | 'BANK'
|
||||||
|
|
||||||
export type Txn<T extends AnyTxnType = AnyTxnType> = {
|
export type Txn<T extends AnyTxnType = AnyTxnType> = {
|
||||||
|
@ -60,10 +66,27 @@ type Referral = {
|
||||||
category: 'REFERRAL'
|
category: 'REFERRAL'
|
||||||
}
|
}
|
||||||
|
|
||||||
type Bonus = {
|
type UniqueBettorBonus = {
|
||||||
fromType: 'BANK'
|
fromType: 'BANK'
|
||||||
toType: 'USER'
|
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
|
export type DonationTxn = Txn & Donation
|
||||||
|
|
|
@ -119,6 +119,7 @@ const updateBettingStreak = async (
|
||||||
token: 'M$',
|
token: 'M$',
|
||||||
category: 'BETTING_STREAK_BONUS',
|
category: 'BETTING_STREAK_BONUS',
|
||||||
description: JSON.stringify(bonusTxnDetails),
|
description: JSON.stringify(bonusTxnDetails),
|
||||||
|
data: bonusTxnDetails,
|
||||||
}
|
}
|
||||||
return await runTxn(trans, bonusTxn)
|
return await runTxn(trans, bonusTxn)
|
||||||
})
|
})
|
||||||
|
@ -186,7 +187,7 @@ const updateUniqueBettorsAndGiveCreatorBonus = async (
|
||||||
// Create combined txn for all new unique bettors
|
// Create combined txn for all new unique bettors
|
||||||
const bonusTxnDetails = {
|
const bonusTxnDetails = {
|
||||||
contractId: contract.id,
|
contractId: contract.id,
|
||||||
uniqueBettorIds: newUniqueBettorIds,
|
uniqueNewBettorId: bettor.id,
|
||||||
}
|
}
|
||||||
const fromUserId = isProd()
|
const fromUserId = isProd()
|
||||||
? HOUSE_LIQUIDITY_PROVIDER_ID
|
? HOUSE_LIQUIDITY_PROVIDER_ID
|
||||||
|
@ -204,6 +205,7 @@ const updateUniqueBettorsAndGiveCreatorBonus = async (
|
||||||
token: 'M$',
|
token: 'M$',
|
||||||
category: 'UNIQUE_BETTOR_BONUS',
|
category: 'UNIQUE_BETTOR_BONUS',
|
||||||
description: JSON.stringify(bonusTxnDetails),
|
description: JSON.stringify(bonusTxnDetails),
|
||||||
|
data: bonusTxnDetails,
|
||||||
}
|
}
|
||||||
return await runTxn(trans, bonusTxn)
|
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