Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/gradle/android/com.halilibo.com…
Browse files Browse the repository at this point in the history
…pose-richtext-richtext-ui-material-android-0.20.0
  • Loading branch information
prybalko authored Jan 5, 2024
2 parents e7e6b3d + 5136ed5 commit 7257da3
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 41 deletions.
35 changes: 22 additions & 13 deletions ios/PolkadotVault/Core/Keychain/SeedsMediator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ enum KeychainError: Error, Equatable {
/// Protocol that gathers all operations related to Keychain storage
protocol SeedsMediating: AnyObject {
/// Accessor property for available seed names
///
/// This should be turned to `private` in future refactors
var seedNames: [String] { get set }
var seedNames: [String] { get }

var seedNamesPublisher: AnyPublisher<[String], Never> { get }

/// Get all seed names from secure storage
///
Expand Down Expand Up @@ -66,7 +66,14 @@ final class SeedsMediator: SeedsMediating {
private let keychainAccessAdapter: KeychainAccessAdapting
private let databaseMediator: DatabaseMediating
private let authenticationStateMediator: AuthenticatedStateMediator
@Published var seedNames: [String] = []
var seedNamesSubject = CurrentValueSubject<[String], Never>([])
var seedNamesPublisher: AnyPublisher<[String], Never> {
seedNamesSubject.eraseToAnyPublisher()
}

var seedNames: [String] {
seedNamesSubject.value
}

init(
queryProvider: KeychainQueryProviding = KeychainQueryProvider(),
Expand All @@ -84,7 +91,7 @@ final class SeedsMediator: SeedsMediating {
let result = keychainAccessAdapter.fetchSeedNames()
switch result {
case let .success(payload):
seedNames = payload.seeds
seedNamesSubject.send(payload.seeds)
authenticationStateMediator.authenticated = true
case .failure:
authenticationStateMediator.authenticated = false
Expand All @@ -107,16 +114,18 @@ final class SeedsMediator: SeedsMediating {
)
switch saveSeedResult {
case .success:
seedNames.append(seedName)
seedNames.sort()
var seeds = seedNamesSubject.value
seeds.append(seedName)
seeds.sort()
seedNamesSubject.send(seeds)
return true
case .failure:
return false
}
}

func checkSeedCollision(seedName: String) -> Bool {
seedNames.contains(seedName)
seedNamesSubject.value.contains(seedName)
}

func getSeedBackup(seedName: String) -> String {
Expand Down Expand Up @@ -165,7 +174,7 @@ final class SeedsMediator: SeedsMediating {
}

func getAllSeeds() -> [String: String] {
getSeeds(seedNames: Set(seedNames))
getSeeds(seedNames: Set(seedNamesSubject.value))
}

func removeSeed(seedName: String) -> Bool {
Expand All @@ -176,7 +185,7 @@ final class SeedsMediator: SeedsMediating {
let result = keychainAccessAdapter.removeSeed(seedName: seedName)
switch result {
case .success:
seedNames = seedNames
seedNamesSubject.value = seedNamesSubject.value
.filter { $0 != seedName }
.sorted()
return true
Expand All @@ -187,11 +196,11 @@ final class SeedsMediator: SeedsMediating {

func removeAllSeeds() -> Bool {
// Fetch seeds first, as this will trigger authentication if passcode is not cached
guard case .success = keychainAccessAdapter.retrieveSeeds(with: Set(seedNames)) else {
guard case .success = keychainAccessAdapter.retrieveSeeds(with: Set(seedNamesSubject.value)) else {
return false
}
guard keychainAccessAdapter.removeAllSeeds() else { return false }
seedNames = []
seedNamesSubject.send([])
return true
}

Expand All @@ -211,6 +220,6 @@ final class SeedsMediator: SeedsMediating {

func removeStalledSeeds() {
_ = keychainAccessAdapter.removeAllSeeds()
seedNames = []
seedNamesSubject.send([])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension AuthenticatedScreenContainer {
init(seedsMediator: SeedsMediating = ServiceLocator.seedsMediator) {
self.seedsMediator = seedsMediator
updateViewState()
seedsMediator.seedNames.publisher
seedsMediator.seedNamesPublisher
.sink { [weak self] _ in
self?.updateViewState()
}
Expand Down
18 changes: 9 additions & 9 deletions ios/PolkadotVaultTests/Core/Keychain/SeedsMediatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ final class SeedsMediatorTests: XCTestCase {
let seedName = "Seed1"
let seedPhrase = "seedPhrase"
// Simulate collision
seedsMediator.seedNames = [seedPhrase]
seedsMediator.seedNamesSubject.value = [seedPhrase]

// When
let result = seedsMediator.createSeed(seedName: seedName, seedPhrase: seedPhrase, shouldCheckForCollision: true)
Expand Down Expand Up @@ -135,7 +135,7 @@ final class SeedsMediatorTests: XCTestCase {
func testCheckSeedCollision_Exists() {
// Given
let existingSeedName = "Seed1"
seedsMediator.seedNames = [existingSeedName]
seedsMediator.seedNamesSubject.value = [existingSeedName]

// When
let result = seedsMediator.checkSeedCollision(seedName: existingSeedName)
Expand All @@ -147,7 +147,7 @@ final class SeedsMediatorTests: XCTestCase {
func testCheckSeedCollision_NotExists() {
// Given
let nonExistingSeedName = "Seed2"
seedsMediator.seedNames = ["Seed1"]
seedsMediator.seedNamesSubject.value = ["Seed1"]

// When
let result = seedsMediator.checkSeedCollision(seedName: nonExistingSeedName)
Expand Down Expand Up @@ -242,7 +242,7 @@ final class SeedsMediatorTests: XCTestCase {

func testGetAllSeeds() {
// Given
seedsMediator.seedNames = ["Seed1", "Seed2"]
seedsMediator.seedNamesSubject.value = ["Seed1", "Seed2"]
let expectedSeeds = ["Seed1": "seedData1", "Seed2": "seedData2"]
keychainAccessAdapterMock.retrieveSeedsReturnValue = .success(expectedSeeds)

Expand All @@ -256,7 +256,7 @@ final class SeedsMediatorTests: XCTestCase {
func testRemoveSeed_Successful() {
// Given
let seedName = "Seed1"
seedsMediator.seedNames = [seedName, "Seed2"]
seedsMediator.seedNamesSubject.value = [seedName, "Seed2"]
keychainAccessAdapterMock.retrieveSeedReturnValue = .success("seedData")
keychainAccessAdapterMock.removeSeedReturnValue = .success(())

Expand All @@ -271,7 +271,7 @@ final class SeedsMediatorTests: XCTestCase {
func testRemoveSeed_Failure() {
// Given
let seedName = "Seed1"
seedsMediator.seedNames = [seedName, "Seed2"]
seedsMediator.seedNamesSubject.value = [seedName, "Seed2"]
keychainAccessAdapterMock.retrieveSeedReturnValue = .failure(.fetchError)

// When
Expand All @@ -284,7 +284,7 @@ final class SeedsMediatorTests: XCTestCase {

func testRemoveAllSeeds_Successful() {
// Given
seedsMediator.seedNames = ["Seed1", "Seed2"]
seedsMediator.seedNamesSubject.value = ["Seed1", "Seed2"]
keychainAccessAdapterMock.retrieveSeedsReturnValue = .success(["Seed1": "seedData1", "Seed2": "seedData2"])
keychainAccessAdapterMock.removeAllSeedsReturnValue = true

Expand All @@ -298,7 +298,7 @@ final class SeedsMediatorTests: XCTestCase {

func testRemoveAllSeeds_Failure() {
// Given
seedsMediator.seedNames = ["Seed1", "Seed2"]
seedsMediator.seedNamesSubject.value = ["Seed1", "Seed2"]
keychainAccessAdapterMock.retrieveSeedsReturnValue = .failure(.fetchError)

// When
Expand Down Expand Up @@ -348,7 +348,7 @@ final class SeedsMediatorTests: XCTestCase {

func testRemoveStalledSeeds() {
// Given
seedsMediator.seedNames = ["Seed1", "Seed2"]
seedsMediator.seedNamesSubject.value = ["Seed1", "Seed2"]
keychainAccessAdapterMock.removeAllSeedsReturnValue = true

// When
Expand Down
16 changes: 8 additions & 8 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/db_handling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ regex = "1.10.2"
sled = "0.34.6"
sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, features = ["full_crypto"], optional = true}
sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, optional = true}
thiserror = "1.0.55"
thiserror = "1.0.56"
time = {version = "0.3.31", features = ["formatting", "macros"]}
tiny-bip39 = {version = "1.0.0", default-features = false, optional = true}
zeroize = { version = "1.7.0", optional = true, features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion rust/defaults/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ lazy_static = {version = "1.4.0", optional = true}
regex = {version = "1.10.2", optional = true}
sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, features = ["full_crypto"]}
sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false}
thiserror = "1.0.55"
thiserror = "1.0.56"

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion rust/definitions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sp-io = {git = "https://github.com/paritytech/substrate", optional = true}
sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false}
sp-version = {git = "https://github.com/paritytech/substrate"}
sp-wasm-interface = {git = "https://github.com/paritytech/substrate", optional = true}
thiserror = "1.0.55"
thiserror = "1.0.56"
constants = {path = "../constants"}

[features]
Expand Down
4 changes: 2 additions & 2 deletions rust/generate_message/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ lazy_static = "1.4.0"
parity-scale-codec = "3.6.9"
qrcode_rtx = {path = "../qrcode_rtx"}
regex = "1.10.2"
serde_json = "1.0.110"
serde_json = "1.0.111"
sled = "0.34.6"
sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, features = ["full_crypto"]}
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false }
sp-keyring = { git = "https://github.com/paritytech/substrate", default-features = false }
thiserror = "1.0.55"
thiserror = "1.0.56"
tokio = { version = "1", features = ["full"] }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion rust/navigator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hex = "0.4.3"
lazy_static = "1.4.0"
sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false}
banana_recovery = { git = "https://github.com/paritytech/banana-recovery-rust" }
thiserror = "1.0.55"
thiserror = "1.0.56"
transaction_parsing = {path = "../transaction_parsing"}
transaction_signing = {path = "../transaction_signing"}
zeroize = { version = "1.7.0", features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion rust/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ scale-info = "2.10.0"
sp-arithmetic = {git = "https://github.com/paritytech/substrate"}
sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, features = ["full_crypto"]}
sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false}
thiserror = "1.0.55"
thiserror = "1.0.56"

[dev-dependencies]
pretty_assertions = "1"
Expand Down
2 changes: 1 addition & 1 deletion rust/qr_reader_phone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2018"
hex = "0.4.3"
raptorq = "1.8.0"
nom = "7.1.3"
thiserror = "1.0.55"
thiserror = "1.0.56"
constants = {path = "../constants"}
banana_recovery = { git = "https://github.com/paritytech/banana-recovery-rust" }
transaction_parsing = { path = "../transaction_parsing" }
Expand Down
2 changes: 1 addition & 1 deletion rust/transaction_parsing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ parser = {path = "../parser", default-features = false}
sled = "0.34.6"
sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, features = ["full_crypto"]}
sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false}
thiserror = "1.0.55"
thiserror = "1.0.56"
nom = "7.1.3"
log = "0.4"

Expand Down
2 changes: 1 addition & 1 deletion rust/transaction_signing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ definitions = { path = "../definitions", default-features = false }
db_handling = { path = "../db_handling", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, features = ["full_crypto"] }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false }
thiserror = "1.0.55"
thiserror = "1.0.56"
anyhow = "1.0.79"
sled = "0.34"

Expand Down

0 comments on commit 7257da3

Please sign in to comment.