-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show only wallet chains in filter (#169)
* Added WalletSupportedChains model to omit code duplications * Updates for AddTokenScene * added tests
- Loading branch information
Showing
9 changed files
with
111 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c). Gem Wallet. All rights reserved. | ||
|
||
import Foundation | ||
import Primitives | ||
import Settings | ||
|
||
enum WalletSupportedChains { | ||
case all | ||
case withTokens | ||
} | ||
|
||
// MARK: - Model extensions | ||
|
||
extension Primitives.Wallet { | ||
func chains(type: WalletSupportedChains) -> [Chain] { | ||
let supportedChains: [Chain] | ||
switch type { | ||
case .all: | ||
supportedChains = AssetConfiguration.allChains | ||
case .withTokens: | ||
supportedChains = AssetConfiguration.supportedChainsWithTokens | ||
} | ||
|
||
let walletChains = accounts.map { $0.chain }.asSet() | ||
return walletChains.intersection(supportedChains).asArray() | ||
.sorted { AssetScore.defaultRank(chain: $0) > AssetScore.defaultRank(chain: $1) } | ||
} | ||
} |
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,41 @@ | ||
import XCTest | ||
import Primitives | ||
@testable import Gem | ||
|
||
final class WalletSupportedChainsTests: XCTestCase { | ||
func testChainsAll() { | ||
let wallet = Wallet.mock(accounts: [ | ||
.mock(chain: .bitcoin), | ||
.mock(chain: .doge), | ||
.mock(chain: .ethereum) | ||
]) | ||
|
||
let result = wallet.chains(type: .all) | ||
let expectedChains: [Chain] = [.bitcoin, .ethereum, .doge] | ||
XCTAssertEqual(result, expectedChains) | ||
} | ||
|
||
func testChainsWithTokens() { | ||
let wallet = Wallet.mock(accounts: [ | ||
.mock(chain: .bitcoin), | ||
.mock(chain: .doge), | ||
.mock(chain: .ethereum) | ||
]) | ||
|
||
let result = wallet.chains(type: .withTokens) | ||
let expectedChains: [Chain] = [.ethereum] | ||
XCTAssertEqual(result, expectedChains) | ||
} | ||
|
||
func testChainSorting() { | ||
let wallet = Wallet.mock(accounts: [ | ||
.mock(chain: .doge), | ||
.mock(chain: .ethereum), | ||
.mock(chain: .bitcoin) | ||
]) | ||
|
||
let result = wallet.chains(type: .all) | ||
let expectedChains: [Chain] = [.bitcoin, .ethereum, .doge] | ||
XCTAssertEqual(result, expectedChains) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Packages/Primitives/TestKit/Account+PrimitivesTestKit.swift
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,17 @@ | ||
// Copyright (c). Gem Wallet. All rights reserved. | ||
|
||
import Foundation | ||
import Primitives | ||
|
||
public extension Account { | ||
static func mock( | ||
chain: Chain = .mock() | ||
) -> Account { | ||
Account( | ||
chain: chain, | ||
address: .empty, | ||
derivationPath: .empty, | ||
extendedPublicKey: .empty | ||
) | ||
} | ||
} |
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