Skip to content

Commit

Permalink
Merge pull request #1330 from novasamatech/fix/dapps-fixes
Browse files Browse the repository at this point in the history
Fix/dapps fixes
  • Loading branch information
svojsu authored Jan 14, 2025
2 parents c2ed5f6 + 6af6608 commit 24b3bd1
Show file tree
Hide file tree
Showing 32 changed files with 531 additions and 202 deletions.
12 changes: 12 additions & 0 deletions novawallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,9 @@
2D1D66022CD82330009C6C2F /* KingfisherIconRetrieveOperationFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D1D66012CD82330009C6C2F /* KingfisherIconRetrieveOperationFactory.swift */; };
2D1D66042CD89573009C6C2F /* AssetListStyleSwitcherView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D1D66032CD89573009C6C2F /* AssetListStyleSwitcherView.swift */; };
2D1D66062CD92209009C6C2F /* QRDisplayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D1D66052CD92209009C6C2F /* QRDisplayView.swift */; };
2D20F1BE2D351936003E9CF2 /* DAppListBannerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D20F1BD2D351936003E9CF2 /* DAppListBannerViewModel.swift */; };
2D20F1C02D351B28003E9CF2 /* DAppListBannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D20F1BF2D351B28003E9CF2 /* DAppListBannerView.swift */; };
2D20F1C22D353495003E9CF2 /* DAppIconViewModelFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D20F1C12D353495003E9CF2 /* DAppIconViewModelFactory.swift */; };
2D2F6F522C50E52D005020EF /* VotingCurveTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D2F6F512C50E52D005020EF /* VotingCurveTests.swift */; };
2D31D3062D149F74004BF46B /* ModalCardPresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D31D3052D149F74004BF46B /* ModalCardPresentationController.swift */; };
2D32BE122C6A49900047F520 /* ExtrinsicAssetConversionFeeEstimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D32BE052C6A49900047F520 /* ExtrinsicAssetConversionFeeEstimator.swift */; };
Expand Down Expand Up @@ -6509,6 +6512,9 @@
2D1D66012CD82330009C6C2F /* KingfisherIconRetrieveOperationFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KingfisherIconRetrieveOperationFactory.swift; sourceTree = "<group>"; };
2D1D66032CD89573009C6C2F /* AssetListStyleSwitcherView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetListStyleSwitcherView.swift; sourceTree = "<group>"; };
2D1D66052CD92209009C6C2F /* QRDisplayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRDisplayView.swift; sourceTree = "<group>"; };
2D20F1BD2D351936003E9CF2 /* DAppListBannerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DAppListBannerViewModel.swift; sourceTree = "<group>"; };
2D20F1BF2D351B28003E9CF2 /* DAppListBannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DAppListBannerView.swift; sourceTree = "<group>"; };
2D20F1C12D353495003E9CF2 /* DAppIconViewModelFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DAppIconViewModelFactory.swift; sourceTree = "<group>"; };
2D2F6F512C50E52D005020EF /* VotingCurveTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VotingCurveTests.swift; sourceTree = "<group>"; };
2D31D3052D149F74004BF46B /* ModalCardPresentationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalCardPresentationController.swift; sourceTree = "<group>"; };
2D32BE052C6A49900047F520 /* ExtrinsicAssetConversionFeeEstimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExtrinsicAssetConversionFeeEstimator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -13404,6 +13410,7 @@
children = (
2D4431E82D0369EB00017951 /* DAppListViewModelFactoryProtocol.swift */,
842BA36C27B64F1000D31EEF /* DAppListViewModelFactory.swift */,
2D20F1C12D353495003E9CF2 /* DAppIconViewModelFactory.swift */,
);
path = DAppListViewModelFactory;
sourceTree = "<group>";
Expand Down Expand Up @@ -16221,6 +16228,7 @@
842BA36A27B64F1000D31EEF /* DAppViewModel.swift */,
2D3EA7DF2CFEDC0F0033AFD2 /* DAppCategoryViewModelFactory.swift */,
2D4431E12D01130E00017951 /* DAppListSection.swift */,
2D20F1BD2D351936003E9CF2 /* DAppListBannerViewModel.swift */,
2D4431EA2D036A0400017951 /* DAppListViewModelFactory */,
);
path = ViewModel;
Expand Down Expand Up @@ -21588,6 +21596,7 @@
children = (
84EE780327C4CF9E0027357F /* DAppListItemsLoadingView.swift */,
84DA03DA275A31B500E8B326 /* DAppListHeaderView.swift */,
2D20F1BF2D351B28003E9CF2 /* DAppListBannerView.swift */,
2D4431DC2D01094B00017951 /* DAppItemView */,
84720731277C370600F593DD /* DAppCategoriesView.swift */,
8448D5B7277DA4C200FAEEBC /* DAppListLoadingView.swift */,
Expand Down Expand Up @@ -26134,6 +26143,7 @@
0CE1A0522BE9E995008206ED /* CloudBackupSettingsView.swift in Sources */,
84E9A05028F000AB00551DC4 /* ReferendumMetadataLocal.swift in Sources */,
84821E84275F93C700ADC8D2 /* TitleMultiValueView+Style.swift in Sources */,
2D20F1BE2D351936003E9CF2 /* DAppListBannerViewModel.swift in Sources */,
84DA03D12758AA6800E8B326 /* BaseAccountImportWireframe.swift in Sources */,
0C38B50E2B7DC42500882A8B /* KodaDotNftOperationFactory.swift in Sources */,
84E8BA1F29FFB38600FD9F40 /* EthereumOperationFactory.swift in Sources */,
Expand Down Expand Up @@ -28037,6 +28047,7 @@
844304622A28C9FA00DE36DE /* MultistakingSyncState.swift in Sources */,
0C626D1F2A92AA0F00CDAF4E /* NominationPoolsDataProviding.swift in Sources */,
8446F5EC2817107D00B7A86C /* TitleAmountView.swift in Sources */,
2D20F1C02D351B28003E9CF2 /* DAppListBannerView.swift in Sources */,
84CEAAF726D7B8010021B881 /* SettingsMigrator.swift in Sources */,
84ABB32B2A16146600B5E95A /* HistoryItemTableViewCell.swift in Sources */,
F4D0546B2729949100210294 /* MoonbeamMakeSignatureResponse.swift in Sources */,
Expand Down Expand Up @@ -30093,6 +30104,7 @@
AD877F7F77F9CB862DC7D5B3 /* DelegationReferendumVotersWireframe.swift in Sources */,
0DD3DB85B0E7FD5692F58787 /* DelegationReferendumVotersPresenter.swift in Sources */,
8A2486E62C3915CB6D1FDED8 /* DelegationReferendumVotersInteractor.swift in Sources */,
2D20F1C22D353495003E9CF2 /* DAppIconViewModelFactory.swift in Sources */,
77740BBE2AD4A7F500E8C06F /* SwapDetailsView.swift in Sources */,
0F073C8161B9852DEB1D40CD /* DelegationReferendumVotersViewController.swift in Sources */,
D274117F06B12F955073D35B /* DelegationReferendumVotersViewLayout.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ final class DAppAddFavoriteInteractor {
if dApps.count == 1, let dApp = dApps.first {
provideProposedModelWithMatchedDApp(dApp)
} else {
provideProposedModelWithMatchedDApp(nil)
let path = browserPage.url
.pathComponents
.first { $0 != "/" }

let dApp = dApps.first {
$0.url
.pathComponents
.first { $0 != "/" } == path
}

provideProposedModelWithMatchedDApp(dApp)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ final class DAppAddFavoritePresenter {
weak var view: DAppAddFavoriteViewProtocol?
let wireframe: DAppAddFavoriteWireframeProtocol
let interactor: DAppAddFavoriteInteractorInputProtocol
let iconViewModelFactory: DAppIconViewModelFactoryProtocol
let localizationManager: LocalizationManagerProtocol

private(set) var titleViewModel: InputViewModelProtocol?
Expand All @@ -15,10 +16,12 @@ final class DAppAddFavoritePresenter {
init(
interactor: DAppAddFavoriteInteractorInputProtocol,
wireframe: DAppAddFavoriteWireframeProtocol,
iconViewModelFactory: DAppIconViewModelFactoryProtocol,
localizationManager: LocalizationManagerProtocol
) {
self.interactor = interactor
self.wireframe = wireframe
self.iconViewModelFactory = iconViewModelFactory
self.localizationManager = localizationManager
}

Expand All @@ -27,14 +30,7 @@ final class DAppAddFavoritePresenter {
return
}

let iconViewModel: ImageViewModelProtocol

if let icon = proposedModel.icon, let url = URL(string: icon) {
iconViewModel = RemoteImageViewModel(url: url)
} else {
let defaultIcon = R.image.iconDefaultDapp()!
iconViewModel = StaticImageViewModel(image: defaultIcon)
}
let iconViewModel = iconViewModelFactory.createIconViewModel(for: proposedModel)

view?.didReceive(iconViewModel: iconViewModel)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ struct DAppAddFavoriteViewFactory {
)

let wireframe = DAppAddFavoriteWireframe()

let localizationManager = LocalizationManager.shared
let iconViewModelFactory = DAppIconViewModelFactory()

let presenter = DAppAddFavoritePresenter(
interactor: interactor,
wireframe: wireframe,
iconViewModelFactory: iconViewModelFactory,
localizationManager: localizationManager
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ struct DAppAuthConfirmViewFactory {

let localizationManager = LocalizationManager.shared

let viewModelFactory = DAppAuthViewModelFactory(
iconViewModelFactory: DAppIconViewModelFactory()
)

let presenter = DAppAuthConfirmPresenter(
wireframe: wireframe,
request: request,
delegate: delegate,
viewModelFactory: DAppAuthViewModelFactory()
viewModelFactory: viewModelFactory
)

let view = DAppAuthConfirmViewController(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ protocol DAppAuthViewModelFactoryProtocol {
}

final class DAppAuthViewModelFactory: DAppAuthViewModelFactoryProtocol {
private let iconViewModelFactory: DAppIconViewModelFactoryProtocol

init(iconViewModelFactory: DAppIconViewModelFactoryProtocol) {
self.iconViewModelFactory = iconViewModelFactory
}

func createViewModel(from request: DAppAuthRequest) -> DAppAuthViewModel {
let sourceViewModel = StaticImageViewModel(image: R.image.iconDappExtension()!)

let destinationViewModel: ImageViewModelProtocol

if let iconUrl = request.dAppIcon {
destinationViewModel = RemoteImageViewModel(url: iconUrl)
} else {
destinationViewModel = StaticImageViewModel(image: R.image.iconDefaultDapp()!)
}
let destinationViewModel = iconViewModelFactory.createIconViewModel(for: request)

let iconGenerator = NovaIconGenerator()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,17 @@ extension DAppBrowserPresenter: DAppBrowserPresenterProtocol {

func close(stateRender: DAppBrowserTabRenderProtocol) {
interactor.process(stateRender: stateRender)

view?.didDecideClose()
wireframe.close(view: view)
}

func showTabs(stateRender: DAppBrowserTabRenderProtocol) {
view?.didDecideClose()
interactor.saveLastTabState(render: stateRender)
}

func willDismissInteractive(stateRender: DAppBrowserTabRenderProtocol) {
view?.didDecideClose()
interactor.saveLastTabState(render: stateRender)
}

Expand Down Expand Up @@ -270,6 +276,7 @@ extension DAppBrowserPresenter: DAppAuthDelegate {

extension DAppBrowserPresenter: DAppPhishingViewDelegate {
func dappPhishingViewDidHide() {
view?.didDecideClose()
wireframe.close(view: view)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protocol DAppBrowserPresenterProtocol: AnyObject {
func showSettings(using isDesktop: Bool)
func close(stateRender: DAppBrowserTabRenderProtocol)
func showTabs(stateRender: DAppBrowserTabRenderProtocol)
func willDismissInteractive(stateRender: DAppBrowserTabRenderProtocol)
}

protocol DAppBrowserInteractorInputProtocol: AnyObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,16 @@ extension DAppBrowserTabListPresenter: DAppBrowserTabListPresenterProtocol {
}

func closeAllTabs() {
interactor.closeAllTabs()
if tabs.count > 1 {
wireframe.presentCloseTabsAlert(
from: view,
with: localizationManager.selectedLocale
) { [weak self] in
self?.interactor.closeAllTabs()
}
} else {
interactor.closeAllTabs()
}
}

func closeTab(with id: UUID) {
Expand All @@ -84,8 +93,12 @@ extension DAppBrowserTabListPresenter: DAppBrowserTabListPresenterProtocol {

extension DAppBrowserTabListPresenter: DAppBrowserTabListInteractorOutputProtocol {
func didReceiveTabs(_ models: [DAppBrowserTab]) {
tabs = models
if !tabs.isEmpty, models.isEmpty {
wireframe.close(from: view)
return
}

tabs = models
provideTabs()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ protocol DAppBrowserTabListInteractorOutputProtocol: AnyObject {

protocol DAppBrowserTabListWireframeProtocol: AlertPresentable,
ErrorPresentable,
DAppBrowserSearchPresentable {
DAppBrowserSearchPresentable,
DAppBrowserTabsClosePresentable {
func showTab(
_ tab: DAppBrowserTab,
from view: ControllerBackedProtocol?
Expand Down
31 changes: 31 additions & 0 deletions novawallet/Modules/DApp/DAppBrowser/DAppBrowserTabTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ enum DAppBrowserTabTransition {
guard let tabId else { return }

let options = UIViewController.Transition.ZoomOptions()
options.interactiveDismissShouldBegin = { context in
guard let destinationController = destController as? DAppBrowserViewController else {
return true
}

let shouldDismiss = atViewEdge(
context.location,
view: destinationController.view
)

let canBeDismissedInteractively: Bool = destinationController.canBeDismissedInteractively()
let willDismiss = shouldDismiss && canBeDismissedInteractively

if willDismiss {
destinationController.willBeDismissedInteractively()
}

return willDismiss
}

options.alignmentRectProvider = { context in
guard let destinationController = context.zoomedViewController as? DAppBrowserViewController else {
return .zero
Expand Down Expand Up @@ -45,4 +65,15 @@ enum DAppBrowserTabTransition {
false
}
}

static func atViewEdge(
_ point: CGPoint,
view: UIView,
edgeWidth: CGFloat = 20
) -> Bool {
let atLeftEdge = point.x <= edgeWidth
let atRightEdge = point.x >= view.bounds.width - edgeWidth

return atLeftEdge || atRightEdge
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class DAppBrowserViewController: UIViewController, ViewHolder {
}

var isLandscape: Bool {
view.frame.size.width > view.frame.size.height
traitCollection.verticalSizeClass == .compact
}

init(
Expand Down Expand Up @@ -103,6 +103,17 @@ final class DAppBrowserViewController: UIViewController, ViewHolder {

presenter.setup()
}

func canBeDismissedInteractively() -> Bool {
!isLandscape
}

func willBeDismissedInteractively() {
snapshotWebView { [weak self] image in
let render = DAppBrowserTabRender(for: image)
self?.presenter.willDismissInteractive(stateRender: render)
}
}
}

// MARK: Private
Expand Down Expand Up @@ -175,8 +186,6 @@ private extension DAppBrowserViewController {
}

func makeStateRender() {
guard let webView = rootView.webView else { return }

snapshotWebView { [weak self] image in
let render = DAppBrowserTabRender(for: image)
self?.presenter.process(stateRender: render)
Expand Down Expand Up @@ -557,13 +566,11 @@ extension DAppBrowserViewController: UIScrollViewDelegate {

if isScrollingUp {
hideBars()

scrollYOffset = scrollView.contentOffset.y
} else if isScrollingDown {
showBars()

scrollYOffset = scrollView.contentOffset.y
}

scrollYOffset = scrollView.contentOffset.y
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ struct DAppFavoritesViewFactory {

let wireframe = DAppFavoritesWireframe()

let categoriesViewModelFactory = DAppCategoryViewModelFactory()
let viewModelFactory = DAppListViewModelFactory(
dappCategoriesViewModelFactory: categoriesViewModelFactory
dappCategoriesViewModelFactory: DAppCategoryViewModelFactory(),
dappIconViewModelFactory: DAppIconViewModelFactory()
)

let wallet: MetaAccountModel = SelectedWalletSettings.shared.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ extension DAppListViewController {
categoriess: models,
indexPath: indexPath
)
case let .banner(model):
setupBannerView(
using: collectionView,
banner: model,
indexPath: indexPath
)
case let .favorites(model, _):
setupDAppView(
using: collectionView,
Expand Down Expand Up @@ -119,6 +125,21 @@ private extension DAppListViewController {
return cell
}

func setupBannerView(
using collectionView: UICollectionView,
banner: DAppListBannerViewModel,
indexPath: IndexPath
) -> UICollectionViewCell {
let cell: DAppListBannerView = collectionView.dequeueReusableCellWithType(
DAppListBannerView.self,
for: indexPath
)!

cell.bind(viewModel: banner)

return cell
}

func setupDAppView(
using collectionView: UICollectionView,
dApp: DAppViewModel,
Expand Down
Loading

0 comments on commit 24b3bd1

Please sign in to comment.