initvglidrbtgrthijl;
This commit is contained in:
@@ -2,7 +2,7 @@ import { Request, Response } from 'express';
|
||||
import { db } from '../config/database';
|
||||
import { WalletModel } from '../models/wallet.model';
|
||||
import { UserModel } from '../models/user.model';
|
||||
import { getBalance, getTransactions } from '../services/wallet-ops.service';
|
||||
import { getBalance, getTransactions, getPortfolio as getPortfolioService } from '../services/wallet-ops.service';
|
||||
import { isValidAddress, isValidAmount, ChainCode } from '../lib/address-validators';
|
||||
import { generateMnemonic, deriveAllAddresses, ALL_CHAINS } from '../services/wallet-generator.service';
|
||||
import { encryptMnemonic, decryptMnemonic, isCryptoReady } from '../services/crypto.service';
|
||||
@@ -233,6 +233,29 @@ export const WalletController = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* GET /api/wallets/portfolio — общий баланс всех 5 сетей.
|
||||
* Возвращает grand totalUsd + per-chain breakdown.
|
||||
* При сбое RPC отдельной сети — возвращает stale snapshot из KeyDB (TTL 1 час).
|
||||
*/
|
||||
async getPortfolio(req: Request, res: Response) {
|
||||
const userId = req.auth!.userId;
|
||||
try {
|
||||
const wallets = await WalletModel.findByUserId(userId);
|
||||
if (wallets.length === 0) {
|
||||
res.status(404).json({ success: false, error: 'No wallets created — POST /wallets/create first' });
|
||||
return;
|
||||
}
|
||||
const addresses: Record<string, string> = {};
|
||||
for (const w of wallets) addresses[w.chain] = w.address;
|
||||
const data = await getPortfolioService(userId, addresses as any);
|
||||
res.json({ success: true, data });
|
||||
} catch (err: any) {
|
||||
logger.error(`getPortfolio failed for user ${userId}: ${err.stack || err.message}`);
|
||||
res.status(502).json({ success: false, error: 'Portfolio fetch error' });
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* GET /api/wallets/:chain/balance
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user