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
{
if (!self.isRunning)
if (!self.isRunning || self.currentMode != PGCameraModePhoto)
return;
if ([metadataObjects.firstObject isKindOfClass:[AVMetadataMachineReadableCodeObject class]])
{
AVMetadataMachineReadableCodeObject *object = (AVMetadataMachineReadableCodeObject *)metadataObjects.firstObject;

View File

@ -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
}
}

View File

@ -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

View File

@ -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)

View File

@ -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?

View File

@ -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
}
}
}

View File

@ -301,7 +301,6 @@ private final class WalletReceiveScreenImpl: ItemListController<WalletReceiveScr
}
private func invoiceUrl(address: String, state: WalletReceiveScreenState, escapeComment: Bool = true) -> 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: {

View File

@ -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)
}
}

View File

@ -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 {

View File

@ -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: "/")
}
}