69 lines
2.5 KiB
TypeScript
69 lines
2.5 KiB
TypeScript
/**
|
|
* Platform deposit/withdraw wallet capabilities (USDT TRC20 + USDT BEP20).
|
|
*/
|
|
|
|
import { WalletType } from '../models';
|
|
import type { SystemSettings } from '../models/settings.model';
|
|
|
|
export const USDT_TRC20_CODE = 'USDT_TRC20';
|
|
export const USDT_BEP20_CODE = 'USDT_BEP20';
|
|
/** @deprecated Prefer USDT_TRC20_CODE — kept for prediction default / legacy imports */
|
|
export const USDT_WALLET_CODE = USDT_TRC20_CODE;
|
|
|
|
export const SUPPORTED_USDT_CODES = [USDT_TRC20_CODE, USDT_BEP20_CODE] as const;
|
|
export type SupportedUsdtCode = (typeof SUPPORTED_USDT_CODES)[number];
|
|
|
|
export type WalletTypeCapabilities = WalletType & {
|
|
depositEnabled: boolean;
|
|
withdrawEnabled: boolean;
|
|
predictionEnabled: boolean;
|
|
};
|
|
|
|
export function isSupportedUsdtCode(code: string): code is SupportedUsdtCode {
|
|
return (SUPPORTED_USDT_CODES as readonly string[]).includes(code);
|
|
}
|
|
|
|
export function assertUsdtWalletType(code: string): void {
|
|
if (!isSupportedUsdtCode(code)) {
|
|
throw new Error(`Only ${SUPPORTED_USDT_CODES.join(' or ')} is supported`);
|
|
}
|
|
}
|
|
|
|
function depositFlagForCode(code: string, settings: SystemSettings): boolean {
|
|
if (code === USDT_TRC20_CODE) return settings.network_usdt_trc20_deposit_enabled;
|
|
if (code === USDT_BEP20_CODE) return settings.network_usdt_bep20_deposit_enabled;
|
|
return false;
|
|
}
|
|
|
|
function withdrawFlagForCode(code: string, settings: SystemSettings): boolean {
|
|
if (code === USDT_TRC20_CODE) return settings.network_usdt_trc20_withdraw_enabled;
|
|
if (code === USDT_BEP20_CODE) return settings.network_usdt_bep20_withdraw_enabled;
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Sync enrich when settings are not needed (prediction still TRC20-primary).
|
|
* Prefer enrichWalletTypeAsync for deposit/withdraw gates.
|
|
*/
|
|
export function enrichWalletType(walletType: WalletType, settings?: SystemSettings): WalletTypeCapabilities {
|
|
const isUsdt = isSupportedUsdtCode(walletType.code);
|
|
const depositEnabled = settings
|
|
? isUsdt && depositFlagForCode(walletType.code, settings)
|
|
: walletType.code === USDT_TRC20_CODE;
|
|
const withdrawEnabled = settings
|
|
? isUsdt && withdrawFlagForCode(walletType.code, settings)
|
|
: isUsdt;
|
|
return {
|
|
...walletType,
|
|
depositEnabled,
|
|
withdrawEnabled,
|
|
predictionEnabled: walletType.code === USDT_TRC20_CODE,
|
|
};
|
|
}
|
|
|
|
export async function enrichWalletTypeAsync(walletType: WalletType): Promise<WalletTypeCapabilities> {
|
|
const { getSettings } = await import('../repositories/settingsRepository');
|
|
const settings = await getSettings();
|
|
return enrichWalletType(walletType, settings);
|
|
}
|