no message

This commit is contained in:
Ilya Laktyushin 2019-09-27 22:36:53 +03:00
parent 462f859f40
commit f79ad6ba2f
10 changed files with 48 additions and 53 deletions

View File

@ -952,9 +952,11 @@ static UIImageOrientation TGSnapshotOrientationForVideoOrientation(bool mirrored
- (void)captureOutput:(AVCaptureOutput *)output didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects fromConnection:(AVCaptureConnection *)connection - (void)captureOutput:(AVCaptureOutput *)output didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects fromConnection:(AVCaptureConnection *)connection
{ {
if (!self.isRunning) if (!self.isRunning || self.currentMode != PGCameraModePhoto)
return; return;
if ([metadataObjects.firstObject isKindOfClass:[AVMetadataMachineReadableCodeObject class]]) if ([metadataObjects.firstObject isKindOfClass:[AVMetadataMachineReadableCodeObject class]])
{ {
AVMetadataMachineReadableCodeObject *object = (AVMetadataMachineReadableCodeObject *)metadataObjects.firstObject; AVMetadataMachineReadableCodeObject *object = (AVMetadataMachineReadableCodeObject *)metadataObjects.firstObject;

View File

@ -1104,7 +1104,7 @@ public func settingsController(context: AccountContext, accountManager: AccountM
|> map { view -> Bool in |> map { view -> Bool in
let appConfiguration = view.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? .defaultValue let appConfiguration = view.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? .defaultValue
let configuration = WalletConfiguration.with(appConfiguration: appConfiguration) let configuration = WalletConfiguration.with(appConfiguration: appConfiguration)
return configuration.enabled return configuration.config != nil
} }
} }

View File

@ -5083,7 +5083,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
if let (host, port, username, password, secret) = parseProxyUrl(code) { if let (host, port, username, password, secret) = parseProxyUrl(code) {
strongSelf.openResolved(ResolvedUrl.proxy(host: host, port: port, username: username, password: password, secret: secret)) strongSelf.openResolved(ResolvedUrl.proxy(host: host, port: port, username: username, password: password, secret: secret))
} else if let url = URL(string: code), let parsedWalletUrl = parseWalletUrl(url) { } else if let url = URL(string: code), let parsedWalletUrl = parseWalletUrl(url) {
strongSelf.openResolved(ResolvedUrl.wallet(address: parsedWalletUrl.address, amount: parsedWalletUrl.amount, comment: parsedWalletUrl.comment)) //strongSelf.openResolved(ResolvedUrl.wallet(address: parsedWalletUrl.address, amount: parsedWalletUrl.amount, comment: parsedWalletUrl.comment))
} }
} }
}, presentSchedulePicker: { [weak self] done in }, presentSchedulePicker: { [weak self] done in

View File

@ -1031,7 +1031,7 @@ public final class SharedAccountContextImpl: SharedAccountContext {
) )
|> deliverOnMainQueue).start(next: { wallets, currentPublicKey, preferences in |> deliverOnMainQueue).start(next: { wallets, currentPublicKey, preferences in
let appConfiguration = preferences.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? .defaultValue let appConfiguration = preferences.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? .defaultValue
guard let config = WalletConfiguration.config(appConfiguration: appConfiguration) else { guard let config = WalletConfiguration.with(appConfiguration: appConfiguration).config else {
return return
} }
let tonContext = storedContext.context(config: config) let tonContext = storedContext.context(config: config)

View File

@ -443,7 +443,6 @@ public struct ParsedWalletUrl {
} }
private let invalidWalletAddressCharacters = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=").inverted private let invalidWalletAddressCharacters = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=").inverted
private func isValidWalletAddress(_ address: String) -> Bool { private func isValidWalletAddress(_ address: String) -> Bool {
if address.count != 48 || address.rangeOfCharacter(from: invalidWalletAddressCharacters) != nil { if address.count != 48 || address.rangeOfCharacter(from: invalidWalletAddressCharacters) != nil {
return false return false
@ -457,7 +456,7 @@ public func parseWalletUrl(_ url: URL) -> ParsedWalletUrl? {
} }
var address: String? var address: String?
if let host = url.host, isValidWalletAddress(host) { if let host = url.host, isValidWalletAddress(host) {
address = host.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/") address = host
} }
var amount: Int64? var amount: Int64?
var comment: String? var comment: String?

View File

@ -3,28 +3,20 @@ import TelegramCore
public struct WalletConfiguration { public struct WalletConfiguration {
static var defaultValue: WalletConfiguration { static var defaultValue: WalletConfiguration {
return WalletConfiguration(enabled: false) return WalletConfiguration(config: nil)
} }
public let enabled: Bool public let config: String?
fileprivate init(enabled: Bool) { fileprivate init(config: String?) {
self.enabled = enabled self.config = config
} }
public static func with(appConfiguration: AppConfiguration) -> WalletConfiguration { public static func with(appConfiguration: AppConfiguration) -> WalletConfiguration {
if let data = appConfiguration.data, let enabled = data["wallet_enabled"] as? Bool, let _ = data["wallet_config"] as? String { if let data = appConfiguration.data, let config = data["wallet_config"] as? String {
return WalletConfiguration(enabled: enabled) return WalletConfiguration(config: config)
} else { } else {
return .defaultValue return .defaultValue
} }
} }
public static func config(appConfiguration: AppConfiguration) -> String? {
if let data = appConfiguration.data, let config = data["wallet_config"] as? String {
return config
} else {
return nil
}
}
} }

View File

@ -301,7 +301,6 @@ private final class WalletReceiveScreenImpl: ItemListController<WalletReceiveScr
} }
private func invoiceUrl(address: String, state: WalletReceiveScreenState, escapeComment: Bool = true) -> String { private func invoiceUrl(address: String, state: WalletReceiveScreenState, escapeComment: Bool = true) -> String {
let escapedAddress = address.replacingOccurrences(of: "+", with: "-").replacingOccurrences(of: "/", with: "_")
var arguments = "" var arguments = ""
if !state.amount.isEmpty { if !state.amount.isEmpty {
arguments += arguments.isEmpty ? "/?" : "&" arguments += arguments.isEmpty ? "/?" : "&"
@ -315,7 +314,7 @@ private func invoiceUrl(address: String, state: WalletReceiveScreenState, escape
arguments += "text=\(state.comment)" arguments += "text=\(state.comment)"
} }
} }
return "ton://\(escapedAddress)\(arguments)" return "ton://\(address)\(arguments)"
} }
func walletReceiveScreen(context: AccountContext, tonContext: TonContext, walletInfo: WalletInfo, address: String) -> ViewController { func walletReceiveScreen(context: AccountContext, tonContext: TonContext, walletInfo: WalletInfo, address: String) -> ViewController {
@ -348,7 +347,7 @@ func walletReceiveScreen(context: AccountContext, tonContext: TonContext, wallet
} }
return state return state
} }
ensureItemVisibleImpl?(tag, false) ensureItemVisibleImpl?(WalletReceiveScreenEntryTag.comment, false)
}, selectNextInputItem: { tag in }, selectNextInputItem: { tag in
selectNextInputItemImpl?(tag) selectNextInputItemImpl?(tag)
}, dismissInput: { }, dismissInput: {

View File

@ -183,12 +183,7 @@ private enum WalletSendScreenEntry: ItemListNodeEntry {
} }
} else if isValidAddress(text) { } else if isValidAddress(text) {
arguments.updateText(WalletSendScreenEntryTag.address, text) arguments.updateText(WalletSendScreenEntryTag.address, text)
if isValidAddress(text, exactLength: true, url: false) { if isValidAddress(text, exactLength: true) {
arguments.selectNextInputItem(WalletSendScreenEntryTag.address)
}
} else if isValidAddress(text, url: true) {
arguments.updateText(WalletSendScreenEntryTag.address, convertedAddress(text, url: false))
if isValidAddress(text, exactLength: true, url: true) {
arguments.selectNextInputItem(WalletSendScreenEntryTag.address) arguments.selectNextInputItem(WalletSendScreenEntryTag.address)
} }
} }

View File

@ -156,6 +156,11 @@ public final class WalletSplashScreen: ViewController {
return return
} }
if let navigationController = strongSelf.navigationController as? NavigationController { if let navigationController = strongSelf.navigationController as? NavigationController {
let _ = (walletAddress(publicKey: walletInfo.publicKey, tonInstance: strongSelf.tonContext.instance)
|> deliverOnMainQueue).start(next: { [weak self] address in
guard let strongSelf = self else {
return
}
var controllers: [UIViewController] = [] var controllers: [UIViewController] = []
for controller in navigationController.viewControllers { for controller in navigationController.viewControllers {
if controller is WalletInfoScreen { if controller is WalletInfoScreen {
@ -167,6 +172,7 @@ public final class WalletSplashScreen: ViewController {
controllers.append(WalletSplashScreen(context: strongSelf.context, tonContext: strongSelf.tonContext, mode: .sent(walletInfo, amount), walletCreatedPreloadState: nil)) controllers.append(WalletSplashScreen(context: strongSelf.context, tonContext: strongSelf.tonContext, mode: .sent(walletInfo, amount), walletCreatedPreloadState: nil))
strongSelf.view.endEditing(true) strongSelf.view.endEditing(true)
navigationController.setViewControllers(controllers, animated: true) navigationController.setViewControllers(controllers, animated: true)
})
} }
}) })
} }
@ -286,8 +292,19 @@ public final class WalletSplashScreen: ViewController {
} }
return true return true
} }
let _ = (walletAddress(publicKey: walletInfo.publicKey, tonInstance: strongSelf.tonContext.instance)
|> deliverOnMainQueue).start(next: { [weak self] address in
guard let strongSelf = self else {
return
}
if !controllers.contains(where: { $0 is WalletInfoScreen }) {
controllers.append(WalletInfoScreen(context: strongSelf.context, tonContext: strongSelf.tonContext, walletInfo: walletInfo, address: address))
}
strongSelf.view.endEditing(true) strongSelf.view.endEditing(true)
navigationController.setViewControllers(controllers, animated: true) navigationController.setViewControllers(controllers, animated: true)
})
} }
case .restoreFailed: case .restoreFailed:
if let navigationController = strongSelf.navigationController as? NavigationController { if let navigationController = strongSelf.navigationController as? NavigationController {

View File

@ -120,11 +120,10 @@ func formatAmountText(_ text: String, decimalSeparator: String) -> String {
return text return text
} }
private let invalidAddressCharacters = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=").inverted private let invalidAddressCharacters = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=").inverted
private let invalidUrlAddressCharacters = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=").inverted
func isValidAddress(_ address: String, exactLength: Bool = false, url: Bool = false) -> Bool { func isValidAddress(_ address: String, exactLength: Bool = false) -> Bool {
if address.count > walletAddressLength || address.rangeOfCharacter(from: url ? invalidUrlAddressCharacters : invalidAddressCharacters) != nil { if address.count > walletAddressLength || address.rangeOfCharacter(from: invalidAddressCharacters) != nil {
return false return false
} }
if exactLength && address.count != walletAddressLength { if exactLength && address.count != walletAddressLength {
@ -132,11 +131,3 @@ func isValidAddress(_ address: String, exactLength: Bool = false, url: Bool = fa
} }
return true return true
} }
func convertedAddress(_ address: String, url: Bool) -> String {
if url {
return address.replacingOccurrences(of: "+", with: "-").replacingOccurrences(of: "/", with: "_")
} else {
return address.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")
}
}