nexushub-commands 2.5.7 → 2.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -252,21 +252,102 @@ tslib_1.__decorate([
252
252
  tslib_1.__param(3, (0, evogram_1.CommandArgument)({
253
253
  name: 'deposit',
254
254
  question: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ context, error, args, validateArgs }) {
255
- var _b, _c;
255
+ var _b, _c, _d, _e;
256
256
  const config = Client_1.Client.config(context);
257
+ const availableMyRequisites = (yield config.API.get('/myrequisites')).data;
258
+ const maxDeposit1 = Number((_c = (_b = availableMyRequisites === null || availableMyRequisites === void 0 ? void 0 : availableMyRequisites.sort((a, b) => a.maxAmount - b.maxAmount)) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.maxAmount);
259
+ const maxDeposit2 = Number(yield config.API.get('/config/maxDepositInService').then((x) => x.data.value));
260
+ const maxDeposit = Number(yield (maxDeposit1 > maxDeposit2 ? maxDeposit1 : maxDeposit2).convert({ from: 'RUB', to: config.currency }));
257
261
  let minAmountSetting = JSON.parse(context.state.settings.find((x) => x.name === 'minDeposit').value);
258
- let minAmount = (_b = minAmountSetting[config.currency]) !== null && _b !== void 0 ? _b : (yield minAmountSetting['RUB'].convert({ from: 'RUB', to: config.currency }));
262
+ let minAmount = (_d = minAmountSetting[config.currency]) !== null && _d !== void 0 ? _d : (yield minAmountSetting['RUB'].convert({ from: 'RUB', to: config.currency }));
259
263
  const minDepositByMethod = yield config.API.get('/config/minDepositByMethod').then((x) => x.data.value);
260
264
  // prettier-ignore
261
265
  if (minDepositByMethod && minDepositByMethod[args.method] !== undefined && (yield minAmount.convert({ from: config.currency, to: 'RUB' })) < minDepositByMethod[args.method])
262
266
  minAmount = yield minDepositByMethod[args.method].convert({ from: 'RUB', to: config.currency });
263
267
  validateArgs.minAmount = minAmount;
268
+ // Функция для красивого округления суммы
269
+ const roundToNiceNumber = (amount) => {
270
+ if (amount <= 0)
271
+ return amount;
272
+ const magnitude = Math.pow(10, Math.floor(Math.log10(amount)));
273
+ const normalized = amount / magnitude;
274
+ let multiplier;
275
+ if (normalized <= 1.5)
276
+ multiplier = 1;
277
+ else if (normalized <= 3)
278
+ multiplier = 2;
279
+ else if (normalized <= 7)
280
+ multiplier = 5;
281
+ else
282
+ multiplier = 10;
283
+ return Math.round((amount / (magnitude * multiplier)) * (magnitude * multiplier));
284
+ };
285
+ // Генерация промежуточных сумм
286
+ const min = Number(minAmount);
287
+ const max = Number(maxDeposit);
288
+ const amounts = [];
289
+ if (max <= min) {
290
+ // Если максимум не больше минимума, показываем только минимум
291
+ amounts.push(min);
292
+ }
293
+ else {
294
+ // Добавляем минимум
295
+ amounts.push(Math.ceil(min));
296
+ // Вычисляем 4 промежуточные суммы
297
+ const range = max - min;
298
+ const step = range / 5;
299
+ const intermediateAmounts = new Set();
300
+ for (let i = 1; i < 5; i++) {
301
+ const rawAmount = min + step * i;
302
+ const rounded = roundToNiceNumber(rawAmount);
303
+ // Ограничиваем между min и max
304
+ const finalAmount = Math.max(min + 1, Math.min(max - 1, rounded));
305
+ if (finalAmount > min && finalAmount < max) {
306
+ intermediateAmounts.add(finalAmount);
307
+ }
308
+ }
309
+ // Добавляем промежуточные суммы, убирая дубликаты
310
+ const sortedIntermediate = Array.from(intermediateAmounts).sort((a, b) => a - b);
311
+ amounts.push(...sortedIntermediate);
312
+ // Добавляем максимум
313
+ if (max > amounts[amounts.length - 1])
314
+ amounts.push(Math.ceil(max));
315
+ // Ограничиваем до 6 сумм максимум
316
+ if (amounts.length > 6) {
317
+ // Берем минимум, максимум и равномерно распределенные промежуточные
318
+ const keepIndices = [0]; // минимум
319
+ const step = (amounts.length - 1) / 4;
320
+ for (let i = 1; i < 5; i++) {
321
+ const idx = Math.round(step * i);
322
+ if (idx < amounts.length - 1)
323
+ keepIndices.push(idx);
324
+ }
325
+ keepIndices.push(amounts.length - 1); // максимум
326
+ const filtered = keepIndices.map((idx) => amounts[idx]).filter((val, idx, arr) => idx === 0 || val !== arr[idx - 1]);
327
+ amounts.length = 0;
328
+ amounts.push(...filtered);
329
+ }
330
+ }
331
+ // Создаем кнопки (6 кнопок в два ряда по 3)
332
+ const buttons = amounts.map((amount) => ({
333
+ text: `${Number(amount).toLocaleString('ru')} ${config.currency}`,
334
+ command: DepositCommand,
335
+ payload: Object.assign(Object.assign({}, args), { deposit: amount }),
336
+ }));
337
+ const keyboard = [
338
+ buttons.slice(0, 3), // Первый ряд
339
+ buttons.slice(3, 6), // Второй ряд
340
+ ].filter((row) => row.length > 0); // Убираем пустые ряды
264
341
  return (yield context.sendFormattedQuestion({
265
342
  //@ts-ignore
266
- designImages: { card: ['deposit-card', 'deposit'], cryptoWallet: [`deposit-crypto-${(_c = args.crypto) === null || _c === void 0 ? void 0 : _c.toLowerCase()}`, 'deposit-crypto-wallet', 'deposit-crypto', 'deposit'], cryptoBot: ['deposit-crypto-bot', 'deposit-crypto', 'deposit'] }[args.method],
343
+ designImages: { card: ['deposit-card', 'deposit'], cryptoWallet: [`deposit-crypto-${(_e = args.crypto) === null || _e === void 0 ? void 0 : _e.toLowerCase()}`, 'deposit-crypto-wallet', 'deposit-crypto', 'deposit'], cryptoBot: ['deposit-crypto-bot', 'deposit-crypto', 'deposit'] }[args.method],
267
344
  photo: ['card', 'qrcode'].includes(args.method) ? config.images.deposit : config.images.depositCrypto,
268
345
  header: `<blockquote><b>${['card', 'qrcode'].includes(args.method) ? '📤' : '🪙'} Пополнение баланса</b></blockquote>\n\n<i>Введите сумму пополнения, минимальная сумма: {{ ${Number(minAmount).toLocaleString('ru')} ${config.currency} }}</i>`,
269
346
  error: error === null || error === void 0 ? void 0 : error.message,
347
+ }, {
348
+ reply_markup: {
349
+ inline_keyboard: keyboard,
350
+ },
270
351
  })).text;
271
352
  }),
272
353
  }, (0, evogram_1.numberValidator)({ allowFloat: true, min: 0 }), (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ value, context, validateArgs }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexushub-commands",
3
- "version": "2.5.7",
3
+ "version": "2.5.9",
4
4
  "main": "./lib/index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -134,6 +134,12 @@ export class DepositCommand extends Command {
134
134
  question: async ({ context, error, args, validateArgs }) => {
135
135
  const config = Client.config(context)
136
136
 
137
+ const availableMyRequisites = (await config.API.get('/myrequisites')).data
138
+
139
+ const maxDeposit1 = Number(availableMyRequisites?.sort((a: any, b: any) => a.maxAmount - b.maxAmount)?.[0]?.maxAmount)
140
+ const maxDeposit2 = Number(await config.API.get('/config/maxDepositInService').then((x) => x.data.value))
141
+ const maxDeposit = Number(await (maxDeposit1 > maxDeposit2 ? maxDeposit1 : maxDeposit2).convert({ from: 'RUB', to: config.currency }))
142
+
137
143
  let minAmountSetting = JSON.parse(context.state.settings.find((x: any) => x.name === 'minDeposit').value)
138
144
  let minAmount = minAmountSetting[config.currency] ?? (await minAmountSetting['RUB'].convert({ from: 'RUB', to: config.currency }))
139
145
 
@@ -143,14 +149,102 @@ export class DepositCommand extends Command {
143
149
  minAmount = await minDepositByMethod[args.method].convert({ from: 'RUB', to: config.currency });
144
150
 
145
151
  validateArgs.minAmount = minAmount
152
+
153
+ // Функция для красивого округления суммы
154
+ const roundToNiceNumber = (amount: number): number => {
155
+ if (amount <= 0) return amount
156
+
157
+ const magnitude = Math.pow(10, Math.floor(Math.log10(amount)))
158
+ const normalized = amount / magnitude
159
+
160
+ let multiplier: number
161
+ if (normalized <= 1.5) multiplier = 1
162
+ else if (normalized <= 3) multiplier = 2
163
+ else if (normalized <= 7) multiplier = 5
164
+ else multiplier = 10
165
+
166
+ return Math.round((amount / (magnitude * multiplier)) * (magnitude * multiplier))
167
+ }
168
+
169
+ // Генерация промежуточных сумм
170
+ const min = Number(minAmount)
171
+ const max = Number(maxDeposit)
172
+ const amounts: number[] = []
173
+
174
+ if (max <= min) {
175
+ // Если максимум не больше минимума, показываем только минимум
176
+ amounts.push(min)
177
+ } else {
178
+ // Добавляем минимум
179
+ amounts.push(Math.ceil(min))
180
+
181
+ // Вычисляем 4 промежуточные суммы
182
+ const range = max - min
183
+ const step = range / 5
184
+
185
+ const intermediateAmounts = new Set<number>()
186
+
187
+ for (let i = 1; i < 5; i++) {
188
+ const rawAmount = min + step * i
189
+ const rounded = roundToNiceNumber(rawAmount)
190
+ // Ограничиваем между min и max
191
+ const finalAmount = Math.max(min + 1, Math.min(max - 1, rounded))
192
+ if (finalAmount > min && finalAmount < max) {
193
+ intermediateAmounts.add(finalAmount)
194
+ }
195
+ }
196
+
197
+ // Добавляем промежуточные суммы, убирая дубликаты
198
+ const sortedIntermediate = Array.from(intermediateAmounts).sort((a, b) => a - b)
199
+ amounts.push(...sortedIntermediate)
200
+
201
+ // Добавляем максимум
202
+ if (max > amounts[amounts.length - 1]) amounts.push(Math.ceil(max))
203
+
204
+ // Ограничиваем до 6 сумм максимум
205
+ if (amounts.length > 6) {
206
+ // Берем минимум, максимум и равномерно распределенные промежуточные
207
+ const keepIndices = [0] // минимум
208
+ const step = (amounts.length - 1) / 4
209
+ for (let i = 1; i < 5; i++) {
210
+ const idx = Math.round(step * i)
211
+ if (idx < amounts.length - 1) keepIndices.push(idx)
212
+ }
213
+ keepIndices.push(amounts.length - 1) // максимум
214
+
215
+ const filtered = keepIndices.map((idx) => amounts[idx]).filter((val, idx, arr) => idx === 0 || val !== arr[idx - 1])
216
+ amounts.length = 0
217
+ amounts.push(...filtered)
218
+ }
219
+ }
220
+
221
+ // Создаем кнопки (6 кнопок в два ряда по 3)
222
+ const buttons = amounts.map((amount) => ({
223
+ text: `${Number(amount).toLocaleString('ru')} ${config.currency}`,
224
+ command: DepositCommand,
225
+ payload: { ...args, deposit: amount },
226
+ }))
227
+
228
+ const keyboard = [
229
+ buttons.slice(0, 3), // Первый ряд
230
+ buttons.slice(3, 6), // Второй ряд
231
+ ].filter((row) => row.length > 0) // Убираем пустые ряды
232
+
146
233
  return (
147
- await context.sendFormattedQuestion({
148
- //@ts-ignore
149
- designImages: { card: ['deposit-card', 'deposit'], cryptoWallet: [`deposit-crypto-${args.crypto?.toLowerCase()}`, 'deposit-crypto-wallet', 'deposit-crypto', 'deposit'], cryptoBot: ['deposit-crypto-bot', 'deposit-crypto', 'deposit'] }[args.method],
150
- photo: ['card', 'qrcode'].includes(args.method) ? config.images.deposit : config.images.depositCrypto,
151
- header: `<blockquote><b>${['card', 'qrcode'].includes(args.method) ? '📤' : '🪙'} Пополнение баланса</b></blockquote>\n\n<i>Введите сумму пополнения, минимальная сумма: {{ ${Number(minAmount).toLocaleString('ru')} ${config.currency} }}</i>`,
152
- error: error?.message,
153
- })
234
+ await context.sendFormattedQuestion(
235
+ {
236
+ //@ts-ignore
237
+ designImages: { card: ['deposit-card', 'deposit'], cryptoWallet: [`deposit-crypto-${args.crypto?.toLowerCase()}`, 'deposit-crypto-wallet', 'deposit-crypto', 'deposit'], cryptoBot: ['deposit-crypto-bot', 'deposit-crypto', 'deposit'] }[args.method],
238
+ photo: ['card', 'qrcode'].includes(args.method) ? config.images.deposit : config.images.depositCrypto,
239
+ header: `<blockquote><b>${['card', 'qrcode'].includes(args.method) ? '📤' : '🪙'} Пополнение баланса</b></blockquote>\n\n<i>Введите сумму пополнения, минимальная сумма: {{ ${Number(minAmount).toLocaleString('ru')} ${config.currency} }}</i>`,
240
+ error: error?.message,
241
+ },
242
+ {
243
+ reply_markup: {
244
+ inline_keyboard: keyboard,
245
+ },
246
+ }
247
+ )
154
248
  ).text
155
249
  },
156
250
  },