mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Wallet improvements
This commit is contained in:
parent
64f54c625c
commit
92d19dd772
@ -3,10 +3,10 @@ import UIKit
|
|||||||
import Display
|
import Display
|
||||||
import AccountContext
|
import AccountContext
|
||||||
|
|
||||||
public func textAlertController(context: AccountContext, title: String?, text: String, actions: [TextAlertAction], actionLayout: TextAlertContentActionLayout = .horizontal) -> AlertController {
|
public func textAlertController(context: AccountContext, title: String?, text: String, actions: [TextAlertAction], actionLayout: TextAlertContentActionLayout = .horizontal, allowInputInset: Bool = true) -> AlertController {
|
||||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||||
|
|
||||||
let controller = standardTextAlertController(theme: AlertControllerTheme(presentationTheme: presentationData.theme), title: title, text: text, actions: actions, actionLayout: actionLayout)
|
let controller = standardTextAlertController(theme: AlertControllerTheme(presentationTheme: presentationData.theme), title: title, text: text, actions: actions, actionLayout: actionLayout, allowInputInset: allowInputInset)
|
||||||
let presentationDataDisposable = context.sharedContext.presentationData.start(next: { [weak controller] presentationData in
|
let presentationDataDisposable = context.sharedContext.presentationData.start(next: { [weak controller] presentationData in
|
||||||
controller?.theme = AlertControllerTheme(presentationTheme: presentationData.theme)
|
controller?.theme = AlertControllerTheme(presentationTheme: presentationData.theme)
|
||||||
})
|
})
|
||||||
@ -17,7 +17,7 @@ public func textAlertController(context: AccountContext, title: String?, text: S
|
|||||||
return controller
|
return controller
|
||||||
}
|
}
|
||||||
|
|
||||||
public func richTextAlertController(context: AccountContext, title: NSAttributedString?, text: NSAttributedString, actions: [TextAlertAction], actionLayout: TextAlertContentActionLayout = .horizontal, dismissAutomatically: Bool = true) -> AlertController {
|
public func richTextAlertController(context: AccountContext, title: NSAttributedString?, text: NSAttributedString, actions: [TextAlertAction], actionLayout: TextAlertContentActionLayout = .horizontal, allowInputInset: Bool = true, dismissAutomatically: Bool = true) -> AlertController {
|
||||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||||
let theme = AlertControllerTheme(presentationTheme: presentationData.theme)
|
let theme = AlertControllerTheme(presentationTheme: presentationData.theme)
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ public func richTextAlertController(context: AccountContext, title: NSAttributed
|
|||||||
}
|
}
|
||||||
action.action()
|
action.action()
|
||||||
})
|
})
|
||||||
}, actionLayout: actionLayout))
|
}, actionLayout: actionLayout), allowInputInset: allowInputInset)
|
||||||
dismissImpl = { [weak controller] in
|
dismissImpl = { [weak controller] in
|
||||||
controller?.dismissAnimated()
|
controller?.dismissAnimated()
|
||||||
}
|
}
|
||||||
|
@ -354,14 +354,14 @@ public func textAlertController(theme: AlertControllerTheme, title: NSAttributed
|
|||||||
return AlertController(theme: theme, contentNode: TextAlertContentNode(theme: theme, title: title, text: text, actions: actions, actionLayout: actionLayout))
|
return AlertController(theme: theme, contentNode: TextAlertContentNode(theme: theme, title: title, text: text, actions: actions, actionLayout: actionLayout))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func standardTextAlertController(theme: AlertControllerTheme, title: String?, text: String, actions: [TextAlertAction], actionLayout: TextAlertContentActionLayout = .horizontal) -> AlertController {
|
public func standardTextAlertController(theme: AlertControllerTheme, title: String?, text: String, actions: [TextAlertAction], actionLayout: TextAlertContentActionLayout = .horizontal, allowInputInset: Bool = true) -> AlertController {
|
||||||
var dismissImpl: (() -> Void)?
|
var dismissImpl: (() -> Void)?
|
||||||
let controller = AlertController(theme: theme, contentNode: TextAlertContentNode(theme: theme, title: title != nil ? NSAttributedString(string: title!, font: Font.semibold(17.0), textColor: theme.primaryColor, paragraphAlignment: .center) : nil, text: NSAttributedString(string: text, font: title == nil ? Font.semibold(17.0) : Font.regular(13.0), textColor: theme.primaryColor, paragraphAlignment: .center), actions: actions.map { action in
|
let controller = AlertController(theme: theme, contentNode: TextAlertContentNode(theme: theme, title: title != nil ? NSAttributedString(string: title!, font: Font.semibold(17.0), textColor: theme.primaryColor, paragraphAlignment: .center) : nil, text: NSAttributedString(string: text, font: title == nil ? Font.semibold(17.0) : Font.regular(13.0), textColor: theme.primaryColor, paragraphAlignment: .center), actions: actions.map { action in
|
||||||
return TextAlertAction(type: action.type, title: action.title, action: {
|
return TextAlertAction(type: action.type, title: action.title, action: {
|
||||||
dismissImpl?()
|
dismissImpl?()
|
||||||
action.action()
|
action.action()
|
||||||
})
|
})
|
||||||
}, actionLayout: actionLayout))
|
}, actionLayout: actionLayout), allowInputInset: allowInputInset)
|
||||||
dismissImpl = { [weak controller] in
|
dismissImpl = { [weak controller] in
|
||||||
controller?.dismissAnimated()
|
controller?.dismissAnimated()
|
||||||
}
|
}
|
||||||
|
@ -236,6 +236,8 @@ private enum WalletReceiveScreenEntry: ItemListNodeEntry {
|
|||||||
case let .comment(theme, placeholder, value):
|
case let .comment(theme, placeholder, value):
|
||||||
return ItemListMultilineInputItem(theme: theme, text: value, placeholder: placeholder, maxLength: ItemListMultilineInputItemTextLimit(value: 128, display: true), sectionId: self.section, style: .blocks, returnKeyType: .done, textUpdated: { text in
|
return ItemListMultilineInputItem(theme: theme, text: value, placeholder: placeholder, maxLength: ItemListMultilineInputItemTextLimit(value: 128, display: true), sectionId: self.section, style: .blocks, returnKeyType: .done, textUpdated: { text in
|
||||||
arguments.updateText(WalletReceiveScreenEntryTag.comment, text)
|
arguments.updateText(WalletReceiveScreenEntryTag.comment, text)
|
||||||
|
}, shouldUpdateText: { text in
|
||||||
|
return text.count <= 128
|
||||||
}, updatedFocus: { focus in
|
}, updatedFocus: { focus in
|
||||||
arguments.updateState { state in
|
arguments.updateState { state in
|
||||||
var state = state
|
var state = state
|
||||||
|
@ -22,15 +22,17 @@ private final class WalletSendScreenArguments {
|
|||||||
let updateState: ((WalletSendScreenState) -> WalletSendScreenState) -> Void
|
let updateState: ((WalletSendScreenState) -> WalletSendScreenState) -> Void
|
||||||
let updateText: (WalletSendScreenEntryTag, String) -> Void
|
let updateText: (WalletSendScreenEntryTag, String) -> Void
|
||||||
let selectNextInputItem: (WalletSendScreenEntryTag) -> Void
|
let selectNextInputItem: (WalletSendScreenEntryTag) -> Void
|
||||||
|
let scrollToBottom: () -> Void
|
||||||
let dismissInput: () -> Void
|
let dismissInput: () -> Void
|
||||||
let openQrScanner: () -> Void
|
let openQrScanner: () -> Void
|
||||||
let proceed: () -> Void
|
let proceed: () -> Void
|
||||||
|
|
||||||
init(context: AccountContext, updateState: @escaping ((WalletSendScreenState) -> WalletSendScreenState) -> Void, updateText: @escaping (WalletSendScreenEntryTag, String) -> Void, selectNextInputItem: @escaping (WalletSendScreenEntryTag) -> Void, dismissInput: @escaping () -> Void, openQrScanner: @escaping () -> Void, proceed: @escaping () -> Void) {
|
init(context: AccountContext, updateState: @escaping ((WalletSendScreenState) -> WalletSendScreenState) -> Void, updateText: @escaping (WalletSendScreenEntryTag, String) -> Void, selectNextInputItem: @escaping (WalletSendScreenEntryTag) -> Void, scrollToBottom: @escaping () -> Void, dismissInput: @escaping () -> Void, openQrScanner: @escaping () -> Void, proceed: @escaping () -> Void) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.updateState = updateState
|
self.updateState = updateState
|
||||||
self.updateText = updateText
|
self.updateText = updateText
|
||||||
self.selectNextInputItem = selectNextInputItem
|
self.selectNextInputItem = selectNextInputItem
|
||||||
|
self.scrollToBottom = scrollToBottom
|
||||||
self.dismissInput = dismissInput
|
self.dismissInput = dismissInput
|
||||||
self.openQrScanner = openQrScanner
|
self.openQrScanner = openQrScanner
|
||||||
self.proceed = proceed
|
self.proceed = proceed
|
||||||
@ -231,6 +233,10 @@ private enum WalletSendScreenEntry: ItemListNodeEntry {
|
|||||||
case let .comment(theme, placeholder, value):
|
case let .comment(theme, placeholder, value):
|
||||||
return ItemListMultilineInputItem(theme: theme, text: value, placeholder: placeholder, maxLength: ItemListMultilineInputItemTextLimit(value: 128, display: true), sectionId: self.section, style: .blocks, returnKeyType: .send, textUpdated: { text in
|
return ItemListMultilineInputItem(theme: theme, text: value, placeholder: placeholder, maxLength: ItemListMultilineInputItemTextLimit(value: 128, display: true), sectionId: self.section, style: .blocks, returnKeyType: .send, textUpdated: { text in
|
||||||
arguments.updateText(WalletSendScreenEntryTag.comment, text)
|
arguments.updateText(WalletSendScreenEntryTag.comment, text)
|
||||||
|
}, updatedFocus: { focus in
|
||||||
|
if focus {
|
||||||
|
arguments.scrollToBottom()
|
||||||
|
}
|
||||||
}, tag: WalletSendScreenEntryTag.comment, action: {
|
}, tag: WalletSendScreenEntryTag.comment, action: {
|
||||||
arguments.proceed()
|
arguments.proceed()
|
||||||
})
|
})
|
||||||
@ -285,7 +291,7 @@ public func walletSendScreen(context: AccountContext, tonContext: TonContext, wa
|
|||||||
var dismissImpl: (() -> Void)?
|
var dismissImpl: (() -> Void)?
|
||||||
var dismissInputImpl: (() -> Void)?
|
var dismissInputImpl: (() -> Void)?
|
||||||
var selectNextInputItemImpl: ((WalletSendScreenEntryTag) -> Void)?
|
var selectNextInputItemImpl: ((WalletSendScreenEntryTag) -> Void)?
|
||||||
var ensureItemVisibleImpl: ((WalletSendScreenEntryTag) -> Void)?
|
var ensureItemVisibleImpl: ((WalletSendScreenEntryTag, Bool) -> Void)?
|
||||||
|
|
||||||
let arguments = WalletSendScreenArguments(context: context, updateState: { f in
|
let arguments = WalletSendScreenArguments(context: context, updateState: { f in
|
||||||
updateState(f)
|
updateState(f)
|
||||||
@ -302,9 +308,11 @@ public func walletSendScreen(context: AccountContext, tonContext: TonContext, wa
|
|||||||
}
|
}
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
ensureItemVisibleImpl?(tag)
|
ensureItemVisibleImpl?(tag, false)
|
||||||
}, selectNextInputItem: { tag in
|
}, selectNextInputItem: { tag in
|
||||||
selectNextInputItemImpl?(tag)
|
selectNextInputItemImpl?(tag)
|
||||||
|
}, scrollToBottom: {
|
||||||
|
ensureItemVisibleImpl?(WalletSendScreenEntryTag.comment, true)
|
||||||
}, dismissInput: {
|
}, dismissInput: {
|
||||||
dismissInputImpl?()
|
dismissInputImpl?()
|
||||||
}, openQrScanner: {
|
}, openQrScanner: {
|
||||||
@ -368,8 +376,9 @@ public func walletSendScreen(context: AccountContext, tonContext: TonContext, wa
|
|||||||
dismissAlertImpl?(true)
|
dismissAlertImpl?(true)
|
||||||
}), TextAlertAction(type: .defaultAction, title: "Confirm", action: {
|
}), TextAlertAction(type: .defaultAction, title: "Confirm", action: {
|
||||||
dismissAlertImpl?(false)
|
dismissAlertImpl?(false)
|
||||||
|
dismissInputImpl?()
|
||||||
pushImpl?(WalletSplashScreen(context: context, tonContext: tonContext, mode: .sending(walletInfo, state.address, amount, state.comment)))
|
pushImpl?(WalletSplashScreen(context: context, tonContext: tonContext, mode: .sending(walletInfo, state.address, amount, state.comment)))
|
||||||
})], dismissAutomatically: false)
|
})], allowInputInset: false, dismissAutomatically: false)
|
||||||
presentInGlobalOverlayImpl?(controller, nil)
|
presentInGlobalOverlayImpl?(controller, nil)
|
||||||
|
|
||||||
dismissAlertImpl = { [weak controller] animated in
|
dismissAlertImpl = { [weak controller] animated in
|
||||||
@ -467,7 +476,7 @@ public func walletSendScreen(context: AccountContext, tonContext: TonContext, wa
|
|||||||
resultItemNode.focus()
|
resultItemNode.focus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ensureItemVisibleImpl = { [weak controller] targetTag in
|
ensureItemVisibleImpl = { [weak controller] targetTag, animated in
|
||||||
controller?.afterLayout({
|
controller?.afterLayout({
|
||||||
guard let controller = controller else {
|
guard let controller = controller else {
|
||||||
return
|
return
|
||||||
@ -486,7 +495,7 @@ public func walletSendScreen(context: AccountContext, tonContext: TonContext, wa
|
|||||||
})
|
})
|
||||||
|
|
||||||
if let resultItemNode = resultItemNode {
|
if let resultItemNode = resultItemNode {
|
||||||
controller.ensureItemNodeVisible(resultItemNode)
|
controller.ensureItemNodeVisible(resultItemNode, animated: animated)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -77,20 +77,17 @@ public final class WalletSplashScreen: ViewController {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let navigationController = strongSelf.navigationController as? NavigationController {
|
if let navigationController = strongSelf.navigationController as? NavigationController {
|
||||||
var controllers = navigationController.viewControllers
|
var controllers: [UIViewController] = []
|
||||||
controllers = controllers.filter { controller in
|
for controller in navigationController.viewControllers {
|
||||||
if controller is WalletSplashScreen {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if controller is WalletSendScreen {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if controller is WalletInfoScreen {
|
if controller is WalletInfoScreen {
|
||||||
return false
|
controllers.append(WalletInfoScreen(context: strongSelf.context, tonContext: strongSelf.tonContext, walletInfo: walletInfo, address: address))
|
||||||
|
} else {
|
||||||
|
controllers.append(controller)
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
controllers.append(WalletSplashScreen(context: strongSelf.context, tonContext: strongSelf.tonContext, mode: .sent(walletInfo, amount)))
|
|
||||||
|
let controller = WalletSplashScreen(context: strongSelf.context, tonContext: strongSelf.tonContext, mode: .sent(walletInfo, amount))
|
||||||
|
controllers.append(controller)
|
||||||
strongSelf.view.endEditing(true)
|
strongSelf.view.endEditing(true)
|
||||||
navigationController.setViewControllers(controllers, animated: true)
|
navigationController.setViewControllers(controllers, animated: true)
|
||||||
}
|
}
|
||||||
@ -144,7 +141,7 @@ public final class WalletSplashScreen: ViewController {
|
|||||||
})
|
})
|
||||||
case let .created(walletInfo, wordList):
|
case let .created(walletInfo, wordList):
|
||||||
strongSelf.push(WalletWordDisplayScreen(context: strongSelf.context, tonContext: strongSelf.tonContext, walletInfo: walletInfo, wordList: wordList, mode: .check))
|
strongSelf.push(WalletWordDisplayScreen(context: strongSelf.context, tonContext: strongSelf.tonContext, walletInfo: walletInfo, wordList: wordList, mode: .check))
|
||||||
case let .success(walletInfo), let .sent(walletInfo, _):
|
case let .success(walletInfo):
|
||||||
let _ = (walletAddress(publicKey: walletInfo.publicKey, tonInstance: strongSelf.tonContext.instance)
|
let _ = (walletAddress(publicKey: walletInfo.publicKey, tonInstance: strongSelf.tonContext.instance)
|
||||||
|> deliverOnMainQueue).start(next: { address in
|
|> deliverOnMainQueue).start(next: { address in
|
||||||
guard let strongSelf = self else {
|
guard let strongSelf = self else {
|
||||||
@ -159,6 +156,9 @@ public final class WalletSplashScreen: ViewController {
|
|||||||
if controller is WalletWordDisplayScreen {
|
if controller is WalletWordDisplayScreen {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if controller is WalletInfoScreen {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if controller is WalletWordCheckScreen {
|
if controller is WalletWordCheckScreen {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -169,6 +169,27 @@ public final class WalletSplashScreen: ViewController {
|
|||||||
navigationController.setViewControllers(controllers, animated: true)
|
navigationController.setViewControllers(controllers, animated: true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
case let .sent(walletInfo, _):
|
||||||
|
if let navigationController = strongSelf.navigationController as? NavigationController {
|
||||||
|
var controllers = navigationController.viewControllers
|
||||||
|
controllers = controllers.filter { controller in
|
||||||
|
if controller is WalletSendScreen {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if controller is WalletSplashScreen {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if controller is WalletWordDisplayScreen {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if controller is WalletWordCheckScreen {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
strongSelf.view.endEditing(true)
|
||||||
|
navigationController.setViewControllers(controllers, animated: true)
|
||||||
|
}
|
||||||
case .restoreFailed:
|
case .restoreFailed:
|
||||||
if let navigationController = strongSelf.navigationController as? NavigationController {
|
if let navigationController = strongSelf.navigationController as? NavigationController {
|
||||||
var controllers = navigationController.viewControllers
|
var controllers = navigationController.viewControllers
|
||||||
|
Loading…
x
Reference in New Issue
Block a user