diff --git a/unstoppable-ios-app/domains-manager-ios/Entities/Wallets/WalletEntity.swift b/unstoppable-ios-app/domains-manager-ios/Entities/Wallets/WalletEntity.swift index 52a12e65e..2449461e3 100644 --- a/unstoppable-ios-app/domains-manager-ios/Entities/Wallets/WalletEntity.swift +++ b/unstoppable-ios-app/domains-manager-ios/Entities/Wallets/WalletEntity.swift @@ -122,7 +122,7 @@ extension WalletEntity: Identifiable { extension Array where Element == WalletEntity { func findWithAddress(_ address: HexAddress?) -> Element? { - guard let address else { return nil } + guard let address = address?.normalized else { return nil } return first(where: { $0.address == address }) } diff --git a/unstoppable-ios-app/domains-manager-ios/Modules/Home/ReverseResolution/ReverseResolutionSelectionView.swift b/unstoppable-ios-app/domains-manager-ios/Modules/Home/ReverseResolution/ReverseResolutionSelectionView.swift index 12c52664c..9205c2a69 100644 --- a/unstoppable-ios-app/domains-manager-ios/Modules/Home/ReverseResolution/ReverseResolutionSelectionView.swift +++ b/unstoppable-ios-app/domains-manager-ios/Modules/Home/ReverseResolution/ReverseResolutionSelectionView.swift @@ -64,7 +64,7 @@ struct ReverseResolutionSelectionView: View, ViewAnalyticsLogger { .onReceive(walletsDataService.walletsPublisher.receive(on: DispatchQueue.main)) { wallets in switch mode { case .selectFirst: - guard let wallet = wallets.first(where: { $0.address == self.wallet.address }), + guard let wallet = wallets.findWithAddress(self.wallet.address), wallet.rrDomain == nil, wallet.isReverseResolutionChangeAllowed() else { dismiss() diff --git a/unstoppable-ios-app/domains-manager-ios/Modules/Messaging/Chat/ChatViewPresenter.swift b/unstoppable-ios-app/domains-manager-ios/Modules/Messaging/Chat/ChatViewPresenter.swift index df92980c8..f9b35b0ca 100644 --- a/unstoppable-ios-app/domains-manager-ios/Modules/Messaging/Chat/ChatViewPresenter.swift +++ b/unstoppable-ios-app/domains-manager-ios/Modules/Messaging/Chat/ChatViewPresenter.swift @@ -493,7 +493,7 @@ private extension ChatViewPresenter { func setupPlaceholder() { Task { let wallets = messagingService.fetchWalletsAvailableForMessaging() - let userWallet = wallets.first(where: { $0.address.normalized == profile.wallet.normalized }) + let userWallet = wallets.findWithAddress(profile.wallet) let sender = userWallet?.rrDomain?.name ?? profile.wallet.walletAddressTruncated let placeholder = String.Constants.chatInputPlaceholderAsDomain.localized(sender) view?.setPlaceholder(placeholder) @@ -648,7 +648,7 @@ private extension ChatViewPresenter { walletAddress: String) { Task { guard let view, - let wallet = appContext.walletsDataService.wallets.first(where: { $0.address == profile.wallet.normalized }) else { return } + let wallet = appContext.walletsDataService.wallets.findWithAddress(profile.wallet) else { return } UDRouter().showPublicDomainProfile(of: .init(walletAddress: walletAddress, name: domainName), by: wallet, diff --git a/unstoppable-ios-app/domains-manager-ios/Modules/Messaging/ChatsList/ChatsListViewPresenter.swift b/unstoppable-ios-app/domains-manager-ios/Modules/Messaging/ChatsList/ChatsListViewPresenter.swift index 0a1e1df61..eb572ba67 100644 --- a/unstoppable-ios-app/domains-manager-ios/Modules/Messaging/ChatsList/ChatsListViewPresenter.swift +++ b/unstoppable-ios-app/domains-manager-ios/Modules/Messaging/ChatsList/ChatsListViewPresenter.swift @@ -496,7 +496,7 @@ private extension ChatsListViewPresenter { func preselectProfile(_ profile: MessagingChatUserProfileDisplayInfo, usingWallets wallets: [WalletEntity]) async throws { - guard let wallet = wallets.first(where: { $0.address == profile.wallet.lowercased() }) else { + guard let wallet = wallets.findWithAddress(profile.wallet) else { try await resolveInitialProfileWith(wallets: wallets) return } diff --git a/unstoppable-ios-app/domains-manager-ios/Modules/PurchaseDomains/Checkout/PurchaseDomainsCheckoutView.swift b/unstoppable-ios-app/domains-manager-ios/Modules/PurchaseDomains/Checkout/PurchaseDomainsCheckoutView.swift index f925339c0..7d204204a 100644 --- a/unstoppable-ios-app/domains-manager-ios/Modules/PurchaseDomains/Checkout/PurchaseDomainsCheckoutView.swift +++ b/unstoppable-ios-app/domains-manager-ios/Modules/PurchaseDomains/Checkout/PurchaseDomainsCheckoutView.swift @@ -545,7 +545,7 @@ private extension PurchaseDomainsCheckoutView { selectAnotherCallback: { isSelectWalletPresented = true }, tryAgainCallback: { - guard let walletWithInfo = self.wallets.first(where: { $0.address == wallet.address }) else { return } + guard let walletWithInfo = self.wallets.findWithAddress(wallet.address) else { return } authorizeWithSelectedWallet(walletWithInfo, forceReload: true) }) case .failedToLoadCalculations(let callback): diff --git a/unstoppable-ios-app/domains-manager-ios/Modules/SignTransactions/TransactionRequestConfirmationView/PaymentTransactionRequestConfirmationView.swift b/unstoppable-ios-app/domains-manager-ios/Modules/SignTransactions/TransactionRequestConfirmationView/PaymentTransactionRequestConfirmationView.swift index 8a4d5e581..d8d6ecfea 100644 --- a/unstoppable-ios-app/domains-manager-ios/Modules/SignTransactions/TransactionRequestConfirmationView/PaymentTransactionRequestConfirmationView.swift +++ b/unstoppable-ios-app/domains-manager-ios/Modules/SignTransactions/TransactionRequestConfirmationView/PaymentTransactionRequestConfirmationView.swift @@ -70,7 +70,7 @@ extension PaymentTransactionRequestConfirmationView { private extension PaymentTransactionRequestConfirmationView { func refresh() async throws { guard let configuration = self.configuration, - let wallet = appContext.walletsDataService.wallets.first(where: { $0.address == configuration.walletAddress }) else { return } + let wallet = appContext.walletsDataService.wallets.findWithAddress(configuration.walletAddress) else { return } let chainId = configuration.chainId let blockchainType: BlockchainType = (try? UnsConfigManager.getBlockchainType(from: chainId)) ?? .Ethereum diff --git a/unstoppable-ios-app/domains-manager-ios/Modules/TransactionInProgress/BaseTransactionInProgressViewPresenter.swift b/unstoppable-ios-app/domains-manager-ios/Modules/TransactionInProgress/BaseTransactionInProgressViewPresenter.swift index c99cf44d5..dde62b8f8 100644 --- a/unstoppable-ios-app/domains-manager-ios/Modules/TransactionInProgress/BaseTransactionInProgressViewPresenter.swift +++ b/unstoppable-ios-app/domains-manager-ios/Modules/TransactionInProgress/BaseTransactionInProgressViewPresenter.swift @@ -95,7 +95,7 @@ extension BaseTransactionInProgressViewPresenter { } func refreshDataForWalletWith(address: String?) async { - guard let wallet = appContext.walletsDataService.wallets.first(where: { $0.address == address }) else { return } + guard let wallet = appContext.walletsDataService.wallets.findWithAddress(address) else { return } try? await appContext.walletsDataService.refreshDataForWallet(wallet) } } diff --git a/unstoppable-ios-app/domains-manager-ios/Modules/Transfer/TransferDomainNavigationManager.swift b/unstoppable-ios-app/domains-manager-ios/Modules/Transfer/TransferDomainNavigationManager.swift index 5e76e50f6..0138de9c8 100644 --- a/unstoppable-ios-app/domains-manager-ios/Modules/Transfer/TransferDomainNavigationManager.swift +++ b/unstoppable-ios-app/domains-manager-ios/Modules/Transfer/TransferDomainNavigationManager.swift @@ -72,7 +72,7 @@ extension TransferDomainNavigationManager: TransferDomainFlowManager { .fromWallet: domain.ownerWallet ?? "", .toWallet: recipient.ownerAddress]) Task.detached { - guard let wallet = appContext.walletsDataService.wallets.first(where: { $0.address == domain.ownerWallet }) else { return } + guard let wallet = appContext.walletsDataService.wallets.findWithAddress(domain.ownerWallet) else { return } try? await appContext.walletsDataService.refreshDataForWallet(wallet) } moveToStep(.transferInProgressOf(domain: domainDisplayInfo)) diff --git a/unstoppable-ios-app/domains-manager-ios/Modules/WalletDetails/WalletDetailsViewPresenter.swift b/unstoppable-ios-app/domains-manager-ios/Modules/WalletDetails/WalletDetailsViewPresenter.swift index 048b798d8..c1e819f88 100644 --- a/unstoppable-ios-app/domains-manager-ios/Modules/WalletDetails/WalletDetailsViewPresenter.swift +++ b/unstoppable-ios-app/domains-manager-ios/Modules/WalletDetails/WalletDetailsViewPresenter.swift @@ -119,7 +119,7 @@ extension WalletDetailsViewPresenter: NetworkReachabilityServiceListener { // MARK: - Private functions private extension WalletDetailsViewPresenter { func walletsUpdated(_ wallets: [WalletEntity]) { - if let wallet = wallets.first(where: { $0.address == wallet.address }) { + if let wallet = wallets.findWithAddress(wallet.address) { self.wallet = wallet showWalletDetails() } else { diff --git a/unstoppable-ios-app/domains-manager-ios/Modules/WalletsList/WalletsListViewPresenter.swift b/unstoppable-ios-app/domains-manager-ios/Modules/WalletsList/WalletsListViewPresenter.swift index 6aff4b17e..3b6a6291b 100644 --- a/unstoppable-ios-app/domains-manager-ios/Modules/WalletsList/WalletsListViewPresenter.swift +++ b/unstoppable-ios-app/domains-manager-ios/Modules/WalletsList/WalletsListViewPresenter.swift @@ -78,7 +78,7 @@ extension WalletsListViewPresenter: WalletsListViewPresenterProtocol { switch item { case .walletInfo(let walletInfo), .selectableWalletInfo(let walletInfo, _): UDVibration.buttonTap.vibrate() - guard let wallet = wallets.first(where: { $0.address == walletInfo.address }) else { return } + guard let wallet = wallets.findWithAddress(walletInfo.address) else { return } logButtonPressedAnalyticEvents(button: .walletInList, parameters: [.wallet : wallet.address]) await didSelectWallet(wallet, walletInfo: walletInfo) @@ -242,7 +242,7 @@ private extension WalletsListViewPresenter { } appContext.toastMessageService.showToast(.walletAdded(walletName: walletName), isSticky: false) if case .createdAndBackedUp(let wallet) = result, - let wallet = wallets.first(where: { $0.address == wallet.address }) { + let wallet = wallets.findWithAddress(wallet.address) { showDetailsOf(wallet: wallet) } AppReviewService.shared.appReviewEventDidOccurs(event: .walletAdded) diff --git a/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/MessagingService+UserProfile.swift b/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/MessagingService+UserProfile.swift index 99516aa52..aa374412f 100644 --- a/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/MessagingService+UserProfile.swift +++ b/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/MessagingService+UserProfile.swift @@ -46,7 +46,7 @@ extension MessagingService { } func findWalletEntityWithAddress(_ walletAddress: String) throws -> WalletEntity { - guard let wallet = appContext.walletsDataService.wallets.first(where: { $0.address == walletAddress }) else { + guard let wallet = appContext.walletsDataService.wallets.findWithAddress(walletAddress) else { throw MessagingServiceError.walletNotFound } return wallet diff --git a/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/MessagingService.swift b/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/MessagingService.swift index 93d4d2f90..5789dc57f 100644 --- a/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/MessagingService.swift +++ b/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/MessagingService.swift @@ -101,7 +101,7 @@ extension MessagingService: MessagingServiceProtocol { if let apiService = try? getDefaultAPIService(), let lastUsedWallet = UserDefaults.currentMessagingOwnerWallet, - let wallet = wallets.first(where: { $0.address == lastUsedWallet }), + let wallet = wallets.findWithAddress(lastUsedWallet), let profile = try? storageService.getUserProfileFor(wallet: wallet.address, serviceIdentifier: apiService.serviceIdentifier) { /// User already used chat with some profile, select last used. diff --git a/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/SubServices/MessagingAPI/MessagingAPIServiceHelper.swift b/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/SubServices/MessagingAPI/MessagingAPIServiceHelper.swift index dcbf6eca2..2c8bff03c 100644 --- a/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/SubServices/MessagingAPI/MessagingAPIServiceHelper.swift +++ b/unstoppable-ios-app/domains-manager-ios/Services/MessagingService/SubServices/MessagingAPI/MessagingAPIServiceHelper.swift @@ -26,7 +26,7 @@ struct MessagingAPIServiceHelper { } static func getWalletEntity(for walletAddress: HexAddress) throws -> WalletEntity { - guard let wallet = appContext.walletsDataService.wallets.first(where: { $0.address == walletAddress }) else { + guard let wallet = appContext.walletsDataService.wallets.findWithAddress(walletAddress) else { throw MessagingHelperError.walletNotFound } diff --git a/unstoppable-ios-app/domains-manager-ios/Services/PullUp/PullUpViewService+Messaging.swift b/unstoppable-ios-app/domains-manager-ios/Services/PullUp/PullUpViewService+Messaging.swift index b3870c449..e14786b51 100644 --- a/unstoppable-ios-app/domains-manager-ios/Services/PullUp/PullUpViewService+Messaging.swift +++ b/unstoppable-ios-app/domains-manager-ios/Services/PullUp/PullUpViewService+Messaging.swift @@ -253,7 +253,7 @@ private extension PullUpViewService { Task { guard let pullUpVC, let domainName = item.userInfo.domainName, - let wallet = appContext.walletsDataService.wallets.first(where: { $0.address == messagingProfile.wallet.normalized }) else { return } + let wallet = appContext.walletsDataService.wallets.findWithAddress(messagingProfile.wallet) else { return } let viewingDomain = wallet.getDomainToViewPublicProfile()?.toDomainItem() let walletAddress = item.userInfo.wallet diff --git a/unstoppable-ios-app/domains-manager-ios/Services/WalletConnect/WalletConnectService_V2/WalletConnectServiceV2.swift b/unstoppable-ios-app/domains-manager-ios/Services/WalletConnect/WalletConnectService_V2/WalletConnectServiceV2.swift index f5166631e..5ee3684fd 100644 --- a/unstoppable-ios-app/domains-manager-ios/Services/WalletConnect/WalletConnectService_V2/WalletConnectServiceV2.swift +++ b/unstoppable-ios-app/domains-manager-ios/Services/WalletConnect/WalletConnectService_V2/WalletConnectServiceV2.swift @@ -958,7 +958,7 @@ extension WalletConnectServiceV2 { } private func detectWallet(by address: HexAddress) throws -> WalletEntity { - guard let wallet = appContext.walletsDataService.wallets.first(where: { $0.address == address.normalized }) else { + guard let wallet = appContext.walletsDataService.wallets.findWithAddress(address) else { Debugger.printFailure("No connected wallet can sign for the wallet address \(address)", critical: true) throw WalletConnectRequestError.failedToFindWalletToSign } @@ -1133,7 +1133,7 @@ extension AnyCodable { extension WCRequestUIConfiguration { init?(connectionIntent: WCConnectionIntentStorage.Intent, sessionProposal: SessionV2.Proposal) { let appInfo = WalletConnectServiceV2.appInfo(from: sessionProposal) - guard let wallet = appContext.walletsDataService.wallets.first(where: { $0.address == connectionIntent.walletAddress.normalized }) else { return nil } + guard let wallet = appContext.walletsDataService.wallets.findWithAddress(connectionIntent.walletAddress) else { return nil } let intendedConfig = WalletConnectServiceV2.ConnectionConfig(wallet: wallet, appInfo: appInfo) self = WCRequestUIConfiguration.connectWallet(intendedConfig) }