After confirming the succes withdrawal1
This commit is contained in:
parent
013ef19ba7
commit
3eb39c2e4a
@ -286,29 +286,67 @@ function shortAssetSymbol(code: string): string {
|
||||
return base.toUpperCase();
|
||||
}
|
||||
|
||||
/** Human network label for share cards (prefer rail metadata over ledger type). */
|
||||
function shareNetworkLabel(network: string | null, assetCode: string): string | null {
|
||||
if (!network && !assetCode) return null;
|
||||
const code = assetCode.toUpperCase();
|
||||
const net = (network || '').toUpperCase();
|
||||
if (code.includes('BEP20') || net === 'BSC') return 'BSC (BEP20)';
|
||||
if (code.includes('TRC20') || net === 'TRON') return 'TRON (TRC20)';
|
||||
return network;
|
||||
}
|
||||
|
||||
async function buildWalletOpCardPayload(
|
||||
tx: Transaction,
|
||||
opts: { includeReferral: boolean; referralCode: string | null }
|
||||
) {
|
||||
const wt = await walletRepository.getWalletTypeById(tx.wallet_type_id);
|
||||
const decimals = wt?.decimals ?? STAKE_DECIMALS;
|
||||
const ledgerWt = await walletRepository.getWalletTypeById(tx.wallet_type_id);
|
||||
const meta = (tx.metadata ?? {}) as Record<string, unknown>;
|
||||
const railCode =
|
||||
typeof meta.rail_wallet_type === 'string'
|
||||
? meta.rail_wallet_type
|
||||
: typeof meta.source_wallet_type === 'string'
|
||||
? meta.source_wallet_type
|
||||
: null;
|
||||
|
||||
// Withdrawals/deposits credit a unified ledger (often USDT_TRC20) but custody/payout
|
||||
// rail is stored in metadata — prefer that for share-card asset/network labels.
|
||||
let displayWt = ledgerWt;
|
||||
if (railCode) {
|
||||
const rail = await walletRepository.getWalletTypeByCode(railCode);
|
||||
if (rail) displayWt = rail;
|
||||
}
|
||||
|
||||
const decimals = ledgerWt?.decimals ?? STAKE_DECIMALS;
|
||||
const amountRaw = BigInt(tx.amount);
|
||||
const feeRaw = BigInt(tx.fee || '0');
|
||||
const amountDisplay = rawToDisplay(amountRaw, decimals);
|
||||
const assetCode = wt?.code ?? 'USDT';
|
||||
const assetCode = displayWt?.code ?? ledgerWt?.code ?? 'USDT';
|
||||
const assetSymbol = shortAssetSymbol(assetCode);
|
||||
const network = wt?.network ?? null;
|
||||
const network = shareNetworkLabel(
|
||||
(typeof meta.network === 'string' && meta.network.trim()
|
||||
? meta.network.trim()
|
||||
: null) ??
|
||||
displayWt?.network ??
|
||||
null,
|
||||
assetCode
|
||||
);
|
||||
const token = createShareVerifyToken('tx', tx.id, tx.user_id);
|
||||
const verifyUrl = buildShareVerifyUrl(token);
|
||||
const registerUrl = opts.referralCode
|
||||
? buildReferralRegisterLink(opts.referralCode)
|
||||
: `${getPublicWebBaseUrl()}/register`;
|
||||
|
||||
const signedDisplay =
|
||||
tx.type === 'withdrawal'
|
||||
? `-${amountDisplay}`
|
||||
: tx.type === 'transfer'
|
||||
? amountDisplay
|
||||
: `+${amountDisplay}`;
|
||||
let signedDisplay: string;
|
||||
if (tx.type === 'withdrawal') {
|
||||
const totalDisplay =
|
||||
feeRaw > 0n ? rawToDisplay(amountRaw + feeRaw, decimals) : amountDisplay;
|
||||
signedDisplay = `-${totalDisplay}`;
|
||||
} else if (tx.type === 'transfer') {
|
||||
signedDisplay = amountDisplay;
|
||||
} else {
|
||||
signedDisplay = `+${amountDisplay}`;
|
||||
}
|
||||
|
||||
return {
|
||||
kind: 'wallet' as const,
|
||||
@ -321,7 +359,7 @@ async function buildWalletOpCardPayload(
|
||||
feeRaw: tx.fee,
|
||||
assetCode,
|
||||
assetSymbol,
|
||||
assetName: wt?.name ?? assetCode,
|
||||
assetName: displayWt?.name ?? assetCode,
|
||||
network,
|
||||
createdAt: tx.created_at.toISOString(),
|
||||
blockchainTxId: tx.blockchain_tx_id,
|
||||
|
||||
@ -124,6 +124,7 @@ class ShareCardPayload {
|
||||
this.operationType,
|
||||
this.amountSignedDisplay,
|
||||
this.amountDisplay,
|
||||
this.feeRaw,
|
||||
this.assetSymbol,
|
||||
this.assetName,
|
||||
this.network,
|
||||
@ -153,6 +154,7 @@ class ShareCardPayload {
|
||||
final String? operationType;
|
||||
final String? amountSignedDisplay;
|
||||
final String? amountDisplay;
|
||||
final String? feeRaw;
|
||||
final String? assetSymbol;
|
||||
final String? assetName;
|
||||
final String? network;
|
||||
@ -187,6 +189,7 @@ class ShareCardPayload {
|
||||
operationType: json['operationType']?.toString(),
|
||||
amountSignedDisplay: json['amountSignedDisplay']?.toString(),
|
||||
amountDisplay: json['amountDisplay']?.toString(),
|
||||
feeRaw: json['feeRaw']?.toString(),
|
||||
assetSymbol: json['assetSymbol']?.toString(),
|
||||
assetName: json['assetName']?.toString(),
|
||||
network: json['network']?.toString(),
|
||||
|
||||
@ -292,6 +292,18 @@ class _WalletCard extends StatelessWidget {
|
||||
_KV(s.t('Asset', 'Actif'), payload.assetName ?? payload.assetSymbol ?? ''),
|
||||
if ((payload.network ?? '').isNotEmpty)
|
||||
_KV(s.t('Network', 'Réseau'), payload.network!),
|
||||
if (payload.operationType == 'withdrawal' &&
|
||||
(payload.feeRaw ?? '0') != '0' &&
|
||||
(payload.feeRaw ?? '').isNotEmpty) ...[
|
||||
_KV(
|
||||
s.t('Withdrawn', 'Retiré'),
|
||||
'${payload.amountDisplay ?? ''} ${payload.assetSymbol ?? ''}'.trim(),
|
||||
),
|
||||
_KV(
|
||||
s.t('Fee', 'Frais'),
|
||||
'${_formatMicroUsdt(payload.feeRaw!)} ${payload.assetSymbol ?? ''}'.trim(),
|
||||
),
|
||||
],
|
||||
if (created != null) _KV(s.t('Date', 'Date'), _fmt(created)),
|
||||
],
|
||||
verifyUrl: payload.verifyUrl,
|
||||
@ -299,6 +311,16 @@ class _WalletCard extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
String _formatMicroUsdt(String raw, {int decimals = 6}) {
|
||||
final n = BigInt.tryParse(raw.trim()) ?? BigInt.zero;
|
||||
final base = BigInt.from(10).pow(decimals);
|
||||
final whole = n ~/ base;
|
||||
final frac = n % base;
|
||||
if (frac == BigInt.zero) return whole.toString();
|
||||
final fracStr = frac.toString().padLeft(decimals, '0').replaceAll(RegExp(r'0+$'), '');
|
||||
return '$whole.$fracStr';
|
||||
}
|
||||
|
||||
class _CardShell extends StatelessWidget {
|
||||
const _CardShell({
|
||||
required this.title,
|
||||
|
||||
@ -96,6 +96,19 @@ function PredictionCard({
|
||||
);
|
||||
}
|
||||
|
||||
function formatMicroUsdt(raw: string, decimals = 6): string {
|
||||
try {
|
||||
const n = BigInt(raw);
|
||||
const base = 10n ** BigInt(decimals);
|
||||
const whole = n / base;
|
||||
const frac = n % base;
|
||||
if (frac === 0n) return whole.toString();
|
||||
return `${whole.toString()}.${frac.toString().padStart(decimals, '0').replace(/0+$/, '')}`;
|
||||
} catch {
|
||||
return raw;
|
||||
}
|
||||
}
|
||||
|
||||
function WalletOpCard({
|
||||
payload,
|
||||
cardRef,
|
||||
@ -136,6 +149,22 @@ function WalletOpCard({
|
||||
/>
|
||||
<Row label={t('shareCard.asset')} value={payload.assetName} />
|
||||
{payload.network ? <Row label={t('shareCard.network')} value={payload.network} /> : null}
|
||||
{payload.operationType === 'withdrawal' &&
|
||||
payload.feeRaw &&
|
||||
payload.feeRaw !== '0' ? (
|
||||
<Row
|
||||
label={t('shareCard.fee', { defaultValue: 'Fee' })}
|
||||
value={`${formatMicroUsdt(payload.feeRaw)} ${payload.assetSymbol}`}
|
||||
/>
|
||||
) : null}
|
||||
{payload.operationType === 'withdrawal' &&
|
||||
payload.feeRaw &&
|
||||
payload.feeRaw !== '0' ? (
|
||||
<Row
|
||||
label={t('shareCard.withdrawn', { defaultValue: 'Withdrawn' })}
|
||||
value={`${payload.amountDisplay} ${payload.assetSymbol}`}
|
||||
/>
|
||||
) : null}
|
||||
<Row
|
||||
label={t('shareCard.date')}
|
||||
value={created.toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' })}
|
||||
|
||||
@ -271,6 +271,8 @@ export const en = {
|
||||
amount: 'Amount',
|
||||
asset: 'Asset',
|
||||
network: 'Network',
|
||||
fee: 'Fee',
|
||||
withdrawn: 'Withdrawn',
|
||||
date: 'Date',
|
||||
txStatus: 'Status',
|
||||
operationType: {
|
||||
|
||||
@ -278,6 +278,8 @@ export const fr = {
|
||||
amount: 'Montant',
|
||||
asset: 'Actif',
|
||||
network: 'Réseau',
|
||||
fee: 'Frais',
|
||||
withdrawn: 'Retiré',
|
||||
date: 'Date',
|
||||
txStatus: 'Statut',
|
||||
operationType: {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user