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

fix(swap): Fix limit price precision / denomination #2771

Merged
merged 11 commits into from
Oct 15, 2023

Conversation

michaeljscript
Copy link
Collaborator

@michaeljscript michaeljscript commented Oct 13, 2023

Resolves YOMO-855

@github-actions github-actions bot added the fix label Oct 13, 2023
@michaeljscript michaeljscript self-assigned this Oct 13, 2023
@michaeljscript michaeljscript marked this pull request as ready for review October 13, 2023 11:28
@michaeljscript michaeljscript changed the title fix(swap): Fix limit price precision / denumeration fix(swap): Fix limit price precision / denomination Oct 13, 2023
fullDecValue = `${int}${decimalSeparator}${dec.slice(0, precision)}1`
value = `${int}${decimalSeparator}${dec.slice(0, precision)}`
}

const fullDecFormat = new BigNumber(fullDecValue.replace(decimalSeparator, '.')).toFormat()
const input = isDec ? fullDecFormat.slice(0, -1) : fullDecFormat
Copy link
Member

@stackchain stackchain Oct 13, 2023

Choose a reason for hiding this comment

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

move inside the if, add a comment that the trailing is removed inside the hasDecimals logic

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll have to declare input as let before and move both lines inside the if

Which is why I preferred everything as const and the ternaries 😅

Copy link
Member

@stackchain stackchain Oct 13, 2023

Choose a reason for hiding this comment

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

BigNumber is object so const/let won't make that difference cuz you still can mutate it, but I also prefer and agree on not changing after declaring with initialization. To look even better I'd move everything dec / not decimal and return based on that, we will have some duplication, but readability is more important than duplication.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's because I wrote it, but it looked more clear to me before. Now with the lets, an if dividing everything, the early return and a couple lines duplicated because of it, looks harder to follow to me.

@@ -129,6 +129,9 @@ describe('Quantities', () => {
expect(Quantities.parseFromText('55.10', 3, english)).toEqual(['55.10', '55100'])

expect(Quantities.parseFromText('ab1.5c,6.5', 3, english)).toEqual(['1.56', '1560'])

expect(Quantities.parseFromText('1.23456', 0, english, 3)).toEqual(['1.234', '1.234'])
expect(Quantities.parseFromText('1.23456', 2, english, 3)).toEqual(['1.234', '123.4'])
Copy link
Member

@stackchain stackchain Oct 13, 2023

Choose a reason for hiding this comment

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

does it have the case for 1.0000 / 1.0 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it has a test for expect(Quantities.parseFromText('55.0', 3, english)).toEqual(['55.0', '55000'])


const value = isDec ? `${parts[0]}${decimalSeparator}${parts[1].slice(0, denomination)}` : sanitized
const quantity = new BigNumber(value.replace(decimalSeparator, '.'))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const quantity = new BigNumber(value.replace(decimalSeparator, '.'))
const quantity = asQuantity(new BigNumber(value.replace(decimalSeparator, '.'))

.shiftedBy(denomination)
.toString(10)
.toString(10) as Balance.Quantity
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.toString(10) as Balance.Quantity
.toString(10))

let fullDecFormat = new BigNumber(fullDecValue.replace(decimalSeparator, '.')).toFormat()
let input = fullDecFormat

if (parts.length >= 2) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe if parts.length <= 1 return earlier and then process the decimals ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's now updated

@stackchain stackchain added this to the 5.0.0 milestone Oct 15, 2023
@stackchain stackchain merged commit d87f736 into develop Oct 15, 2023
@stackchain stackchain deleted the fix/fix-limit-price-calc branch October 15, 2023 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants