Skip to content

Commit

Permalink
add copy and ehterscan buttons to profile
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Nov 27, 2023
1 parent b66db4c commit b51814c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Abacus
import dydxStateManager
import dydxViews
import RoutingKit
import Utilities

protocol dydxProfileHeaderViewPresenterProtocol: HostedViewPresenterProtocol {
var viewModel: dydxProfileHeaderViewModel? { get }
Expand Down Expand Up @@ -38,9 +39,6 @@ class dydxProfileHeaderViewPresenter: HostedViewPresenter<dydxProfileHeaderViewM
}
.store(in: &self.subscriptions)
}
self.viewModel?.seeMoreInfoAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/my-profile/address"), animated: true, completion: nil)
}
}

override func start() {
Expand All @@ -49,6 +47,20 @@ class dydxProfileHeaderViewPresenter: HostedViewPresenter<dydxProfileHeaderViewM
AbacusStateManager.shared.state.walletState
.sink { [weak self] walletState in
self?.viewModel?.dydxAddress = walletState.currentWallet?.cosmoAddress
if let address = walletState.currentWallet?.cosmoAddress {
self?.viewModel?.copyAction = {
UIPasteboard.general.string = address
}
self?.viewModel?.openInEtherscanAction = {
let urlString = "https://etherscan.io/address/\(address)"
if let url = URL(string: urlString), URLHandler.shared?.canOpenURL(url) ?? false {
URLHandler.shared?.open(url, completionHandler: nil)
}
}
} else {
self?.viewModel?.copyAction = nil
self?.viewModel?.openInEtherscanAction = nil
}
}
.store(in: &subscriptions)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icon_copy.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import Utilities
public class dydxProfileHeaderViewModel: PlatformViewModel {
@Published public var dydxChainLogoUrl: URL?
@Published public var dydxAddress: String?
@Published public var seeMoreInfoAction: (() -> Void)?
@Published public var copyAction: (() -> Void)?
@Published public var openInEtherscanAction: (() -> Void)?
@Published public var manageWalletAction: (() -> Void)?

public init() { }
Expand Down Expand Up @@ -55,7 +56,32 @@ public class dydxProfileHeaderViewModel: PlatformViewModel {
.truncationMode(.middle)
}

let seeMoreButton = self.dydxAddress != nil ? PlatformIconViewModel(type: .system(name: "chevron.right"), size: CGSize(width: 16, height: 16)) : PlatformView.nilViewModel
let iconDim: CGFloat = 40
let iconSpacing: CGFloat = 18

let copyButton: Button? = copyAction == nil ? nil : Button { [weak self] in
if let copyAction = self?.copyAction {
copyAction()
ErrorInfo.shared?.info(title: nil,
message: DataLocalizer.localize(path: "APP.V4.DYDX_ADDRESS_COPIED"),
type: .info,
error: nil, time: 3)
}
} label: {
PlatformIconViewModel(type: .asset(name: "icon_copy", bundle: .dydxView),
clip: .circle(background: .layer4, spacing: iconSpacing, borderColor: .layer6),
size: CGSize(width: iconDim, height: iconDim))
.createView()
}

let openInEtherscanAction: Button? = openInEtherscanAction == nil ? nil : Button { [weak self] in
self?.openInEtherscanAction?()
} label: {
PlatformIconViewModel(type: .asset(name: "icon_external_link", bundle: .dydxView),
clip: .circle(background: .layer4, spacing: iconSpacing, borderColor: .layer6),
size: CGSize(width: iconDim, height: iconDim))
.createView()
}

let content = VStack(spacing: 16) {
HStack(alignment: .top) {
Expand All @@ -66,16 +92,13 @@ public class dydxProfileHeaderViewModel: PlatformViewModel {
manageWalletButton
}
}
HStack {
HStack(spacing: 0) {
addressInfoView
Spacer()
seeMoreButton
.createView(parentStyle: parentStyle)
.onTapGesture { [weak self] in
if self?.dydxAddress != nil {
self?.seeMoreInfoAction?()
}
}
Spacer(minLength: 12)
HStack(spacing: 12) {
copyButton
openInEtherscanAction
}
}
}
.padding(.all, 20)
Expand Down

0 comments on commit b51814c

Please sign in to comment.