@@ -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+
5058interface 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
276283const 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
309318const getOrder = async (
0 commit comments