Skip to content

Commit

Permalink
MOB-297: Fix total dydx amount not populated from Profile tab (#101)
Browse files Browse the repository at this point in the history
* MOB-297: Fix total dydx amount not populated from Profile tab

* Address feedback
  • Loading branch information
ruixhuang authored and mike-dydx committed Aug 21, 2024
1 parent 1af129f commit 2b0b66f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dydx/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 9e6e5d5e9ea0594fa77a099c8fd30545318f1cb9

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion dydx/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,36 @@ public class dydxProfileBalancesViewPresenter: HostedViewPresenter<dydxProfileBa
public override func start() {
super.start()

AbacusStateManager.shared.state.accountBalance(of: AbacusStateManager.shared.environment?.dydxTokenInfo?.denom)
.sink { [weak self] dydxAmount in
if let dydxAmount = dydxAmount {
self?.viewModel?.walletAmount = dydxFormatter.shared.raw(number: Parser.standard.asNumber(dydxAmount), digits: 4)
let decimal = 4
let dydxTokenDenom = AbacusStateManager.shared.environment?.dydxTokenInfo?.denom
Publishers
.CombineLatest(
AbacusStateManager.shared.state.accountBalance(of: dydxTokenDenom),
AbacusStateManager.shared.state.stakingBalance(of: dydxTokenDenom)
)
.sink { [weak self] accountBalance, stakingBalance in
if let accountBalance = accountBalance {
self?.viewModel?.walletAmount = dydxFormatter.shared.raw(number: Parser.standard.asNumber(accountBalance), digits: decimal)
self?.viewModel?.transferAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/transfer", params: ["section": "transferOut"]), animated: true, completion: nil)
}
} else {
self?.viewModel?.walletAmount = "-"
self?.viewModel?.transferAction = nil
}
}
.store(in: &subscriptions)

AbacusStateManager.shared.state.stakingBalance(of: AbacusStateManager.shared.environment?.dydxTokenInfo?.denom ?? "")
.sink { [weak self] dydxAmount in
if let dydxAmount = dydxAmount {
self?.viewModel?.stakedAmount = dydxFormatter.shared.raw(number: Parser.standard.asNumber(dydxAmount), digits: 4)
if let stakingBalance = stakingBalance {
self?.viewModel?.stakedAmount = dydxFormatter.shared.raw(number: Parser.standard.asNumber(stakingBalance), digits: decimal)
} else {
self?.viewModel?.stakedAmount = "-"
}

if accountBalance != nil || stakingBalance != nil {
let totalAmount = (accountBalance ?? 0.0) + (stakingBalance ?? 0.0)
self?.viewModel?.totalAmount = dydxFormatter.shared.raw(number: Parser.standard.asNumber(totalAmount), digits: decimal)
} else {
self?.viewModel?.totalAmount = "-"
}
}
.store(in: &subscriptions)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ public final class AbacusState {
.eraseToAnyPublisher()
}

public func stakingBalance(of tokenDenom: String) -> AnyPublisher<Double?, Never> {
public func stakingBalance(of tokenDenom: String?) -> AnyPublisher<Double?, Never> {
account
.map { account in
self.parser.asDecimal(account?.stakingBalances?[tokenDenom]?.amount)?.doubleValue
self.parser.asDecimal(account?.stakingBalances?[tokenDenom ?? ""]?.amount)?.doubleValue
}
.removeDuplicates()
.share()
Expand Down

0 comments on commit 2b0b66f

Please sign in to comment.