forked from trustwallet/trust-wallet-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BalanceStatus for insufficient wordings (trustwallet#400)
* Add BalanceStatus for insufficient texts * add protected logic (set gasSufficient = false) * Remove private _L(), use switch instead of if-else * Add BalanceStatusTests
- Loading branch information
1 parent
1fcc92a
commit 31f94aa
Showing
8 changed files
with
200 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright SIX DAY LLC. All rights reserved. | ||
|
||
import Foundation | ||
|
||
enum BalanceStatus { | ||
case ether(etherSufficient: Bool, gasSufficient: Bool) | ||
case token(tokenSufficient: Bool, gasSufficient: Bool) | ||
} | ||
|
||
extension BalanceStatus { | ||
|
||
enum Key { | ||
case insufficientEther | ||
case insufficientGas | ||
case insufficientToken | ||
case correct | ||
|
||
var string: String { | ||
switch self { | ||
case .insufficientEther: | ||
return "send.error.insufficientEther" | ||
case .insufficientGas: | ||
return "send.error.insufficientGas" | ||
case .insufficientToken: | ||
return "send.error.insufficientToken" | ||
case .correct: | ||
return "" | ||
} | ||
} | ||
} | ||
|
||
var sufficient: Bool { | ||
switch self { | ||
case .ether(let etherSufficient, let gasSufficient): | ||
return etherSufficient && gasSufficient | ||
case .token(let tokenSufficient, let gasSufficient): | ||
return tokenSufficient && gasSufficient | ||
} | ||
} | ||
|
||
var insufficientTextKey: Key { | ||
switch self { | ||
case .ether(let etherSufficient, let gasSufficient): | ||
if !etherSufficient { | ||
return .insufficientEther | ||
} | ||
if !gasSufficient { | ||
return .insufficientGas | ||
} | ||
case .token(let tokenSufficient, let gasSufficient): | ||
if !tokenSufficient { | ||
return .insufficientToken | ||
} | ||
if !gasSufficient { | ||
return .insufficientGas | ||
} | ||
} | ||
return .correct | ||
} | ||
|
||
var insufficientText: String { | ||
let key = insufficientTextKey | ||
switch key { | ||
case .insufficientEther: | ||
return NSLocalizedString(key.string, value: "Insufficient ethers", comment: "") | ||
case .insufficientGas: | ||
return NSLocalizedString(key.string, value: "Insufficient ethers for gas fee", comment: "") | ||
case .insufficientToken: | ||
return NSLocalizedString(key.string, value: "Insufficient tokens", comment: "") | ||
case .correct: | ||
return "" | ||
} | ||
} | ||
} |
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,51 @@ | ||
// Copyright SIX DAY LLC. All rights reserved. | ||
|
||
import XCTest | ||
@testable import Trust | ||
|
||
class BalanceStatusTests: XCTestCase { | ||
|
||
func testSufficientEth() { | ||
let status: BalanceStatus = .ether(etherSufficient: true, gasSufficient: true) | ||
XCTAssertTrue(status.sufficient) | ||
XCTAssertEqual(.correct, status.insufficientTextKey) | ||
} | ||
|
||
func testInsufficientGasForEth() { | ||
let status: BalanceStatus = .ether(etherSufficient: true, gasSufficient: false) | ||
XCTAssertFalse(status.sufficient) | ||
XCTAssertEqual(.insufficientGas, status.insufficientTextKey) | ||
} | ||
|
||
func testInsufficientEth() { | ||
let status: BalanceStatus = .ether(etherSufficient: false, gasSufficient: true) | ||
XCTAssertFalse(status.sufficient) | ||
XCTAssertEqual(.insufficientEther, status.insufficientTextKey) | ||
|
||
let status2: BalanceStatus = .ether(etherSufficient: false, gasSufficient: false) | ||
XCTAssertFalse(status2.sufficient) | ||
XCTAssertEqual(.insufficientEther, status2.insufficientTextKey) | ||
} | ||
|
||
func testSufficientTokens() { | ||
let status: BalanceStatus = .token(tokenSufficient: true, gasSufficient: true) | ||
XCTAssertTrue(status.sufficient) | ||
XCTAssertEqual(.correct, status.insufficientTextKey) | ||
} | ||
|
||
func testInsufficientGasForTokens() { | ||
let status: BalanceStatus = .token(tokenSufficient: true, gasSufficient: false) | ||
XCTAssertFalse(status.sufficient) | ||
XCTAssertEqual(.insufficientGas, status.insufficientTextKey) | ||
} | ||
|
||
func testInsufficientTokens() { | ||
let status: BalanceStatus = .token(tokenSufficient: false, gasSufficient: true) | ||
XCTAssertFalse(status.sufficient) | ||
XCTAssertEqual(.insufficientToken, status.insufficientTextKey) | ||
|
||
let status2: BalanceStatus = .token(tokenSufficient: false, gasSufficient: false) | ||
XCTAssertFalse(status2.sufficient) | ||
XCTAssertEqual(.insufficientToken, status2.insufficientTextKey) | ||
} | ||
} |