Skip to content

Commit

Permalink
Merge pull request #1174 from novasamatech/fix/network-management-fix
Browse files Browse the repository at this point in the history
Fix/network management fix
  • Loading branch information
svojsu authored Aug 2, 2024
2 parents f882465 + 4a356f2 commit 9dfdcc2
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 109 deletions.
4 changes: 0 additions & 4 deletions novawallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3595,7 +3595,6 @@
84DBEA56265ED62700FDF73C /* BaseErrorPresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DBEA55265ED62700FDF73C /* BaseErrorPresentable.swift */; };
84DBEA5E265EDAD300FDF73C /* BaseDataValidatorFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DBEA5D265EDAD300FDF73C /* BaseDataValidatorFactory.swift */; };
84DBEA7729DAF5EC00A504A7 /* ConnectionNodeSwitchCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DBEA7629DAF5EC00A504A7 /* ConnectionNodeSwitchCode.swift */; };
84DBEA7929DB09BB00A504A7 /* ConnectionNodeSchema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DBEA7829DB09BB00A504A7 /* ConnectionNodeSchema.swift */; };
84DC3CE12795DEBF0038E2ED /* SubqueryHistoryOperationFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84412EE026DAC3300049577A /* SubqueryHistoryOperationFactory.swift */; };
84DC3CE32795E0340038E2ED /* SubqueryHistoryOperationFactory+RemoteHistory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DC3CE22795E0340038E2ED /* SubqueryHistoryOperationFactory+RemoteHistory.swift */; };
84DC3CE52796768A0038E2ED /* SubqueryHistoryContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DC3CE42796768A0038E2ED /* SubqueryHistoryContext.swift */; };
Expand Down Expand Up @@ -8538,7 +8537,6 @@
84DBEA55265ED62700FDF73C /* BaseErrorPresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseErrorPresentable.swift; sourceTree = "<group>"; };
84DBEA5D265EDAD300FDF73C /* BaseDataValidatorFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseDataValidatorFactory.swift; sourceTree = "<group>"; };
84DBEA7629DAF5EC00A504A7 /* ConnectionNodeSwitchCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionNodeSwitchCode.swift; sourceTree = "<group>"; };
84DBEA7829DB09BB00A504A7 /* ConnectionNodeSchema.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionNodeSchema.swift; sourceTree = "<group>"; };
84DC3CE22795E0340038E2ED /* SubqueryHistoryOperationFactory+RemoteHistory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SubqueryHistoryOperationFactory+RemoteHistory.swift"; sourceTree = "<group>"; };
84DC3CE42796768A0038E2ED /* SubqueryHistoryContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubqueryHistoryContext.swift; sourceTree = "<group>"; };
84DC3CE6279679230038E2ED /* SubqueryHistory+Wallet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SubqueryHistory+Wallet.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -14062,7 +14060,6 @@
846A68282746234000D1A47A /* ChainConnection.swift */,
840D627429CB46E900D5E894 /* ConnectionApiKeys.swift */,
84DBEA7629DAF5EC00A504A7 /* ConnectionNodeSwitchCode.swift */,
84DBEA7829DB09BB00A504A7 /* ConnectionNodeSchema.swift */,
0C63909C2BF34A970015D467 /* ConnectionTransportFactory.swift */,
0CA5BDF22C4476A3000A4CDD /* ConnectionCreationParams.swift */,
);
Expand Down Expand Up @@ -24239,7 +24236,6 @@
849ABE63262785F200011A2A /* ControllerMapper.swift in Sources */,
841BFD6727BA4865000A16CE /* EthereumSerializationFactory.swift in Sources */,
8467FD0224E5D2D9005D486C /* OnboardingMainInteractor.swift in Sources */,
84DBEA7929DB09BB00A504A7 /* ConnectionNodeSchema.swift in Sources */,
F4C086BD26D114F700716AEC /* SubqueryEraValidatorInfo.swift in Sources */,
84939B1826E1690D000111DA /* TreasuryDepositEvent.swift in Sources */,
844CB56426F945E200396E13 /* SubstrateLocalSubscriptionFactory.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extension NSPredicate {
"[a-z0-9\\u00a1-\\uffff]" +
"[a-z0-9\\u00a1-\\uffff_-]{0,62}" +
")?" +
"[a-z0-9\\u00a1-\\uffff]\\." +
"[a-z0-9\\u00a1-\\uffff_-]\\." +
")+" +
// TLD identifier name, may end with dot
"(?:[a-z\\u00a1-\\uffff]{2,}\\.?)" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension ConnectionFactory: ConnectionFactoryProtocol {
) throws -> ChainConnection {
let urlModels = extractNodeUrls(
from: chain,
schema: ConnectionNodeSchema.wss
schemaPredicate: .ws
)

return try createConnection(
Expand All @@ -76,7 +76,10 @@ extension ConnectionFactory: ConnectionFactoryProtocol {
}

func updateConnection(_ connection: ChainConnection, chain: ChainNodeConnectable) {
let newUrlModels = extractNodeUrls(from: chain, schema: ConnectionNodeSchema.wss)
let newUrlModels = extractNodeUrls(
from: chain,
schemaPredicate: .ws
)
let newUrls = newUrlModels.map(\.url)

if Set(connection.urls) != Set(newUrls) {
Expand All @@ -85,7 +88,10 @@ extension ConnectionFactory: ConnectionFactoryProtocol {
}

func createOneShotConnection(for chain: ChainNodeConnectable) throws -> OneShotConnection {
let urls = extractNodeUrls(from: chain, schema: ConnectionNodeSchema.https).map(\.url)
let urls = extractNodeUrls(
from: chain,
schemaPredicate: .urlPredicate
).map(\.url)

let nodeSwitcher = JSONRRPCodeNodeSwitcher(codes: ConnectionNodeSwitchCode.allCodes)

Expand All @@ -108,7 +114,10 @@ extension ConnectionFactory: ConnectionFactoryProtocol {
_ connection: OneShotConnection,
chain: ChainNodeConnectable
) {
let newUrls = extractNodeUrls(from: chain, schema: ConnectionNodeSchema.https).map(\.url)
let newUrls = extractNodeUrls(
from: chain,
schemaPredicate: .urlPredicate
).map(\.url)

if Set(connection.urls) != Set(newUrls) {
connection.changeUrls(newUrls)
Expand Down Expand Up @@ -159,14 +168,14 @@ extension ConnectionFactory: ConnectionFactoryProtocol {

private func extractNodeUrls(
from chain: ChainNodeConnectable,
schema: String
schemaPredicate: NSPredicate
) -> [ConnectionCreationParams] {
let filteredNodes = if case let .manual(selectedNode) = chain.connectionMode {
selectedNode.url.hasPrefix(schema)
schemaPredicate.evaluate(with: selectedNode.url)
? Set([selectedNode])
: Set()
} else {
chain.nodes.filter { $0.url.hasPrefix(schema) }
chain.nodes.filter { schemaPredicate.evaluate(with: $0.url) }
}

let nodes: [ChainNodeModel]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ struct CustomNetworkViewFactory {
operationQueue: operationQueue
)

let setupFinishStrategyFactory = CustomNetworkSetupFinishStrategyFactory(
chainRegistry: chainRegistry,
repository: repository,
operationQueue: operationQueue
)

let interactor = CustomNetworkAddInteractor(
networkToAdd: networkToAdd,
chainRegistry: chainRegistry,
customNetworkSetupFactory: customNetworkSetupFactory,
connectionFactory: connectionFactory,
repository: repository,
priceIdParser: CoingeckoUrlParser(),
setupFinishStrategyFactory: setupFinishStrategyFactory,
operationQueue: operationQueue
)

Expand Down Expand Up @@ -99,6 +106,12 @@ struct CustomNetworkViewFactory {
operationQueue: operationQueue
)

let setupFinishStrategyFactory = CustomNetworkSetupFinishStrategyFactory(
chainRegistry: chainRegistry,
repository: repository,
operationQueue: operationQueue
)

let interactor = CustomNetworkEditInteractor(
networkToEdit: network,
selectedNode: selectedNode,
Expand All @@ -107,6 +120,7 @@ struct CustomNetworkViewFactory {
connectionFactory: connectionFactory,
repository: repository,
priceIdParser: CoingeckoUrlParser(),
setupFinishStrategyFactory: setupFinishStrategyFactory,
operationQueue: operationQueue
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ final class CustomNetworkAddInteractor: CustomNetworkBaseInteractor {
connectionFactory: ConnectionFactoryProtocol,
repository: AnyDataProviderRepository<ChainModel>,
priceIdParser: PriceUrlParserProtocol,
setupFinishStrategyFactory: CustomNetworkSetupFinishStrategyFactory,
operationQueue: OperationQueue
) {
self.networkToAdd = networkToAdd
Expand All @@ -21,6 +22,7 @@ final class CustomNetworkAddInteractor: CustomNetworkBaseInteractor {
connectionFactory: connectionFactory,
repository: repository,
priceIdParser: priceIdParser,
setupFinishStrategyFactory: setupFinishStrategyFactory,
operationQueue: operationQueue
)
}
Expand All @@ -41,10 +43,7 @@ final class CustomNetworkAddInteractor: CustomNetworkBaseInteractor {

extension CustomNetworkAddInteractor: CustomNetworkAddInteractorInputProtocol {
func addNetwork(with request: CustomNetwork.AddRequest) {
setupFinishStrategy = CustomNetworkAddNewStrategy(
repository: repository,
operationQueue: operationQueue
)
setupFinishStrategy = setupFinishStrategyFactory.createAddNewStrategy()

let type: ChainType = if let networkToAdd {
networkToAdd.isEthereumBased ? .evm : .substrate
Expand All @@ -63,7 +62,7 @@ extension CustomNetworkAddInteractor: CustomNetworkAddInteractorInputProtocol {
}

func fetchNetworkProperties(for url: String) {
setupFinishStrategy = CustomNetworkProvideStrategy()
setupFinishStrategy = setupFinishStrategyFactory.createProvideStrategy()

let request = CustomNetwork.SetupRequest(
networkType: .substrate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class CustomNetworkBaseInteractor: NetworkNodeCreatorTrait,
let priceIdParser: PriceUrlParserProtocol
let operationQueue: OperationQueue

let setupFinishStrategyFactory: CustomNetworkSetupFinishStrategyFactory

var currentConnectingNode: ChainNodeModel?
var currentConnection: ChainConnection?

Expand All @@ -26,13 +28,15 @@ class CustomNetworkBaseInteractor: NetworkNodeCreatorTrait,
connectionFactory: ConnectionFactoryProtocol,
repository: AnyDataProviderRepository<ChainModel>,
priceIdParser: PriceUrlParserProtocol,
setupFinishStrategyFactory: CustomNetworkSetupFinishStrategyFactory,
operationQueue: OperationQueue
) {
self.chainRegistry = chainRegistry
self.customNetworkSetupFactory = customNetworkSetupFactory
self.connectionFactory = connectionFactory
self.repository = repository
self.priceIdParser = priceIdParser
self.setupFinishStrategyFactory = setupFinishStrategyFactory
self.operationQueue = operationQueue
}

Expand Down Expand Up @@ -247,7 +251,7 @@ private extension CustomNetworkBaseInteractor {
case let .success(chain):
self?.setupFinishStrategy?.handleSetupFinished(
for: chain,
presenter: self?.presenter
output: self?.presenter
)
case let .failure(error):
self?.presenter?.didReceive(.init(from: error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class CustomNetworkEditInteractor: CustomNetworkBaseInteractor {
connectionFactory: ConnectionFactoryProtocol,
repository: AnyDataProviderRepository<ChainModel>,
priceIdParser: PriceUrlParserProtocol,
setupFinishStrategyFactory: CustomNetworkSetupFinishStrategyFactory,
operationQueue: OperationQueue
) {
self.networkToEdit = networkToEdit
Expand All @@ -24,6 +25,7 @@ final class CustomNetworkEditInteractor: CustomNetworkBaseInteractor {
connectionFactory: connectionFactory,
repository: repository,
priceIdParser: priceIdParser,
setupFinishStrategyFactory: setupFinishStrategyFactory,
operationQueue: operationQueue
)
}
Expand All @@ -40,11 +42,9 @@ final class CustomNetworkEditInteractor: CustomNetworkBaseInteractor {

extension CustomNetworkEditInteractor: CustomNetworkEditInteractorInputProtocol {
func editNetwork(with request: CustomNetwork.EditRequest) {
setupFinishStrategy = CustomNetworkEditStrategy(
setupFinishStrategy = setupFinishStrategyFactory.createEditStrategy(
networkToEdit: networkToEdit,
selectedNode: selectedNode,
repository: repository,
operationQueue: operationQueue
selectedNode: selectedNode
)

let setupRequest = CustomNetwork.SetupRequest(
Expand Down
Loading

0 comments on commit 9dfdcc2

Please sign in to comment.