Skip to content

Commit c664a0d

Browse files
committed
refactor: split order title i18n keys into no-amount and with-amount variants
1 parent 0e87ea9 commit c664a0d

12 files changed

Lines changed: 151 additions & 108 deletions

File tree

bot/ordersActions.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ interface BuildDescriptionArguments {
4747
currency: IFiat;
4848
}
4949

50+
interface OrderTitleArguments {
51+
user: UserDocument;
52+
type: string;
53+
amount: number;
54+
fiatCode: string;
55+
priceFromAPI: boolean;
56+
}
57+
5058
interface FiatAmountData {
5159
fiat_amount?: number;
5260
min_amount?: number;
@@ -248,14 +256,13 @@ const buildDescription = (
248256

249257
const ageInDays = getUserAge(user);
250258

251-
const firstLine = getOrderTitleMessage(
259+
const firstLine = getOrderTitleMessage(i18n, {
252260
user,
253261
type,
254262
amount,
255263
fiatCode,
256264
priceFromAPI,
257-
i18n,
258-
);
265+
});
259266

260267
let description: string = `${firstLine}\n`;
261268
description += i18n.t('for') + ` ${currencyString}\n`;
@@ -274,36 +281,38 @@ const buildDescription = (
274281
};
275282

276283
const getOrderTitleMessage = (
277-
user: UserDocument,
278-
type: string,
279-
amount: number,
280-
fiatCode: string,
281-
priceFromAPI: boolean,
282284
i18n: I18nContext,
285+
{ user, type, amount, fiatCode, priceFromAPI }: OrderTitleArguments,
283286
) => {
284287
const isSell = type === 'sell';
285288

286-
// For fixed orders we show the sats amount; for market/range orders
287-
// (priceFromAPI, amount === 0) the amount is omitted.
288-
const amountText = priceFromAPI ? '' : `${numberFormat(fiatCode, amount)} `;
289+
// Market and range orders take their price from the API and have no fixed
290+
// sats amount at creation time, so their title shows no amount.
291+
if (priceFromAPI) {
292+
if (user.show_username) {
293+
return isSell
294+
? i18n.t('showusername_selling_sats', { username: user.username })
295+
: i18n.t('showusername_buying_sats', { username: user.username });
296+
}
297+
return isSell ? i18n.t('selling_sats') : i18n.t('buying_sats');
298+
}
289299

290-
// Guard Clause: The user DOES want to show their name, we resolve and leave.
300+
// Fixed orders show the sats amount.
301+
const formattedAmount = numberFormat(fiatCode, amount);
291302
if (user.show_username) {
292303
return isSell
293-
? i18n.t('showusername_selling_sats', {
304+
? i18n.t('showusername_selling_sats_with_amount', {
294305
username: user.username,
295-
amount: amountText,
306+
amount: formattedAmount,
296307
})
297-
: i18n.t('showusername_buying_sats', {
308+
: i18n.t('showusername_buying_sats_with_amount', {
298309
username: user.username,
299-
amount: amountText,
310+
amount: formattedAmount,
300311
});
301312
}
302-
303-
// The user DOES NOT want to show their name.
304313
return isSell
305-
? i18n.t('selling_sats', { amount: amountText })
306-
: i18n.t('buying_sats', { amount: amountText });
314+
? i18n.t('selling_sats_with_amount', { amount: formattedAmount })
315+
: i18n.t('buying_sats_with_amount', { amount: formattedAmount });
307316
};
308317

309318
const getOrder = async (

locales/de.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,15 @@ pending_payment_failed_to_admin: |
452452
Zahlungsversuche: ${attempts}
453453
selling: Verkaufe
454454
buying: Kaufe
455-
selling_sats: 'Verkaufe ${amount}Sats'
456-
buying_sats: 'Kaufe ${amount}Sats'
455+
selling_sats: Verkaufe Sats
456+
selling_sats_with_amount: 'Verkaufe ${amount} Sats'
457+
buying_sats: Kaufe Sats
458+
buying_sats_with_amount: 'Kaufe ${amount} Sats'
457459
receive_payment: Zahlung erhalten
458-
showusername_buying_sats: '@${username} kauft ${amount}Sats'
459-
showusername_selling_sats: '@${username} verkauft ${amount}Sats'
460+
showusername_buying_sats: '@${username} kauft Sats'
461+
showusername_buying_sats_with_amount: '@${username} kauft ${amount} Sats'
462+
showusername_selling_sats: '@${username} verkauft Sats'
463+
showusername_selling_sats_with_amount: '@${username} verkauft ${amount} Sats'
460464
pay: Bezahlen
461465
is: ist
462466
trading_volume: 'Handelsvolumen: ${Volumen} Sats'

locales/en.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,14 @@ pending_payment_failed_to_admin: |
459459
Payment attempts: ${attempts}
460460
selling: Selling
461461
buying: Buying
462-
selling_sats: 'Selling ${amount}sats'
463-
buying_sats: 'Buying ${amount}sats'
464-
showusername_selling_sats: '@${username} is selling ${amount}sats'
465-
showusername_buying_sats: '@${username} is buying ${amount}sats'
462+
selling_sats: Selling sats
463+
selling_sats_with_amount: 'Selling ${amount} sats'
464+
buying_sats: Buying sats
465+
buying_sats_with_amount: 'Buying ${amount} sats'
466+
showusername_selling_sats: '@${username} is selling sats'
467+
showusername_selling_sats_with_amount: '@${username} is selling ${amount} sats'
468+
showusername_buying_sats: '@${username} is buying sats'
469+
showusername_buying_sats_with_amount: '@${username} is buying ${amount} sats'
466470
receive_payment: Receive payment
467471
pay: Pay
468472
is: is

locales/es.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,14 @@ pending_payment_failed_to_admin: |
454454
Intento de pago: ${attempts}
455455
selling: Vendiendo
456456
buying: Comprando
457-
selling_sats: 'Vendiendo ${amount}sats'
458-
buying_sats: 'Comprando ${amount}sats'
459-
showusername_buying_sats: '@${username} está comprando ${amount}sats'
460-
showusername_selling_sats: '@${username} está vendiendo ${amount}sats'
457+
selling_sats: Vendiendo sats
458+
selling_sats_with_amount: 'Vendiendo ${amount} sats'
459+
buying_sats: Comprando sats
460+
buying_sats_with_amount: 'Comprando ${amount} sats'
461+
showusername_buying_sats: '@${username} está comprando sats'
462+
showusername_buying_sats_with_amount: '@${username} está comprando ${amount} sats'
463+
showusername_selling_sats: '@${username} está vendiendo sats'
464+
showusername_selling_sats_with_amount: '@${username} está vendiendo ${amount} sats'
461465
receive_payment: Recibo pago
462466
pay: Pago
463467
is: está

locales/fa.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,18 @@ pending_payment_failed_to_admin: |
535535
تعداد تلاش‌های پرداخت: ${attempts}
536536
selling: فروختن
537537
buying: خریدن
538-
selling_sats: 'فروش ${amount}ساتوشی'
539-
buying_sats: 'خرید ${amount}ساتوشی'
538+
selling_sats: فروش ساتوشی
539+
selling_sats_with_amount: 'فروش ${amount} ساتوشی'
540+
buying_sats: خرید ساتوشی
541+
buying_sats_with_amount: 'خرید ${amount} ساتوشی'
540542
receive_payment: دریافت وجه
541543
pay: پرداخت
542544
is: هست
543545
trading_volume: 'حجم معاملات: ${volume} sat'
544-
showusername_buying_sats: '@${username} در حال خرید ${amount}ساتوشی است'
545-
showusername_selling_sats: '@${username} در حال فروش ${amount}ساتوشی است'
546+
showusername_buying_sats: '@${username} در حال خرید ساتوشی است'
547+
showusername_buying_sats_with_amount: '@${username} در حال خرید ${amount} ساتوشی است'
548+
showusername_selling_sats: '@${username} در حال فروش ساتوشی است'
549+
showusername_selling_sats_with_amount: '@${username} در حال فروش ${amount} ساتوشی است'
546550
satoshis: ساتوشی‌ها
547551
by: توسط
548552
rate: نرخ

locales/fr.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,15 @@ pending_payment_failed_to_admin: |
451451
Tentatives de paiement : ${attempts}
452452
selling: Vente
453453
buying: Achat
454-
selling_sats: 'Vente de ${amount}sats'
455-
buying_sats: 'Achat de ${amount}sats'
454+
selling_sats: Vente de sats
455+
selling_sats_with_amount: 'Vente de ${amount} sats'
456+
buying_sats: Achat de sats
457+
buying_sats_with_amount: 'Achat de ${amount} sats'
456458
receive_payment: Réception du paiement
457-
showusername_buying_sats: "@${username} achète ${amount}sats"
458-
showusername_selling_sats: "@${username} vend ${amount}sats"
459+
showusername_buying_sats: "@${username} achète des sats"
460+
showusername_buying_sats_with_amount: "@${username} achète ${amount} sats"
461+
showusername_selling_sats: "@${username} vend des sats"
462+
showusername_selling_sats_with_amount: "@${username} vend ${amount} sats"
459463
pay: Payer
460464
is: est
461465
trading_volume: 'Volume de transactions : ${volume} sats'

locales/it.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,18 @@ pending_payment_failed_to_admin: |
449449
Payment attempts: ${attempts}
450450
selling: Vendita
451451
buying: Acquisto
452-
selling_sats: 'Vendita ${amount}sats'
453-
buying_sats: 'Acquisto ${amount}sats'
452+
selling_sats: Vendita sats
453+
selling_sats_with_amount: 'Vendita ${amount} sats'
454+
buying_sats: Acquisto sats
455+
buying_sats_with_amount: 'Acquisto ${amount} sats'
454456
receive_payment: Ricezione del pagamento
455457
pay: Paga
456458
is: è
457459
trading_volume: 'Volume scambio: ${volume} sats'
458-
showusername_buying_sats: '@${username} sta comprando ${amount}sats'
459-
showusername_selling_sats: '@${username} sta vendendo ${amount}sats'
460+
showusername_buying_sats: '@${username} sta comprando sats'
461+
showusername_buying_sats_with_amount: '@${username} sta comprando ${amount} sats'
462+
showusername_selling_sats: '@${username} sta vendendo sats'
463+
showusername_selling_sats_with_amount: '@${username} sta vendendo ${amount} sats'
460464
satoshis: satoshi
461465
by: da
462466
rate: Valutazione

locales/ko.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,18 @@ pending_payment_failed_to_admin: |
449449
450450
selling: 팝니다
451451
buying: 삽니다
452-
selling_sats: '${amount}sats 판매'
453-
buying_sats: '${amount}sats 구매'
452+
selling_sats: sats 판매
453+
selling_sats_with_amount: '${amount} sats 판매'
454+
buying_sats: sats 구매
455+
buying_sats_with_amount: '${amount} sats 구매'
454456
receive_payment: 입금
455457
pay: 결제
456458
is: is
457459
trading_volume: '거래량: ${volume} sats'
458-
showusername_buying_sats: '@${username} 님이 ${amount}sats를 구매합니다'
459-
showusername_selling_sats: '@${username} 님이 ${amount}sats를 판매합니다'
460+
showusername_buying_sats: '@${username} 님이 sats를 구매합니다'
461+
showusername_buying_sats_with_amount: '@${username} 님이 ${amount} sats를 구매합니다'
462+
showusername_selling_sats: '@${username} 님이 sats를 판매합니다'
463+
showusername_selling_sats_with_amount: '@${username} 님이 ${amount} sats를 판매합니다'
460464
satoshis: 사토시
461465
by: 방법 -
462466
rate: 환율

locales/pt.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,16 @@ pending_payment_failed_to_admin: |
451451
Tentativas de pagamento: ${attempts}
452452
selling: Vendendo
453453
buying: Comprando
454-
selling_sats: 'Vendendo ${amount}sats'
455-
buying_sats: 'Comprando ${amount}sats'
454+
selling_sats: Vendendo sats
455+
selling_sats_with_amount: 'Vendendo ${amount} sats'
456+
buying_sats: Comprando sats
457+
buying_sats_with_amount: 'Comprando ${amount} sats'
456458
receive_payment: Receber pagamento
457459
pay: Pagar
458-
showusername_buying_sats: '@${username} está comprando ${amount}sats'
459-
showusername_selling_sats: '@${username} está vendendo ${amount}sats'
460+
showusername_buying_sats: '@${username} está comprando sats'
461+
showusername_buying_sats_with_amount: '@${username} está comprando ${amount} sats'
462+
showusername_selling_sats: '@${username} está vendendo sats'
463+
showusername_selling_sats_with_amount: '@${username} está vendendo ${amount} sats'
460464
is: é
461465
trading_volume: 'Volume de negócios: ${volume} sats'
462466
satoshis: satoshis

locales/ru.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,15 @@ pending_payment_failed_to_admin: |
452452
Попытка оплаты: ${attempts}
453453
selling: Продаю
454454
buying: Покупаю
455-
selling_sats: 'Продажа ${amount}сат'
456-
buying_sats: 'Покупка ${amount}сат'
455+
selling_sats: Продажа сат
456+
selling_sats_with_amount: 'Продажа ${amount} сат'
457+
buying_sats: Покупка сат
458+
buying_sats_with_amount: 'Покупка ${amount} сат'
457459
receive_payment: Расчет
458-
showusername_buying_sats: '@${username} покупает ${amount}саты'
459-
showusername_selling_sats: '@${username} продает ${amount}саты'
460+
showusername_buying_sats: '@${username} покупает саты'
461+
showusername_buying_sats_with_amount: '@${username} покупает ${amount} саты'
462+
showusername_selling_sats: '@${username} продает саты'
463+
showusername_selling_sats_with_amount: '@${username} продает ${amount} саты'
460464
pay: Расчет
461465
is: Я
462466
trading_volume: 'Обьем торгов: ${volume} сат'

0 commit comments

Comments
 (0)