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

CLI-625: reflect vault balance in portfolio positions #252

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class dydxPortfolioPositionsViewPresenter: HostedViewPresenter<dydxPortfolioPosi
super.init()

self.viewModel = viewModel

viewModel?.vaultTapAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/vault"), animated: true, completion: nil)
}
}

override func start() {
Expand All @@ -50,6 +54,22 @@ class dydxPortfolioPositionsViewPresenter: HostedViewPresenter<dydxPortfolioPosi
self?.updatePendingPositions(pendingPositions: pendingPositions, marketMap: marketMap, assetMap: assetMap)
}
.store(in: &subscriptions)

Publishers.CombineLatest(
AbacusStateManager.shared.state.onboarded,
//TODO: replace with actual vault info from abacus
AbacusStateManager.shared.state.onboarded
).sink { [weak self] onboarded, _ in
if onboarded,
let viewModel = self?.viewModel,
//TODO: replace with actual vault info from abacus
let vaultBalance = Optional<Double>(420.42),
let vaultApy = Optional<Double>(Double.random(in: -30...30)) {
viewModel.vaultBalance = dydxFormatter.shared.dollar(number: vaultBalance, digits: 2)
viewModel.vaultApy = vaultApy
}
}
.store(in: &subscriptions)
}

private func updatePositions(positions: [SubaccountPosition], marketMap: [String: PerpetualMarket], assetMap: [String: Asset]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private class dydxVaultDepositWithdrawConfirmationViewPresenter: HostedViewPrese
guard let viewModel else { return }

viewModel.amount = amount
viewModel.faqUrl = AbacusStateManager.shared.environment?.links?.vaultLearnMore ?? ""
viewModel.faqUrl = AbacusStateManager.shared.environment?.links?.vaultLearnMore
viewModel.transferType = transferType

initializeSubmitState()
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note icon_token was not being used prior to rename. It is this image which is the chain, not the token

File renamed without changes.
4 changes: 2 additions & 2 deletions dydx/dydxViews/dydxViews/Themes/dydxStyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"_textColor": "color_red"
},
"signed-plus-layer": {
"_layerColor": "#3ED9A433"
"_layerColor": "color_faded_green"
},
"signed-minus-layer": {
"_layerColor": "#E4555533"
"_layerColor": "color_faded_red"
},
"side-plus": {
"_textColor": "color_green"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,17 @@ public class dydxPortfolioPositionsViewModel: PlatformViewModel {
contentChanged?()
}
}

@Published public var vaultBalance: String?
@Published public var vaultApy: Double?
@Published public var vaultTapAction: (() -> Void)?

public var contentChanged: (() -> Void)?

init(
positionItems: [dydxPortfolioPositionItemViewModel] = [],
pendingPositionItems: [dydxPortfolioPendingPositionsItemViewModel] = [],
vaultBalance: String? = nil,
vaultApy: String? = nil,
emptyText: String? = nil
) {
self.positionItems = positionItems
Expand All @@ -275,6 +280,7 @@ public class dydxPortfolioPositionsViewModel: PlatformViewModel {
pendingPositionItems: [
.previewValue
],
vaultBalance: "324.320",
emptyText: "empty")
}

Expand Down Expand Up @@ -314,16 +320,91 @@ public class dydxPortfolioPositionsViewModel: PlatformViewModel {
}
}

@ViewBuilder
private var pendingPositionsView: AnyView? {
let unopenedItems = self.pendingPositionItems.map { $0.createView() }
return LazyVStack {
self.pendingPositionsHeader?.createView()
if !pendingPositionItems.isEmpty {
let unopenedItems = self.pendingPositionItems.map { $0.createView() }
LazyVStack {
self.pendingPositionsHeader?.createView()

ForEach(unopenedItems.indices, id: \.self) { index in
unopenedItems[index]
ForEach(unopenedItems.indices, id: \.self) { index in
unopenedItems[index]
}
}
.wrappedInAnyView()
}
}

@ViewBuilder
public var apyAccessory: some View {
if let vaultApy, let vaultApyText = dydxFormatter.shared.percent(number: vaultApy, digits: 2) {
Text(vaultApyText)
.themeFont(fontSize: .smaller)
.padding(.horizontal, 4)
.padding(.vertical, 2)
.themeColor(foreground: vaultApy < 0 ? ThemeSettings.negativeColor : ThemeSettings.positiveColor)
.themeColor(background: vaultApy < 0 ? ThemeSettings.negativeColorLayer : ThemeSettings.positiveColorLayer)
.cornerRadius(4)
}
}

public var megaVaultBalanceRowHeader: some View {
HStack(spacing: 0) {
Text(localizerPathKey: "APP.GENERAL.DETAILS")
.themeFont(fontType: .plus, fontSize: .small)
.themeColor(foreground: .textTertiary)
Spacer()
Text(localizerPathKey: "APP.VAULTS.YOUR_VAULT_BALANCE")
.themeFont(fontType: .plus, fontSize: .small)
.themeColor(foreground: .textTertiary)
}
.padding(.horizontal, 16)
}

@ViewBuilder
public var megaVaultBalanceRow: some View {
if let vaultBalance {
HStack(spacing: 0) {
PlatformIconViewModel(type: .asset(name: "icon_chain", bundle: .dydxView),
clip: .noClip,
size: .init(width: 32, height: 32),
templateColor: nil)
.createView()
Color.clear.frame(width: 16)
Text(localizerPathKey: "APP.VAULTS.MEGAVAULT")
.themeFont(fontSize: .medium)
.themeColor(foreground: .textSecondary)
Color.clear.frame(width: 6)
apyAccessory
Spacer()
Text(vaultBalance)
.themeFont(fontSize: .small)
.themeColor(foreground: .textPrimary)
}
.padding(.all, 16)
.themeColor(background: .layer3)
.cornerRadius(16)
}
}

@ViewBuilder
public var megaVaultSection: some View {
if dydxBoolFeatureFlag.isVaultEnabled.isEnabled {
VStack(spacing: 16) {
Text(localizerPathKey: "APP.VAULTS.MEGAVAULT")
.themeFont(fontType: .plus, fontSize: .larger)
.themeColor(foreground: .textPrimary)
.fixedSize()
.leftAligned()
VStack(spacing: 8) {
megaVaultBalanceRowHeader
megaVaultBalanceRow
}
}
.onTapGesture { [weak self] in
self?.vaultTapAction?()
}
}
.wrappedInAnyView()
}

public override func createView(parentStyle: ThemeStyle = ThemeStyle.defaultStyle, styleKey: String? = nil) -> PlatformView {
Expand All @@ -335,6 +416,7 @@ public class dydxPortfolioPositionsViewModel: PlatformViewModel {
VStack(spacing: 24) {
self.openPositionsView
self.pendingPositionsView
self.megaVaultSection
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public enum VaultTransferType: CaseIterable, RadioButtonContentDisplayable {

var confirmTransferText: String {
switch self {
case .deposit: return DataLocalizer.localize(path: "APP.GENERAL.CONFIRM_DEPOSIT")
case .withdraw: return DataLocalizer.localize(path: "APP.GENERAL.CONFIRM_WITHDRAW")
case .deposit: return DataLocalizer.localize(path: "APP.VAULTS.CONFIRM_DEPOSIT_CTA")
case .withdraw: return DataLocalizer.localize(path: "APP.VAULTS.CONFIRM_WITHDRAW_CTA")
}
}

Expand All @@ -60,7 +60,7 @@ public enum VaultTransferType: CaseIterable, RadioButtonContentDisplayable {

var transferDestinationImage: Image? {
switch self {
case .deposit: return Image("icon_token", bundle: .dydxView)
case .deposit: return Image("icon_chain", bundle: .dydxView)
case .withdraw: return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ private struct VaultDepositWithdrawConfirmationView: View {
if let faqUrl = viewModel.faqUrl,
let slippage = viewModel.slippage, viewModel.requiresAcknowledgeHighSlippage {
let withdrawalSlippageInlineAlertAttributedText = AttributedString(localizerPathKey: "APP.VAULTS.SLIPPAGE_WARNING",
params: ["LINK": DataLocalizer.localize(path: "APP.VAULTS.VAULT_FAQS"),
params: ["LINK": DataLocalizer.localize(path: "APP.VAULTS.MEGAVAULT_FAQS"),
"AMOUNT": dydxFormatter.shared.percent(number: slippage, digits: 2) ?? "--"],
hyperlinks: ["APP.VAULTS.VAULT_FAQS": faqUrl],
hyperlinks: ["APP.VAULTS.MEGAVAULT_FAQS": faqUrl],
foreground: .textPrimary)
InlineAlertViewModel(.init(title: nil,
body: withdrawalSlippageInlineAlertAttributedText,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ private struct dydxVaultView: View {
}

private var titleImage: some View {
PlatformIconViewModel(type: .asset(name: "icon_token", bundle: .dydxView),
PlatformIconViewModel(type: .asset(name: "icon_chain", bundle: .dydxView),
clip: .noClip,
size: .init(width: 40, height: 40),
templateColor: nil)
.createView()
}

private var titleText: some View {
Text(DataLocalizer.shared?.localize(path: "APP.VAULTS.VAULT", params: nil) ?? "")
Text(DataLocalizer.shared?.localize(path: "APP.VAULTS.MEGAVAULT", params: nil) ?? "")
.themeColor(foreground: .textPrimary)
.themeFont(fontType: .plus, fontSize: .largest)
}
Expand Down
Loading