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

Fix/balance on network selection #1272

Merged
merged 5 commits into from
Nov 11, 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
26 changes: 21 additions & 5 deletions novawallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,8 @@
2D6F51A72CDD035900564C00 /* AssetDecorationAttributesFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D6F51A62CDD035900564C00 /* AssetDecorationAttributesFactory.swift */; };
2D6F51A92CDD2C3100564C00 /* AssetListFlowLayout+Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D6F51A82CDD2C3100564C00 /* AssetListFlowLayout+Types.swift */; };
2D6F51AB2CDDD98300564C00 /* AssetsSearchFlowLayout+Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D6F51AA2CDDD98300564C00 /* AssetsSearchFlowLayout+Types.swift */; };
2D6F51B12CE11EB100564C00 /* SpendAssetOperationNetworkBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D6F51B02CE11EB100564C00 /* SpendAssetOperationNetworkBuilder.swift */; };
2D6F51B32CE120AB00564C00 /* SpendAssetOperationNetworkListInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D6F51B22CE120AB00564C00 /* SpendAssetOperationNetworkListInteractor.swift */; };
2D7748772C89B5450059607B /* VoteCardViewModelFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D7748762C89B5450059607B /* VoteCardViewModelFactory.swift */; };
2D7748802C8B48C40059607B /* CIKeys.generated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D77487F2C8B48C40059607B /* CIKeys.generated.swift */; };
2D7748822C8CFB0B0059607B /* ReferendumAmountOperationFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D7748812C8CFB0B0059607B /* ReferendumAmountOperationFactory.swift */; };
Expand Down Expand Up @@ -1725,7 +1727,7 @@
77CB33D72A3998FD00B6709A /* Array+Sort.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77CB33D62A3998FC00B6709A /* Array+Sort.swift */; };
77CBD39C2ABBA98900D646D6 /* AssetListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77CBD39B2ABBA98900D646D6 /* AssetListModel.swift */; };
77CBD39E2ABC28BE00D646D6 /* SendAssetsOperationInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77CBD39D2ABC28BE00D646D6 /* SendAssetsOperationInteractor.swift */; };
77CBD3A02ABC35D900D646D6 /* SendAssetSearchBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77CBD39F2ABC35D900D646D6 /* SendAssetSearchBuilder.swift */; };
77CBD3A02ABC35D900D646D6 /* SpendAssetSearchBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77CBD39F2ABC35D900D646D6 /* SpendAssetSearchBuilder.swift */; };
77CC82A32A984BC3002D022F /* StartStakingSelectedValidatorsListWireframe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77CC82A22A984BC3002D022F /* StartStakingSelectedValidatorsListWireframe.swift */; };
77CC82A52A984EDA002D022F /* UINavigaionController+Pop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77CC82A42A984EDA002D022F /* UINavigaionController+Pop.swift */; };
77CC82A72A986CF1002D022F /* StakingSelectValidatorsDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77CC82A62A986CF1002D022F /* StakingSelectValidatorsDelegate.swift */; };
Expand Down Expand Up @@ -6218,6 +6220,8 @@
2D6F51A62CDD035900564C00 /* AssetDecorationAttributesFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetDecorationAttributesFactory.swift; sourceTree = "<group>"; };
2D6F51A82CDD2C3100564C00 /* AssetListFlowLayout+Types.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AssetListFlowLayout+Types.swift"; sourceTree = "<group>"; };
2D6F51AA2CDDD98300564C00 /* AssetsSearchFlowLayout+Types.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AssetsSearchFlowLayout+Types.swift"; sourceTree = "<group>"; };
2D6F51B02CE11EB100564C00 /* SpendAssetOperationNetworkBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpendAssetOperationNetworkBuilder.swift; sourceTree = "<group>"; };
2D6F51B22CE120AB00564C00 /* SpendAssetOperationNetworkListInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpendAssetOperationNetworkListInteractor.swift; sourceTree = "<group>"; };
2D7748762C89B5450059607B /* VoteCardViewModelFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VoteCardViewModelFactory.swift; sourceTree = "<group>"; };
2D77487F2C8B48C40059607B /* CIKeys.generated.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CIKeys.generated.swift; sourceTree = SOURCE_ROOT; };
2D7748812C8CFB0B0059607B /* ReferendumAmountOperationFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReferendumAmountOperationFactory.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6856,7 +6860,7 @@
77CB33D62A3998FC00B6709A /* Array+Sort.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+Sort.swift"; sourceTree = "<group>"; };
77CBD39B2ABBA98900D646D6 /* AssetListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetListModel.swift; sourceTree = "<group>"; };
77CBD39D2ABC28BE00D646D6 /* SendAssetsOperationInteractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendAssetsOperationInteractor.swift; sourceTree = "<group>"; };
77CBD39F2ABC35D900D646D6 /* SendAssetSearchBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendAssetSearchBuilder.swift; sourceTree = "<group>"; };
77CBD39F2ABC35D900D646D6 /* SpendAssetSearchBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpendAssetSearchBuilder.swift; sourceTree = "<group>"; };
77CC82A22A984BC3002D022F /* StartStakingSelectedValidatorsListWireframe.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StartStakingSelectedValidatorsListWireframe.swift; sourceTree = "<group>"; };
77CC82A42A984EDA002D022F /* UINavigaionController+Pop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigaionController+Pop.swift"; sourceTree = "<group>"; };
77CC82A62A986CF1002D022F /* StakingSelectValidatorsDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StakingSelectValidatorsDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -10697,7 +10701,7 @@
isa = PBXGroup;
children = (
0C1FE4F32A52EE51003769E7 /* AssetSearchBuilder.swift */,
77CBD39F2ABC35D900D646D6 /* SendAssetSearchBuilder.swift */,
77CBD39F2ABC35D900D646D6 /* SpendAssetSearchBuilder.swift */,
0C1FE4F52A52F137003769E7 /* AssetSearchBuilderResult.swift */,
);
path = Model;
Expand Down Expand Up @@ -12650,6 +12654,7 @@
2D4F55202CCBE18400B65B76 /* AssetOperationNetworkListViewModelFactory.swift */,
2D4F552B2CCC383100B65B76 /* AssetOperationNetworkViewModel.swift */,
2D4F55222CCBE58000B65B76 /* AssetOperationNetworkBuilder.swift */,
2D6F51B02CE11EB100564C00 /* SpendAssetOperationNetworkBuilder.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -12840,6 +12845,15 @@
path = AssetListStyleSwitcher;
sourceTree = "<group>";
};
2D6F51B42CE120AF00564C00 /* Interactor */ = {
isa = PBXGroup;
children = (
3C3ADD92DEC7B0142C5C6696 /* AssetOperationNetworkListInteractor.swift */,
2D6F51B22CE120AB00564C00 /* SpendAssetOperationNetworkListInteractor.swift */,
);
path = Interactor;
sourceTree = "<group>";
};
2D77488A2C9042800059607B /* Model */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -22853,9 +22867,9 @@
2D4F55302CCC38FB00B65B76 /* Model */,
2D4F55242CCBFC2D00B65B76 /* View */,
2D4F553C2CCC5DA400B65B76 /* Presenter */,
2D6F51B42CE120AF00564C00 /* Interactor */,
699926F12D454980392BAF03 /* AssetOperationNetworkListProtocols.swift */,
3C402A458F6B80E4CD6DBFE3 /* AssetOperationNetworkListWireframe.swift */,
3C3ADD92DEC7B0142C5C6696 /* AssetOperationNetworkListInteractor.swift */,
891FBCE49A51A9120ED9F861 /* AssetOperationNetworkListViewController.swift */,
B54E04B6D25A2DCD254CF1C4 /* AssetOperationNetworkListViewLayout.swift */,
3E646AC94F6AD246B0FD17EB /* AssetOperationNetworkListViewFactory.swift */,
Expand Down Expand Up @@ -24835,7 +24849,7 @@
846B749528B422C800C39B93 /* ChainAccountAddViewModel.swift in Sources */,
84EBFCE4285E734C0006327E /* XcmTransferDestination.swift in Sources */,
0CD8462E2BDE10C20026B5CA /* OnboardingImportOptionsPresenter.swift in Sources */,
77CBD3A02ABC35D900D646D6 /* SendAssetSearchBuilder.swift in Sources */,
77CBD3A02ABC35D900D646D6 /* SpendAssetSearchBuilder.swift in Sources */,
AE805FC726B3E54E00007CE9 /* YourValidatorInfoInteractor.swift in Sources */,
844DBC69274E3422009F8351 /* AccountImportSeedView.swift in Sources */,
84644AC52567EC05004EAA4B /* MultilineTriangularedView.swift in Sources */,
Expand Down Expand Up @@ -27349,6 +27363,7 @@
8427495728FEBFA400B2B70B /* ConvictionVoting+ConstantPath.swift in Sources */,
845B823829C9031800D187CB /* EtherscanPagination.swift in Sources */,
84C5ADDF28133F3E006D7388 /* UnknownAddressView.swift in Sources */,
2D6F51B12CE11EB100564C00 /* SpendAssetOperationNetworkBuilder.swift in Sources */,
84F6B6502619E1ED0038F10D /* Int+Operations.swift in Sources */,
8487010E2907DF2F00F2C0C3 /* MultiValueView+Style.swift in Sources */,
84770F2A291F864500852A33 /* GovernanceUnlockInitData.swift in Sources */,
Expand Down Expand Up @@ -27666,6 +27681,7 @@
270C21973CB61F0BF3D2D1E3 /* CrowdloanListProtocols.swift in Sources */,
6D61E43A79BDF5EA6CA9E85D /* CrowdloanListWireframe.swift in Sources */,
A090FF206B56A0E465C62072 /* CrowdloanListPresenter.swift in Sources */,
2D6F51B32CE120AB00564C00 /* SpendAssetOperationNetworkListInteractor.swift in Sources */,
846CA7802709A41E0011124C /* StakingAnalyticsLocalSubscriptionHandler.swift in Sources */,
849DF02D26C40B7900B702F4 /* RuntimeFilesOperationFactory.swift in Sources */,
2DCC87672C5989CC0028C3CA /* CloudBackupCreateViewFactory+NewBackup.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions novawallet/Modules/AssetList/AssetListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ extension AssetListViewController: AssetListCollectionManagerDelegate {
extension AssetListViewController: Localizable {
func applyLocalization() {
if isViewLoaded {
collectionViewManager.updateSelectedLocale(with: selectedLocale)
rootView.collectionView.reloadData()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct AssetOperationNetworkListViewFactory {

let logger = Logger.shared

let interactor = AssetOperationNetworkListInteractor(
let interactor = SpendAssetOperationNetworkListInteractor(
multichainToken: multichainToken,
stateObservable: stateObservable,
logger: logger
Expand Down Expand Up @@ -52,7 +52,8 @@ struct AssetOperationNetworkListViewFactory {
interactor: dependencies.interactor,
wireframe: wireframe,
multichainToken: dependencies.multichainToken,
viewModelFactory: viewModelFactory
viewModelFactory: viewModelFactory,
localizationManager: LocalizationManager.shared
)
}

Expand Down Expand Up @@ -129,7 +130,8 @@ extension AssetOperationNetworkListViewFactory {
multichainToken: dependencies.multichainToken,
viewModelFactory: viewModelFactory,
selectedAccount: dependencies.selectedAccount,
purchaseProvider: dependencies.purchaseProvider
purchaseProvider: dependencies.purchaseProvider,
localizationManager: LocalizationManager.shared
)
}
}
Expand Down Expand Up @@ -184,7 +186,8 @@ extension AssetOperationNetworkListViewFactory {
wireframe: wireframe,
multichainToken: dependencies.multichainToken,
viewModelFactory: viewModelFactory,
selectedAccount: dependencies.selectedAccount
selectedAccount: dependencies.selectedAccount,
localizationManager: LocalizationManager.shared
)
}
}
Expand All @@ -204,7 +207,7 @@ extension AssetOperationNetworkListViewFactory {

let logger = Logger.shared

let interactor = AssetOperationNetworkListInteractor(
let interactor = SpendAssetOperationNetworkListInteractor(
multichainToken: multichainToken,
stateObservable: stateObservable,
logger: logger
Expand Down Expand Up @@ -242,7 +245,8 @@ extension AssetOperationNetworkListViewFactory {
multichainToken: dependencies.multichainToken,
viewModelFactory: viewModelFactory,
selectClosure: dependencies.selectClosure,
selectClosureStrategy: dependencies.selectClosureStrategy
selectClosureStrategy: dependencies.selectClosureStrategy,
localizationManager: LocalizationManager.shared
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import UIKit
import Operation_iOS

final class AssetOperationNetworkListInteractor {
class AssetOperationNetworkListInteractor {
weak var presenter: AssetOperationNetworkListInteractorOutputProtocol?

private let workingQueueLabel: String = "com.nova.wallet.assets.networks.builder"
private let stateObservable: AssetListModelObservable
private let multichainToken: MultichainToken
let workingQueueLabel: String = "com.nova.wallet.assets.networks.builder"
let stateObservable: AssetListModelObservable
let multichainToken: MultichainToken

private let logger: LoggerProtocol
let logger: LoggerProtocol

private var chainAssets: [ChainAsset] = []

Expand All @@ -23,6 +23,22 @@ final class AssetOperationNetworkListInteractor {
self.stateObservable = stateObservable
self.logger = logger
}

func createModelBuilder(
with chainAssets: [ChainAsset],
resultClosure: @escaping (AssetOperationNetworkBuilderResult?) -> Void
) -> AssetOperationNetworkBuilder {
.init(
chainAssets: chainAssets,
workingQueue: .init(
label: workingQueueLabel,
qos: .userInteractive
),
callbackQueue: .main,
callbackClosure: resultClosure,
logger: logger
)
}
}

// MARK: AssetOperationNetworkListInteractorInputProtocol
Expand All @@ -46,15 +62,9 @@ extension AssetOperationNetworkListInteractor: AssetOperationNetworkListInteract
self?.presenter?.didReceive(result: result)
}

builder = .init(
chainAssets: chainAssets,
workingQueue: .init(
label: workingQueueLabel,
qos: .userInteractive
),
callbackQueue: .main,
callbackClosure: resultClosure,
logger: logger
builder = createModelBuilder(
with: chainAssets,
resultClosure: resultClosure
)

builder?.apply(model: stateObservable.state.value)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Foundation
import Operation_iOS

final class SpendAssetOperationNetworkListInteractor: AssetOperationNetworkListInteractor {
override func createModelBuilder(
with chainAssets: [ChainAsset],
resultClosure: @escaping (AssetOperationNetworkBuilderResult?) -> Void
) -> AssetOperationNetworkBuilder {
SpendAssetOperationNetworkBuilder(
chainAssets: chainAssets,
workingQueue: .init(
label: workingQueueLabel,
qos: .userInteractive
),
callbackQueue: .main,
callbackClosure: resultClosure,
logger: logger
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private extension AssetOperationNetworkListViewModelFactory {

let balanceValueString = if let priceData {
balanceFactory.priceFromAmount(
asset.totalValue ?? .zero,
asset.totalAmountDecimal ?? .zero,
priceData: priceData
).value(for: locale)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Foundation
import BigInt

class SpendAssetOperationNetworkBuilder: AssetOperationNetworkBuilder {
override func assetListState(from model: AssetListModel) -> AssetListState {
let chainAssets = model.allChains.flatMap { _, chain in
chain.assets.map { ChainAssetId(chainId: chain.chainId, assetId: $0.assetId) }
}

let balanceResults = chainAssets.reduce(into: [ChainAssetId: Result<BigUInt, Error>]()) {
switch model.balances[$1] {
case let .success(amount):
$0[$1] = .success(amount.transferable)
case let .failure(error):
$0[$1] = .failure(error)
case .none:
$0[$1] = .success(0)
}
}

return AssetListState(
priceResult: model.priceResult,
balanceResults: balanceResults,
allChains: model.allChains,
externalBalances: nil
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class AssetOperationNetworkListPresenter {
init(
interactor: AssetOperationNetworkListInteractorInputProtocol,
multichainToken: MultichainToken,
viewModelFactory: AssetOperationNetworkListViewModelFactory
viewModelFactory: AssetOperationNetworkListViewModelFactory,
localizationManager: LocalizationManagerProtocol
) {
self.interactor = interactor
self.multichainToken = multichainToken
self.viewModelFactory = viewModelFactory
self.localizationManager = localizationManager
}

func provideTitle() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import SoraFoundation

class BuyOperationNetworkListPresenter: AssetOperationNetworkListPresenter, PurchaseFlowManaging {
let selectedAccount: MetaAccountModel
Expand All @@ -13,7 +14,8 @@ class BuyOperationNetworkListPresenter: AssetOperationNetworkListPresenter, Purc
multichainToken: MultichainToken,
viewModelFactory: AssetOperationNetworkListViewModelFactory,
selectedAccount: MetaAccountModel,
purchaseProvider: PurchaseProviderProtocol
purchaseProvider: PurchaseProviderProtocol,
localizationManager: LocalizationManagerProtocol
) {
self.selectedAccount = selectedAccount
self.purchaseProvider = purchaseProvider
Expand All @@ -22,7 +24,8 @@ class BuyOperationNetworkListPresenter: AssetOperationNetworkListPresenter, Purc
super.init(
interactor: interactor,
multichainToken: multichainToken,
viewModelFactory: viewModelFactory
viewModelFactory: viewModelFactory,
localizationManager: localizationManager
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import SoraFoundation

class ReceiveOperationNetworkListPresenter: AssetOperationNetworkListPresenter {
let wireframe: ReceiveAssetOperationWireframeProtocol
Expand All @@ -10,15 +11,17 @@ class ReceiveOperationNetworkListPresenter: AssetOperationNetworkListPresenter {
wireframe: ReceiveAssetOperationWireframeProtocol,
multichainToken: MultichainToken,
viewModelFactory: AssetOperationNetworkListViewModelFactory,
selectedAccount: MetaAccountModel
selectedAccount: MetaAccountModel,
localizationManager: LocalizationManagerProtocol
) {
self.selectedAccount = selectedAccount
self.wireframe = wireframe

super.init(
interactor: interactor,
multichainToken: multichainToken,
viewModelFactory: viewModelFactory
viewModelFactory: viewModelFactory,
localizationManager: localizationManager
)
}

Expand Down
Loading
Loading