Skip to content

Commit ef3b593

Browse files
author
Isaac
committed
Fix ref duration
1 parent 7eed291 commit ef3b593

File tree

5 files changed

+69
-55
lines changed

5 files changed

+69
-55
lines changed

submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,18 @@ func _internal_removeChatManagingBot(account: Account, chatId: EnginePeer.Id) ->
589589
}
590590
}
591591

592+
public func formatPermille(_ value: Int32) -> String {
593+
return formatPermille(Int(value))
594+
}
595+
596+
public func formatPermille(_ value: Int) -> String {
597+
if value % 10 == 0 {
598+
return "\(value / 10)"
599+
} else {
600+
return String(format: "%.1f", Double(value) / 10.0)
601+
}
602+
}
603+
592604
func _internal_updateStarRefProgram(account: Account, id: EnginePeer.Id, program: (commissionPermille: Int32, durationMonths: Int32?)?) -> Signal<Never, NoError> {
593605
return account.postbox.transaction { transaction -> Api.InputUser? in
594606
return transaction.getPeer(id).flatMap(apiInputUser)

submodules/TelegramUI/Components/PeerInfo/AffiliateProgramSetupScreen/Sources/AffiliateProgramSetupScreen.swift

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ final class AffiliateProgramSetupScreenComponent: Component {
176176
let programPermille: Int32 = Int32(self.commissionPermille)
177177
let programDuration: Int32? = self.durationValue == Int(Int32.max) ? nil : Int32(self.durationValue)
178178

179-
let commissionTitle: String = "\(programPermille / 10)%"
179+
let commissionTitle: String = "\(formatPermille(programPermille))%"
180180
let durationTitle: String
181181
if let durationMonths = programDuration {
182-
durationTitle = timeIntervalString(strings: environment.strings, value: durationMonths * (24 * 60 * 60))
182+
durationTitle = timeIntervalString(strings: environment.strings, value: durationMonths * (30 * 24 * 60 * 60))
183183
} else {
184184
durationTitle = "Lifetime"
185185
}
@@ -378,7 +378,7 @@ If you end your affiliate program:
378378
}
379379
UIPasteboard.general.string = bot.url
380380
let presentationData = component.context.sharedContext.currentPresentationData.with({ $0 })
381-
self.environment?.controller()?.present(UndoOverlayController(presentationData: presentationData, content: .linkCopied(title: "Link copied to clipboard", text: "Share this link and earn **\(bot.commissionPermille / 10)%** of what people who use it spend in **\(bot.peer.compactDisplayTitle)**!"), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), in: .current)
381+
self.environment?.controller()?.present(UndoOverlayController(presentationData: presentationData, content: .linkCopied(title: "Link copied to clipboard", text: "Share this link and earn **\(formatPermille(bot.commissionPermille))%** of what people who use it spend in **\(bot.peer.compactDisplayTitle)**!"), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), in: .current)
382382
}
383383
))
384384
))
@@ -557,13 +557,15 @@ If you end your affiliate program:
557557
self.commissionPermille = 10
558558
self.commissionSliderValue = 0.0
559559
self.commissionMinPermille = 10
560-
self.durationValue = 10
560+
self.durationValue = 1
561+
self.durationMinValue = 0
561562
}
562563
} else {
563564
self.commissionPermille = 10
564565
self.commissionSliderValue = 0.0
565566
self.commissionMinPermille = 10
566-
self.durationValue = 10
567+
self.durationValue = 1
568+
self.durationMinValue = 0
567569
}
568570
case .connectedPrograms:
569571
self.connectedStarBotListDisposable = (component.context.engine.peers.requestConnectedStarRefBots(
@@ -875,7 +877,7 @@ If you end your affiliate program:
875877
minValue: commissionMinSliderValue,
876878
lowerBoundTitle: "1%",
877879
upperBoundTitle: "90%",
878-
title: "\(self.commissionPermille / 10)%",
880+
title: "\(formatPermille(self.commissionPermille))%",
879881
valueUpdated: { [weak self] value in
880882
guard let self else {
881883
return
@@ -1183,11 +1185,11 @@ If you end your affiliate program:
11831185
for item in connectedStarBotList.items {
11841186
let durationTitle: String
11851187
if let durationMonths = item.durationMonths {
1186-
durationTitle = timeIntervalString(strings: environment.strings, value: durationMonths * (24 * 60 * 60))
1188+
durationTitle = timeIntervalString(strings: environment.strings, value: durationMonths * (30 * 24 * 60 * 60))
11871189
} else {
11881190
durationTitle = "Lifetime"
11891191
}
1190-
let commissionTitle = "\(item.commissionPermille / 10)%"
1192+
let commissionTitle = "\(formatPermille(item.commissionPermille))%"
11911193

11921194
let itemContextAction: (EnginePeer, ContextExtractedContentContainingView, ContextGesture?) -> Void = { [weak self] peer, sourceView, gesture in
11931195
guard let self, let component = self.component, let environment = self.environment else {
@@ -1249,7 +1251,7 @@ If you end your affiliate program:
12491251
let presentationData = component.context.sharedContext.currentPresentationData.with({ $0 })
12501252

12511253
UIPasteboard.general.string = item.url
1252-
environment.controller()?.present(UndoOverlayController(presentationData: presentationData, content: .linkCopied(title: "Link copied to clipboard", text: "Share this link and earn **\(item.commissionPermille / 10)%** of what people who use it spend in **\(item.peer.compactDisplayTitle)**!"), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), in: .current)
1254+
environment.controller()?.present(UndoOverlayController(presentationData: presentationData, content: .linkCopied(title: "Link copied to clipboard", text: "Share this link and earn **\(formatPermille(item.commissionPermille))%** of what people who use it spend in **\(item.peer.compactDisplayTitle)**!"), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), in: .current)
12531255
})))
12541256

12551257
itemList.append(.action(ContextMenuActionItem(text: "Leave", textColor: .destructive, icon: { theme in
@@ -1364,17 +1366,21 @@ If you end your affiliate program:
13641366
do {
13651367
var suggestedSectionItems: [AnyComponentWithIdentity<Empty>] = []
13661368
if suggestedStarBotListItems.isEmpty {
1367-
suggestedSectionItems.append(AnyComponentWithIdentity(id: "empty", component: AnyComponent(TransformContents(
1368-
content: AnyComponent(),
1369-
fixedSize: CGSize(width: 1.0, height: 100.0),
1370-
translation: CGPoint()
1371-
))))
1369+
suggestedSectionItems.append(AnyComponentWithIdentity(id: "empty", component: AnyComponent(ZStack([
1370+
AnyComponentWithIdentity(id: 0, component: AnyComponent(Rectangle(color: .clear, width: nil, height: 100.0))),
1371+
AnyComponentWithIdentity(id: 1, component: AnyComponent(MultilineTextComponent(
1372+
text: .plain(NSAttributedString(string: "No available programs yet.\nPlease check the page later.", font: Font.regular(15.0), textColor: environment.theme.list.itemSecondaryTextColor)),
1373+
horizontalAlignment: .center,
1374+
maximumNumberOfLines: 0,
1375+
lineSpacing: 0.2
1376+
)))
1377+
]))))
13721378
}
13731379
for item in suggestedStarBotListItems {
1374-
let commissionTitle = "\(item.program.commissionPermille / 10)%"
1380+
let commissionTitle = "\(formatPermille(item.program.commissionPermille))%"
13751381
let durationTitle: String
13761382
if let durationMonths = item.program.durationMonths {
1377-
durationTitle = timeIntervalString(strings: environment.strings, value: durationMonths * (24 * 60 * 60))
1383+
durationTitle = timeIntervalString(strings: environment.strings, value: durationMonths * (30 * 24 * 60 * 60))
13781384
} else {
13791385
durationTitle = "Lifetime"
13801386
}
@@ -1467,31 +1473,34 @@ If you end your affiliate program:
14671473
))))
14681474
}
14691475

1476+
var suggestedHeaderItems: [AnyComponentWithIdentity<Empty>] = []
1477+
suggestedHeaderItems.append(AnyComponentWithIdentity(id: 0, component: AnyComponent(MultilineTextComponent(
1478+
text: .plain(NSAttributedString(
1479+
string: "PROGRAMS",
1480+
font: Font.regular(13.0),
1481+
textColor: environment.theme.list.freeTextColor
1482+
)),
1483+
maximumNumberOfLines: 0
1484+
))))
1485+
if suggestedStarBotListItems.count > 1 {
1486+
suggestedHeaderItems.append(AnyComponentWithIdentity(id: 1, component: AnyComponent(BotSectionSortButtonComponent(
1487+
theme: environment.theme,
1488+
strings: environment.strings,
1489+
sortMode: self.suggestedSortMode,
1490+
action: { [weak self] sourceView in
1491+
guard let self else {
1492+
return
1493+
}
1494+
self.openSortModeMenu(sourceView: sourceView)
1495+
}
1496+
))))
1497+
}
1498+
14701499
let suggestedProgramsSectionSize = self.suggestedProgramsSection.update(
14711500
transition: transition,
14721501
component: AnyComponent(ListSectionComponent(
14731502
theme: environment.theme,
1474-
header: AnyComponent(HStack([
1475-
AnyComponentWithIdentity(id: 0, component: AnyComponent(MultilineTextComponent(
1476-
text: .plain(NSAttributedString(
1477-
string: "PROGRAMS",
1478-
font: Font.regular(13.0),
1479-
textColor: environment.theme.list.freeTextColor
1480-
)),
1481-
maximumNumberOfLines: 0
1482-
))),
1483-
AnyComponentWithIdentity(id: 1, component: AnyComponent(BotSectionSortButtonComponent(
1484-
theme: environment.theme,
1485-
strings: environment.strings,
1486-
sortMode: self.suggestedSortMode,
1487-
action: { [weak self] sourceView in
1488-
guard let self else {
1489-
return
1490-
}
1491-
self.openSortModeMenu(sourceView: sourceView)
1492-
}
1493-
)))
1494-
], spacing: 4.0, alignment: .alternatingLeftRight)),
1503+
header: AnyComponent(HStack(suggestedHeaderItems, spacing: 4.0, alignment: .alternatingLeftRight)),
14951504
footer: nil,
14961505
items: suggestedSectionItems,
14971506
displaySeparators: true
@@ -1506,19 +1515,12 @@ If you end your affiliate program:
15061515
self.scrollView.addSubview(suggestedProgramsSectionView)
15071516
}
15081517
transition.setFrame(view: suggestedProgramsSectionView, frame: suggestedProgramsSectionFrame)
1509-
if !suggestedStarBotListItems.isEmpty {
1510-
suggestedProgramsSectionView.isHidden = false
1511-
} else {
1512-
suggestedProgramsSectionView.isHidden = true
1513-
}
15141518

15151519
suggestedProgramsSectionView.contentViewImpl.alpha = self.isSuggestedSortModeUpdating ? 0.6 : 1.0
15161520
suggestedProgramsSectionView.contentViewImpl.isUserInteractionEnabled = !self.isSuggestedSortModeUpdating
15171521
}
1518-
if !suggestedStarBotListItems.isEmpty {
1519-
contentHeight += suggestedProgramsSectionSize.height
1520-
contentHeight += sectionSpacing
1521-
}
1522+
contentHeight += suggestedProgramsSectionSize.height
1523+
contentHeight += sectionSpacing
15221524
}
15231525
}
15241526
}

submodules/TelegramUI/Components/PeerInfo/AffiliateProgramSetupScreen/Sources/JoinAffiliateProgramScreen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ private final class JoinAffiliateProgramScreenComponent: Component {
637637
))
638638
),
639639
AnyComponentWithIdentity(id: 1, component: AnyComponent(MultilineTextComponent(
640-
text: .plain(NSAttributedString(string: "\(component.commissionPermille / 10)%", font: Font.regular(13.0), textColor: environment.theme.list.itemCheckColors.foregroundColor))
640+
text: .plain(NSAttributedString(string: "\(formatPermille(component.commissionPermille))%", font: Font.regular(13.0), textColor: environment.theme.list.itemCheckColors.foregroundColor))
641641
)))
642642
], spacing: 2.0)),
643643
insets: UIEdgeInsets(top: 3.0, left: 6.0, bottom: 3.0, right: 6.0),
@@ -766,7 +766,7 @@ private final class JoinAffiliateProgramScreenComponent: Component {
766766
contentHeight += linkIconBackgroundSize.height + 21.0
767767
}
768768

769-
let commissionTitle = "\(component.commissionPermille / 10)%"
769+
let commissionTitle = "\(formatPermille(component.commissionPermille))%"
770770
let durationTitle: String
771771
if let durationMonths = component.programDuration {
772772
durationTitle = timeIntervalString(strings: environment.strings, value: durationMonths * (24 * 60 * 60))

0 commit comments

Comments
 (0)