-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor address security issues and integrate to send flow
- Loading branch information
Showing
12 changed files
with
217 additions
and
135 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
47 changes: 0 additions & 47 deletions
47
UnstoppableWallet/UnstoppableWallet/Core/Address/AddressSecurityCheckerChain.swift
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
UnstoppableWallet/UnstoppableWallet/Core/Address/AddressSecurityIssueType.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,40 @@ | ||
import MarketKit | ||
|
||
enum AddressSecurityIssueType: CaseIterable, Identifiable { | ||
case phishing | ||
case sanctioned | ||
|
||
var id: Self { | ||
self | ||
} | ||
|
||
var title: String { | ||
switch self { | ||
case .phishing: return "send.address.phishing_check".localized | ||
case .sanctioned: return "send.address.blacklist_check".localized | ||
} | ||
} | ||
|
||
var caution: CautionNew { | ||
switch self { | ||
case .phishing: return CautionNew(title: "send.address.phishing.title".localized, text: "send.address.phishing.description".localized, type: .error) | ||
case .sanctioned: return CautionNew(title: "send.address.blacklist.title".localized, text: "send.address.blacklist.description".localized, type: .error) | ||
} | ||
} | ||
|
||
func supports(blockchainType: BlockchainType) -> Bool { | ||
switch self { | ||
case .phishing: return EvmBlockchainManager.blockchainTypes.contains(blockchainType) | ||
case .sanctioned: return true | ||
} | ||
} | ||
|
||
static func issueTypes(blockchainType: BlockchainType) -> [Self] { | ||
allCases.filter { $0.supports(blockchainType: blockchainType) } | ||
} | ||
} | ||
|
||
struct ResolvedAddress: Hashable { | ||
let address: String | ||
let issueTypes: [AddressSecurityIssueType] | ||
} |
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
34 changes: 7 additions & 27 deletions
34
UnstoppableWallet/UnstoppableWallet/Core/Factories/AddressSecurityCheckerFactory.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 |
---|---|---|
@@ -1,32 +1,12 @@ | ||
import MarketKit | ||
protocol IAddressSecurityChecker { | ||
func check(address: Address) async throws -> Bool | ||
} | ||
|
||
enum AddressSecurityCheckerFactory { | ||
static func securityCheckerChainHandlers(blockchainType: BlockchainType) -> [IAddressSecurityCheckerItem] { | ||
switch blockchainType { | ||
case .ethereum, .gnosis, .fantom, .polygon, .arbitrumOne, .avalanche, .optimism, .binanceSmartChain, .base: | ||
let evmAddressSecurityCheckerItem = SpamAddressDetector() | ||
let chainalysisAddressValidator = ChainalysisAddressValidator(networkManager: App.shared.networkManager) | ||
|
||
var handlers = [IAddressSecurityCheckerItem]() | ||
handlers.append(evmAddressSecurityCheckerItem) | ||
handlers.append(chainalysisAddressValidator) | ||
|
||
return handlers | ||
default: | ||
return [] | ||
static func addressSecurityChecker(type: AddressSecurityIssueType) -> IAddressSecurityChecker { | ||
switch type { | ||
case .phishing: return SpamAddressDetector() | ||
case .sanctioned: return ChainalysisAddressValidator() | ||
} | ||
} | ||
|
||
static func securityCheckerChain(blockchainType: BlockchainType?) -> AddressSecurityCheckerChain { | ||
if let blockchainType { | ||
return AddressSecurityCheckerChain().append(handlers: securityCheckerChainHandlers(blockchainType: blockchainType)) | ||
} | ||
|
||
var handlers = [IAddressSecurityCheckerItem]() | ||
for blockchainType in BlockchainType.supported { | ||
handlers.append(contentsOf: securityCheckerChainHandlers(blockchainType: blockchainType)) | ||
} | ||
|
||
return AddressSecurityCheckerChain().append(handlers: handlers) | ||
} | ||
} |
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
Oops, something went wrong.