After changing about commission dispatch and adding sharing card6
This commit is contained in:
parent
b7df0da453
commit
867a8c830d
@ -228,3 +228,40 @@ export async function mergeGameStakeBetStatus(
|
||||
[betId, JSON.stringify({ bet_status: betStatus })]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach candle_predict_bets.status onto game_stake metadata as bet_status
|
||||
* so clients can label losses and show share consistently (even across pages).
|
||||
*/
|
||||
export async function enrichGameStakeBetStatus<T extends { type: string; metadata: Record<string, unknown> | null }>(
|
||||
txs: T[]
|
||||
): Promise<T[]> {
|
||||
const betIds = [
|
||||
...new Set(
|
||||
txs
|
||||
.filter((t) => t.type === 'game_stake' && t.metadata?.bet_id)
|
||||
.map((t) => String(t.metadata!.bet_id))
|
||||
),
|
||||
];
|
||||
if (betIds.length === 0) return txs;
|
||||
|
||||
const rows = await query<Array<{ id: string; status: string }>>(
|
||||
`SELECT id::text AS id, status
|
||||
FROM candle_predict_bets
|
||||
WHERE id = ANY($1::uuid[])`,
|
||||
[betIds]
|
||||
);
|
||||
const statusById = new Map(rows.map((r) => [r.id, r.status]));
|
||||
|
||||
return txs.map((tx) => {
|
||||
if (tx.type !== 'game_stake') return tx;
|
||||
const betId = tx.metadata?.bet_id ? String(tx.metadata.bet_id) : '';
|
||||
if (!betId) return tx;
|
||||
const status = statusById.get(betId);
|
||||
if (status !== 'won' && status !== 'lost' && status !== 'refunded') return tx;
|
||||
return {
|
||||
...tx,
|
||||
metadata: { ...(tx.metadata ?? {}), bet_status: status },
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@ -113,7 +113,8 @@ export async function listUserTransactions(
|
||||
offset: number,
|
||||
category?: transactionRepository.TransactionActivityCategory
|
||||
): Promise<Transaction[]> {
|
||||
return transactionRepository.listByUserId(userId, limit, offset, category);
|
||||
const items = await transactionRepository.listByUserId(userId, limit, offset, category);
|
||||
return transactionRepository.enrichGameStakeBetStatus(items);
|
||||
}
|
||||
|
||||
export async function listUserTransactionsPaginated(
|
||||
@ -126,5 +127,10 @@ export async function listUserTransactionsPaginated(
|
||||
transactionRepository.listByUserId(userId, limit, offset, category),
|
||||
transactionRepository.countByUserId(userId, category),
|
||||
]);
|
||||
return { items, total, limit, offset };
|
||||
return {
|
||||
items: await transactionRepository.enrichGameStakeBetStatus(items),
|
||||
total,
|
||||
limit,
|
||||
offset,
|
||||
};
|
||||
}
|
||||
|
||||
@ -1073,14 +1073,12 @@ class _PredictionTxTile extends StatelessWidget {
|
||||
stakeAccountKind: stakeAccountKind(tx),
|
||||
)
|
||||
else if (tx.type == 'game_stake' &&
|
||||
tx.metadata?['bet_status']?.toString() != 'won' &&
|
||||
tx.metadata?['bet_status']?.toString() != 'refunded')
|
||||
tx.metadata?['bet_status']?.toString() == 'lost')
|
||||
ShareResultIconButton(
|
||||
key: ValueKey('share-pred-${tx.id}'),
|
||||
betId: (tx.metadata!['bet_id']).toString(),
|
||||
status: tx.metadata?['bet_status']?.toString() == 'lost' ? 'lost' : null,
|
||||
status: 'lost',
|
||||
stakeAccountKind: stakeAccountKind(tx),
|
||||
requireStatus: tx.metadata?['bet_status']?.toString() == 'lost',
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
@ -33,7 +33,9 @@ String transactionLabel(TransactionModel tx, AppStrings s) {
|
||||
? s.txTypeTransferIn
|
||||
: s.txTypeTransferOut;
|
||||
case 'game_stake':
|
||||
return s.txTypeGameStake;
|
||||
return tx.metadata?['bet_status']?.toString() == 'lost'
|
||||
? s.txTypeGameLoss
|
||||
: s.txTypeGameStake;
|
||||
case 'game_payout':
|
||||
return s.txTypeGamePayout;
|
||||
case 'game_refund':
|
||||
|
||||
@ -213,6 +213,7 @@ class AppStrings {
|
||||
String get txTypeTransferIn => t('Transfer in', 'Transfert reçu');
|
||||
String get txTypeTransferOut => t('Transfer out', 'Transfert envoyé');
|
||||
String get txTypeGameStake => t('Stake', 'Mise');
|
||||
String get txTypeGameLoss => t('Prediction loss', 'Perte de prédiction');
|
||||
String get txTypeGamePayout => t('Payout', 'Gain');
|
||||
String get txTypeGameRefund => t('Refund', 'Remboursement');
|
||||
String get txTypeBonus => t('Bonus', 'Bonus');
|
||||
|
||||
@ -37,10 +37,7 @@ type TransactionListProps = {
|
||||
emptyHint?: string;
|
||||
};
|
||||
|
||||
function predictionShareMeta(
|
||||
tx: WalletTransaction,
|
||||
outcomeByBetId: Map<string, 'won' | 'refunded'>
|
||||
): {
|
||||
function predictionShareMeta(tx: WalletTransaction): {
|
||||
betId: string;
|
||||
status?: 'won' | 'lost' | 'refunded';
|
||||
stakeAccountKind?: string;
|
||||
@ -57,29 +54,11 @@ function predictionShareMeta(
|
||||
if (tx.type === 'game_refund') {
|
||||
return { betId, status: 'refunded', stakeAccountKind };
|
||||
}
|
||||
// game_stake: prefer sharing from payout/refund rows when present on this page.
|
||||
const siblingOutcome = outcomeByBetId.get(betId);
|
||||
if (siblingOutcome) return null;
|
||||
const metaStatus = tx.metadata?.bet_status;
|
||||
if (metaStatus === 'won' || metaStatus === 'refunded') return null;
|
||||
if (metaStatus === 'lost') {
|
||||
// Losses only: stake rows for won/refunded bets share from the outcome row.
|
||||
if (tx.metadata?.bet_status === 'lost') {
|
||||
return { betId, status: 'lost', stakeAccountKind };
|
||||
}
|
||||
// Legacy rows / pending: allow share; API returns the settled result (or 403 if still open).
|
||||
return { betId, stakeAccountKind };
|
||||
}
|
||||
|
||||
function buildPredictionOutcomeMap(
|
||||
transactions: WalletTransaction[]
|
||||
): Map<string, 'won' | 'refunded'> {
|
||||
const map = new Map<string, 'won' | 'refunded'>();
|
||||
for (const tx of transactions) {
|
||||
const betId = tx.metadata?.bet_id;
|
||||
if (!betId) continue;
|
||||
if (tx.type === 'game_payout') map.set(betId, 'won');
|
||||
else if (tx.type === 'game_refund') map.set(betId, 'refunded');
|
||||
}
|
||||
return map;
|
||||
return null;
|
||||
}
|
||||
|
||||
function walletOpShareMeta(
|
||||
@ -126,7 +105,6 @@ export function TransactionList({
|
||||
const pageCount = Math.max(1, Math.ceil(total / pageSize));
|
||||
const from = total === 0 ? 0 : page * pageSize + 1;
|
||||
const to = Math.min(total, (page + 1) * pageSize);
|
||||
const outcomeByBetId = buildPredictionOutcomeMap(transactions);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
@ -184,7 +162,7 @@ export function TransactionList({
|
||||
const credit = isCredit(tx);
|
||||
const [c1, c2] = coinColors(code);
|
||||
const human = rawToHuman(tx.amount, decimals);
|
||||
const predictionShare = predictionShareMeta(tx, outcomeByBetId);
|
||||
const predictionShare = predictionShareMeta(tx);
|
||||
const walletShare = walletOpShareMeta(tx);
|
||||
const shareButton = predictionShare ? (
|
||||
<ShareResultButton
|
||||
|
||||
@ -27,7 +27,9 @@ export function txLabel(tx: WalletTransaction): string {
|
||||
? i18n.t('wallet.transactions.types.transferIn')
|
||||
: i18n.t('wallet.transactions.types.transferOut');
|
||||
case 'game_stake':
|
||||
return i18n.t('wallet.transactions.types.gameStake');
|
||||
return tx.metadata?.bet_status === 'lost'
|
||||
? i18n.t('wallet.transactions.types.gameLoss')
|
||||
: i18n.t('wallet.transactions.types.gameStake');
|
||||
case 'game_payout':
|
||||
return i18n.t('wallet.transactions.types.gamePayout');
|
||||
case 'game_refund':
|
||||
|
||||
@ -397,6 +397,7 @@ export const en = {
|
||||
transferIn: 'Transfer in',
|
||||
transferOut: 'Transfer out',
|
||||
gameStake: 'Prediction stake',
|
||||
gameLoss: 'Prediction loss',
|
||||
gamePayout: 'Prediction win',
|
||||
gameRefund: 'Prediction refund',
|
||||
bonus: 'Bonus credit',
|
||||
|
||||
@ -405,6 +405,7 @@ export const fr = {
|
||||
transferIn: 'Transfert entrant',
|
||||
transferOut: 'Transfert sortant',
|
||||
gameStake: 'Mise de prédiction',
|
||||
gameLoss: 'Perte de prédiction',
|
||||
gamePayout: 'Gain de prédiction',
|
||||
gameRefund: 'Remboursement de prédiction',
|
||||
bonus: 'Crédit bonus',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user