Fix build

This commit is contained in:
Peter 2019-09-27 19:09:40 +04:00
parent d034233388
commit 96fa70f26d
5 changed files with 84 additions and 57 deletions

View File

@ -4879,3 +4879,4 @@ Any member of this group will be able to see messages in the channel.";
"Wallet.Send.ErrorInvalidAddress" = "Invalid wallet address. Please correct and try again."; "Wallet.Send.ErrorInvalidAddress" = "Invalid wallet address. Please correct and try again.";
"Wallet.Send.ErrorDecryptionFailed" = "Encryption error. Please check device passcode settings and try again."; "Wallet.Send.ErrorDecryptionFailed" = "Encryption error. Please check device passcode settings and try again.";
"Wallet.Send.SendAnyway" = "Send Anyway";

View File

@ -292,7 +292,7 @@ public final class TonInstance {
} }
} }
fileprivate func sendGramsFromWallet(keychain: TonKeychain, serverSalt: Data, walletInfo: WalletInfo, fromAddress: String, toAddress: String, amount: Int64, textMessage: String, randomId: Int64) -> Signal<Never, SendGramsFromWalletError> { fileprivate func sendGramsFromWallet(keychain: TonKeychain, serverSalt: Data, walletInfo: WalletInfo, fromAddress: String, toAddress: String, amount: Int64, textMessage: String, forceIfDestinationNotInitialized: Bool, timeout: Int32, randomId: Int64) -> Signal<Never, SendGramsFromWalletError> {
return keychain.decrypt(walletInfo.encryptedSecret) return keychain.decrypt(walletInfo.encryptedSecret)
|> mapError { _ -> SendGramsFromWalletError in |> mapError { _ -> SendGramsFromWalletError in
return .secretDecryptionFailed return .secretDecryptionFailed
@ -304,7 +304,7 @@ public final class TonInstance {
self.impl.with { impl in self.impl.with { impl in
impl.withInstance { ton in impl.withInstance { ton in
let cancel = ton.sendGrams(from: key, localPassword: serverSalt, fromAddress: fromAddress, toAddress: toAddress, amount: amount, textMessage: textMessage, forceIfDestinationNotInitialized: true, timeout: 0, randomId: randomId).start(next: { result in let cancel = ton.sendGrams(from: key, localPassword: serverSalt, fromAddress: fromAddress, toAddress: toAddress, amount: amount, textMessage: textMessage, forceIfDestinationNotInitialized: forceIfDestinationNotInitialized, timeout: timeout, randomId: randomId).start(next: { result in
guard let result = result as? TONSendGramsResult else { guard let result = result as? TONSendGramsResult else {
subscriber.putError(.generic) subscriber.putError(.generic)
return return
@ -314,6 +314,8 @@ public final class TonInstance {
if let error = error as? TONError { if let error = error as? TONError {
if error.text == "Failed to parse account address" { if error.text == "Failed to parse account address" {
subscriber.putError(.invalidAddress) subscriber.putError(.invalidAddress)
} else if error.text.hasPrefix("DANGEROUS_TRANSACTION") {
subscriber.putError(.destinationIsNotInitialized)
} else { } else {
subscriber.putError(.generic) subscriber.putError(.generic)
} }
@ -699,9 +701,10 @@ public enum SendGramsFromWalletError {
case generic case generic
case secretDecryptionFailed case secretDecryptionFailed
case invalidAddress case invalidAddress
case destinationIsNotInitialized
} }
public func sendGramsFromWallet(network: Network, tonInstance: TonInstance, keychain: TonKeychain, walletInfo: WalletInfo, toAddress: String, amount: Int64, textMessage: String, randomId: Int64) -> Signal<Never, SendGramsFromWalletError> { public func sendGramsFromWallet(network: Network, tonInstance: TonInstance, keychain: TonKeychain, walletInfo: WalletInfo, toAddress: String, amount: Int64, textMessage: String, forceIfDestinationNotInitialized: Bool, timeout: Int32, randomId: Int64) -> Signal<Never, SendGramsFromWalletError> {
return getServerWalletSalt(network: network) return getServerWalletSalt(network: network)
|> mapError { _ -> SendGramsFromWalletError in |> mapError { _ -> SendGramsFromWalletError in
return .generic return .generic
@ -710,7 +713,7 @@ public func sendGramsFromWallet(network: Network, tonInstance: TonInstance, keyc
return walletAddress(publicKey: walletInfo.publicKey, tonInstance: tonInstance) return walletAddress(publicKey: walletInfo.publicKey, tonInstance: tonInstance)
|> castError(SendGramsFromWalletError.self) |> castError(SendGramsFromWalletError.self)
|> mapToSignal { fromAddress in |> mapToSignal { fromAddress in
return tonInstance.sendGramsFromWallet(keychain: keychain, serverSalt: serverSalt, walletInfo: walletInfo, fromAddress: fromAddress, toAddress: toAddress, amount: amount, textMessage: textMessage, randomId: randomId) return tonInstance.sendGramsFromWallet(keychain: keychain, serverSalt: serverSalt, walletInfo: walletInfo, fromAddress: fromAddress, toAddress: toAddress, amount: amount, textMessage: textMessage, forceIfDestinationNotInitialized: forceIfDestinationNotInitialized, timeout: timeout, randomId: randomId)
} }
} }
} }

View File

@ -28,6 +28,7 @@ static_library(
"//submodules/TelegramStringFormatting:TelegramStringFormatting", "//submodules/TelegramStringFormatting:TelegramStringFormatting",
"//submodules/GlassButtonNode:GlassButtonNode", "//submodules/GlassButtonNode:GlassButtonNode",
"//submodules/UrlHandling:UrlHandling", "//submodules/UrlHandling:UrlHandling",
"//submodules/LocalAuth:LocalAuth",
], ],
frameworks = [ frameworks = [
"$SDKROOT/System/Library/Frameworks/Foundation.framework", "$SDKROOT/System/Library/Frameworks/Foundation.framework",

View File

@ -88,8 +88,32 @@ public final class WalletSplashScreen: ViewController {
self.navigationItem.setRightBarButton(UIBarButtonItem(title: self.presentationData.strings.Wallet_Intro_ImportExisting, style: .plain, target: self, action: #selector(self.importPressed)), animated: false) self.navigationItem.setRightBarButton(UIBarButtonItem(title: self.presentationData.strings.Wallet_Intro_ImportExisting, style: .plain, target: self, action: #selector(self.importPressed)), animated: false)
case let .sending(walletInfo, address, amount, textMessage, randomId): case let .sending(walletInfo, address, amount, textMessage, randomId):
self.navigationItem.setLeftBarButton(UIBarButtonItem(customDisplayNode: ASDisplayNode())!, animated: false) self.navigationItem.setLeftBarButton(UIBarButtonItem(customDisplayNode: ASDisplayNode())!, animated: false)
self.sendGrams(walletInfo: walletInfo, address: address, amount: amount, textMessage: textMessage, forceIfDestinationNotInitialized: false, randomId: randomId)
case .sent, .created:
self.navigationItem.setLeftBarButton(UIBarButtonItem(customDisplayNode: ASDisplayNode())!, animated: false)
case .restoreFailed, .secureStorageNotAvailable, .secureStorageReset:
break
case .success:
break
}
let _ = (sendGramsFromWallet(network: self.context.account.network, tonInstance: self.tonContext.instance, keychain: self.tonContext.keychain, walletInfo: walletInfo, toAddress: address, amount: amount, textMessage: textMessage, randomId: randomId) self.navigationItem.backBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Back, style: .plain, target: nil, action: nil)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc private func backPressed() {
self.dismiss()
}
@objc private func importPressed() {
self.push(WalletWordCheckScreen(context: self.context, tonContext: self.tonContext, mode: .import, walletCreatedPreloadState: nil))
}
private func sendGrams(walletInfo: WalletInfo, address: String, amount: Int64, textMessage: String, forceIfDestinationNotInitialized: Bool, randomId: Int64) {
let _ = (sendGramsFromWallet(network: self.context.account.network, tonInstance: self.tonContext.instance, keychain: self.tonContext.keychain, walletInfo: walletInfo, toAddress: address, amount: amount, textMessage: textMessage, forceIfDestinationNotInitialized: forceIfDestinationNotInitialized, timeout: 0, randomId: randomId)
|> deliverOnMainQueue).start(error: { [weak self] error in |> deliverOnMainQueue).start(error: { [weak self] error in
guard let strongSelf = self else { guard let strongSelf = self else {
return return
@ -102,6 +126,24 @@ public final class WalletSplashScreen: ViewController {
text = strongSelf.presentationData.strings.Wallet_Send_ErrorInvalidAddress text = strongSelf.presentationData.strings.Wallet_Send_ErrorInvalidAddress
case .secretDecryptionFailed: case .secretDecryptionFailed:
text = strongSelf.presentationData.strings.Wallet_Send_ErrorDecryptionFailed text = strongSelf.presentationData.strings.Wallet_Send_ErrorDecryptionFailed
case .destinationIsNotInitialized:
if !forceIfDestinationNotInitialized {
text = "This address belongs to an empty wallet. Are you sure you want to transfer grams to it?"
let controller = textAlertController(context: strongSelf.context, title: "Warning", text: text, actions: [
TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_Cancel, action: {
if let navigationController = strongSelf.navigationController as? NavigationController {
navigationController.popViewController(animated: true)
}
}),
TextAlertAction(type: .defaultAction, title: "Send Anyway", action: {
self?.sendGrams(walletInfo: walletInfo, address: address, amount: amount, textMessage: textMessage, forceIfDestinationNotInitialized: true, randomId: randomId)
})
])
strongSelf.present(controller, in: .window(.root))
return
} else {
text = strongSelf.presentationData.strings.Login_UnknownError
}
} }
let controller = textAlertController(context: strongSelf.context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: { let controller = textAlertController(context: strongSelf.context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {
if let navigationController = strongSelf.navigationController as? NavigationController { if let navigationController = strongSelf.navigationController as? NavigationController {
@ -132,27 +174,6 @@ public final class WalletSplashScreen: ViewController {
navigationController.setViewControllers(controllers, animated: true) navigationController.setViewControllers(controllers, animated: true)
} }
}) })
case .sent, .created:
self.navigationItem.setLeftBarButton(UIBarButtonItem(customDisplayNode: ASDisplayNode())!, animated: false)
case .restoreFailed, .secureStorageNotAvailable, .secureStorageReset:
break
case .success:
break
}
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Back, style: .plain, target: nil, action: nil)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc private func backPressed() {
self.dismiss()
}
@objc private func importPressed() {
self.push(WalletWordCheckScreen(context: self.context, tonContext: self.tonContext, mode: .import, walletCreatedPreloadState: nil))
} }
override public func loadDisplayNode() { override public func loadDisplayNode() {

View File

@ -2175,6 +2175,7 @@ public final class WalletWordCheckScreen: ViewController {
TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: { TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {
}) })
], actionLayout: .vertical), in: .window(.root)) ], actionLayout: .vertical), in: .window(.root))
return
} }
let _ = (importWallet(postbox: strongSelf.context.account.postbox, network: strongSelf.context.account.network, tonInstance: strongSelf.tonContext.instance, keychain: strongSelf.tonContext.keychain, wordList: enteredWords) let _ = (importWallet(postbox: strongSelf.context.account.postbox, network: strongSelf.context.account.network, tonInstance: strongSelf.tonContext.instance, keychain: strongSelf.tonContext.keychain, wordList: enteredWords)
|> deliverOnMainQueue).start(next: { walletInfo in |> deliverOnMainQueue).start(next: { walletInfo in
@ -2719,17 +2720,17 @@ private final class WalletWordCheckScreenNode: ViewControllerTracingNode, UIScro
} }
} }
focused = { [weak self] node in focused = { [weak self] node in
DispatchQueue.main.async {
guard let strongSelf = self else { guard let strongSelf = self else {
return return
} }
if node.isLast { if node.isLast {
UIView.animate(withDuration: 0.3, animations: { strongSelf.scrollNode.view.scrollRectToVisible(strongSelf.buttonNode.frame.insetBy(dx: 0.0, dy: -10.0), animated: true)
strongSelf.scrollNode.view.scrollRectToVisible(strongSelf.buttonNode.frame.insetBy(dx: 0.0, dy: -10.0), animated: false)
})
} else { } else {
strongSelf.scrollNode.view.scrollRectToVisible(node.frame.insetBy(dx: 0.0, dy: -10.0), animated: true) strongSelf.scrollNode.view.scrollRectToVisible(node.frame.insetBy(dx: 0.0, dy: -10.0), animated: true)
} }
} }
}
pasteWords = { [weak self] wordList in pasteWords = { [weak self] wordList in
guard let strongSelf = self else { guard let strongSelf = self else {
return return