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-2249 Transfer Max LSU #759

Merged
merged 7 commits into from
Sep 18, 2023
Merged

ABW-2249 Transfer Max LSU #759

merged 7 commits into from
Sep 18, 2023

Conversation

maciek-rdx
Copy link
Contributor

@maciek-rdx maciek-rdx commented Sep 14, 2023

Jira ticket: paste link here

Description

This PR removes the usage of BigDecimal.toString(withPrecision:) in the code that translates BigDecimals into EngineToolkit.Decimal.

Notes

EngineToolkit.Decimal has a very specific validation criteria and we should rely solely on that. I think also that we may want to propagate that knowledge to the UI layer. Currently we allow numbers of any length in the UI. I know - it's extreme if we want to make a number of 1000 digits in integer part and (we actually can't do that ⬅️ - we have a validation logic for that) 1000 digits in decimal part, but still - this can seem like a valid input to the user.
This code is also a great candidate to be moved into the Rust library that we're about to create. Maybe its worth to have a Jira ticket or at least a FIXME for that?

How to test

Additionally you can test what @GhenadieVP experienced here

Video

RPReplay_Final1694765435.MP4

PR submission checklist

  • I have tested account to account transfer flow and have confirmed that it works

@CyonAlexRDX
Copy link
Contributor

@maciek-rdx can you help explain what you have done, why, how, rationale, etc...? :)

@maciek-rdx
Copy link
Contributor Author

@maciek-rdx can you help explain what you have done, why, how, rationale, etc...? :)

Sure, sorry, I should have marked it as a Draft.

@maciek-rdx maciek-rdx marked this pull request as draft September 15, 2023 07:23
import Prelude

extension EngineToolkit.Decimal {
public static let integerAndDecimalPartsSeparator = "."
Copy link
Contributor

Choose a reason for hiding this comment

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

please retain the comment about why we hardcode "." instead of using Locale.current.decimalSeparator:

		// 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:
		// https://github.com/Zollerboy1/BigDecimal/blob/main/Sources/BigDecimal/BigDecimal.swift#L469

Copy link
Contributor

Choose a reason for hiding this comment

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

oh wait, you have it in two places...?

Copy link
Contributor

Choose a reason for hiding this comment

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

so it ought to be deleted from here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment that you mentioned does not apply here. These can change for independent reasons. This one is about the dot required by the EngineToolkit.Decimal.init(value:). I can add something in the shape of "Required by EngineToolkit.Decimal to construct it from a String", but for me, the current name (EngineToolkit.Decimal.integerAndDecimalPartsSeparator) is good enough.

However you prefer.

@maciek-rdx maciek-rdx marked this pull request as ready for review September 15, 2023 11:09

extension BigDecimal {
public func asDecimal(withDivisibility divisibility: Int? = nil) throws -> EngineToolkit.Decimal {
let (integerPart, decimalPart) = integerAndDecimalPart(
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this is not the same as withPrecision(divisibility).removeTrailingZeros?

At the same time, why do we care what is the divisibility of the resource itself?

Copy link
Contributor Author

@maciek-rdx maciek-rdx Sep 15, 2023

Choose a reason for hiding this comment

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

I wonder if this is not the same as withPrecision(divisibility).removeTrailingZeros?

I think in general it's better and simpler to maintain our own logic for that. It's not complicated and we're sure that we do only what's essential for our case without a necessity to rely on and understand anything else.

... why do we care what is the divisibility of the resource itself?

Engine Toolkit will reject numbers that have more decimal digits than divisibility. Ultimately, I think we should solve that problem/do not allow more decimals than divisibility in the UI (what I proposed in the description of the PR).

Copy link
Contributor

@GhenadieVP GhenadieVP Sep 15, 2023

Choose a reason for hiding this comment

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

... more decimal digits than divisibility.

You mean in the context of say a transaction manifest? that it checks the a given decimal value against divisibility of the resource it refers to?

Copy link
Contributor Author

@maciek-rdx maciek-rdx Sep 15, 2023

Choose a reason for hiding this comment

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

Yes, exactly. Here's a message from @0xOmarA that confirms it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I didn't see the explicit message about what I have described above, I mean when constructing the EngineToolkit Decimal there is no resource context, so EngineToolkit cannot know what is the correct divisibility. The only place it could do so, is when creating the instruction for the manifest when we do also pass the resource address along with the decimal value.

but I guess it is ok to take into account the resource divisibility for the scenario when we don't forbid users at UI level to enter more decimals than possible - maybe we should.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when constructing the EngineToolkit Decimal there is no resource context, so EngineToolkit cannot know what is the correct divisibility. The only place it could do so, is when creating the instruction for the manifest when we do also pass the resource address along with the decimal value.

Ah, I see what you mean. But yeah, ultimately I'd do that in the UI, so there's no surprise to the user. But would rather do that as a separate thing. Thoughts @CyonAlexRDX ?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is good enough now, if a resource has 2 as divisibility, even if user enters 10 decimals, in the transaction review they will see the value adjusted to the divisibility, so it is not completely silent operation.

# Conflicts:
#	Sources/EngineKit/BigDecimal.swift
Copy link
Contributor

@GhenadieVP GhenadieVP left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Contributor

@CyonAlexRDX CyonAlexRDX left a comment

Choose a reason for hiding this comment

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

Approved

@maciek-rdx maciek-rdx merged commit 2a9a406 into main Sep 18, 2023
5 checks passed
@maciek-rdx maciek-rdx deleted the ABW-2249-max-lsu branch September 18, 2023 09:56
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants