Skip to content

Commit

Permalink
MOB-252 : Add link to share app on profile screen (#98)
Browse files Browse the repository at this point in the history
* add in-line share action

* use app url instead of website

* add analytics event
  • Loading branch information
mike-dydx committed Aug 21, 2024
1 parent ccc178b commit c4fae9a
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"destination":"Refresh.xib"
},
"/action/share":{
"destination":"Share.xib"
"destination":"PlatformRouting.ShareActionBuilder"
},
"/action/wallet":{
"destination":"Wallet.xib"
Expand Down
16 changes: 16 additions & 0 deletions PlatformRouting/PlatformRouting/_Actions/ShareAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
//

import RoutingKit
import Utilities
import UIToolkits

public class ShareActionBuilder: NSObject, ObjectBuilderProtocol {
public func build<T>() -> T? {
let action = ShareAction()
return action as? T
}
}

open class ShareAction: NSObject, NavigableProtocol {
private var completion: RoutingCompletionBlock?
open func navigate(to request: RoutingRequest?, animated: Bool, completion: RoutingCompletionBlock?) {
Expand All @@ -25,6 +33,14 @@ open class ShareAction: NSObject, NavigableProtocol {
activityVC.popoverPresentationController?.sourceView = UserInteraction.shared.sender as? UIView
activityVC.popoverPresentationController?.barButtonItem = UserInteraction.shared.sender as? UIBarButtonItem
UIViewController.topmost()?.present(activityVC, animated: true, completion: nil)

let data: [String: String]?
if let shareSource = request?.params?["share_source"] as? String {
data = ["share_source": shareSource]
} else {
data = nil
}
Tracking.shared?.log(event: "ShareDialogDisplayed", data: data)
completion?(nil, true)
} else {
completion?(nil, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"destination":"dydxPresenters.dydxCancelOrderActionBuilder"
},
"/action/share": {
"destination":"ShareAction.xib"
"destination":"PlatformRouting.ShareActionBuilder"
},
"/action/wallet/connect": {
"destination":"dydxPresenters.WalletActionBuilder"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import PlatformParticles
import RoutingKit
import ParticlesKit
import PlatformUI
import dydxStateManager

public class dydxProfileViewBuilder: NSObject, ObjectBuilderProtocol {
public func build<T>() -> T? {
Expand Down Expand Up @@ -72,5 +73,13 @@ private class dydxProfileViewPresenter: HostedViewPresenter<dydxProfileViewModel
balancesPresenter.$viewModel.assign(to: &viewModel.$balances)

attachChildren(workers: childPresenters)

viewModel.share?.shareAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/action/share",
params: ["text": DataLocalizer.shared?.localize(path: "APP.GENERAL.SHARE_MESSAGE", params: nil) ?? "",
"link": AbacusStateManager.shared.environment?.apps?.ios?.url ?? AbacusStateManager.shared.deploymentUri,
"share_source": "account_screen_share_app_inline_button"]),
animated: true, completion: nil)
}
}
}
4 changes: 4 additions & 0 deletions dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
276909102AAFD8BE0075B2D6 /* dydxPortfolioTransfersViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2769090F2AAFD8BE0075B2D6 /* dydxPortfolioTransfersViewModel.swift */; };
277442972AD88C4900C91357 /* Satoshi-Bold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 277442952AD88C4900C91357 /* Satoshi-Bold.otf */; };
277442982AD88C4900C91357 /* Satoshi-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 277442962AD88C4900C91357 /* Satoshi-Regular.otf */; };
27759F5C2B89125F002865A9 /* dydxInlineShareView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27759F5B2B89125F002865A9 /* dydxInlineShareView.swift */; };
277E8F9F2B1A847D005CCBCB /* dydxTitledCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277E8F9E2B1A847D005CCBCB /* dydxTitledCardView.swift */; };
277E8FCB2B1E5798005CCBCB /* dydxProfileRewardsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277E8FCA2B1E5798005CCBCB /* dydxProfileRewardsViewModel.swift */; };
277E90132B1EA0D3005CCBCB /* dydxTradingRewardsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277E90122B1EA0D3005CCBCB /* dydxTradingRewardsView.swift */; };
Expand Down Expand Up @@ -504,6 +505,7 @@
2769090F2AAFD8BE0075B2D6 /* dydxPortfolioTransfersViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxPortfolioTransfersViewModel.swift; sourceTree = "<group>"; };
277442952AD88C4900C91357 /* Satoshi-Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Satoshi-Bold.otf"; sourceTree = "<group>"; };
277442962AD88C4900C91357 /* Satoshi-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Satoshi-Regular.otf"; sourceTree = "<group>"; };
27759F5B2B89125F002865A9 /* dydxInlineShareView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxInlineShareView.swift; sourceTree = "<group>"; };
277E8F9E2B1A847D005CCBCB /* dydxTitledCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTitledCardView.swift; sourceTree = "<group>"; };
277E8FCA2B1E5798005CCBCB /* dydxProfileRewardsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxProfileRewardsViewModel.swift; sourceTree = "<group>"; };
277E90122B1EA0D3005CCBCB /* dydxTradingRewardsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTradingRewardsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1376,6 +1378,7 @@
277E91072B2241C1005CCBCB /* dydxRewardsRewardView.swift */,
277E91492B23BB74005CCBCB /* dydxRewardsLearnMoreView.swift */,
277E918A2B27762F005CCBCB /* dydxRewardsLaunchIncentivesView.swift */,
27759F5B2B89125F002865A9 /* dydxInlineShareView.swift */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -1988,6 +1991,7 @@
024F488E2965C91E00E40247 /* dydxPortfolioChartView.swift in Sources */,
645299F22AE86FC3000810E6 /* dydxUpdateView.swift in Sources */,
02031F052AC373B50069E00D /* dydxTradeSheetTipBuySellView.swift in Sources */,
27759F5C2B89125F002865A9 /* dydxInlineShareView.swift in Sources */,
0230377328C13BBB00412B72 /* dydxMarketsView.swift in Sources */,
02F958142A1BDEE500828F9A /* dydxKeyExportView.swift in Sources */,
0238B90B29FB38F200FCE4D0 /* dydxThemeLoader.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "Share.pdf",
"filename" : "icon_share.pdf",
"idiom" : "universal"
}
],
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// dydxInlineShareView.swift
// dydxUI
//
// Created by Michael Maguire on 2/23/24.
// Copyright © 2024 dYdX Trading Inc. All rights reserved.
//

import SwiftUI
import PlatformUI
import Utilities

public class dydxInlineShareViewModel: PlatformViewModel {
@Published public var shareAction: (() -> Void)?

private let shareCta: AttributedString = {
let localizedString = DataLocalizer.shared?.localize(path: "APP.GENERAL.SHARE_DYDX", params: nil) ?? ""
let unhighlightedString = DataLocalizer.shared?.localize(path: "APP.GENERAL.SHARE", params: nil) ?? ""

var attributedString = AttributedString(localizedString)
.themeFont(fontType: .text, fontSize: .medium)

attributedString = attributedString.themeColor(foreground: .textSecondary)
if let unhighlightedStringRange = attributedString.range(of: unhighlightedString) {
attributedString = attributedString.themeColor(foreground: .textTertiary, to: unhighlightedStringRange)
}

return attributedString
}()

public static var previewValue: dydxInlineShareViewModel = {
let vm = dydxInlineShareViewModel()
return vm
}()

public override func createView(parentStyle: ThemeStyle = ThemeStyle.defaultStyle, styleKey: String? = nil) -> PlatformView {
PlatformView(viewModel: self, parentStyle: parentStyle, styleKey: styleKey) { [weak self] style in
guard let self = self else { return AnyView(PlatformView.nilView) }

return AnyView(
HStack(alignment: .center, spacing: 6) {
Text(self.shareCta)
PlatformIconViewModel(type: .asset(name: "icon_share", bundle: .dydxView),
clip: .noClip,
size: CGSize(width: 20, height: 20),
templateColor: .textSecondary)
.createView(parentStyle: style)
}
.onTapGesture { [weak self] in
self?.shareAction?()
}
)
}
}
}

#Preview {
Group {
dydxInlineShareViewModel.previewValue
.createView()
.environmentObject(ThemeSettings.shared)
.previewLayout(.sizeThatFits)
}
}
6 changes: 5 additions & 1 deletion dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class dydxProfileViewModel: PlatformViewModel {
@Published public var fees: dydxProfileFeesViewModel? = dydxProfileFeesViewModel()
@Published public var balances: dydxProfileBalancesViewModel? = dydxProfileBalancesViewModel()
@Published public var rewards: dydxProfileRewardsViewModel? = dydxProfileRewardsViewModel()
@Published public var share: dydxInlineShareViewModel? = dydxInlineShareViewModel()

public init() { }

Expand Down Expand Up @@ -58,7 +59,10 @@ public class dydxProfileViewModel: PlatformViewModel {
self.history?
.createView(parentStyle: style)

Spacer(minLength: 100)
self.share?
.createView(parentStyle: style)

Spacer(minLength: 136)
}
}
.padding(.horizontal)
Expand Down

0 comments on commit c4fae9a

Please sign in to comment.