@@ -339,7 +339,7 @@ private final class InputView : GeneralRowView {
339339 transition. updateFrame ( view: inputView, frame: CGRect ( origin: CGPoint ( x: starView. frame. maxX + 10 , y: 7 ) , size: textSize) )
340340 inputView. updateLayout ( size: textSize, textHeight: textHeight, transition: transition)
341341
342- transition . updateFrame ( view: usdView, frame: usdView. centerFrameY ( x: size. width - usdView. frame. width - 10 ) )
342+ ContainedViewLayoutTransition . immediate . updateFrame ( view: usdView, frame: usdView. centerFrameY ( x: size. width - usdView. frame. width - 10 ) )
343343 }
344344
345345 private func set( _ state: Updated_ChatTextInputState ) {
@@ -415,7 +415,8 @@ private final class Arguments {
415415}
416416
417417private struct State : Equatable {
418- var amount : Int64 = 0
418+ var starAmount : Int64 = 0
419+ var tonAmount : Int64 = 0
419420 var currency : CurrencyAmount . Currency
420421 var inputState : Updated_ChatTextInputState = . init( )
421422 var date : Int32 ?
@@ -433,13 +434,31 @@ private struct State : Equatable {
433434 }
434435 }
435436
437+ var amount : Int64 {
438+ get {
439+ switch currency {
440+ case . stars:
441+ return starAmount
442+ case . ton:
443+ return tonAmount
444+ }
445+ }
446+ set {
447+ switch currency {
448+ case . stars:
449+ starAmount = newValue
450+ case . ton:
451+ tonAmount = newValue
452+ }
453+ }
454+ }
436455
437456 var starsAmount : StarsAmount {
438457 switch currency {
439458 case . stars:
440- return . init( value: amount , nanos: 0 )
459+ return . init( value: starAmount , nanos: 0 )
441460 case . ton:
442- return . init( value: amount * 1_000_000_000 , nanos: 0 )
461+ return . init( value: tonAmount * 1_000_000_000 , nanos: 0 )
443462 }
444463 }
445464
@@ -456,9 +475,7 @@ private struct State : Equatable {
456475 case . edit, . suggest:
457476 return strings ( ) . editPostSuggestionActionUpdate
458477 case . new:
459- return amount == 0 ?
460- strings ( ) . editPostSuggestionActionFree :
461- strings ( ) . editPostSuggestionActionOffer ( currencyAmount. fullyFormatted)
478+ return strings ( ) . editPostSuggestionActionOffer ( currencyAmount. fullyFormatted)
462479 }
463480 }
464481}
@@ -553,12 +570,29 @@ func EditPostSuggestionController(chatInteraction: ChatInteraction, data: ChatIn
553570 let actionsDisposable = DisposableSet ( )
554571
555572 let min_stars = context. appConfiguration. getGeneralValue64 ( " stars_suggested_post_amount_min " , orElse: 5 )
556- let min_ton = context. appConfiguration. getGeneralValue64 ( " ton_suggested_post_amount_min " , orElse: 1_000_000_000 ) / 1_000_000_000
573+ let min_ton = max ( 1 , context. appConfiguration. getGeneralValue64 ( " ton_suggested_post_amount_min " , orElse: 1_000_000_000 ) / 1_000_000_000 )
557574
558575
559576 let amount = data. amount ?? . init( amount: . init( value: min_stars, nanos: 0 ) , currency: . stars)
560577
561- let initialState = State ( amount: Int64 ( amount. formatted) ?? 0 , currency: amount. currency, inputState: . init( inputText: . initialize( string: " \( amount. formatted) " ) ) , date: data. date, mode: data. mode)
578+ let starAmount : Int64
579+ let tonAmount : Int64
580+
581+ if let currency = data. amount {
582+ switch currency. currency {
583+ case . stars:
584+ starAmount = Int64 ( currency. formatted) ?? 0
585+ tonAmount = min_ton
586+ case . ton:
587+ tonAmount = Int64 ( currency. formatted) ?? 0
588+ starAmount = min_stars
589+ }
590+ } else {
591+ starAmount = min_stars
592+ tonAmount = min_ton
593+ }
594+
595+ let initialState = State ( starAmount: starAmount, tonAmount: tonAmount, currency: amount. currency, inputState: . init( inputText: . initialize( string: " \( amount. formatted) " ) ) , date: data. date, mode: data. mode)
562596
563597 let statePromise = ValuePromise ( initialState, ignoreRepeated: true )
564598 let stateValue = Atomic ( value: initialState)
@@ -659,12 +693,20 @@ func EditPostSuggestionController(chatInteraction: ChatInteraction, data: ChatIn
659693 return current
660694 }
661695 } ) , for: context. window)
662- } , currency: { value in
696+ } , currency: { [ weak interactions ] value in
663697 updateState { current in
664698 var current = current
665699 current. currency = value
666700 return current
667701 }
702+ let amount = stateValue. with { $0. amount }
703+ let value = Updated_ChatTextInputState ( inputText: . initialize( string: " \( amount) " ) )
704+
705+ DispatchQueue . main. async {
706+ interactions? . update { _ in
707+ return value
708+ }
709+ }
668710 } )
669711
670712 let signal = statePromise. get ( ) |> deliverOnPrepareQueue |> map { state in
0 commit comments