Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue when communities profiles could have incorrect state #390

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down