Merge pull request #4343 from AlphaWallet/remove-unnecessary-implement-equatable-unnecessary-equals-func-implementation

Removes unnecessary `func ==()` implementations and a few Equatable(s)
pull/4349/head
Hwee-Boon Yar 3 years ago committed by GitHub
commit e8548d7fc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      AlphaWallet.xcodeproj/project.pbxproj
  2. 13
      AlphaWallet/Core/Types/SortTokensParam.swift
  3. 20
      AlphaWallet/Core/Views/WebImageView.swift
  4. 8
      AlphaWallet/Tokens/Types/AddressAndRPCServer.swift
  5. 27
      AlphaWallet/Tokens/ViewModels/TokensViewModel.swift
  6. 15
      AlphaWalletTests/Tokens/AddressAndRPCServerTests.swift
  7. 12
      AlphaWalletTests/modules/AlphaWalletAddress/AlphaWalletAddressTests.swift
  8. 6
      modules/AlphaWalletAddress/AlphaWalletAddress/AlphaWallet.swift

@ -436,6 +436,7 @@
5E7C76AFBBACDD13BEF25DA9 /* ToolsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7F970B01399530F62569 /* ToolsViewModel.swift */; };
5E7C76B7DDF7BB124B12A738 /* DappButtonViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C754BF8B4CC2DA82B1025 /* DappButtonViewModel.swift */; };
5E7C76B917517C93D1E26B0A /* LockEnterPasscodeCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7981AB6584B25C72D46B /* LockEnterPasscodeCoordinator.swift */; };
5E7C76C4BDFB2FA2F6289AF0 /* AddressAndRPCServerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C72CDD54E5A0C5BB23C89 /* AddressAndRPCServerTests.swift */; };
5E7C76C8A983A91A82F646E5 /* TokenInstanceWebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C704499C81ACA3B08A752 /* TokenInstanceWebView.swift */; };
5E7C76D28BB14C7685296BEF /* DappsHomeEmptyViewViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C74B424FB5DE3A4D6A2F4 /* DappsHomeEmptyViewViewModel.swift */; };
5E7C76D464BD797FF3A962F8 /* Origin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C786486937661D0DCD4E2 /* Origin.swift */; };
@ -1417,6 +1418,7 @@
5E7C72B3371522B5C1B1B5BE /* GeneralisedTime.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneralisedTime.swift; sourceTree = "<group>"; };
5E7C72BEB789700C49FF64A6 /* DeletedContract.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeletedContract.swift; sourceTree = "<group>"; };
5E7C72CD0C22247A6AF7C95E /* GetERC721BalanceEncode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GetERC721BalanceEncode.swift; sourceTree = "<group>"; };
5E7C72CDD54E5A0C5BB23C89 /* AddressAndRPCServerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddressAndRPCServerTests.swift; sourceTree = "<group>"; };
5E7C72D0003C5C2C385DBFC9 /* ENSReverseResolver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ENSReverseResolver.swift; sourceTree = "<group>"; };
5E7C72D0E7CA03ADE5CFAE7A /* ImportMagicTokenViewControllerViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImportMagicTokenViewControllerViewModel.swift; sourceTree = "<group>"; };
5E7C72DDBF109139E4C661D5 /* DelegateContract.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DelegateContract.swift; sourceTree = "<group>"; };
@ -4068,6 +4070,7 @@
5E7C71E355BD14E975AF7491 /* TokensDataStoreTest.swift */,
5E7C76AB57FE8E8E084CF4A8 /* Coordinators */,
5E7C7DB349EEDBC8AE9AD500 /* Helpers */,
5E7C72CDD54E5A0C5BB23C89 /* AddressAndRPCServerTests.swift */,
);
path = Tokens;
sourceTree = "<group>";
@ -6927,6 +6930,7 @@
5E7C7264B6B898A90F1761F0 /* AlphaWalletAddressTests.swift in Sources */,
5E7C7BA90D4D854B33D0E355 /* WebImageUrlTests.swift in Sources */,
5E7C7900E8FF0E478376861B /* URLTests.swift in Sources */,
5E7C76C4BDFB2FA2F6289AF0 /* AddressAndRPCServerTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -22,20 +22,9 @@ extension TokenObject {
}
/// Enum represents token objects sorting cases
enum SortTokensParam: CaseIterable {
enum SortTokensParam: CaseIterable, Equatable {
case byField(field: TokenObject.Field, direction: SortDirection)
case mostUsed
static var allCases: [SortTokensParam] = Constants.defaultSortTokensParams
static func == (lhs: Self, rhs: Self) -> Bool {
switch (lhs, rhs) {
case (.mostUsed, .mostUsed):
return true
case (.byField(let field1, let direction1), .byField(let field2, let direction2)):
return field1 == field2 && direction1 == direction2
case (.byField, .mostUsed), (.mostUsed, .byField):
return false
}
}
}

@ -7,26 +7,6 @@ import Kingfisher
enum WebImageViewImage: Hashable, Equatable {
case url(WebImageURL)
case image(UIImage)
static func == (lhs: WebImageViewImage, rhs: WebImageViewImage) -> Bool {
switch (lhs, rhs) {
case (.url(let v1), .url(let v2)):
return v1 == v2
case (.image(let v1), .image(let v2)):
return v1 == v2
case (_, _):
return false
}
}
func hash(into hasher: inout Hasher) {
switch self {
case .url(let uRL):
hasher.combine(uRL)
case .image(let uIImage):
hasher.combine(uIImage)
}
}
}
final class FixedContentModeImageView: UIImageView {

@ -18,10 +18,4 @@ struct AddressAndRPCServer: Hashable, Codable, CustomStringConvertible {
func hash(into hasher: inout Hasher) {
hasher.combine(description)
}
}
extension AddressAndRPCServer: Equatable {
static func == (lhs: AddressAndRPCServer, rhs: AddressAndRPCServer) -> Bool {
lhs.address.sameContract(as: rhs.address) && lhs.server == rhs.server
}
}
}

@ -44,27 +44,6 @@ struct CollectiblePairs: Hashable {
extension TokensViewModel {
enum Section: Equatable {
static func == (lhs: Section, rhs: Section) -> Bool {
switch (lhs, rhs) {
case (.walletSummary, .walletSummary):
return true
case (.filters, .filters):
return true
case (.testnetTokens, .testnetTokens):
return true
case (.search, .search):
return true
case (.tokens, .tokens):
return true
case (.collectiblePairs, .collectiblePairs):
return true
case (.activeWalletSession(let count1), .activeWalletSession(let count2)):
return count1 == count2
case (_, _):
return false
}
}
case walletSummary
case filters
case testnetTokens
@ -161,15 +140,15 @@ class TokensViewModel {
switch filter {
case .all, .keyword:
return true
case .assets, .collectiblesOnly, .type, .defi, .governance:
case .assets, .collectiblesOnly, .type, .defi, .governance:
return false
}
}
}
var hasContent: Bool {
return !collectiblePairs.isEmpty
}
var shouldShowCollectiblesCollectionView: Bool {
switch filter {
case .all, .defi, .governance, .assets, .keyword, .type:

@ -0,0 +1,15 @@
// Copyright © 2022 Stormbird PTE. LTD.
import XCTest
@testable import AlphaWallet
class AddressAndRPCServerTests: XCTestCase {
func testEquality() {
let address1 = AlphaWallet.Address(string: "0x007bee82bdD9e866B2bD114780A47F2261C6840E")!
let address2 = AlphaWallet.Address(string: "0x007bee82bdD9e866B2bD114780A47F2261C6840e")!
let address3 = AlphaWallet.Address(string: "0xA66A3F08068174e8F005112A8b2c7A507a822335")!
XCTAssert(AddressAndRPCServer(address: address1, server: .main) == AddressAndRPCServer(address: address2, server: .main))
XCTAssert(AddressAndRPCServer(address: address1, server: .rinkeby) != AddressAndRPCServer(address: address2, server: .main))
XCTAssert(AddressAndRPCServer(address: address1, server: .main) != AddressAndRPCServer(address: address3, server: .main))
}
}

@ -8,4 +8,14 @@ class AlphaWalletAddressTests: XCTestCase {
XCTAssertNotNil(AlphaWallet.Address(string: "0x007bee82bdD9e866B2bD114780A47F2261C6840E"))
XCTAssertNil(AlphaWallet.Address(string: "0x007bee82bdD9e866B2bD114780A47F2261C6840"))
}
}
func testEquality() {
let address1 = AlphaWallet.Address(string: "0x007bee82bdD9e866B2bD114780A47F2261C6840E")!
let address2 = AlphaWallet.Address(string: "0x007bee82bdD9e866B2bD114780A47F2261C6840E")!
let address3 = AlphaWallet.Address(string: "0x007bee82bdD9e866B2bD114780A47F2261C6840e")!
let address4 = AlphaWallet.Address(string: "0xA66A3F08068174e8F005112A8b2c7A507a822335")!
XCTAssert(address1 == address2)
XCTAssert(address1 == address3)
XCTAssert(address1 != address4)
}
}

@ -91,12 +91,6 @@ extension AlphaWallet {
}
}
extension AlphaWallet.Address {
public static func == (lsh: AlphaWallet.Address, rhs: AlphaWallet.Address) -> Bool {
return lsh.sameContract(as: rhs)
}
}
extension AlphaWallet.Address: CustomStringConvertible {
//TODO should not be using this in production code
public var description: String {

Loading…
Cancel
Save