Deploy Bot commited on
Commit
2cbca83
·
1 Parent(s): a549203

Fix: Robust i18n checks in Checkout to prevent crashes

Browse files
Files changed (1) hide show
  1. src/scenes/user/checkout.js +18 -9
src/scenes/user/checkout.js CHANGED
@@ -11,7 +11,9 @@ const formatPrice = (price) => {
11
 
12
  // Common Keyboard
13
  const navKeyboard = (ctx, i18n, extras = []) => {
14
- const k = [[i18n.btn_back_nav, i18n.btn_cancel]];
 
 
15
  if (extras.length) k.unshift(...extras);
16
  return Markup.keyboard(k).resize().oneTime();
17
  };
@@ -21,13 +23,16 @@ const checkNav = (ctx) => {
21
  const text = ctx.message.text;
22
  const i18n = ctx.i18n || require('../../locales').uz;
23
 
 
 
 
24
  // Robust checking against localised strings
25
- if (text === i18n.btn_cancel || text === '❌ Bekor qilish' || text === '❌ Отмена' || text === '❌ Cancel') {
26
  ctx.scene.leave();
27
- ctx.reply(i18n.cancel_process, Markup.removeKeyboard());
28
  return 'STOP';
29
  }
30
- if (text === i18n.btn_back_nav || text === '⬅️ Ortga' || text === '⬅️ Назад' || text === '⬅️ Back') {
31
  return 'BACK';
32
  }
33
  return null;
@@ -136,15 +141,19 @@ const checkoutScene = new Scenes.WizardScene(
136
  const user = await User.findOne({ id: ctx.from.id });
137
  ctx.wizard.state.user = user;
138
 
139
- let keyboard = [[Markup.button.contactRequest(i18n.phone_button)], [i18n.btn_cancel]];
140
- let msg = i18n.phone_prompt;
 
 
 
 
141
 
142
  if (user && user.phone) {
143
- keyboard = [[i18n.checkout_phone_saved.replace('{phone}', user.phone)], [Markup.button.contactRequest(i18n.phone_button)], [i18n.btn_cancel]];
144
- msg = i18n.phone_prompt;
145
  }
146
 
147
- ctx.reply(msg, Markup.keyboard(keyboard).resize().oneTime());
148
  return ctx.wizard.next();
149
  },
150
  // Step 1: Handle Phone -> Delivery
 
11
 
12
  // Common Keyboard
13
  const navKeyboard = (ctx, i18n, extras = []) => {
14
+ const back = i18n.btn_back_nav || "⬅️ Back";
15
+ const cancel = i18n.btn_cancel || "❌ Cancel";
16
+ const k = [[back, cancel]];
17
  if (extras.length) k.unshift(...extras);
18
  return Markup.keyboard(k).resize().oneTime();
19
  };
 
23
  const text = ctx.message.text;
24
  const i18n = ctx.i18n || require('../../locales').uz;
25
 
26
+ const btnCancel = i18n.btn_cancel || "❌ Cancel";
27
+ const btnBack = i18n.btn_back_nav || "⬅️ Back";
28
+
29
  // Robust checking against localised strings
30
+ if (text === btnCancel || text === '❌ Bekor qilish' || text === '❌ Отмена' || text === '❌ Cancel') {
31
  ctx.scene.leave();
32
+ ctx.reply(i18n.cancel_process || "Cancelled", Markup.removeKeyboard());
33
  return 'STOP';
34
  }
35
+ if (text === btnBack || text === '⬅️ Ortga' || text === '⬅️ Назад' || text === '⬅️ Back') {
36
  return 'BACK';
37
  }
38
  return null;
 
141
  const user = await User.findOne({ id: ctx.from.id });
142
  ctx.wizard.state.user = user;
143
 
144
+ // Defensive i18n
145
+ const btnPhone = i18n.phone_button || "📱 Send Number";
146
+ const btnCancel = i18n.btn_cancel || "❌ Cancel";
147
+ const msgText = i18n.phone_prompt || "Send Phone";
148
+
149
+ let keyboard = [[Markup.button.contactRequest(btnPhone)], [btnCancel]];
150
 
151
  if (user && user.phone) {
152
+ const savedText = i18n.checkout_phone_saved || "📱 Saved: {phone}";
153
+ keyboard = [[savedText.replace('{phone}', user.phone)], [Markup.button.contactRequest(btnPhone)], [btnCancel]];
154
  }
155
 
156
+ ctx.reply(msgText, Markup.keyboard(keyboard).resize().oneTime());
157
  return ctx.wizard.next();
158
  },
159
  // Step 1: Handle Phone -> Delivery