After correcting the problem of withdrawal3
This commit is contained in:
parent
71ad7598d7
commit
69c8d29b53
@ -1 +1 @@
|
||||
{"version":3,"file":"candlePredictController.d.ts","sourceRoot":"","sources":["../../src/controllers/candlePredictController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA6JjD,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA2G7E;AAID,wBAAsB,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAwC/E;AAID,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA2D7E;AAID,wBAAsB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAuClF;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA+C9E;AAID,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAwBpF;AAID,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BvF;AAID,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBnF;AAID,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBtF;AAID,w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AID,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBzF;AAID,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAoB3F"}
|
||||
@ -53,6 +53,7 @@ const crypto_1 = require("crypto");
|
||||
const roleAccess_1 = require("../utils/roleAccess");
|
||||
const candlePredictService = __importStar(require("../services/candlePredictService"));
|
||||
const testWalletService_1 = require("../services/testWalletService");
|
||||
const securityService_1 = require("../services/securityService");
|
||||
const stakeAmountValidation_1 = require("../utils/stakeAmountValidation");
|
||||
const placeBetResponse_1 = require("../utils/placeBetResponse");
|
||||
const stateVersions_1 = require("../realtime/redis/stateVersions");
|
||||
@ -64,7 +65,25 @@ function placeBetErrorBody(e, fallback) {
|
||||
...(e.waitLabel ? { wait: e.waitLabel } : {}),
|
||||
};
|
||||
}
|
||||
return { error: e instanceof Error ? e.message : fallback };
|
||||
if (e instanceof securityService_1.SecurityBlockedError) {
|
||||
return { error: e.message, code: e.code };
|
||||
}
|
||||
const code = e?.code;
|
||||
return {
|
||||
error: e instanceof Error ? e.message : fallback,
|
||||
...(typeof code === 'string' ? { code } : {}),
|
||||
};
|
||||
}
|
||||
function placeBetHttpStatus(e) {
|
||||
if (e instanceof securityService_1.SecurityBlockedError)
|
||||
return 403;
|
||||
const code = e?.code;
|
||||
if (code === 'WITHDRAWALS_SUSPENDED' ||
|
||||
code === 'ACCOUNT_UNDER_SURVEILLANCE' ||
|
||||
code === 'ACCOUNT_DISABLED') {
|
||||
return 403;
|
||||
}
|
||||
return 400;
|
||||
}
|
||||
const STATE_CACHE_TTL_MS = 1200;
|
||||
const STATE_CACHE_MAX_ENTRIES = 500;
|
||||
@ -321,7 +340,7 @@ async function placeBet(req, res) {
|
||||
console.warn('[candle-predict] placeBet rejected:', body.error, {
|
||||
userId: req.user?.userId,
|
||||
});
|
||||
res.status(400).json(body);
|
||||
res.status(placeBetHttpStatus(e)).json(body);
|
||||
}
|
||||
}
|
||||
async function getBetOutcome(req, res) {
|
||||
@ -508,7 +527,7 @@ async function placeMultiBet(req, res) {
|
||||
res.status(201).json(bet);
|
||||
}
|
||||
catch (e) {
|
||||
res.status(400).json(placeBetErrorBody(e, 'Failed to place multi-candle prediction'));
|
||||
res.status(placeBetHttpStatus(e)).json(placeBetErrorBody(e, 'Failed to place multi-candle prediction'));
|
||||
}
|
||||
}
|
||||
async function listAdminMultiLevels(req, res) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
{"version":3,"file":"gamePlayController.d.ts","sourceRoot":"","sources":["../../src/controllers/gamePlayController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AASnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA0CjD,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAS7E;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC7E;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAa9E;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBpF;AAED,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBvF;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAe9E"}
|
||||
{"version":3,"file":"gamePlayController.d.ts","sourceRoot":"","sources":["../../src/controllers/gamePlayController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AASnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAmDjD,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAS7E;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC7E;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAa9E;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBpF;AAED,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBvF;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAe9E"}
|
||||
11
backend/dist/controllers/gamePlayController.js
vendored
11
backend/dist/controllers/gamePlayController.js
vendored
@ -7,6 +7,7 @@ exports.getAutoSettings = getAutoSettings;
|
||||
exports.updateAutoSettings = updateAutoSettings;
|
||||
exports.customGet = customGet;
|
||||
const errors_1 = require("../games/errors");
|
||||
const securityService_1 = require("../services/securityService");
|
||||
const gamePlayService_1 = require("../services/gamePlayService");
|
||||
const placeBetResponse_1 = require("../utils/placeBetResponse");
|
||||
function buildCtx(req) {
|
||||
@ -36,8 +37,16 @@ function sendGameError(res, e, fallbackStatus = 500) {
|
||||
res.status(401).json({ error: 'Unauthorized' });
|
||||
return;
|
||||
}
|
||||
if (e instanceof securityService_1.SecurityBlockedError) {
|
||||
res.status(403).json({ error: e.message, code: e.code });
|
||||
return;
|
||||
}
|
||||
const msg = e instanceof Error ? e.message : 'Request failed';
|
||||
res.status(fallbackStatus).json({ error: msg });
|
||||
const code = e?.code;
|
||||
res.status(fallbackStatus).json({
|
||||
error: msg,
|
||||
...(typeof code === 'string' ? { code } : {}),
|
||||
});
|
||||
}
|
||||
function assertAction(mod, action) {
|
||||
if (!mod.capabilities.actions.includes(action)) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
{"version":3,"file":"referralController.d.ts","sourceRoot":"","sources":["../../src/controllers/referralController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAYjD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAOtF;AAED,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAO3F;AAED,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAY7F;AAED,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAQrF;AAED,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBxF;AAED,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAO5F;AAED,wBAAsB,2BAA2B,CAAC,GAAG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+58,7 @@ const referralRepository = __importStar(require("../repositories/referralReposit
|
||||
const bonusPoolRepository = __importStar(require("../repositories/bonusPoolRepository"));
|
||||
const referralExportService_1 = require("../services/referralExportService");
|
||||
const referralRegularizationService_1 = require("../services/referralRegularizationService");
|
||||
const securityService_1 = require("../services/securityService");
|
||||
async function getMyReferralInfo(req, res) {
|
||||
try {
|
||||
const info = await referralService.getUserReferralInfo(req.user.userId);
|
||||
@ -115,7 +116,15 @@ async function transferBonusToMain(req, res) {
|
||||
res.json({ message: 'Bonus transferred to main account' });
|
||||
}
|
||||
catch (e) {
|
||||
res.status(400).json({ error: e instanceof Error ? e.message : 'Transfer failed' });
|
||||
if (e instanceof securityService_1.SecurityBlockedError) {
|
||||
res.status(403).json({ error: e.message, code: e.code });
|
||||
return;
|
||||
}
|
||||
const code = e?.code;
|
||||
res.status(400).json({
|
||||
error: e instanceof Error ? e.message : 'Transfer failed',
|
||||
...(typeof code === 'string' ? { code } : {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
async function getAdminReferralConfig(_req, res) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
2
backend/dist/middleware/auth.d.ts.map
vendored
2
backend/dist/middleware/auth.d.ts.map
vendored
@ -1 +1 @@
|
||||
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAUtC,0EAA0E;AAC1E,MAAM,WAAW,WAAY,SAAQ,OAAO;IAC1C,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAoDD;;GAEG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BvG;AAED;;;;GAIG;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KAAK,EAAE,MAAM,EAAE,IACrC,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC,CAoBlF;AAED,4BAA4B;AAC5B,wBAAgB,YAAY,UAtDP,WAAW,OAAO,QAAQ,QAAQ,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC,CAwDlF;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,KACZ,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC,CA2BlF"}
|
||||
24
backend/dist/middleware/auth.js
vendored
24
backend/dist/middleware/auth.js
vendored
@ -115,18 +115,30 @@ async function authMiddleware(req, res, next) {
|
||||
const token = authHeader.slice(7);
|
||||
try {
|
||||
const payload = await (0, authService_1.verifyToken)(token);
|
||||
const gate = await userRepository.getAuthGate(payload.userId);
|
||||
if (!gate || gate.deleted_at) {
|
||||
res.status(401).json({ error: 'Invalid or expired token' });
|
||||
return;
|
||||
}
|
||||
if (!config_1.config.security.skipAccessTokenVersionCheck) {
|
||||
const dbVersion = await userRepository.getTokenVersion(payload.userId);
|
||||
if (dbVersion === null) {
|
||||
res.status(401).json({ error: 'Invalid or expired token' });
|
||||
return;
|
||||
}
|
||||
const jwtVersion = payload.tv ?? 1;
|
||||
if (jwtVersion !== dbVersion) {
|
||||
if (jwtVersion !== gate.token_version) {
|
||||
res.status(401).json({ error: 'Invalid or expired token', code: 'TOKEN_REVOKED' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (gate.is_enabled === false) {
|
||||
res.status(403).json({ error: 'Account is disabled.', code: 'ACCOUNT_DISABLED' });
|
||||
return;
|
||||
}
|
||||
if (gate.is_account_non_locked === false) {
|
||||
res.status(403).json({ error: 'Account is locked.', code: 'ACCOUNT_LOCKED' });
|
||||
return;
|
||||
}
|
||||
if (gate.is_account_non_expired === false || gate.is_credentials_non_expired === false) {
|
||||
res.status(403).json({ error: 'Account is not available.', code: 'ACCOUNT_DISABLED' });
|
||||
return;
|
||||
}
|
||||
req.user = payload;
|
||||
if (payload.userId)
|
||||
void (0, onlinePresence_1.touchAppPresence)(payload.userId);
|
||||
|
||||
2
backend/dist/middleware/auth.js.map
vendored
2
backend/dist/middleware/auth.js.map
vendored
File diff suppressed because one or more lines are too long
10
backend/dist/repositories/userRepository.d.ts
vendored
10
backend/dist/repositories/userRepository.d.ts
vendored
@ -140,6 +140,16 @@ export declare function updateAccountFlags(userId: string, flags: {
|
||||
is_account_non_locked?: boolean;
|
||||
is_credentials_non_expired?: boolean;
|
||||
}): Promise<void>;
|
||||
export type AuthGateRow = {
|
||||
token_version: number;
|
||||
is_enabled: boolean;
|
||||
is_account_non_locked: boolean;
|
||||
is_account_non_expired: boolean;
|
||||
is_credentials_non_expired: boolean;
|
||||
deleted_at: Date | null;
|
||||
};
|
||||
/** Lightweight account gate fields for authenticated request middleware. */
|
||||
export declare function getAuthGate(userId: string): Promise<AuthGateRow | null>;
|
||||
/**
|
||||
* Updates security surveillance and withdrawal suspension flags.
|
||||
*/
|
||||
|
||||
File diff suppressed because one or more lines are too long
13
backend/dist/repositories/userRepository.js
vendored
13
backend/dist/repositories/userRepository.js
vendored
@ -49,6 +49,7 @@ exports.adminListHasActiveFilters = adminListHasActiveFilters;
|
||||
exports.listForAdmin = listForAdmin;
|
||||
exports.getForAdmin = getForAdmin;
|
||||
exports.updateAccountFlags = updateAccountFlags;
|
||||
exports.getAuthGate = getAuthGate;
|
||||
exports.updateSecurityFlags = updateSecurityFlags;
|
||||
exports.getProfileForUser = getProfileForUser;
|
||||
exports.getSelfProfileForUser = getSelfProfileForUser;
|
||||
@ -536,11 +537,23 @@ async function updateAccountFlags(userId, flags) {
|
||||
updates.push(`is_credentials_non_expired = $${i++}`);
|
||||
values.push(flags.is_credentials_non_expired);
|
||||
}
|
||||
// Disabling / locking must revoke live JWTs immediately (auth middleware checks token_version).
|
||||
const revokeSessions = flags.is_enabled === false || flags.is_account_non_locked === false;
|
||||
if (revokeSessions) {
|
||||
updates.push(`token_version = token_version + 1`);
|
||||
}
|
||||
if (updates.length === 0)
|
||||
return;
|
||||
values.push(userId);
|
||||
await (0, connection_1.query)(`UPDATE users SET ${updates.join(', ')}, updated_at = NOW() WHERE id = $${i}`, values);
|
||||
}
|
||||
/** Lightweight account gate fields for authenticated request middleware. */
|
||||
async function getAuthGate(userId) {
|
||||
const rows = await (0, connection_1.query)(`SELECT token_version, is_enabled, is_account_non_locked, is_account_non_expired,
|
||||
is_credentials_non_expired, deleted_at
|
||||
FROM users WHERE id = $1`, [userId]);
|
||||
return rows[0] ?? null;
|
||||
}
|
||||
/**
|
||||
* Updates security surveillance and withdrawal suspension flags.
|
||||
*/
|
||||
|
||||
File diff suppressed because one or more lines are too long
2
backend/dist/services/bonusService.d.ts.map
vendored
2
backend/dist/services/bonusService.d.ts.map
vendored
@ -1 +1 @@
|
||||
{"version":3,"file":"bonusService.d.ts","sourceRoot":"","sources":["../../src/services/bonusService.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,KAAK,CAAC;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAYjF;AAED,wBAAsB,mBAAmB,CAAC,KAAK,EAAE;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6BhB;AAED,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAG5D"}
|
||||
{"version":3,"file":"bonusService.d.ts","sourceRoot":"","sources":["../../src/services/bonusService.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,KAAK,CAAC;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAYjF;AAED,wBAAsB,mBAAmB,CAAC,KAAK,EAAE;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BhB;AAED,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAG5D"}
|
||||
2
backend/dist/services/bonusService.js
vendored
2
backend/dist/services/bonusService.js
vendored
@ -46,6 +46,7 @@ const walletRepository = __importStar(require("../repositories/walletRepository"
|
||||
const auditLogRepository = __importStar(require("../repositories/auditLogRepository"));
|
||||
const crypto_1 = require("crypto");
|
||||
const userAdminStatsService_1 = require("./userAdminStatsService");
|
||||
const securityService_1 = require("./securityService");
|
||||
class BonusError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
@ -67,6 +68,7 @@ async function getUserBonusBalances(userId) {
|
||||
return result;
|
||||
}
|
||||
async function transferBonusToMain(input) {
|
||||
await (0, securityService_1.assertUserCanMoveFunds)(input.userId);
|
||||
const settings = await referralRepository.getSettings();
|
||||
if (!settings.bonus_withdrawable) {
|
||||
throw new BonusError('Bonus balance cannot be transferred to main account (platform policy)');
|
||||
|
||||
2
backend/dist/services/bonusService.js.map
vendored
2
backend/dist/services/bonusService.js.map
vendored
@ -1 +1 @@
|
||||
{"version":3,"file":"bonusService.js","sourceRoot":"","sources":["../../src/services/bonusService.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBH,oDAcC;AAED,kDAiC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D,IAAI,MAAM,IAAI,EAAE;QAAE,MAAM,IAAI,UAAU,CAAC,yBAAyB,CAAC,CAAC;IAElE,MAAM,YAAY,GAAG,MAAM,gBAAgB,CAAC,uBAAuB,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IACtG,MAAM,WAAW,GAAG,MAAM,gBAAgB,CAAC,kBAAkB,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IACxG,MAAM,KAAK,GAAG,IAAA,mBAAU,GAAE,CAAC;IAE3B,MAAM,gBAAgB,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;IAChG,MAAM,gBAAgB,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;IAEhG,MAAM,kBAAkB,CAAC,MAAM,CAAC;QAC9B,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,MAAM,EAAE,2BAA2B;QACnC,YAAY,EAAE,gBAAgB;QAC9B,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,EAAE,cAAc,EAAE,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE;KAC5E,CAAC,CAAC;IACH,IAAA,kDAA0B,EAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC3C,CAAC;AAEM,KAAK,UAAU,mBAAmB;IACvC,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAC,WAAW,EAAE,CAAC;IACxD,OAAO,QAAQ,CAAC,kBAAkB,CAAC;AACrC,CAAC"}
|
||||
8
backend/dist/services/securityService.d.ts
vendored
8
backend/dist/services/securityService.d.ts
vendored
@ -9,6 +9,14 @@ export declare class SecurityBlockedError extends Error {
|
||||
readonly code: string;
|
||||
constructor(message: string, code: string);
|
||||
}
|
||||
/** Blocks API use when the account itself is disabled / locked / deleted. */
|
||||
export declare function assertAccountUsable(userId: string): Promise<void>;
|
||||
/**
|
||||
* Blocks cash-out style money movement (withdrawals, peer transfers, bonus→main)
|
||||
* when the account is under a security hold. Predictions remain allowed.
|
||||
*/
|
||||
export declare function assertUserCanMoveFunds(userId: string): Promise<void>;
|
||||
/** @deprecated Prefer assertUserCanMoveFunds — kept as a clear alias for withdrawal call sites. */
|
||||
export declare function assertUserCanWithdraw(userId: string): Promise<void>;
|
||||
export declare function suspendUserForSecurity(userId: string, reason: string, alertType: string, severity?: SecurityAlertSeverity): Promise<void>;
|
||||
export declare function raiseAlert(input: {
|
||||
|
||||
@ -1 +1 @@
|
||||
{"version":3,"file":"securityService.d.ts","sourceRoot":"","sources":["../../src/services/securityService.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,yBAAyB,MAAM,2CAA2C,CAAC;AASvF,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE1G,iEAAiE;AACjE,eAAO,MAAM,uBAAuB,aAclC,CAAC;AAEH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAK1C;AAED,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAezE;AAED,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,QAAQ,GAAE,qBAA8B,GACvC,OAAO,CAAC,IAAI,CAAC,CAiBf;AAED,wBAAsB,UAAU,CAAC,KAAK,EAAE;IACtC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,qBAAqB,CAAC;IAChC,SAAS,EA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iB,EAC3C,mBAAmB,GAAG,gBAAgB,GAAG,aAAa,GAAG,eAAe,CACzE,EACD,IAAI,EAAE,IAAI,CACR,yBAAyB,CAAC,iBAAiB,EAC3C,mBAAmB,GAAG,gBAAgB,GAAG,aAAa,GAAG,eAAe,CACzE,GACA,OAAO,CAQT;AAED,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAoHzE;AAED,wBAAsB,mBAAmB,IAAI,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAE9E;AAED,wBAAsB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAYtG;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE;IAC7C,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;;;;;;;;;;;;;;;;;GAsBA;AAED,wBAAgB,2BAA2B,IAAI,MAAM,CAEpD;AAED,qGAAqG;AACrG,wBAAsB,2BAA2B,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAsBtF"}
|
||||
53
backend/dist/services/securityService.js
vendored
53
backend/dist/services/securityService.js
vendored
@ -37,6 +37,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SecurityBlockedError = exports.AUTHORIZED_LEDGER_TYPES = void 0;
|
||||
exports.assertAccountUsable = assertAccountUsable;
|
||||
exports.assertUserCanMoveFunds = assertUserCanMoveFunds;
|
||||
exports.assertUserCanWithdraw = assertUserCanWithdraw;
|
||||
exports.suspendUserForSecurity = suspendUserForSecurity;
|
||||
exports.raiseAlert = raiseAlert;
|
||||
@ -85,17 +87,58 @@ class SecurityBlockedError extends Error {
|
||||
}
|
||||
}
|
||||
exports.SecurityBlockedError = SecurityBlockedError;
|
||||
async function assertUserCanWithdraw(userId) {
|
||||
/** Blocks API use when the account itself is disabled / locked / deleted. */
|
||||
async function assertAccountUsable(userId) {
|
||||
const user = await userRepository.findById(userId);
|
||||
if (!user)
|
||||
throw new Error('User not found');
|
||||
if (!user || user.deleted_at) {
|
||||
throw new SecurityBlockedError('Account is not available.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_enabled === false) {
|
||||
throw new SecurityBlockedError('Account is disabled.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_account_non_locked === false) {
|
||||
// Distinct from login lockout `ACCOUNT_LOCKED` (429 + retry timer).
|
||||
throw new SecurityBlockedError('Account is locked.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_account_non_expired === false) {
|
||||
throw new SecurityBlockedError('Account has expired.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_credentials_non_expired === false) {
|
||||
throw new SecurityBlockedError('Credentials have expired.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Blocks cash-out style money movement (withdrawals, peer transfers, bonus→main)
|
||||
* when the account is under a security hold. Predictions remain allowed.
|
||||
*/
|
||||
async function assertUserCanMoveFunds(userId) {
|
||||
const user = await userRepository.findById(userId);
|
||||
if (!user || user.deleted_at) {
|
||||
throw new SecurityBlockedError('Account is not available.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_enabled === false) {
|
||||
throw new SecurityBlockedError('Account is disabled.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_account_non_locked === false) {
|
||||
throw new SecurityBlockedError('Account is locked.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_account_non_expired === false) {
|
||||
throw new SecurityBlockedError('Account has expired.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_credentials_non_expired === false) {
|
||||
throw new SecurityBlockedError('Credentials have expired.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.withdrawals_suspended) {
|
||||
throw new SecurityBlockedError('Withdrawals are suspended on your account pending security review. Contact support.', 'WITHDRAWALS_SUSPENDED');
|
||||
throw new SecurityBlockedError('Outgoing funds are suspended on your account pending security review. Withdrawals and transfers are temporarily disabled. Contact support.', 'WITHDRAWALS_SUSPENDED');
|
||||
}
|
||||
if (user.under_surveillance) {
|
||||
throw new SecurityBlockedError('Your account is under security surveillance. Withdrawals are temporarily disabled. Contact support.', 'ACCOUNT_UNDER_SURVEILLANCE');
|
||||
throw new SecurityBlockedError('Your account is under security surveillance. Withdrawals and transfers are temporarily disabled. Contact support.', 'ACCOUNT_UNDER_SURVEILLANCE');
|
||||
}
|
||||
}
|
||||
/** @deprecated Prefer assertUserCanMoveFunds — kept as a clear alias for withdrawal call sites. */
|
||||
async function assertUserCanWithdraw(userId) {
|
||||
await assertUserCanMoveFunds(userId);
|
||||
}
|
||||
async function suspendUserForSecurity(userId, reason, alertType, severity = 'high') {
|
||||
await userRepository.updateSecurityFlags(userId, {
|
||||
withdrawals_suspended: true,
|
||||
|
||||
2
backend/dist/services/securityService.js.map
vendored
2
backend/dist/services/securityService.js.map
vendored
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
{"version":3,"file":"transferService.d.ts","sourceRoot":"","sources":["../../src/services/transferService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmBH;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CA8FpD"}
|
||||
{"version":3,"file":"transferService.d.ts","sourceRoot":"","sources":["../../src/services/transferService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CA+FpD"}
|
||||
2
backend/dist/services/transferService.js
vendored
2
backend/dist/services/transferService.js
vendored
@ -51,6 +51,7 @@ const walletCapabilities_1 = require("./walletCapabilities");
|
||||
const withdrawalFee_1 = require("../utils/withdrawalFee");
|
||||
const userAdminStatsService_1 = require("./userAdminStatsService");
|
||||
const walletNotificationService = __importStar(require("./walletNotificationService"));
|
||||
const securityService_1 = require("./securityService");
|
||||
/**
|
||||
* Transfers balance from one user to another identified by email.
|
||||
* Peer transfers always debit/credit the unified main ledger (USDT_TRC20).
|
||||
@ -74,6 +75,7 @@ async function requestTransfer(userId, toEmail, walletTypeCode, amountRaw, totpC
|
||||
throw new Error('Unknown wallet type');
|
||||
if (amountRaw <= 0n)
|
||||
throw new Error('Invalid amount');
|
||||
await (0, securityService_1.assertUserCanMoveFunds)(userId);
|
||||
await authService.assertWithdrawalSecondFactor(userId, totpCode);
|
||||
const toEmailHash = (0, crypto_2.hashForIndex)(toEmail.trim().toLowerCase());
|
||||
const recipient = await userRepository.findByEmailHash(toEmailHash);
|
||||
|
||||
2
backend/dist/services/transferService.js.map
vendored
2
backend/dist/services/transferService.js.map
vendored
@ -1 +1 @@
|
||||
{"version":3,"file":"transferService.js","sourceRoot":"","sources":["../../src/services/transferService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BH,0CAoGC;AAjID,mCAAoC;AACpC,4CAA+C;AAC/C,2DAA6C;AAC7C,mFAAqE;AACrE,uFAAyE;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a,EAAE,UAAU,CAAC,EAAE;KAC7B,CAAC,CAAC;IAEH,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AAC7D,CAAC"}
|
||||
{"version":3,"file":"transferService.js","sourceRoot":"","sources":["../../src/services/transferService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCH,0CAqGC;AAnID,mCAAoC;AACpC,4CAA+C;AAC/C,2DAA6C;AAC7C,mFAAqE;AACrE,uFAAyE;AACzE,6FAA+E;AAC/E,+EAAiE;AACjE,mFAAqE;AACrE,uFAAyE;AACzE,6DAAuD;AACvD,0DAGgC;AAChC,mEAAqE;AACrE,uFAAyE;AACzE,uDAA2D;AAE3D;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,eAAe,CACnC,MAAc,EACd,OAAe,EACf,cAAsB,EACtB,SAAiB,EACjB,QAAiB;IAEjB,IAAI,cAAc,KAAK,oCAAe,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,IAAI,KAAK,CACnB,+EAA+E,CACnD,CAAC;QAC/B,GAAG,CAAC,IAAI,GAAG,sBAAsB,CAAC;QAClC,MAAM,GAAG,CAAC;IACZ,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,gBAAgB,CAAC,mBAAmB,CAAC,oCAAe,CAAC,CAAC;IAC/E,IAAI,CAAC,UAAU;QAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACxD,IAAI,SAAS,IAAI,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAEvD,MAAM,IAAA,wCAAsB,EAAC,MAAM,CAAC,CAAC;IACrC,MAAM,WAAW,CAAC,4BAA4B,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEjE,MAAM,WAAW,GAAG,IAAA,qBAAY,EAAC,OAAO,CAAC,IAAI,EAAE,CAAC,WAAW,EAA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;IAEH,IAAA,kDAA0B,EAAC,MAAM,CAAC,CAAC;IACnC,IAAA,kDAA0B,EAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAEzC,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACpD,KAAK,yBAAyB,CAAC,kBAAkB,CAAC,MAAM,EAAE;QACxD,SAAS;QACT,OAAO,EAAE,cAAc;QACvB,aAAa,EAAE,QAAQ,CAAC,EAAE;KAC3B,CAAC,CAAC;IACH,KAAK,yBAAyB,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,EAAE;QAClE,SAAS;QACT,UAAU,EAAE,MAAM;QAClB,aAAa,EAAE,UAAU,CAAC,EAAE;KAC7B,CAAC,CAAC;IAEH,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AAC7D,CAAC"}
|
||||
@ -6,6 +6,7 @@ import { hasAdminAccess } from '../utils/roleAccess';
|
||||
|
||||
import * as candlePredictService from '../services/candlePredictService';
|
||||
import { TestWalletError } from '../services/testWalletService';
|
||||
import { SecurityBlockedError } from '../services/securityService';
|
||||
import { parseStakeAmountFromBody } from '../utils/stakeAmountValidation';
|
||||
import { readIdempotencyKey, sendPlaceBetResult } from '../utils/placeBetResponse';
|
||||
import {
|
||||
@ -21,7 +22,27 @@ function placeBetErrorBody(e: unknown, fallback: string): { error: string; code?
|
||||
...(e.waitLabel ? { wait: e.waitLabel } : {}),
|
||||
};
|
||||
}
|
||||
return { error: e instanceof Error ? e.message : fallback };
|
||||
if (e instanceof SecurityBlockedError) {
|
||||
return { error: e.message, code: e.code };
|
||||
}
|
||||
const code = (e as { code?: string })?.code;
|
||||
return {
|
||||
error: e instanceof Error ? e.message : fallback,
|
||||
...(typeof code === 'string' ? { code } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function placeBetHttpStatus(e: unknown): number {
|
||||
if (e instanceof SecurityBlockedError) return 403;
|
||||
const code = (e as { code?: string })?.code;
|
||||
if (
|
||||
code === 'WITHDRAWALS_SUSPENDED' ||
|
||||
code === 'ACCOUNT_UNDER_SURVEILLANCE' ||
|
||||
code === 'ACCOUNT_DISABLED'
|
||||
) {
|
||||
return 403;
|
||||
}
|
||||
return 400;
|
||||
}
|
||||
const STATE_CACHE_TTL_MS = 1200;
|
||||
const STATE_CACHE_MAX_ENTRIES = 500;
|
||||
@ -368,7 +389,7 @@ export async function placeBet(req: AuthRequest, res: Response): Promise<void> {
|
||||
userId: req.user?.userId,
|
||||
});
|
||||
|
||||
res.status(400).json(body);
|
||||
res.status(placeBetHttpStatus(e)).json(body);
|
||||
|
||||
}
|
||||
|
||||
@ -756,7 +777,7 @@ export async function placeMultiBet(req: AuthRequest, res: Response): Promise<vo
|
||||
|
||||
} catch (e) {
|
||||
|
||||
res.status(400).json(placeBetErrorBody(e, 'Failed to place multi-candle prediction'));
|
||||
res.status(placeBetHttpStatus(e)).json(placeBetErrorBody(e, 'Failed to place multi-candle prediction'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import {
|
||||
} from '../games/errors';
|
||||
import type { GameApiAction, GameModule, GameRequestContext } from '../games/types';
|
||||
import { AuthRequest } from '../middleware/auth';
|
||||
import { SecurityBlockedError } from '../services/securityService';
|
||||
import { resolveModuleBySlug } from '../services/gamePlayService';
|
||||
import { readIdempotencyKey, sendPlaceBetResult } from '../utils/placeBetResponse';
|
||||
|
||||
@ -39,8 +40,16 @@ function sendGameError(res: Response, e: unknown, fallbackStatus = 500): void {
|
||||
res.status(401).json({ error: 'Unauthorized' });
|
||||
return;
|
||||
}
|
||||
if (e instanceof SecurityBlockedError) {
|
||||
res.status(403).json({ error: e.message, code: e.code });
|
||||
return;
|
||||
}
|
||||
const msg = e instanceof Error ? e.message : 'Request failed';
|
||||
res.status(fallbackStatus).json({ error: msg });
|
||||
const code = (e as { code?: string })?.code;
|
||||
res.status(fallbackStatus).json({
|
||||
error: msg,
|
||||
...(typeof code === 'string' ? { code } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
function assertAction(mod: GameModule, action: GameApiAction): void {
|
||||
|
||||
@ -10,6 +10,7 @@ import {
|
||||
getRegularizationSnapshot,
|
||||
ReferralRegularizationError,
|
||||
} from '../services/referralRegularizationService';
|
||||
import { SecurityBlockedError } from '../services/securityService';
|
||||
|
||||
export async function getMyReferralInfo(req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
@ -67,7 +68,15 @@ export async function transferBonusToMain(req: AuthRequest, res: Response): Prom
|
||||
});
|
||||
res.json({ message: 'Bonus transferred to main account' });
|
||||
} catch (e) {
|
||||
res.status(400).json({ error: e instanceof Error ? e.message : 'Transfer failed' });
|
||||
if (e instanceof SecurityBlockedError) {
|
||||
res.status(403).json({ error: e.message, code: e.code });
|
||||
return;
|
||||
}
|
||||
const code = (e as { code?: string })?.code;
|
||||
res.status(400).json({
|
||||
error: e instanceof Error ? e.message : 'Transfer failed',
|
||||
...(typeof code === 'string' ? { code } : {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -84,18 +84,30 @@ export async function authMiddleware(req: AuthRequest, res: Response, next: Next
|
||||
const token = authHeader.slice(7);
|
||||
try {
|
||||
const payload = await verifyToken(token);
|
||||
const gate = await userRepository.getAuthGate(payload.userId);
|
||||
if (!gate || gate.deleted_at) {
|
||||
res.status(401).json({ error: 'Invalid or expired token' });
|
||||
return;
|
||||
}
|
||||
if (!config.security.skipAccessTokenVersionCheck) {
|
||||
const dbVersion = await userRepository.getTokenVersion(payload.userId);
|
||||
if (dbVersion === null) {
|
||||
res.status(401).json({ error: 'Invalid or expired token' });
|
||||
return;
|
||||
}
|
||||
const jwtVersion = payload.tv ?? 1;
|
||||
if (jwtVersion !== dbVersion) {
|
||||
if (jwtVersion !== gate.token_version) {
|
||||
res.status(401).json({ error: 'Invalid or expired token', code: 'TOKEN_REVOKED' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (gate.is_enabled === false) {
|
||||
res.status(403).json({ error: 'Account is disabled.', code: 'ACCOUNT_DISABLED' });
|
||||
return;
|
||||
}
|
||||
if (gate.is_account_non_locked === false) {
|
||||
res.status(403).json({ error: 'Account is locked.', code: 'ACCOUNT_LOCKED' });
|
||||
return;
|
||||
}
|
||||
if (gate.is_account_non_expired === false || gate.is_credentials_non_expired === false) {
|
||||
res.status(403).json({ error: 'Account is not available.', code: 'ACCOUNT_DISABLED' });
|
||||
return;
|
||||
}
|
||||
req.user = payload;
|
||||
if (payload.userId) void touchAppPresence(payload.userId);
|
||||
next();
|
||||
|
||||
@ -690,6 +690,12 @@ export async function updateAccountFlags(
|
||||
updates.push(`is_credentials_non_expired = $${i++}`);
|
||||
values.push(flags.is_credentials_non_expired);
|
||||
}
|
||||
// Disabling / locking must revoke live JWTs immediately (auth middleware checks token_version).
|
||||
const revokeSessions =
|
||||
flags.is_enabled === false || flags.is_account_non_locked === false;
|
||||
if (revokeSessions) {
|
||||
updates.push(`token_version = token_version + 1`);
|
||||
}
|
||||
if (updates.length === 0) return;
|
||||
values.push(userId);
|
||||
await query(
|
||||
@ -698,6 +704,26 @@ export async function updateAccountFlags(
|
||||
);
|
||||
}
|
||||
|
||||
export type AuthGateRow = {
|
||||
token_version: number;
|
||||
is_enabled: boolean;
|
||||
is_account_non_locked: boolean;
|
||||
is_account_non_expired: boolean;
|
||||
is_credentials_non_expired: boolean;
|
||||
deleted_at: Date | null;
|
||||
};
|
||||
|
||||
/** Lightweight account gate fields for authenticated request middleware. */
|
||||
export async function getAuthGate(userId: string): Promise<AuthGateRow | null> {
|
||||
const rows = await query<AuthGateRow[]>(
|
||||
`SELECT token_version, is_enabled, is_account_non_locked, is_account_non_expired,
|
||||
is_credentials_non_expired, deleted_at
|
||||
FROM users WHERE id = $1`,
|
||||
[userId]
|
||||
);
|
||||
return rows[0] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates security surveillance and withdrawal suspension flags.
|
||||
*/
|
||||
|
||||
@ -8,6 +8,7 @@ import * as walletRepository from '../repositories/walletRepository';
|
||||
import * as auditLogRepository from '../repositories/auditLogRepository';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { queueUserAdminStatsRefresh } from './userAdminStatsService';
|
||||
import { assertUserCanMoveFunds } from './securityService';
|
||||
|
||||
export class BonusError extends Error {
|
||||
constructor(message: string) {
|
||||
@ -37,6 +38,8 @@ export async function transferBonusToMain(input: {
|
||||
walletTypeId: number;
|
||||
amountRaw: string;
|
||||
}): Promise<void> {
|
||||
await assertUserCanMoveFunds(input.userId);
|
||||
|
||||
const settings = await referralRepository.getSettings();
|
||||
if (!settings.bonus_withdrawable) {
|
||||
throw new BonusError('Bonus balance cannot be transferred to main account (platform policy)');
|
||||
|
||||
@ -43,23 +43,67 @@ export class SecurityBlockedError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export async function assertUserCanWithdraw(userId: string): Promise<void> {
|
||||
/** Blocks API use when the account itself is disabled / locked / deleted. */
|
||||
export async function assertAccountUsable(userId: string): Promise<void> {
|
||||
const user = await userRepository.findById(userId);
|
||||
if (!user) throw new Error('User not found');
|
||||
if (!user || user.deleted_at) {
|
||||
throw new SecurityBlockedError('Account is not available.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_enabled === false) {
|
||||
throw new SecurityBlockedError('Account is disabled.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_account_non_locked === false) {
|
||||
// Distinct from login lockout `ACCOUNT_LOCKED` (429 + retry timer).
|
||||
throw new SecurityBlockedError('Account is locked.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_account_non_expired === false) {
|
||||
throw new SecurityBlockedError('Account has expired.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_credentials_non_expired === false) {
|
||||
throw new SecurityBlockedError('Credentials have expired.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocks cash-out style money movement (withdrawals, peer transfers, bonus→main)
|
||||
* when the account is under a security hold. Predictions remain allowed.
|
||||
*/
|
||||
export async function assertUserCanMoveFunds(userId: string): Promise<void> {
|
||||
const user = await userRepository.findById(userId);
|
||||
if (!user || user.deleted_at) {
|
||||
throw new SecurityBlockedError('Account is not available.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_enabled === false) {
|
||||
throw new SecurityBlockedError('Account is disabled.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_account_non_locked === false) {
|
||||
throw new SecurityBlockedError('Account is locked.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_account_non_expired === false) {
|
||||
throw new SecurityBlockedError('Account has expired.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.is_credentials_non_expired === false) {
|
||||
throw new SecurityBlockedError('Credentials have expired.', 'ACCOUNT_DISABLED');
|
||||
}
|
||||
if (user.withdrawals_suspended) {
|
||||
throw new SecurityBlockedError(
|
||||
'Withdrawals are suspended on your account pending security review. Contact support.',
|
||||
'Outgoing funds are suspended on your account pending security review. Withdrawals and transfers are temporarily disabled. Contact support.',
|
||||
'WITHDRAWALS_SUSPENDED'
|
||||
);
|
||||
}
|
||||
if (user.under_surveillance) {
|
||||
throw new SecurityBlockedError(
|
||||
'Your account is under security surveillance. Withdrawals are temporarily disabled. Contact support.',
|
||||
'Your account is under security surveillance. Withdrawals and transfers are temporarily disabled. Contact support.',
|
||||
'ACCOUNT_UNDER_SURVEILLANCE'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated Prefer assertUserCanMoveFunds — kept as a clear alias for withdrawal call sites. */
|
||||
export async function assertUserCanWithdraw(userId: string): Promise<void> {
|
||||
await assertUserCanMoveFunds(userId);
|
||||
}
|
||||
|
||||
export async function suspendUserForSecurity(
|
||||
userId: string,
|
||||
reason: string,
|
||||
|
||||
@ -19,6 +19,7 @@ import {
|
||||
} from '../utils/withdrawalFee';
|
||||
import { queueUserAdminStatsRefresh } from './userAdminStatsService';
|
||||
import * as walletNotificationService from './walletNotificationService';
|
||||
import { assertUserCanMoveFunds } from './securityService';
|
||||
|
||||
/**
|
||||
* Transfers balance from one user to another identified by email.
|
||||
@ -51,6 +52,7 @@ export async function requestTransfer(
|
||||
if (!walletType) throw new Error('Unknown wallet type');
|
||||
if (amountRaw <= 0n) throw new Error('Invalid amount');
|
||||
|
||||
await assertUserCanMoveFunds(userId);
|
||||
await authService.assertWithdrawalSecondFactor(userId, totpCode);
|
||||
|
||||
const toEmailHash = hashForIndex(toEmail.trim().toLowerCase());
|
||||
|
||||
@ -5,25 +5,28 @@ import { SecurityBlockedError } from '../services/securityService';
|
||||
import { clientErrorMessage } from '../utils/safeError';
|
||||
import { httpStatusForError } from '../utils/httpError';
|
||||
|
||||
describe('security withdrawal block errors', () => {
|
||||
test('maps suspended / surveillance to 403 with a stable code', () => {
|
||||
describe('security fund-movement block errors', () => {
|
||||
test('maps suspended / surveillance / disabled to 403 with stable codes', () => {
|
||||
const suspended = new SecurityBlockedError(
|
||||
'Withdrawals are suspended on your account pending security review. Contact support.',
|
||||
'Outgoing funds are suspended on your account pending security review.',
|
||||
'WITHDRAWALS_SUSPENDED'
|
||||
);
|
||||
const surveillance = new SecurityBlockedError(
|
||||
'Your account is under security surveillance. Withdrawals are temporarily disabled. Contact support.',
|
||||
'Your account is under security surveillance.',
|
||||
'ACCOUNT_UNDER_SURVEILLANCE'
|
||||
);
|
||||
const disabled = new SecurityBlockedError('Account is disabled.', 'ACCOUNT_DISABLED');
|
||||
assert.equal(httpStatusForError(suspended), 403);
|
||||
assert.equal(httpStatusForError(surveillance), 403);
|
||||
assert.equal(httpStatusForError(disabled), 403);
|
||||
assert.equal(suspended.code, 'WITHDRAWALS_SUSPENDED');
|
||||
assert.equal(surveillance.code, 'ACCOUNT_UNDER_SURVEILLANCE');
|
||||
assert.equal(disabled.code, 'ACCOUNT_DISABLED');
|
||||
});
|
||||
|
||||
test('exposes a clear client message (not generic Request failed)', () => {
|
||||
const err = new SecurityBlockedError(
|
||||
'Withdrawals are suspended on your account pending security review. Contact support.',
|
||||
'Outgoing funds are suspended on your account pending security review. Contact support.',
|
||||
'WITHDRAWALS_SUSPENDED'
|
||||
);
|
||||
const msg = clientErrorMessage(err, 'Request failed');
|
||||
|
||||
@ -25,7 +25,8 @@ export function httpStatusForError(error: unknown): number {
|
||||
code === 'WITHDRAWALS_DISABLED' ||
|
||||
code === 'WITHDRAWAL_NETWORK_DISABLED' ||
|
||||
code === 'WITHDRAWALS_SUSPENDED' ||
|
||||
code === 'ACCOUNT_UNDER_SURVEILLANCE'
|
||||
code === 'ACCOUNT_UNDER_SURVEILLANCE' ||
|
||||
code === 'ACCOUNT_DISABLED'
|
||||
) {
|
||||
return 403;
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ export function clientErrorMessage(error: unknown, fallback = 'Request failed'):
|
||||
'WITHDRAWAL_NETWORK_DISABLED',
|
||||
'WITHDRAWALS_SUSPENDED',
|
||||
'ACCOUNT_UNDER_SURVEILLANCE',
|
||||
'ACCOUNT_DISABLED',
|
||||
'HOT_WALLET_INSUFFICIENT_LIQUIDITY',
|
||||
'INSUFFICIENT_BALANCE',
|
||||
'DAILY_WITHDRAWAL_LIMIT_EXCEEDED',
|
||||
|
||||
@ -118,11 +118,13 @@ class AppException implements Exception {
|
||||
code: 'TRANSFER_MIN_REMAINING',
|
||||
);
|
||||
}
|
||||
if (code == 'WITHDRAWALS_SUSPENDED' || code == 'ACCOUNT_UNDER_SURVEILLANCE') {
|
||||
if (code == 'WITHDRAWALS_SUSPENDED' ||
|
||||
code == 'ACCOUNT_UNDER_SURVEILLANCE' ||
|
||||
code == 'ACCOUNT_DISABLED') {
|
||||
return AppException(
|
||||
_t(
|
||||
'Withdrawals are suspended on your account pending a security review. Please contact support for help.',
|
||||
'Les retraits sont suspendus sur votre compte en attendant une vérification de sécurité. Contactez le support pour obtenir de l’aide.',
|
||||
'Your account is under a security hold. Withdrawals and transfers are temporarily disabled. Please contact support for help.',
|
||||
'Votre compte est sous restriction de sécurité. Les retraits et transferts sont temporairement désactivés. Contactez le support pour obtenir de l’aide.',
|
||||
),
|
||||
statusCode: status,
|
||||
code: code is String ? code : 'WITHDRAWALS_SUSPENDED',
|
||||
|
||||
@ -40,6 +40,7 @@ class _TransferScreenState extends State<TransferScreen> {
|
||||
final _totpController = TextEditingController();
|
||||
bool? _totpEnabled;
|
||||
bool _requireWithdrawal2fa = true;
|
||||
bool _transfersSuspended = false;
|
||||
String _transferMinRemainingRaw = '0';
|
||||
bool _submitting = false;
|
||||
bool _confirming = false;
|
||||
@ -47,6 +48,8 @@ class _TransferScreenState extends State<TransferScreen> {
|
||||
String? _localError;
|
||||
|
||||
bool get _needs2faSetup => _requireWithdrawal2fa && _totpEnabled == false;
|
||||
bool get _formEnabled =>
|
||||
!_transfersSuspended && !_needs2faSetup && !_confirming && !_submitting;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -63,6 +66,7 @@ class _TransferScreenState extends State<TransferScreen> {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_totpEnabled = profile.totpEnabled;
|
||||
_transfersSuspended = profile.withdrawalsSuspended;
|
||||
_requireWithdrawal2fa = health.requireWithdrawal2fa;
|
||||
_transferMinRemainingRaw = health.transferMinRemainingRaw;
|
||||
_securityFailed = false;
|
||||
@ -94,6 +98,12 @@ class _TransferScreenState extends State<TransferScreen> {
|
||||
final s = context.strings;
|
||||
setState(() => _localError = null);
|
||||
|
||||
if (_transfersSuspended) {
|
||||
setState(() => _localError = s.transfersSuspendedAccount);
|
||||
showErrorSnackBar(context, s.transfersSuspendedAccount);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_needs2faSetup) {
|
||||
setState(() => _localError = s.transferTwoFaRequiredBody);
|
||||
showErrorSnackBar(context, s.transferTwoFaRequiredBody);
|
||||
@ -374,7 +384,17 @@ class _TransferScreenState extends State<TransferScreen> {
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
if (_needs2faSetup) ...[
|
||||
if (_transfersSuspended) ...[
|
||||
PredCard(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Text(
|
||||
s.transfersSuspendedAccount,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
if (_needs2faSetup && !_transfersSuspended) ...[
|
||||
PredCard(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Column(
|
||||
@ -432,7 +452,7 @@ class _TransferScreenState extends State<TransferScreen> {
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
autocorrect: false,
|
||||
enabled: !_needs2faSetup && !busy,
|
||||
enabled: _formEnabled,
|
||||
decoration: InputDecoration(
|
||||
labelText: s.emailAddressLabel,
|
||||
prefixIcon:
|
||||
@ -462,7 +482,7 @@ class _TransferScreenState extends State<TransferScreen> {
|
||||
const SizedBox(height: 14),
|
||||
TextField(
|
||||
controller: _amountController,
|
||||
enabled: !_needs2faSetup && !busy,
|
||||
enabled: _formEnabled,
|
||||
keyboardType:
|
||||
const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
@ -525,7 +545,7 @@ class _TransferScreenState extends State<TransferScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (!_needs2faSetup) ...[
|
||||
if (!_needs2faSetup && !_transfersSuspended) ...[
|
||||
const SizedBox(height: 12),
|
||||
PredCard(
|
||||
padding: const EdgeInsets.all(14),
|
||||
@ -541,7 +561,7 @@ class _TransferScreenState extends State<TransferScreen> {
|
||||
const SizedBox(height: 8),
|
||||
TextField(
|
||||
controller: _totpController,
|
||||
enabled: !busy,
|
||||
enabled: _formEnabled,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 6,
|
||||
decoration: InputDecoration(
|
||||
@ -557,7 +577,7 @@ class _TransferScreenState extends State<TransferScreen> {
|
||||
const SizedBox(height: 20),
|
||||
FilledButton(
|
||||
key: const Key('transfer_submit'),
|
||||
onPressed: busy ? null : _submitTransfer,
|
||||
onPressed: _formEnabled ? _submitTransfer : null,
|
||||
child: busy
|
||||
? const SizedBox(
|
||||
width: 22,
|
||||
|
||||
@ -346,7 +346,17 @@ class _WalletOverviewScreenState extends State<WalletOverviewScreen>
|
||||
_WalletAction(
|
||||
icon: Icons.north_east_rounded,
|
||||
label: s.send,
|
||||
onTap: () => context.push('/transfer'),
|
||||
enabled: !_withdrawalsSuspended,
|
||||
onTap: () {
|
||||
if (_withdrawalsSuspended) {
|
||||
showAppSnackBar(
|
||||
context,
|
||||
message: s.transfersSuspendedAccount,
|
||||
);
|
||||
return;
|
||||
}
|
||||
context.push('/transfer');
|
||||
},
|
||||
),
|
||||
_WalletAction(
|
||||
icon: Icons.south_west_rounded,
|
||||
|
||||
@ -297,8 +297,12 @@ class AppStrings {
|
||||
'Les retraits sont temporairement désactivés par la plateforme.',
|
||||
);
|
||||
String get withdrawalsSuspendedAccount => t(
|
||||
'Withdrawals are suspended on your account pending a security review. Please contact support for help.',
|
||||
'Les retraits sont suspendus sur votre compte en attendant une vérification de sécurité. Contactez le support pour obtenir de l’aide.',
|
||||
'Your account is under a security hold. Withdrawals and transfers are temporarily disabled. Please contact support for help.',
|
||||
'Votre compte est sous restriction de sécurité. Les retraits et transferts sont temporairement désactivés. Contactez le support pour obtenir de l’aide.',
|
||||
);
|
||||
String get transfersSuspendedAccount => t(
|
||||
'Transfers are suspended on your account pending a security review. Please contact support for help.',
|
||||
'Les transferts sont suspendus sur votre compte en attendant une vérification de sécurité. Contactez le support pour obtenir de l’aide.',
|
||||
);
|
||||
String get noWithdrawNetworks => t(
|
||||
'No withdrawal networks enabled',
|
||||
|
||||
@ -221,14 +221,28 @@ export function WalletPage() {
|
||||
>
|
||||
{t('wallet.receiveUsdt')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="outlined"
|
||||
startIcon={<SendRoundedIcon />}
|
||||
onClick={() => openDialog('transfer', USDT_WALLET_CODE)}
|
||||
sx={{ flex: 1 }}
|
||||
<Tooltip
|
||||
title={withdrawalsSuspended ? t('wallet.transferDisabledAccountSuspended') : ''}
|
||||
disableHoverListener={!withdrawalsSuspended}
|
||||
>
|
||||
{t('wallet.send')}
|
||||
</Button>
|
||||
<span style={{ flex: 1, display: 'flex' }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
startIcon={<SendRoundedIcon />}
|
||||
onClick={() => {
|
||||
if (withdrawalsSuspended) {
|
||||
setToast(t('wallet.transferDisabledAccountSuspended'));
|
||||
return;
|
||||
}
|
||||
openDialog('transfer', USDT_WALLET_CODE);
|
||||
}}
|
||||
disabled={withdrawalsSuspended}
|
||||
sx={{ flex: 1, width: '100%' }}
|
||||
>
|
||||
{t('wallet.send')}
|
||||
</Button>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip
|
||||
title={!withdrawEligibility.allowed ? withdrawBlockReasonText : ''}
|
||||
disableHoverListener={withdrawEligibility.allowed}
|
||||
|
||||
@ -19,6 +19,7 @@ import { useEffect, useMemo, useState } from 'react';
|
||||
import { Trans, useTranslation } from 'react-i18next';
|
||||
import { api } from '../../../shared/services/api';
|
||||
import { apiErrorMessage } from '../../../shared/utils/apiError';
|
||||
import { useProfile } from '../../profile/hooks/useProfile';
|
||||
import type { BalanceEntry } from '../types';
|
||||
import { USDT_TRC20_CODE } from '../utils/walletCapabilities';
|
||||
import { scaleWithdrawalFeeRaw } from '../utils/coinDisplay';
|
||||
@ -46,6 +47,7 @@ export function TransferDialog({
|
||||
}: TransferDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const qc = useQueryClient();
|
||||
const profileQ = useProfile();
|
||||
const [toEmail, setToEmail] = useState('');
|
||||
const [amount, setAmount] = useState('');
|
||||
const [totpCode, setTotpCode] = useState('');
|
||||
@ -53,6 +55,7 @@ export function TransferDialog({
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
const asset = USDT_TRC20_CODE;
|
||||
const transfersSuspended = profileQ.data?.withdrawalsSuspended === true;
|
||||
|
||||
const policyQ = useQuery({
|
||||
queryKey: ['health', 'transfer-min-remaining'],
|
||||
@ -134,6 +137,12 @@ export function TransferDialog({
|
||||
min: rawToHuman(minRemainingRaw.toString(), selected.walletType.decimals),
|
||||
})
|
||||
);
|
||||
} else if (
|
||||
err.response?.data?.code === 'WITHDRAWALS_SUSPENDED' ||
|
||||
err.response?.data?.code === 'ACCOUNT_UNDER_SURVEILLANCE' ||
|
||||
err.response?.data?.code === 'ACCOUNT_DISABLED'
|
||||
) {
|
||||
onError?.(t('wallet.transferDisabledAccountSuspended'));
|
||||
} else {
|
||||
onError?.(apiErrorMessage(err, t('common.transferFailed')));
|
||||
}
|
||||
@ -144,6 +153,7 @@ export function TransferDialog({
|
||||
};
|
||||
|
||||
const canProceed =
|
||||
!transfersSuspended &&
|
||||
!!selected &&
|
||||
toEmail.trim().length > 3 &&
|
||||
Number(amount) > 0 &&
|
||||
@ -155,6 +165,12 @@ export function TransferDialog({
|
||||
<DialogTitle sx={{ fontWeight: 900 }}>{t('wallet.transferDialog.title')}</DialogTitle>
|
||||
<DialogContent>
|
||||
<Stack spacing={2} sx={{ pt: 0.5 }}>
|
||||
{transfersSuspended && (
|
||||
<Alert severity="error" sx={{ borderRadius: 2 }}>
|
||||
{t('wallet.transferDisabledAccountSuspended')}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<Typography variant="body2" sx={{ opacity: 0.75 }}>
|
||||
{t('wallet.transferDialog.subtitle')}
|
||||
</Typography>
|
||||
@ -166,6 +182,7 @@ export function TransferDialog({
|
||||
value={toEmail}
|
||||
onChange={(e) => setToEmail(e.target.value)}
|
||||
autoComplete="email"
|
||||
disabled={transfersSuspended}
|
||||
/>
|
||||
|
||||
<Alert severity="info" sx={{ borderRadius: 2 }}>
|
||||
@ -182,6 +199,7 @@ export function TransferDialog({
|
||||
onChange={(e) => setAmount(e.target.value)}
|
||||
inputMode="decimal"
|
||||
helperText={amountHelper}
|
||||
disabled={transfersSuspended}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
@ -192,6 +210,7 @@ export function TransferDialog({
|
||||
inputMode="numeric"
|
||||
placeholder={t('wallet.transferDialog.totpPlaceholder')}
|
||||
helperText={t('wallet.transferDialog.totpRequired')}
|
||||
disabled={transfersSuspended}
|
||||
/>
|
||||
</Stack>
|
||||
</DialogContent>
|
||||
|
||||
@ -393,7 +393,9 @@ export const en = {
|
||||
withdraw: 'Withdraw',
|
||||
withdrawDisabledGlobal: 'Withdrawals are temporarily disabled by the platform.',
|
||||
withdrawDisabledAccountSuspended:
|
||||
'Withdrawals are suspended on your account pending a security review. Please contact support for help.',
|
||||
'Your account is under a security hold. Withdrawals and transfers are temporarily disabled. Please contact support for help.',
|
||||
transferDisabledAccountSuspended:
|
||||
'Transfers are suspended on your account pending a security review. Please contact support for help.',
|
||||
withdrawDisabledNoNetwork: 'No withdrawal network is enabled right now.',
|
||||
withdrawDisabledInsufficientFee:
|
||||
'Insufficient balance for a withdrawal (need more than the {{fee}} USDT network fee).',
|
||||
|
||||
@ -401,7 +401,9 @@ export const fr = {
|
||||
withdraw: 'Retirer',
|
||||
withdrawDisabledGlobal: 'Les retraits sont temporairement désactivés par la plateforme.',
|
||||
withdrawDisabledAccountSuspended:
|
||||
'Les retraits sont suspendus sur votre compte en attendant une vérification de sécurité. Contactez le support pour obtenir de l’aide.',
|
||||
'Votre compte est sous restriction de sécurité. Les retraits et transferts sont temporairement désactivés. Contactez le support pour obtenir de l’aide.',
|
||||
transferDisabledAccountSuspended:
|
||||
'Les transferts sont suspendus sur votre compte en attendant une vérification de sécurité. Contactez le support pour obtenir de l’aide.',
|
||||
withdrawDisabledNoNetwork: 'Aucun réseau de retrait n’est activé pour le moment.',
|
||||
withdrawDisabledInsufficientFee:
|
||||
'Solde insuffisant pour un retrait (il faut plus que les frais réseau de {{fee}} USDT).',
|
||||
|
||||
@ -54,6 +54,9 @@ export function apiErrorMessage(error: unknown, fallback?: string): string {
|
||||
if (data?.code === 'WITHDRAWALS_SUSPENDED' || data?.code === 'ACCOUNT_UNDER_SURVEILLANCE') {
|
||||
return i18n.t('wallet.withdrawDisabledAccountSuspended');
|
||||
}
|
||||
if (data?.code === 'ACCOUNT_DISABLED') {
|
||||
return i18n.t('wallet.withdrawDisabledAccountSuspended');
|
||||
}
|
||||
const apiMsg = data?.error ?? data?.message;
|
||||
if (typeof apiMsg === 'string' && apiMsg.trim()) {
|
||||
return sanitizeApiText(apiMsg, fb);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user