This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Error messaging for send amount too small (#297)
commit 7dace9e2532da36faa84ee2aeb3ca1e8eda42d00 Merge: 305bce9 a04e48d Author: Otto Suess <[email protected]> Date: Thu Nov 14 10:34:26 2019 +0100 Merge branch 'dustEstimateError' of github.com:chitowncrispy/zap-iOS into chitowncrispy-dustEstimateError # Conflicts: # SwiftLnd/Api/Helper/LndApiError.swift # SwiftLnd/Api/Helper/RpcZapHelper.swift commit a04e48d Author: Christopher Pinski <[email protected]> Date: Sat Nov 9 17:49:19 2019 -0600 Created a LoadingError which translates any error from the app to a specific UI state commit 369f379 Author: Christopher Pinski <[email protected]> Date: Thu Oct 31 13:06:08 2019 -0500 Using a result type for the Loadable enum element case commit 31c8d9d Author: Christopher Pinski <[email protected]> Date: Thu Oct 31 09:47:33 2019 -0500 Setting initial value for subtitleText back to nil since we aren't showing an error initially commit 3dabcde Author: Christopher Pinski <[email protected]> Date: Wed Oct 30 23:02:00 2019 -0500 Removing error messaging from fee label commit a5b7658 Author: Christopher Pinski <[email protected]> Date: Fri Oct 25 08:52:26 2019 -0500 Cleaning up code based on PR comments commit 4f3094b Author: Christopher Pinski <[email protected]> Date: Thu Oct 24 20:19:53 2019 -0500 Setting up the primary currency listener only once commit 2b3f895 Author: Christopher Pinski <[email protected]> Date: Thu Oct 24 13:01:42 2019 -0500 Updating the view to show the on chain balance when the user hasn't input any amount commit cfe8917 Author: Christopher Pinski <[email protected]> Date: Wed Oct 23 20:47:51 2019 -0500 Not allowing the user to send if the transaction is dust commit 54986bd Author: Christopher Pinski <[email protected]> Date: Wed Oct 23 20:00:08 2019 -0500 Rebasing PR Co-authored-by: Christopher Pinski <[email protected]>
- Loading branch information
1 parent
305bce9
commit 58d5f03
Showing
8 changed files
with
215 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Zap | ||
// | ||
// Created by Otto Suess on 20.03.18. | ||
// Copyright © 2018 Otto Suess. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Logger | ||
import SwiftGRPC | ||
|
||
public enum LndApiError: Error, LocalizedError, Equatable { | ||
case invalidInput | ||
case walletEncrypted | ||
case lndNotRunning | ||
case localizedError(String) | ||
case unknownError | ||
case walletAlreadyUnlocked | ||
case transactionDust | ||
|
||
public init(callResult: CallResult) { | ||
switch callResult.statusCode { | ||
|
||
case .unimplemented: | ||
self = .walletEncrypted | ||
case .internalError: | ||
self = .lndNotRunning | ||
default: | ||
if | ||
let statusMessage = callResult.statusMessage, | ||
!statusMessage.isEmpty { | ||
self = .localizedError(statusMessage) | ||
} else { | ||
self = .unknownError | ||
} | ||
} | ||
} | ||
|
||
public var errorDescription: String? { | ||
switch self { | ||
case .localizedError(let description): | ||
return description | ||
case .walletEncrypted: | ||
return "Wallet is encrypted." | ||
case .lndNotRunning: | ||
return "Lnd does not seem to be running properly." | ||
case .transactionDust: | ||
return "Transaction amount too small." | ||
case .invalidInput, .unknownError, .walletAlreadyUnlocked: | ||
return nil | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// SwiftLnd | ||
// | ||
// Created by 0 on 07.05.19. | ||
// Copyright © 2019 Zap. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
#if !REMOTEONLY | ||
import Lndmobile | ||
#endif | ||
import Logger | ||
import SwiftGRPC | ||
import SwiftProtobuf | ||
|
||
// MARK: - Helper Methods | ||
#if !REMOTEONLY | ||
final class LndCallback<T: SwiftProtobuf.Message>: NSObject, LndmobileCallbackProtocol, LndmobileRecvStreamProtocol { | ||
private let completion: ApiCompletion<T> | ||
|
||
init(_ completion: @escaping ApiCompletion<T>) { | ||
self.completion = completion | ||
} | ||
|
||
func onError(_ error: Error?) { | ||
if let error = error { | ||
Logger.error(error) | ||
let result: LndApiError | ||
if error.localizedDescription == "Closed" { | ||
result = .walletAlreadyUnlocked | ||
} else if error.localizedDescription == "rpc error: code = Unknown desc = transaction output is dust" { | ||
result = .transactionDust | ||
} else { | ||
result = .localizedError(error.localizedDescription) | ||
} | ||
completion(.failure(result)) | ||
} else { | ||
completion(.failure(.unknownError)) | ||
} | ||
} | ||
|
||
func onResponse(_ data: Data?) { | ||
if let data = data, | ||
let result = try? T(serializedData: data) { | ||
completion(.success(result)) | ||
} else { | ||
let result = T() | ||
completion(.success(result)) | ||
} | ||
} | ||
} | ||
#endif | ||
|
||
func handleStreamResult<T>(_ result: ResultOrRPCError<T?>, completion: @escaping ApiCompletion<T>) throws { | ||
switch result { | ||
case .result(let value): | ||
guard let value = value else { return } | ||
completion(.success(value)) | ||
case .error(let error): | ||
throw error | ||
} | ||
} | ||
|
||
func createHandler<T>(_ completion: @escaping ApiCompletion<T>) -> (T?, CallResult) -> Void { | ||
return { (response: T?, callResult: CallResult) in | ||
if let response = response { | ||
completion(.success(response)) | ||
} else { | ||
let error = LndApiError(callResult: callResult) | ||
Logger.error(error) | ||
completion(.failure(error)) | ||
} | ||
} | ||
} | ||
|
||
extension Result { | ||
init(value: Success?, error: Failure) { | ||
if let value = value { | ||
self = .success(value) | ||
} else { | ||
self = .failure(error) | ||
} | ||
} | ||
} |