After trying to recuparate money from cold wallet8
This commit is contained in:
parent
9982c8bee0
commit
a9c0346db8
@ -42,6 +42,19 @@ import {
|
||||
} from '../utils/usdtUnits';
|
||||
import { assertHotWalletCanPay } from './hotLiquidityService';
|
||||
|
||||
function assertPayoutAddress(network: 'TRON' | 'BSC', toAddress: string): void {
|
||||
const a = toAddress.trim();
|
||||
if (network === 'BSC') {
|
||||
if (!/^0x[a-fA-F0-9]{40}$/.test(a)) {
|
||||
throw new Error('Invalid BEP20 address. Use a 0x… address on BNB Smart Chain.');
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!/^T[1-9A-HJ-NP-Za-km-z]{33}$/.test(a)) {
|
||||
throw new Error('Invalid TRC20 address. Use a T… address on TRON.');
|
||||
}
|
||||
}
|
||||
|
||||
async function assertWithdrawalWithinLimits(
|
||||
userId: string,
|
||||
railWalletType: WalletType,
|
||||
@ -145,6 +158,7 @@ export async function requestWithdrawal(
|
||||
throw err;
|
||||
}
|
||||
if (amountRaw <= 0n) throw new Error('Invalid amount');
|
||||
assertPayoutAddress(network, toAddress);
|
||||
|
||||
const ledgerWalletType = await walletRepository.getWalletTypeByCode(USDT_TRC20_CODE);
|
||||
if (!ledgerWalletType) throw new Error('USDT ledger wallet type not configured');
|
||||
|
||||
@ -4,14 +4,32 @@ import { config } from '../config';
|
||||
* Returns a client-safe error message. Internal details are hidden in production.
|
||||
*/
|
||||
export function clientErrorMessage(error: unknown, fallback = 'Request failed'): string {
|
||||
const msg = error instanceof Error ? error.message : String(error);
|
||||
const code = (error as { code?: string })?.code;
|
||||
|
||||
if (config.env !== 'production') {
|
||||
return error instanceof Error ? error.message : String(error);
|
||||
return msg;
|
||||
}
|
||||
|
||||
const exposeByCode = new Set([
|
||||
'WITHDRAWALS_DISABLED',
|
||||
'WITHDRAWAL_NETWORK_DISABLED',
|
||||
'HOT_WALLET_INSUFFICIENT_LIQUIDITY',
|
||||
'INSUFFICIENT_BALANCE',
|
||||
'DAILY_WITHDRAWAL_LIMIT_EXCEEDED',
|
||||
'WITHDRAWAL_2FA_REQUIRED',
|
||||
]);
|
||||
if (code && exposeByCode.has(code) && msg.trim()) {
|
||||
return msg;
|
||||
}
|
||||
|
||||
if (error instanceof Error && error.message) {
|
||||
const msg = error.message;
|
||||
if (/^(Invalid|Unauthorized|Forbidden|Not found|2FA|Account|Password|Email|Phone|Referrer|referral)/i.test(msg)) {
|
||||
return msg;
|
||||
}
|
||||
if (/Withdrawals are disabled/i.test(msg)) {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
@ -34,8 +34,8 @@ class WalletTypeModel {
|
||||
network: json['network'] as String,
|
||||
decimals: json['decimals'] as int? ?? 6,
|
||||
contractAddress: json['contract_address'] as String?,
|
||||
depositEnabled: json['depositEnabled'] as bool? ?? true,
|
||||
withdrawEnabled: json['withdrawEnabled'] as bool? ?? true,
|
||||
depositEnabled: json['depositEnabled'] as bool? ?? false,
|
||||
withdrawEnabled: json['withdrawEnabled'] as bool? ?? false,
|
||||
predictionEnabled: json['predictionEnabled'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
@ -81,8 +81,7 @@ class _WithdrawScreenState extends State<WithdrawScreen> {
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (_selectedWalletType == null ||
|
||||
_addressController.text.isEmpty ||
|
||||
if (_addressController.text.isEmpty ||
|
||||
_amountController.text.isEmpty ||
|
||||
_totpController.text.length != 6) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@ -91,6 +90,17 @@ class _WithdrawScreenState extends State<WithdrawScreen> {
|
||||
return;
|
||||
}
|
||||
final state = context.read<WalletBloc>().state;
|
||||
final enabledRails = state.walletTypes.where((t) => t.withdrawEnabled == true).toList();
|
||||
final railCode = (_selectedWalletType != null &&
|
||||
enabledRails.any((t) => t.code == _selectedWalletType))
|
||||
? _selectedWalletType!
|
||||
: (enabledRails.isNotEmpty ? enabledRails.first.code : null);
|
||||
if (railCode == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('No withdrawal network is enabled right now.')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final amountHuman = _amountController.text.trim();
|
||||
// Always ledger micro-USDT (6), even when payout rail is BEP20.
|
||||
final amountRaw = humanAmountToRaw(amountHuman, _kLedgerUsdtDecimals);
|
||||
@ -165,7 +175,7 @@ class _WithdrawScreenState extends State<WithdrawScreen> {
|
||||
if (confirmed == true && context.mounted) {
|
||||
context.read<WalletBloc>().add(
|
||||
WalletWithdrawRequested(
|
||||
walletType: _selectedWalletType!,
|
||||
walletType: railCode,
|
||||
toAddress: address,
|
||||
amount: amountRaw,
|
||||
totpCode: _totpController.text,
|
||||
@ -212,9 +222,16 @@ class _WithdrawScreenState extends State<WithdrawScreen> {
|
||||
if (types.isEmpty) {
|
||||
return const Center(child: Text('No withdrawal networks enabled'));
|
||||
}
|
||||
_selectedWalletType ??= types.first.code;
|
||||
final selectedTypeList = types.where((t) => t.code == _selectedWalletType);
|
||||
final selectedType = selectedTypeList.isEmpty ? types.first : selectedTypeList.first;
|
||||
final selectedCode = (_selectedWalletType != null &&
|
||||
types.any((t) => t.code == _selectedWalletType))
|
||||
? _selectedWalletType!
|
||||
: types.first.code;
|
||||
if (_selectedWalletType != selectedCode) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) setState(() => _selectedWalletType = selectedCode);
|
||||
});
|
||||
}
|
||||
final selectedType = types.firstWhere((t) => t.code == selectedCode);
|
||||
final networkLabel = CoinDisplay.networkLabel(selectedType.code);
|
||||
final feeRaw = CoinDisplay.scaleWithdrawalFeeRaw(_networkFeeRaw, _kLedgerUsdtDecimals);
|
||||
final feeHuman = rawAmountToHuman(feeRaw.toString(), _kLedgerUsdtDecimals);
|
||||
@ -268,9 +285,7 @@ class _WithdrawScreenState extends State<WithdrawScreen> {
|
||||
const Text('Payout network'),
|
||||
const SizedBox(height: 8),
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: types.any((t) => t.code == _selectedWalletType)
|
||||
? _selectedWalletType
|
||||
: types.first.code,
|
||||
value: selectedCode,
|
||||
items: types
|
||||
.map(
|
||||
(t) => DropdownMenuItem(
|
||||
|
||||
@ -90,13 +90,15 @@ export function WithdrawDialog({
|
||||
}, [networkFeeRaw]);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setRail(initialRail ?? withdrawRails[0]?.code ?? '');
|
||||
setToAddress('');
|
||||
setAmount('');
|
||||
setTotpCode('');
|
||||
setConfirmOpen(false);
|
||||
}
|
||||
if (!open) return;
|
||||
const fallback = withdrawRails[0]?.code ?? '';
|
||||
const next =
|
||||
initialRail && withdrawRails.some((n) => n.code === initialRail) ? initialRail : fallback;
|
||||
setRail(next);
|
||||
setToAddress('');
|
||||
setAmount('');
|
||||
setTotpCode('');
|
||||
setConfirmOpen(false);
|
||||
}, [open, initialRail, withdrawRails]);
|
||||
|
||||
const selectedRail = useMemo(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user