-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
6 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
42 changes: 42 additions & 0 deletions
42
novawallet/Common/Storage/WalletStorageCleaning/Cleaners/DAppSettingsCleaner.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,42 @@ | ||
import Foundation | ||
import Operation_iOS | ||
|
||
final class DAppSettingsCleaner { | ||
private let authorizedDAppRepository: AnyDataProviderRepository<DAppSettings> | ||
|
||
init(authorizedDAppRepository: AnyDataProviderRepository<DAppSettings>) { | ||
self.authorizedDAppRepository = authorizedDAppRepository | ||
} | ||
} | ||
|
||
// MARK: WalletStorageCleaning | ||
|
||
extension DAppSettingsCleaner: WalletStorageCleaning { | ||
func cleanStorage( | ||
for removedItems: @escaping () throws -> [MetaAccountModel] | ||
) -> CompoundOperationWrapper<Void> { | ||
let fetchOptions = RepositoryFetchOptions() | ||
let fetchSettingsOperation = authorizedDAppRepository.fetchAllOperation(with: fetchOptions) | ||
|
||
let deletionBlock: () throws -> [String] = { | ||
let removedWallets = Set(try removedItems().map(\.metaId)) | ||
let dappSettingsIds = try fetchSettingsOperation.extractNoCancellableResultData() | ||
.compactMap(\.metaId) | ||
.filter { removedWallets.contains($0) } | ||
|
||
return dappSettingsIds | ||
} | ||
|
||
let removeSettingsOperation = authorizedDAppRepository.saveOperation( | ||
{ [] }, | ||
deletionBlock | ||
) | ||
|
||
removeSettingsOperation.addDependency(fetchSettingsOperation) | ||
|
||
return CompoundOperationWrapper( | ||
targetOperation: removeSettingsOperation, | ||
dependencies: [fetchSettingsOperation] | ||
) | ||
} | ||
} |
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