Skip to content

Commit

Permalink
code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bnsports committed Aug 2, 2024
1 parent 8cd7da4 commit 229e5e4
Show file tree
Hide file tree
Showing 30 changed files with 136 additions and 136 deletions.
14 changes: 1 addition & 13 deletions fearless.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,6 @@
85B1B7387F09A8405C4E688A /* WalletSendConfirmTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AF4258723E2FACBBA556D00 /* WalletSendConfirmTests.swift */; };
872DF7DE5A001DF5B8A4E288 /* StakingBondMoreConfirmationFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BA5883C1103D3A2218D839 /* StakingBondMoreConfirmationFlow.swift */; };
87C1FC2909A8360DDBA625E5 /* LiquidityPoolSupplyInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BA528679A82B9A327853804 /* LiquidityPoolSupplyInteractor.swift */; };
8852522BE02B6244A00E85A1 /* AccountStatisticsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26222D0DBE5CEF0BA7DCCEF7 /* AccountStatisticsTests.swift */; };
885551F78A5926D16D5AF0CB /* ControllerAccountPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E5CB64B91B35804B3671456 /* ControllerAccountPresenter.swift */; };
886E8CF81EF2566D98D9693E /* ExportSeedViewFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62FA66143B25AA70B02CE461 /* ExportSeedViewFactory.swift */; };
887CE12C7C59F5DB092E9227 /* AccountStatisticsRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD63BEB84A28855006BE680 /* AccountStatisticsRouter.swift */; };
Expand Down Expand Up @@ -3403,7 +3402,6 @@
25B80FDDB5C3032A0BBBD826 /* NftCollectionPresenter.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = NftCollectionPresenter.swift; sourceTree = "<group>"; };
25D9454047EBBD8D8A0174A4 /* LiquidityPoolRemoveLiquidityRouter.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = LiquidityPoolRemoveLiquidityRouter.swift; sourceTree = "<group>"; };
25FF82C2FD912021A1F20876 /* PolkaswapAdjustmentViewLayout.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = PolkaswapAdjustmentViewLayout.swift; sourceTree = "<group>"; };
26222D0DBE5CEF0BA7DCCEF7 /* AccountStatisticsTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AccountStatisticsTests.swift; sourceTree = "<group>"; };
262F98DEF54FA9592BE22B94 /* AllDoneAssembly.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AllDoneAssembly.swift; sourceTree = "<group>"; };
2648EEF96694A7FEC94520E8 /* WalletHistoryFilterTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = WalletHistoryFilterTests.swift; sourceTree = "<group>"; };
26635BD49FBF19DB1253906E /* NetworkInfoTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = NetworkInfoTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7321,14 +7319,6 @@
path = ExportMnemonicConfirm;
sourceTree = "<group>";
};
2CFE52D4FA09CD95EA70283E /* AccountStatistics */ = {
isa = PBXGroup;
children = (
26222D0DBE5CEF0BA7DCCEF7 /* AccountStatisticsTests.swift */,
);
path = AccountStatistics;
sourceTree = "<group>";
};
2E04CA9A3624EA1AD62722E8 /* WalletOption */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -7760,7 +7750,6 @@
749EAA035EECE4D63C56C358 /* LiquidityPoolSupplyConfirm */,
48EAF80DCC0C537917FC5A23 /* LiquidityPoolRemoveLiquidity */,
BDB80385E6818AE7707DDFF8 /* LiquidityPoolRemoveLiquidityConfirm */,
2CFE52D4FA09CD95EA70283E /* AccountStatistics */,
);
path = Modules;
sourceTree = "<group>";
Expand Down Expand Up @@ -19266,7 +19255,6 @@
B40863AA7377BFE5F8A30259 /* LiquidityPoolSupplyConfirmTests.swift in Sources */,
6BF307ADE63FA92389340779 /* LiquidityPoolRemoveLiquidityTests.swift in Sources */,
ECA54AB8148BBA63084353FD /* LiquidityPoolRemoveLiquidityConfirmTests.swift in Sources */,
8852522BE02B6244A00E85A1 /* AccountStatisticsTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -19817,7 +19805,7 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/soramitsu/shared-features-spm.git";
requirement = {
branch = "network-module-update";
branch = "fearless-wallet";
kind = branch;
};
};
Expand Down
4 changes: 2 additions & 2 deletions fearless.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/soramitsu/shared-features-spm.git",
"state" : {
"branch" : "network-module-update",
"revision" : "ef034cd4466dda1eadec92b1a8a0c4a1f4e8b71e"
"branch" : "fearless-wallet",
"revision" : "c914f1e729c4238bf6e18030e4f4c3895a94e088"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ extension NomisAccountStatisticsFetcher: AccountStatisticsFetching {
address: String,
cacheOptions: CachedNetworkRequestTrigger
) async throws -> AsyncThrowingStream<CachedNetworkResponse<AccountStatisticsResponse>, Error> {
guard let baseURL = URL(string: "https://api.nomis.cc/api/v1/multichain-score/wallet/") else {
throw NomisAccountStatisticsFetcherError.badBaseURL
}

let request = try NomisAccountStatisticsRequest(
baseURL: baseURL,
baseURL: ApplicationConfig.shared.nomisAccountScoreURL,
address: address,
endpoint: "score"
)
Expand All @@ -38,12 +34,8 @@ extension NomisAccountStatisticsFetcher: AccountStatisticsFetching {
}

func fetchStatistics(address: String) async throws -> AccountStatisticsResponse? {
guard let baseURL = URL(string: "https://api.nomis.cc/api/v1/multichain-score/wallet/") else {
throw NomisAccountStatisticsFetcherError.badBaseURL
}

let request = try NomisAccountStatisticsRequest(
baseURL: baseURL,
baseURL: ApplicationConfig.shared.nomisAccountScoreURL,
address: address,
endpoint: "score"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import SSFModels
import SoraFoundation

protocol ScamInfoFetching {
func fetch(address: String, chain: ChainModel) async throws -> ScamInfo?
Expand All @@ -12,10 +13,13 @@ final class ScamInfoFetcher: ScamInfoFetching {

init(
scamServiceOperationFactory: ScamServiceOperationFactoryProtocol,
accountScoreFetching: AccountStatisticsFetching
accountScoreFetching: AccountStatisticsFetching,
localizationManager: LocalizationManagerProtocol
) {
self.scamServiceOperationFactory = scamServiceOperationFactory
self.accountScoreFetching = accountScoreFetching

self.localizationManager = localizationManager
}

func fetch(address: String, chain: ChainModel) async throws -> ScamInfo? {
Expand Down Expand Up @@ -59,13 +63,17 @@ final class ScamInfoFetcher: ScamInfoFetching {
}

return ScamInfo(
name: "Nomis multi-chain score",
name: R.string.localizable.scamInfoNomisName(preferredLanguages: selectedLocale.rLanguages),
address: address,
type: .lowScore,
subtype: "Proceed with caution"
subtype: R.string.localizable.scamInfoNomisSubtypeText(preferredLanguages: selectedLocale.rLanguages)
)
}

return scamInfo
}
}

extension ScamInfoFetcher: Localizable {
func applyLocalization() {}
}
4 changes: 4 additions & 0 deletions fearless/Common/Configs/ApplicationConfigs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ extension ApplicationConfig: ApplicationConfigProtocol, XcmConfigProtocol {
GitHubUrl.url(suffix: "appConfigs/onboarding/mobile v2.json")
#endif
}

var nomisAccountScoreURL: URL {
URL(string: "https://api.nomis.cc/api/v1/multichain-score/wallet/")!
}
}

private enum GitHubUrl {
Expand Down
1 change: 0 additions & 1 deletion fearless/Common/DataProvider/Sources/PriceDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ final class PriceDataSource: SingleValueProviderSourceProtocol {
}

private func createChainlinkOperations() -> [BaseOperation<PriceData>] {
return []
guard currencies?.count == 1, currencies?.first?.id == Currency.defaultCurrency().id else {
return []
}
Expand Down
8 changes: 0 additions & 8 deletions fearless/Common/Extension/Foundation/NumberFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,4 @@ extension NumberFormatter {
formatter.usesGroupingSeparator = usesIntGrouping
return formatter
}

static var nomisHours: NumberFormatter {
let formatter = NumberFormatter.amount
formatter.roundingMode = .floor
formatter.minimumFractionDigits = 0
formatter.maximumFractionDigits = 8
return formatter
}
}
37 changes: 21 additions & 16 deletions fearless/Common/Services/ChainRegistry/ChainRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ protocol ChainRegistryProtocol: AnyObject {
func getConnection(for chainId: ChainModel.Id) -> ChainConnection?
func getRuntimeProvider(for chainId: ChainModel.Id) -> RuntimeProviderProtocol?
func getChain(for chainId: ChainModel.Id) -> ChainModel?
func getChainUnsafe(for chainId: ChainModel.Id) -> ChainModel?
func chainsSubscribe(
_ target: AnyObject,
runningInQueue: DispatchQueue,
Expand Down Expand Up @@ -228,14 +227,24 @@ final class ChainRegistry {
}
chains.append(newChain)

_ = try? ethereumConnectionPool.setupConnection(for: newChain)
do {
_ = try ethereumConnectionPool.setupConnection(for: newChain)
} catch {
logger?.customError(error)
}
}

private func handleUpdatedEthereumChain(updatedChain: ChainModel) throws {
guard let ethereumConnectionPool = self.ethereumConnectionPool else {
return
}
_ = try? ethereumConnectionPool.setupConnection(for: updatedChain)

do {
_ = try ethereumConnectionPool.setupConnection(for: updatedChain)
} catch {
logger?.customError(error)
}

chains = chains.filter { $0.chainId != updatedChain.chainId }
chains.append(updatedChain)
}
Expand Down Expand Up @@ -312,26 +321,22 @@ extension ChainRegistry: ChainRegistryProtocol {
}

func getEthereumConnection(for chainId: ChainModel.Id) -> Web3.Eth? {
// readLock.concurrentlyRead {
guard
let ethereumConnectionPool = self.ethereumConnectionPool,
let chain = chains.first(where: { $0.chainId == chainId })
else {
return nil
}
readLock.concurrentlyRead {
guard
let ethereumConnectionPool = self.ethereumConnectionPool,
let chain = chains.first(where: { $0.chainId == chainId })
else {
return nil
}

return try? ethereumConnectionPool.setupConnection(for: chain)
// }
return try? ethereumConnectionPool.setupConnection(for: chain)
}
}

func getChain(for chainId: ChainModel.Id) -> ChainModel? {
readLock.concurrentlyRead { chains.first(where: { $0.chainId == chainId }) }
}

func getChainUnsafe(for chainId: ChainModel.Id) -> ChainModel? {
chains.first(where: { $0.chainId == chainId })
}

func getRuntimeProvider(for chainId: ChainModel.Id) -> RuntimeProviderProtocol? {
runtimeProviderPool.getRuntimeProvider(for: chainId)
}
Expand Down
13 changes: 6 additions & 7 deletions fearless/Common/View/AccountScore/AccountScoreView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import SoraUI
import Cosmos

class AccountScoreView: UIView {
private enum Constants {
static let skeletonSize = CGSize(width: 32, height: 15)
}

private var viewModel: AccountScoreViewModel?

private var skeletonView: SkrullableView?
Expand Down Expand Up @@ -151,12 +155,7 @@ extension AccountScoreView: SkeletonLoadable {
}

private func setupSkeleton() {
let spaceSize = CGSize(width: 32, height: 15)

guard spaceSize != .zero else {
self.skeletonView = Skrull(size: .zero, decorations: [], skeletons: []).build()
return
}
let spaceSize = Constants.skeletonSize

let skeletonView = Skrull(
size: spaceSize,
Expand All @@ -181,7 +180,7 @@ extension AccountScoreView: SkeletonLoadable {
SingleSkeleton.createRow(
spaceSize: spaceSize,
position: CGPoint(x: 0, y: 0.5),
size: CGSize(width: 32, height: 15)
size: Constants.skeletonSize
)
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class AccountScoreViewModel {
private let fetcher: AccountStatisticsFetching
private let chain: ChainModel?
private let settings: SettingsManagerProtocol
private let logger: LoggerProtocol?

let address: String?
var scoringEnabled: Bool

Expand All @@ -44,13 +46,15 @@ class AccountScoreViewModel {
address: String?,
chain: ChainModel?,
settings: SettingsManagerProtocol,
eventCenter: EventCenterProtocol
eventCenter: EventCenterProtocol,
logger: LoggerProtocol?
) {
self.fetcher = fetcher
self.address = address
self.chain = chain
self.settings = settings
self.eventCenter = eventCenter
self.logger = logger

scoringEnabled = (chain?.isNomisSupported == true || chain == nil) && settings.accountScoreEnabled == true
}
Expand All @@ -70,7 +74,7 @@ class AccountScoreViewModel {
handle(response: statistics.value)
}
} catch {
print("Account statistics fetching error: ", error)
logger?.debug("Account statistics fetching error: \(error)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ final class AccountStatisticsAssembly {
interactor: interactor,
router: router,
localizationManager: localizationManager,
viewModelFactory: AccountStatisticsViewModelFactoryImpl()
viewModelFactory: AccountStatisticsViewModelFactoryImpl(),
logger: Logger.shared
)

let view = AccountStatisticsViewController(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final class AccountStatisticsPresenter {
private let router: AccountStatisticsRouterInput
private let interactor: AccountStatisticsInteractorInput
private let viewModelFactory: AccountStatisticsViewModelFactory
private let logger: LoggerProtocol?

private var accountStatistics: AccountStatistics?

Expand All @@ -27,11 +28,13 @@ final class AccountStatisticsPresenter {
interactor: AccountStatisticsInteractorInput,
router: AccountStatisticsRouterInput,
localizationManager: LocalizationManagerProtocol,
viewModelFactory: AccountStatisticsViewModelFactory
viewModelFactory: AccountStatisticsViewModelFactory,
logger: LoggerProtocol?
) {
self.interactor = interactor
self.router = router
self.viewModelFactory = viewModelFactory
self.logger = logger

self.localizationManager = localizationManager
}
Expand Down Expand Up @@ -81,7 +84,9 @@ extension AccountStatisticsPresenter: AccountStatisticsInteractorOutput {
provideViewModel()
}

func didReceiveAccountStatisticsError(_: Error) {}
func didReceiveAccountStatisticsError(_ error: Error) {
logger?.debug("didReceiveAccountStatisticsError \(error)")
}

func didReceiveNoDataAvailableState() {
view?.didReceiveError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ final class AddressBookViewModelFactory: AddressBookViewModelFactoryProtocol {
address: contactType.address,
chain: chain,
settings: settings,
eventCenter: EventCenter.shared
eventCenter: EventCenter.shared,
logger: Logger.shared
)

return ContactTableCellModel(
Expand Down Expand Up @@ -74,7 +75,8 @@ final class AddressBookViewModelFactory: AddressBookViewModelFactoryProtocol {
address: contact.address,
chain: chain,
settings: settings,
eventCenter: EventCenter.shared
eventCenter: EventCenter.shared,
logger: Logger.shared
)

return ContactTableCellModel(contactType: .saved(contact), delegate: cellsDelegate, accountScoreViewModel: accountScoreViewModel)
Expand Down
6 changes: 5 additions & 1 deletion fearless/Modules/NFT/NftSend/NftSendAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ enum NftSendAssembly {
let accountInfoSubscriptionAdapter = AccountInfoSubscriptionAdapter(walletLocalSubscriptionFactory: walletLocalSubscriptionFactory, selectedMetaAccount: wallet)

let accountStatisticsFetcher = NomisAccountStatisticsFetcher(networkWorker: NetworkWorkerImpl(), signer: NomisRequestSigner())
let scamInfoFetcher = ScamInfoFetcher(scamServiceOperationFactory: scamServiceOperationFactory, accountScoreFetching: accountStatisticsFetcher)
let scamInfoFetcher = ScamInfoFetcher(
scamServiceOperationFactory: scamServiceOperationFactory,
accountScoreFetching: accountStatisticsFetcher,
localizationManager: LocalizationManager.shared
)
let interactor = NftSendInteractor(
transferService: transferService,
operationManager: OperationManagerFacade.sharedManager,
Expand Down
3 changes: 2 additions & 1 deletion fearless/Modules/Send/SendAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ final class SendAssembly {
let accountStatisticsFetcher = NomisAccountStatisticsFetcher(networkWorker: NetworkWorkerImpl(), signer: NomisRequestSigner())
let scamInfoFetcher = ScamInfoFetcher(
scamServiceOperationFactory: scamServiceOperationFactory,
accountScoreFetching: accountStatisticsFetcher
accountScoreFetching: accountStatisticsFetcher,
localizationManager: LocalizationManager.shared
)
let interactor = SendInteractor(
accountInfoSubscriptionAdapter: AccountInfoSubscriptionAdapter(
Expand Down
Loading

0 comments on commit 229e5e4

Please sign in to comment.