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

ABW-2217 Value of some resources showing as 00 when contributing to Pool #736

Merged
merged 7 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 4 additions & 2 deletions Sources/Core/SharedModels/Assets/AccountPortfolio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@ extension AccountPortfolio.PoolUnitResources {
self.poolResources = poolResources
}

public func redemptionValue(for resource: AccountPortfolio.FungibleResource) -> BigDecimal {
public func redemptionValue(for resource: AccountPortfolio.FungibleResource) -> String {
let poolUnitTotalSupply = poolUnitResource.totalSupply ?? .one
let unroundedRedemptionValue = poolUnitResource.amount * resource.amount / poolUnitTotalSupply
return resource.divisibility.map { unroundedRedemptionValue.withPrecision($0) } ?? unroundedRedemptionValue
return resource.divisibility
.map { unroundedRedemptionValue.format(maxPlaces: UInt($0)) }
?? (unroundedRedemptionValue.format())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extension AccountPortfolio.PoolUnitResources.PoolUnit {
PoolUnitResourceViewState(
thumbnail: .xrd,
symbol: Constants.xrdTokenName,
tokenAmount: redemptionValue(for: $0).format()
tokenAmount: redemptionValue(for: $0)
)
}

Expand All @@ -85,7 +85,7 @@ extension AccountPortfolio.PoolUnitResources.PoolUnit {
PoolUnitResourceViewState(
thumbnail: .known($0.iconURL),
symbol: $0.symbol ?? $0.name ?? L10n.Account.PoolUnits.unknownSymbolName,
tokenAmount: redemptionValue(for: $0).format()
tokenAmount: redemptionValue(for: $0)
)
}
)! // Safe to unwrap, guaranteed to not be empty
Expand Down
8 changes: 7 additions & 1 deletion Sources/Prelude/Extensions/BigDecimal+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Foundation
extension BigDecimal {
// Used for development purposes
public static let temporaryStandardFee: BigDecimal = 25
public static let defaultMaxPlacesFormattted: UInt = 8
}

extension BigDecimal {
Expand All @@ -16,9 +17,14 @@ extension BigDecimal {

/// Formats the number for human consumtion
public func format(
maxPlaces maxPlacesNonNegative: UInt = 8,
maxPlaces maxPlacesNonNegative: UInt = BigDecimal.defaultMaxPlacesFormattted,
locale: Locale = .autoupdatingCurrent
) -> String {
let maxPlacesNonNegative = min(
BigDecimal.defaultMaxPlacesFormattted,
maxPlacesNonNegative
)

// N.B. We cannot use `Local.current.decimalSeperator` here because
// `github.com/Zollerbo1/BigDecimal` package **hardcodes** usage of
// the decimal separator ".", see this line here:
Expand Down
Loading