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

feat(swap): Slippage screen #2639

Merged
merged 20 commits into from
Aug 30, 2023
Merged

feat(swap): Slippage screen #2639

merged 20 commits into from
Aug 30, 2023

Conversation

michaeljscript
Copy link
Collaborator

@michaeljscript michaeljscript commented Aug 25, 2023

Resolves YOMO-610

@michaeljscript michaeljscript marked this pull request as ready for review August 25, 2023 14:42
}

const normalizeInputValue = (value: string) => {
return value.length === 0 ? '0' : value.replace(',', '.').replace(/^0+(?=\d)/, '')
Copy link
Collaborator Author

@michaeljscript michaeljscript Aug 25, 2023

Choose a reason for hiding this comment

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

  1. When the input is an empty string, convert to '0'
  2. Convert ',' to '.'
  3. Remove leading zeros for inputs like '03'

Copy link
Member

Choose a reason for hiding this comment

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

🤔 @MichalSzorad can you check to use intl number formatter? It might affect these rules. I think @nistadev updated extension.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @stackchain I'll have a look

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@stackchain Would we need a library like this one d2l-intl to be able to parse the number?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added parsing using BigNumber, but I don't think we can format the output using BigNumber, can we? Eg when the user types 3. we do not want to convert the number to 3 and this seems what BigNumber is doing

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is still WIP, as I'm trying to integrate the util made by Jordi

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 is now integrated @stackchain

@@ -103,12 +117,11 @@ const invalidSwapContext = () => {

// * === SETTINGS ===
// * NOTE maybe it should be moved as part of wallet settings package
export const useSwapSlippage = () => {
const {slippage} = useSwap()
export const useSwapSlippage = (swapManager: Readonly<Swap.Manager>) => {
Copy link
Member

@stackchain stackchain Aug 27, 2023

Choose a reason for hiding this comment

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

what this change for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wanted to reuse the hook in SwapProvider to get the default values from the storage and the swapManager is responsible for storing the values.

Copy link
Member

@stackchain stackchain left a comment

Choose a reason for hiding this comment

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

⬆️

@stackchain stackchain added this to the 5.0.0 milestone Aug 27, 2023
@@ -61,7 +61,7 @@ export const EditSlippageScreen = () => {
}

const onSubmit = () => {
const parsedNumber = selectedChoice ? BigNumber(inputValue, 10) : BigNumber(selectedChoice.value, 10)
const parsedNumber = isSelectedChoiceManual ? BigNumber(inputValue, 10) : BigNumber(selectedChoice.value, 10)
Copy link
Member

Choose a reason for hiding this comment

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

according to confluence docs, it should .format to 1 decimal only, can you check it?

Copy link
Collaborator Author

@michaeljscript michaeljscript Aug 29, 2023

Choose a reason for hiding this comment

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

@stackchain there is a validateSlippage which checks if only 1 decimal is used. The button is disabled if there are more than 1 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.

I've removed the decimal check from the validateSlippage, because this is now validated in Quantities.parseFromText

@michaeljscript michaeljscript changed the title feat(swap): Slippage screen WIP: feat(swap): Slippage screen Aug 29, 2023
@michaeljscript
Copy link
Collaborator Author

After #2646 is merged, I'll rebase and use same approach to parse slippage

@michaeljscript michaeljscript changed the title WIP: feat(swap): Slippage screen feat(swap): Slippage screen Aug 30, 2023
@stackchain stackchain merged commit aa6a945 into develop Aug 30, 2023
@stackchain stackchain deleted the feat/swap-slippage branch August 30, 2023 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants