diff --git a/submodules/LegacyComponents/LegacyComponents/PGCameraCaptureSession.m b/submodules/LegacyComponents/LegacyComponents/PGCameraCaptureSession.m index 7bcc710026..9654c1b342 100644 --- a/submodules/LegacyComponents/LegacyComponents/PGCameraCaptureSession.m +++ b/submodules/LegacyComponents/LegacyComponents/PGCameraCaptureSession.m @@ -952,9 +952,11 @@ static UIImageOrientation TGSnapshotOrientationForVideoOrientation(bool mirrored - (void)captureOutput:(AVCaptureOutput *)output didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects fromConnection:(AVCaptureConnection *)connection { - if (!self.isRunning) + if (!self.isRunning || self.currentMode != PGCameraModePhoto) return; + + if ([metadataObjects.firstObject isKindOfClass:[AVMetadataMachineReadableCodeObject class]]) { AVMetadataMachineReadableCodeObject *object = (AVMetadataMachineReadableCodeObject *)metadataObjects.firstObject; diff --git a/submodules/SettingsUI/Sources/SettingsController.swift b/submodules/SettingsUI/Sources/SettingsController.swift index 555d189061..cc607669fd 100644 --- a/submodules/SettingsUI/Sources/SettingsController.swift +++ b/submodules/SettingsUI/Sources/SettingsController.swift @@ -1104,7 +1104,7 @@ public func settingsController(context: AccountContext, accountManager: AccountM |> map { view -> Bool in let appConfiguration = view.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? .defaultValue let configuration = WalletConfiguration.with(appConfiguration: appConfiguration) - return configuration.enabled + return configuration.config != nil } } diff --git a/submodules/TelegramUI/TelegramUI/ChatController.swift b/submodules/TelegramUI/TelegramUI/ChatController.swift index 213126eedf..52042de4a5 100644 --- a/submodules/TelegramUI/TelegramUI/ChatController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatController.swift @@ -5083,7 +5083,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G if let (host, port, username, password, secret) = parseProxyUrl(code) { 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) { - 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 diff --git a/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift b/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift index 2aa6b768e7..8414b342a2 100644 --- a/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift +++ b/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift @@ -1031,7 +1031,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { ) |> deliverOnMainQueue).start(next: { wallets, currentPublicKey, preferences in 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 } let tonContext = storedContext.context(config: config) diff --git a/submodules/UrlHandling/Sources/UrlHandling.swift b/submodules/UrlHandling/Sources/UrlHandling.swift index 97b4988ec9..cf64372a36 100644 --- a/submodules/UrlHandling/Sources/UrlHandling.swift +++ b/submodules/UrlHandling/Sources/UrlHandling.swift @@ -443,7 +443,6 @@ public struct ParsedWalletUrl { } private let invalidWalletAddressCharacters = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=").inverted - private func isValidWalletAddress(_ address: String) -> Bool { if address.count != 48 || address.rangeOfCharacter(from: invalidWalletAddressCharacters) != nil { return false @@ -457,7 +456,7 @@ public func parseWalletUrl(_ url: URL) -> ParsedWalletUrl? { } var address: String? if let host = url.host, isValidWalletAddress(host) { - address = host.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/") + address = host } var amount: Int64? var comment: String? diff --git a/submodules/WalletUI/Sources/WalletConfiguration.swift b/submodules/WalletUI/Sources/WalletConfiguration.swift index 3e99a47bea..68cc6548ad 100644 --- a/submodules/WalletUI/Sources/WalletConfiguration.swift +++ b/submodules/WalletUI/Sources/WalletConfiguration.swift @@ -3,28 +3,20 @@ import TelegramCore public struct 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) { - self.enabled = enabled + fileprivate init(config: String?) { + self.config = config } 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 { - return WalletConfiguration(enabled: enabled) + if let data = appConfiguration.data, let config = data["wallet_config"] as? String { + return WalletConfiguration(config: config) } else { 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 - } - } } diff --git a/submodules/WalletUI/Sources/WalletReceiveScreen.swift b/submodules/WalletUI/Sources/WalletReceiveScreen.swift index 82cc5fe580..e8d741f6af 100644 --- a/submodules/WalletUI/Sources/WalletReceiveScreen.swift +++ b/submodules/WalletUI/Sources/WalletReceiveScreen.swift @@ -301,7 +301,6 @@ private final class WalletReceiveScreenImpl: ItemListController String { - let escapedAddress = address.replacingOccurrences(of: "+", with: "-").replacingOccurrences(of: "/", with: "_") var arguments = "" if !state.amount.isEmpty { arguments += arguments.isEmpty ? "/?" : "&" @@ -315,7 +314,7 @@ private func invoiceUrl(address: String, state: WalletReceiveScreenState, escape arguments += "text=\(state.comment)" } } - return "ton://\(escapedAddress)\(arguments)" + return "ton://\(address)\(arguments)" } func walletReceiveScreen(context: AccountContext, tonContext: TonContext, walletInfo: WalletInfo, address: String) -> ViewController { @@ -348,7 +347,7 @@ func walletReceiveScreen(context: AccountContext, tonContext: TonContext, wallet } return state } - ensureItemVisibleImpl?(tag, false) + ensureItemVisibleImpl?(WalletReceiveScreenEntryTag.comment, false) }, selectNextInputItem: { tag in selectNextInputItemImpl?(tag) }, dismissInput: { diff --git a/submodules/WalletUI/Sources/WalletSendScreen.swift b/submodules/WalletUI/Sources/WalletSendScreen.swift index a98d870937..ba9dc49709 100644 --- a/submodules/WalletUI/Sources/WalletSendScreen.swift +++ b/submodules/WalletUI/Sources/WalletSendScreen.swift @@ -183,12 +183,7 @@ private enum WalletSendScreenEntry: ItemListNodeEntry { } } else if isValidAddress(text) { arguments.updateText(WalletSendScreenEntryTag.address, text) - if isValidAddress(text, exactLength: true, url: false) { - 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) { + if isValidAddress(text, exactLength: true) { arguments.selectNextInputItem(WalletSendScreenEntryTag.address) } } diff --git a/submodules/WalletUI/Sources/WalletSplashScreen.swift b/submodules/WalletUI/Sources/WalletSplashScreen.swift index c1791a7d44..5028313810 100644 --- a/submodules/WalletUI/Sources/WalletSplashScreen.swift +++ b/submodules/WalletUI/Sources/WalletSplashScreen.swift @@ -156,17 +156,23 @@ public final class WalletSplashScreen: ViewController { return } if let navigationController = strongSelf.navigationController as? NavigationController { - var controllers: [UIViewController] = [] - for controller in navigationController.viewControllers { - if controller is WalletInfoScreen { - controllers.append(WalletInfoScreen(context: strongSelf.context, tonContext: strongSelf.tonContext, walletInfo: walletInfo, address: address)) - } else { - controllers.append(controller) + let _ = (walletAddress(publicKey: walletInfo.publicKey, tonInstance: strongSelf.tonContext.instance) + |> deliverOnMainQueue).start(next: { [weak self] address in + guard let strongSelf = self else { + return } - } - controllers.append(WalletSplashScreen(context: strongSelf.context, tonContext: strongSelf.tonContext, mode: .sent(walletInfo, amount), walletCreatedPreloadState: nil)) - strongSelf.view.endEditing(true) - navigationController.setViewControllers(controllers, animated: true) + var controllers: [UIViewController] = [] + for controller in navigationController.viewControllers { + if controller is WalletInfoScreen { + controllers.append(WalletInfoScreen(context: strongSelf.context, tonContext: strongSelf.tonContext, walletInfo: walletInfo, address: address)) + } else { + controllers.append(controller) + } + } + controllers.append(WalletSplashScreen(context: strongSelf.context, tonContext: strongSelf.tonContext, mode: .sent(walletInfo, amount), walletCreatedPreloadState: nil)) + strongSelf.view.endEditing(true) + navigationController.setViewControllers(controllers, animated: true) + }) } }) } @@ -286,8 +292,19 @@ public final class WalletSplashScreen: ViewController { } return true } - strongSelf.view.endEditing(true) - navigationController.setViewControllers(controllers, animated: 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) + navigationController.setViewControllers(controllers, animated: true) + }) } case .restoreFailed: if let navigationController = strongSelf.navigationController as? NavigationController { diff --git a/submodules/WalletUI/Sources/WalletUtils.swift b/submodules/WalletUI/Sources/WalletUtils.swift index 7b31075067..1d62a41c12 100644 --- a/submodules/WalletUI/Sources/WalletUtils.swift +++ b/submodules/WalletUI/Sources/WalletUtils.swift @@ -120,11 +120,10 @@ func formatAmountText(_ text: String, decimalSeparator: String) -> String { return text } -private let invalidAddressCharacters = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=").inverted -private let invalidUrlAddressCharacters = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=").inverted +private let invalidAddressCharacters = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=").inverted -func isValidAddress(_ address: String, exactLength: Bool = false, url: Bool = false) -> Bool { - if address.count > walletAddressLength || address.rangeOfCharacter(from: url ? invalidUrlAddressCharacters : invalidAddressCharacters) != nil { +func isValidAddress(_ address: String, exactLength: Bool = false) -> Bool { + if address.count > walletAddressLength || address.rangeOfCharacter(from: invalidAddressCharacters) != nil { return false } if exactLength && address.count != walletAddressLength { @@ -132,11 +131,3 @@ func isValidAddress(_ address: String, exactLength: Bool = false, url: Bool = fa } 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: "/") - } -}