whallets upgrade function
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import db from '../../config/database.js';
|
import db from '../../config/database.js';
|
||||||
import WalletGenerator from '../../utils/walletGenerator.js';
|
import WalletGenerator from '../../utils/walletGenerator.js';
|
||||||
import WalletService from '../../utils/walletService.js';
|
import WalletUtils from '../../utils/walletUtils.js';
|
||||||
import UserService from "../../services/userService.js";
|
import UserService from "../../services/userService.js";
|
||||||
|
import WalletService from "../../services/walletService.js";
|
||||||
import bot from "../../context/bot.js";
|
import bot from "../../context/bot.js";
|
||||||
|
|
||||||
export default class UserWalletsHandler {
|
export default class UserWalletsHandler {
|
||||||
@@ -28,7 +29,7 @@ export default class UserWalletsHandler {
|
|||||||
let message = '💰 *Your Active Wallets:*\n\n';
|
let message = '💰 *Your Active Wallets:*\n\n';
|
||||||
|
|
||||||
if (cryptoWallets.length > 0) {
|
if (cryptoWallets.length > 0) {
|
||||||
const walletService = new WalletService(
|
const walletUtilsInstance = new WalletUtils(
|
||||||
cryptoWallets.find(w => w.wallet_type === 'BTC')?.address,
|
cryptoWallets.find(w => w.wallet_type === 'BTC')?.address,
|
||||||
cryptoWallets.find(w => w.wallet_type === 'LTC')?.address,
|
cryptoWallets.find(w => w.wallet_type === 'LTC')?.address,
|
||||||
cryptoWallets.find(w => w.wallet_type === 'TRON')?.address,
|
cryptoWallets.find(w => w.wallet_type === 'TRON')?.address,
|
||||||
@@ -37,7 +38,7 @@ export default class UserWalletsHandler {
|
|||||||
Date.now() - 30 * 24 * 60 * 60 * 1000
|
Date.now() - 30 * 24 * 60 * 60 * 1000
|
||||||
);
|
);
|
||||||
|
|
||||||
const balances = await walletService.getAllBalances();
|
const balances = await walletUtilsInstance.getAllBalances();
|
||||||
let totalUsdValue = 0;
|
let totalUsdValue = 0;
|
||||||
|
|
||||||
// Show active wallets
|
// Show active wallets
|
||||||
@@ -64,11 +65,7 @@ export default class UserWalletsHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if user has archived wallets
|
// Check if user has archived wallets
|
||||||
const archivedCount = await db.getAsync(`
|
const archivedCount = await WalletService.getArchivedWalletsCount(user);
|
||||||
SELECT COUNT(*) as count
|
|
||||||
FROM crypto_wallets
|
|
||||||
WHERE user_id = ? AND wallet_type LIKE '%_%'
|
|
||||||
`, [user.id]);
|
|
||||||
|
|
||||||
const keyboard = {
|
const keyboard = {
|
||||||
inline_keyboard: [
|
inline_keyboard: [
|
||||||
@@ -76,15 +73,14 @@ export default class UserWalletsHandler {
|
|||||||
{ text: '➕ Add Crypto Wallet', callback_data: 'add_wallet' },
|
{ text: '➕ Add Crypto Wallet', callback_data: 'add_wallet' },
|
||||||
{ text: '💸 Top Up', callback_data: 'top_up_wallet' }
|
{ text: '💸 Top Up', callback_data: 'top_up_wallet' }
|
||||||
],
|
],
|
||||||
[{ text: '🔄 Refresh Balance', callback_data: 'refresh_balance' }],
|
[{ text: '🔄 Refresh Balance', callback_data: 'refresh_balance' }]
|
||||||
[{ text: '📊 Transaction History', callback_data: 'wallet_history' }]
|
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add archived wallets button if any exist
|
// Add archived wallets button if any exist
|
||||||
if (archivedCount.count > 0) {
|
if (archivedCount > 0) {
|
||||||
keyboard.inline_keyboard.splice(2, 0, [
|
keyboard.inline_keyboard.splice(2, 0, [
|
||||||
{ text: `📁 Archived Wallets (${archivedCount.count})`, callback_data: 'view_archived_wallets' }
|
{ text: `📁 Archived Wallets (${archivedCount})`, callback_data: 'view_archived_wallets' }
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,9 +256,9 @@ export default class UserWalletsHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let message = '💰 *Available Wallets:*\n\n';
|
let message = '💰 *Available wallets for replenishment, all you need to do is click on the wallet where you will replenish funds and it will be copied to the clipboard, then paste it on the crypto exchange as the recipient of funds.:*\n\n';
|
||||||
|
|
||||||
const walletService = new WalletService(
|
const walletUtilsInstance = new WalletUtils(
|
||||||
cryptoWallets.find(w => w.wallet_type === 'BTC')?.address,
|
cryptoWallets.find(w => w.wallet_type === 'BTC')?.address,
|
||||||
cryptoWallets.find(w => w.wallet_type === 'LTC')?.address,
|
cryptoWallets.find(w => w.wallet_type === 'LTC')?.address,
|
||||||
cryptoWallets.find(w => w.wallet_type === 'TRON')?.address,
|
cryptoWallets.find(w => w.wallet_type === 'TRON')?.address,
|
||||||
@@ -271,7 +267,7 @@ export default class UserWalletsHandler {
|
|||||||
Date.now() - 30 * 24 * 60 * 60 * 1000
|
Date.now() - 30 * 24 * 60 * 60 * 1000
|
||||||
);
|
);
|
||||||
|
|
||||||
const balances = await walletService.getAllBalances();
|
const balances = await walletUtilsInstance.getAllBalances();
|
||||||
|
|
||||||
for (const [type, balance] of Object.entries(balances)) {
|
for (const [type, balance] of Object.entries(balances)) {
|
||||||
if (cryptoWallets.some(w => w.wallet_type === type.split(' ')[0] ||
|
if (cryptoWallets.some(w => w.wallet_type === type.split(' ')[0] ||
|
||||||
@@ -417,7 +413,7 @@ export default class UserWalletsHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create wallet service instance
|
// Create wallet service instance
|
||||||
const walletService = new WalletService(
|
const walletUtilsInstance = new WalletUtils(
|
||||||
groupedWallets['BTC']?.[0]?.address,
|
groupedWallets['BTC']?.[0]?.address,
|
||||||
groupedWallets['LTC']?.[0]?.address,
|
groupedWallets['LTC']?.[0]?.address,
|
||||||
groupedWallets['TRON']?.[0]?.address,
|
groupedWallets['TRON']?.[0]?.address,
|
||||||
@@ -427,7 +423,7 @@ export default class UserWalletsHandler {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Get all balances
|
// Get all balances
|
||||||
const balances = await walletService.getAllBalances();
|
const balances = await walletUtilsInstance.getAllBalances();
|
||||||
|
|
||||||
let message = '📁 *Archived Wallets:*\n\n';
|
let message = '📁 *Archived Wallets:*\n\n';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import db from "../config/database.js";
|
import db from "../config/database.js";
|
||||||
import WalletService from "../utils/walletService.js";
|
import WalletUtils from "../utils/walletUtils.js";
|
||||||
|
|
||||||
export default class Wallet {
|
export default class Wallet {
|
||||||
static getBaseWalletType(walletType) {
|
static getBaseWalletType(walletType) {
|
||||||
@@ -50,7 +50,7 @@ export default class Wallet {
|
|||||||
static async getActiveWalletsBalance(userId) {
|
static async getActiveWalletsBalance(userId) {
|
||||||
const activeWallets = await this.getActiveWallets(userId);
|
const activeWallets = await this.getActiveWallets(userId);
|
||||||
|
|
||||||
const walletService = new WalletService(
|
const walletUtilsInstance = new WalletUtils(
|
||||||
activeWallets.btc,
|
activeWallets.btc,
|
||||||
activeWallets.ltc,
|
activeWallets.ltc,
|
||||||
activeWallets.tron,
|
activeWallets.tron,
|
||||||
@@ -59,7 +59,7 @@ export default class Wallet {
|
|||||||
Date.now() - 30 * 24 * 60 * 60 * 1000
|
Date.now() - 30 * 24 * 60 * 60 * 1000
|
||||||
);
|
);
|
||||||
|
|
||||||
const balances = await walletService.getAllBalances();
|
const balances = await walletUtilsInstance.getAllBalances();
|
||||||
|
|
||||||
let totalUsdBalance = 0;
|
let totalUsdBalance = 0;
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ export default class Wallet {
|
|||||||
static async getArchivedWalletsBalance(userId) {
|
static async getArchivedWalletsBalance(userId) {
|
||||||
const archiveWallets = await this.getArchivedWallets(userId);
|
const archiveWallets = await this.getArchivedWallets(userId);
|
||||||
|
|
||||||
const walletService = new WalletService(
|
const walletUtilsInstance = new WalletUtils(
|
||||||
archiveWallets.btc,
|
archiveWallets.btc,
|
||||||
archiveWallets.ltc,
|
archiveWallets.ltc,
|
||||||
archiveWallets.tron,
|
archiveWallets.tron,
|
||||||
@@ -95,7 +95,7 @@ export default class Wallet {
|
|||||||
Date.now() - 30 * 24 * 60 * 60 * 1000
|
Date.now() - 30 * 24 * 60 * 60 * 1000
|
||||||
);
|
);
|
||||||
|
|
||||||
const balances = await walletService.getAllBalances();
|
const balances = await walletUtilsInstance.getAllBalances();
|
||||||
|
|
||||||
let totalUsdBalance = 0;
|
let totalUsdBalance = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,23 @@
|
|||||||
class WalletService {
|
import db from "../config/database.js";
|
||||||
|
|
||||||
|
class WalletService {
|
||||||
|
static async getArchivedWalletsCount(user) {
|
||||||
|
try {
|
||||||
|
// Получаем количество архивных кошельков пользователя
|
||||||
|
const archivedWallets = await db.getAsync(
|
||||||
|
`SELECT COUNT(*) AS total
|
||||||
|
FROM crypto_wallets
|
||||||
|
WHERE user_id = ? AND wallet_type LIKE '%#_%' ESCAPE '#'`, // Считаем только архивные кошельки
|
||||||
|
[user.id]
|
||||||
|
);
|
||||||
|
console.log('[SERVICE] Fetching archived wallets for user:', user.id, 'with telegramId:', user.telegram_id, ' and tolal arhived wallet: ', archivedWallets.total);
|
||||||
|
// Возвращаем количество архивных кошельков
|
||||||
|
return archivedWallets.total;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching archived wallets count:', error);
|
||||||
|
throw new Error('Failed to fetch archived wallets count');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default WalletService;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
export default class WalletService {
|
export default class WalletUtils{
|
||||||
constructor(btcAddress, ltcAddress, trxAddress, ethAddress, userId, minTimestamp) {
|
constructor(btcAddress, ltcAddress, trxAddress, ethAddress, userId, minTimestamp) {
|
||||||
this.btcAddress = btcAddress;
|
this.btcAddress = btcAddress;
|
||||||
this.ltcAddress = ltcAddress;
|
this.ltcAddress = ltcAddress;
|
||||||
@@ -148,7 +148,7 @@ export default class WalletService {
|
|||||||
this.getUsdcErc20Balance(),
|
this.getUsdcErc20Balance(),
|
||||||
this.getUsdtTrc20Balance(),
|
this.getUsdtTrc20Balance(),
|
||||||
this.getUsddTrc20Balance(),
|
this.getUsddTrc20Balance(),
|
||||||
WalletService.getCryptoPrices()
|
WalletUtils.getCryptoPrices()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Reference in New Issue
Block a user