Skip to content

Commit

Permalink
Merge pull request #1143 from novasamatech/fix/evm-networks-connectio…
Browse files Browse the repository at this point in the history
…n-on-syncMode-switch

Fix evm networks connection on sync mode switch and warnings
  • Loading branch information
svojsu authored Jul 18, 2024
2 parents 7c193a5 + 252b617 commit d1ea1af
Show file tree
Hide file tree
Showing 11 changed files with 425 additions and 46 deletions.
4 changes: 4 additions & 0 deletions novawallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@
2D7E4A152C4028E300455509 /* CustomNetworkSetupFinishStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D7E4A142C4028E300455509 /* CustomNetworkSetupFinishStrategy.swift */; };
2D7E4A172C403E1800455509 /* ChainNameOperationFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D7E4A162C403E1800455509 /* ChainNameOperationFactory.swift */; };
2D7E4A192C406FED00455509 /* CustomNetworkDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D7E4A182C406FED00455509 /* CustomNetworkDTO.swift */; };
2D8463662C488416007E2986 /* ChainFilterStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D8463652C488416007E2986 /* ChainFilterStrategyTests.swift */; };
2D8684552BFF7F6000A663D2 /* ExportPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D8684542BFF7F6000A663D2 /* ExportPresenter.swift */; };
2D8684582BFF8CE600A663D2 /* BaseExportPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D8684572BFF8CE600A663D2 /* BaseExportPresenter.swift */; };
2D86845E2BFF9DA000A663D2 /* BackupAttentionInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D86845D2BFF9DA000A663D2 /* BackupAttentionInteractor.swift */; };
Expand Down Expand Up @@ -5838,6 +5839,7 @@
2D7E4A142C4028E300455509 /* CustomNetworkSetupFinishStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNetworkSetupFinishStrategy.swift; sourceTree = "<group>"; };
2D7E4A162C403E1800455509 /* ChainNameOperationFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChainNameOperationFactory.swift; sourceTree = "<group>"; };
2D7E4A182C406FED00455509 /* CustomNetworkDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNetworkDTO.swift; sourceTree = "<group>"; };
2D8463652C488416007E2986 /* ChainFilterStrategyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChainFilterStrategyTests.swift; sourceTree = "<group>"; };
2D8684542BFF7F6000A663D2 /* ExportPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExportPresenter.swift; sourceTree = "<group>"; };
2D8684572BFF8CE600A663D2 /* BaseExportPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseExportPresenter.swift; sourceTree = "<group>"; };
2D86845D2BFF9DA000A663D2 /* BackupAttentionInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackupAttentionInteractor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -20032,6 +20034,7 @@
84452F5C25D5CB3B00F47EC5 /* FileManagerTests.swift */,
84BAFCCF26AF585900871E86 /* SharedArrayTests.swift */,
847F2D5627AB08D200AFD476 /* GradientColorFactoryTests.swift */,
2D8463652C488416007E2986 /* ChainFilterStrategyTests.swift */,
842B2FCC2947239B002829B6 /* CoinGeckoUrlParserTests.swift */,
840D627029CB3FD900D5E894 /* URLBuilderTests.swift */,
);
Expand Down Expand Up @@ -28111,6 +28114,7 @@
84B7C745289BFA79001A3566 /* AssetsManageTests.swift in Sources */,
84B7C728289BFA79001A3566 /* YourValidatorListTests.swift in Sources */,
84B7C72F289BFA79001A3566 /* CustomValidatorListComposerTests.swift in Sources */,
2D8463662C488416007E2986 /* ChainFilterStrategyTests.swift in Sources */,
84B7C717289BFA79001A3566 /* DAppAuthConfirmTests.swift in Sources */,
84F4387F25D9D61300AEDA56 /* SubstrateStorageTestFacade.swift in Sources */,
84B7C730289BFA79001A3566 /* CustomValidatorListTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Foundation
import Operation_iOS

// swiftlint:disable switch_case_alignment
enum ChainFilterStrategy {
typealias Filter = (DataProviderChange<ChainModel>) -> Bool
typealias Transform = (DataProviderChange<ChainModel>, ChainModel?) -> DataProviderChange<ChainModel>
Expand Down Expand Up @@ -104,8 +103,6 @@ enum ChainFilterStrategy {
.compactMap(\.transform)
.reduce(change) { $1($0, currentChain) }
}
default:
nil
}
}

Expand Down
5 changes: 4 additions & 1 deletion novawallet/Common/Services/ChainRegistry/ChainRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@ extension ChainRegistry: ChainRegistryProtocol {
mutex.unlock()
}

let closure: ([DataProviderChange<ChainModel>], [ChainModel.Id: ChainModel]) -> Void = { changes, currentChains in
let closure: (
[DataProviderChange<ChainModel>],
[ChainModel.Id: ChainModel]
) -> Void = { changes, currentChains in
runningInQueue.async {
let filtered = if let filterStrategy {
filterStrategy.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ extension ConnectionPool: ConnectionPoolProtocol {

if let connection = connections[chain.chainId]?.target as? ChainConnection {
connectionFactory.updateConnection(connection, chain: chain)

if case .notConnected = connection.state {
connection.connect()
}

return connection
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ extension ChainModelMapper: CoreDataMapperProtocol {
return try createChainNode(from: node)
} ?? []

let selectedNode: ChainNodeModel? = if let entitySelectedNode = entity.selectedNode as? CDChainNodeItem {
let selectedNode: ChainNodeModel? = if let entitySelectedNode = entity.selectedNode {
try createChainNode(from: entitySelectedNode)
} else {
nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ protocol CustomNetworkViewProtocol: ControllerBackedProtocol {
func didReceiveButton(viewModel: NetworkNodeViewLayout.LoadingButtonViewModel)
}

protocol CustomNetworkWireframeProtocol: AlertPresentable, ErrorPresentable, ModalAlertPresenting, TokenAddErrorPresentable {
protocol CustomNetworkWireframeProtocol: AlertPresentable,
ErrorPresentable,
ModalAlertPresenting,
TokenAddErrorPresentable {
func showNetworksList(
from view: CustomNetworkViewProtocol?,
locale: Locale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private extension CustomNetworkBasePresenter {
)
)
}
),
)
],
closeAction: R.string.localizable.commonClose(preferredLanguages: selectedLocale.rLanguages)
)
Expand Down Expand Up @@ -404,7 +404,7 @@ private extension CustomNetworkBasePresenter {

confirm()
}
),
)
],
closeAction: R.string.localizable.commonClose(preferredLanguages: selectedLocale.rLanguages)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,39 +155,7 @@ final class NetworkDetailsNodeView: UIView {
selectionImageView.stopShimmeringOpacity()
}

switch viewModel.connectionState {
case let .connecting(string):
networkStatusLabel.text = string
networkStatusIcon.image = R.image.iconConnectionStatusConnecting()

networkStatusLabel.applyShimmer(style: .semiboldCaps2Secondary)
networkStatusLabel.startShimmering()
case let .pinged(ping):
networkStatusLabel.stopShimmering()

switch ping {
case let .low(text):
networkStatusLabel.text = text
networkStatusLabel.textColor = R.color.colorTextPositive()
networkStatusIcon.image = R.image.iconConnectionStatusPerfect()
case let .medium(text):
networkStatusLabel.text = text
networkStatusLabel.textColor = R.color.colorTextWarning()
networkStatusIcon.image = R.image.iconConnectionStatusGood()
case let .high(text):
networkStatusLabel.text = text
networkStatusLabel.textColor = R.color.colorTextNegative()
networkStatusIcon.image = R.image.iconConnectionStatusBad()
}
case .disconnected:
networkStatusLabel.text = nil
networkStatusIcon.image = R.image.iconConnectionStatusConnecting()
case let .unknown(string):
networkStatusLabel.stopShimmering()
networkStatusLabel.apply(style: .semiboldCaps2Secondary)
networkStatusLabel.text = string
networkStatusIcon.image = R.image.iconConnectionStatusConnecting()
}
updateNetworkStatus(with: viewModel)
}
}

Expand Down Expand Up @@ -262,6 +230,42 @@ private extension NetworkDetailsNodeView {
accessoryIcon.isUserInteractionEnabled = true
}

func updateNetworkStatus(with viewModel: NetworkDetailsViewLayout.NodeModel) {
switch viewModel.connectionState {
case let .connecting(string):
networkStatusLabel.text = string
networkStatusIcon.image = R.image.iconConnectionStatusConnecting()

networkStatusLabel.applyShimmer(style: .semiboldCaps2Secondary)
networkStatusLabel.startShimmering()
case let .pinged(ping):
networkStatusLabel.stopShimmering()

switch ping {
case let .low(text):
networkStatusLabel.text = text
networkStatusLabel.textColor = R.color.colorTextPositive()
networkStatusIcon.image = R.image.iconConnectionStatusPerfect()
case let .medium(text):
networkStatusLabel.text = text
networkStatusLabel.textColor = R.color.colorTextWarning()
networkStatusIcon.image = R.image.iconConnectionStatusGood()
case let .high(text):
networkStatusLabel.text = text
networkStatusLabel.textColor = R.color.colorTextNegative()
networkStatusIcon.image = R.image.iconConnectionStatusBad()
}
case .disconnected:
networkStatusLabel.text = nil
networkStatusIcon.image = R.image.iconConnectionStatusConnecting()
case let .unknown(string):
networkStatusLabel.stopShimmering()
networkStatusLabel.apply(style: .semiboldCaps2Secondary)
networkStatusLabel.text = string
networkStatusIcon.image = R.image.iconConnectionStatusConnecting()
}
}

@objc func actionMore() {
guard
let viewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private extension NetworksListViewController {
let cell: UITableViewCell

switch viewModel {
case let .banner:
case .banner:
let bannerCell = tableView.dequeueReusableCellWithType(
BannerCell.self,
forIndexPath: indexPath
Expand Down
Loading

0 comments on commit d1ea1af

Please sign in to comment.