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

Add Slippage Slider Component #2068

Merged
merged 15 commits into from
Jan 5, 2021

Conversation

tlip
Copy link
Contributor

@tlip tlip commented Dec 14, 2020

Description

This pull request introduces a SlippageSlider component. Although it was designed for the amount of allowable slippage in a swap (1-5%), it has been created to be somewhat customizable to facilitate future cases of reusability:

  • Custom ranges
  • Custom tick increments
  • A function to format the text/content in the tooltip

Checklist

  • There is a related GitHub issue
  • Tests are included if applicable
  • Any added code is fully documented

Issue

Resolves Issue #2026

@tlip tlip requested a review from a team as a code owner December 14, 2020 21:33
Copy link
Member

@wachunei wachunei left a comment

Choose a reason for hiding this comment

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

It looks good 👍, I'd suggest these changes:

  • safe range/step numbers as mentioned in the other comment (this is mostly a dev experience improvement)
  • add a boolean prop to have onChange called when the slider snaps in place (we are most likely responding to a snap change in the ui than upon release)

Update:

I just realized the defaultValue does not correctly set the slider at the right position

Screen Shot 2020-12-17 at 16 35 45

app/components/UI/SlippageSlider/index.js Outdated Show resolved Hide resolved
@wachunei
Copy link
Member

wachunei commented Dec 23, 2020

Refactor includes:

  • Slider does not depend on device dimensions anymore
  • Slider does not need to be centered in the screen
  • Slider calls onChange when changing slider position (although it can be called only when gesture is finished by setting changeOnRelease prop to true)
  • All the position/layout was redone so changing paddings and diameters won't affect the positing of the elements within the component
  • Slider reacts to changed value from the props and sets the position correctly
  • Gradient image was updated and stretches correctly, the rounded tips are overflows and not part of the image.
  • When range is not divisible by increment the component won't crash
  • PanHandlers are memoized (they were recreated every render)

@wachunei wachunei requested a review from estebanmino January 4, 2021 13:37
@wachunei wachunei dismissed their stale review January 4, 2021 13:39

Reviewer refactored code

// easing: Easing.linear,
// duration: 20,
// useNativeDriver: false
// }).start();
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this?

Copy link
Member

Choose a reason for hiding this comment

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

Removed 👌

</Animated.View>
<Animated.View
{...panResponder.panHandlers}
style={[styles.slider, { left: sliderPosition }, { backgroundColor: sliderColor }]}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
style={[styles.slider, { left: sliderPosition }, { backgroundColor: sliderColor }]}
style={[styles.slider, { left: sliderPosition, backgroundColor: sliderColor }]}

Copy link
Member

Choose a reason for hiding this comment

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

Fixed 👍


<View style={styles.slippageWrapper}>
<View style={styles.warningTextWrapper}>
{slippage >= 5 && (
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this check be in the view above?

Copy link
Member

Choose a reason for hiding this comment

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

This is the modal itself (not the slider). I think the check and range values belong here instead of the amount view.

Screen Shot 2021-01-04 at 14 39 34

@wachunei wachunei merged commit c92680c into feature/swaps-quotes-view Jan 5, 2021
@wachunei wachunei deleted the issue-2026-slippage-slider branch January 5, 2021 00:42
estebanmino added a commit that referenced this pull request Jan 21, 2021
* Squashed commit of the following:

commit d552524
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Tue Nov 17 14:05:22 2020 -0300

    Remove unnecessary styling

commit 24b5456
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Tue Nov 17 13:13:16 2020 -0300

    Update tokens dependency for effect

commit 1662700
Author: Esteban Mino <[email protected]>
Date:   Tue Nov 17 12:50:48 2020 -0300

    bumpcontrollers

commit 94a14dd
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Mon Nov 16 13:52:01 2020 -0300

    Update main navigation snapshot

commit f9ba8af
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Mon Nov 16 13:43:14 2020 -0300

    Add TokenSelectButton label prop to test

commit 637452f
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Mon Nov 16 13:34:37 2020 -0300

    Add i18n to swaps amount view

commit 6dfd9a4
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Fri Nov 13 15:52:21 2020 -0300

    Fix TokenIcon border radius

commit 54c17c2
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Fri Nov 13 13:30:16 2020 -0300

    Remove unused key in token search for swaps

commit 4bb4bcb
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Thu Nov 12 23:30:58 2020 -0300

    Add asset balance in swaps amount view

commit b262b4e
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Thu Nov 12 22:48:36 2020 -0300

    Add token balances in token search modal list

commit 6ca34c9
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Thu Nov 12 14:04:33 2020 -0300

    Add invalid decimal warning

commit 539d1e7
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Wed Nov 11 23:11:26 2020 -0300

    Add empty list message and clear search on modal hide

commit 65a31a6
Author: Esteban Mino <[email protected]>
Date:   Wed Nov 11 22:00:20 2020 -0300

    bumpcontrollers

commit 36a2289
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Wed Nov 11 19:18:40 2020 -0300

    Update Receiver Modal snapshot, it uses ModalHandler now

commit c69c414
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Wed Nov 11 19:13:31 2020 -0300

    Add tokens from SwapsController

commit 4f4e87f
Author: Esteban Mino <[email protected]>
Date:   Tue Nov 10 21:57:42 2020 -0300

    inception

commit 2367393
Author: Esteban Mino <[email protected]>
Date:   Tue Nov 10 19:09:15 2020 -0300

    package

commit 707b491
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Wed Nov 11 17:49:41 2020 -0300

    Add Initial Token Selector with dummy tokens

commit 8644be0
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Tue Nov 10 12:40:34 2020 -0300

    Switch Swaps feature flag to false

commit 0696f10
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Mon Nov 9 20:40:44 2020 -0300

    Add Keypad rules and swap token button

commit 3173290
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Fri Nov 6 17:08:56 2020 -0300

    Update snapshot for main nav

commit 5f03198
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Fri Nov 6 12:41:01 2020 -0300

    Add SWAPS.ACTIVE flag

* Disable flag

* Remove console.log

* Fix linting

* bump and getch quotes

* bump

* bump

* fetchingcorrectly

* fetchQuotesfetchQuotes

* Use SwapsController state

* Add initial generic error view

* bumpcontroller

* Add swaps app utils

* Add ratio and values from top quote

* bump

* bump

* bump

* effect

* Add gas price

* Remove console.log

* Add quotes modal and i18n

* tradefees

* bump

* tradefees

* orderedtradesfees

* bump

* bumpcontrolker

* snaps

* walletaddress

* bump

* bump

* quotevalues

* Order quotes by overall quote value

* Add enable asset text row

* bump

* bump

* 500

* Swaps amount view: use max for tokens (#2052)

* Add slider button component (#2046)

* Add slider buttons and useBalance

useBalance should be used to show balance alerts

* detecting

* bump

* REVERTTHISVALIDATION

* Add Alert component (#2061)

* Add balance alert to quotes view

* fixsendto

* networkfix

* Fix use max handler usecallback deps

* Add Slippage Slider Component (#2068)

Co-authored-by: Pedro Pablo Aste Kompen <[email protected]>

* controllers

* circle

* circlerevert

* 9

* bumpcontrollers

* CURRENT_PROJECT_VERSION

* Refactor slider button

* Add visual feedback

- Nav title
- Spacing
- Text color and size

* Adjust token symbol text colors

* Update ios/MetaMask.xcodeproj/project.pbxproj

* Update ios/MetaMask.xcodeproj/project.pbxproj

* Fix SliderButton infinite effect

* Update ios/MetaMask.xcodeproj/project.pbxproj

* Update ios/MetaMask.xcodeproj/project.pbxproj

* gasprice

* 561

* Make onComplete optional

* averagegas

* 42

* Add touchable ratio switcher

* Add default 3% slippage constant

* Add fee variable to fee modal

* Add hitSlop area to modal close buttons

* Add quotes overview string

* Add error views styling

* merge

* networkupdated

Co-authored-by: Pedro Pablo Aste Kompen <[email protected]>
Co-authored-by: tlip <[email protected]>
Co-authored-by: tlip <[email protected]>
ejwessel added a commit that referenced this pull request Feb 2, 2021
* Squashed commit of the following:

commit d552524
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Tue Nov 17 14:05:22 2020 -0300

    Remove unnecessary styling

commit 24b5456
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Tue Nov 17 13:13:16 2020 -0300

    Update tokens dependency for effect

commit 1662700
Author: Esteban Mino <[email protected]>
Date:   Tue Nov 17 12:50:48 2020 -0300

    bumpcontrollers

commit 94a14dd
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Mon Nov 16 13:52:01 2020 -0300

    Update main navigation snapshot

commit f9ba8af
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Mon Nov 16 13:43:14 2020 -0300

    Add TokenSelectButton label prop to test

commit 637452f
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Mon Nov 16 13:34:37 2020 -0300

    Add i18n to swaps amount view

commit 6dfd9a4
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Fri Nov 13 15:52:21 2020 -0300

    Fix TokenIcon border radius

commit 54c17c2
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Fri Nov 13 13:30:16 2020 -0300

    Remove unused key in token search for swaps

commit 4bb4bcb
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Thu Nov 12 23:30:58 2020 -0300

    Add asset balance in swaps amount view

commit b262b4e
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Thu Nov 12 22:48:36 2020 -0300

    Add token balances in token search modal list

commit 6ca34c9
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Thu Nov 12 14:04:33 2020 -0300

    Add invalid decimal warning

commit 539d1e7
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Wed Nov 11 23:11:26 2020 -0300

    Add empty list message and clear search on modal hide

commit 65a31a6
Author: Esteban Mino <[email protected]>
Date:   Wed Nov 11 22:00:20 2020 -0300

    bumpcontrollers

commit 36a2289
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Wed Nov 11 19:18:40 2020 -0300

    Update Receiver Modal snapshot, it uses ModalHandler now

commit c69c414
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Wed Nov 11 19:13:31 2020 -0300

    Add tokens from SwapsController

commit 4f4e87f
Author: Esteban Mino <[email protected]>
Date:   Tue Nov 10 21:57:42 2020 -0300

    inception

commit 2367393
Author: Esteban Mino <[email protected]>
Date:   Tue Nov 10 19:09:15 2020 -0300

    package

commit 707b491
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Wed Nov 11 17:49:41 2020 -0300

    Add Initial Token Selector with dummy tokens

commit 8644be0
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Tue Nov 10 12:40:34 2020 -0300

    Switch Swaps feature flag to false

commit 0696f10
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Mon Nov 9 20:40:44 2020 -0300

    Add Keypad rules and swap token button

commit 3173290
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Fri Nov 6 17:08:56 2020 -0300

    Update snapshot for main nav

commit 5f03198
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Fri Nov 6 12:41:01 2020 -0300

    Add SWAPS.ACTIVE flag

* Disable flag

* Remove console.log

* Fix linting

* bump and getch quotes

* bump

* bump

* fetchingcorrectly

* fetchQuotesfetchQuotes

* Use SwapsController state

* Add initial generic error view

* bumpcontroller

* Add swaps app utils

* Add ratio and values from top quote

* bump

* bump

* bump

* effect

* Add gas price

* Remove console.log

* Add quotes modal and i18n

* tradefees

* bump

* tradefees

* orderedtradesfees

* bump

* bumpcontrolker

* snaps

* walletaddress

* bump

* bump

* quotevalues

* Order quotes by overall quote value

* Add enable asset text row

* bump

* bump

* 500

* Swaps amount view: use max for tokens (#2052)

* Add slider button component (#2046)

* Add slider buttons and useBalance

useBalance should be used to show balance alerts

* detecting

* bump

* REVERTTHISVALIDATION

* Add Alert component (#2061)

* Add balance alert to quotes view

* fixsendto

* networkfix

* Fix use max handler usecallback deps

* Add Slippage Slider Component (#2068)

Co-authored-by: Pedro Pablo Aste Kompen <[email protected]>

* controllers

* circle

* circlerevert

* 9

* bumpcontrollers

* CURRENT_PROJECT_VERSION

* Refactor slider button

* Add visual feedback

- Nav title
- Spacing
- Text color and size

* Adjust token symbol text colors

* Update ios/MetaMask.xcodeproj/project.pbxproj

* Update ios/MetaMask.xcodeproj/project.pbxproj

* Fix SliderButton infinite effect

* Update ios/MetaMask.xcodeproj/project.pbxproj

* Update ios/MetaMask.xcodeproj/project.pbxproj

* gasprice

* 561

* Make onComplete optional

* averagegas

* 42

* Add touchable ratio switcher

* Add default 3% slippage constant

* Add fee variable to fee modal

* Add hitSlop area to modal close buttons

* Add quotes overview string

* Add error views styling

* Metaswap Metrics

* Add Swap Actions

* move swap actions to names; actions are wip

* add analytics event opt

* merge

* networkupdated

* publish swap open metric

* logstomixpanel

* moredev

* remove depdendency on initialSource

* add back depdendency on initialSource to prevent multi publish

* add quote view metrics

* checkpoint for quotes received

* quotes received metrics

* quotes timeout metric

* remove console log

* add metric to quotes modal opening, no data sent

* publish quotes modal with data

* swaps started metrics

* update timed out and no quotes available metrics

* fix broken styling

* remove param

* handle custom slippage detection

* update swaps opened view metric and custom slippage

* update request type data point in metrics

* datapoint all available quotes

* other quote selected data point

* available quotes and remove console log

* available quotes metric

* additional data point

* move quotes received metric

* added best quote source for quotes received

* max fetch time for all quotes

* request type order for modal view

* add InteractionManager

* remove metrics from quotes modal

* remove commented out lines

* add param to nav bar

* publish cancel quote metrics on dismissal of quote request

* publish response time for cancellation

* run after interactions

* use callbacks

* detect when user has backed out before a trade has been selected

* handle navigation param

* implement feedback

* fix inconsistencies in metrics

* comments for react-hooks/exhaustive-dep disabled

* add state for request and received

Co-authored-by: Pedro Pablo Aste Kompen <[email protected]>
Co-authored-by: Esteban Mino <[email protected]>
Co-authored-by: tlip <[email protected]>
Co-authored-by: tlip <[email protected]>
rickycodes pushed a commit that referenced this pull request Jan 31, 2022
* Squashed commit of the following:

commit d552524
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Tue Nov 17 14:05:22 2020 -0300

    Remove unnecessary styling

commit 24b5456
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Tue Nov 17 13:13:16 2020 -0300

    Update tokens dependency for effect

commit 1662700
Author: Esteban Mino <[email protected]>
Date:   Tue Nov 17 12:50:48 2020 -0300

    bumpcontrollers

commit 94a14dd
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Mon Nov 16 13:52:01 2020 -0300

    Update main navigation snapshot

commit f9ba8af
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Mon Nov 16 13:43:14 2020 -0300

    Add TokenSelectButton label prop to test

commit 637452f
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Mon Nov 16 13:34:37 2020 -0300

    Add i18n to swaps amount view

commit 6dfd9a4
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Fri Nov 13 15:52:21 2020 -0300

    Fix TokenIcon border radius

commit 54c17c2
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Fri Nov 13 13:30:16 2020 -0300

    Remove unused key in token search for swaps

commit 4bb4bcb
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Thu Nov 12 23:30:58 2020 -0300

    Add asset balance in swaps amount view

commit b262b4e
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Thu Nov 12 22:48:36 2020 -0300

    Add token balances in token search modal list

commit 6ca34c9
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Thu Nov 12 14:04:33 2020 -0300

    Add invalid decimal warning

commit 539d1e7
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Wed Nov 11 23:11:26 2020 -0300

    Add empty list message and clear search on modal hide

commit 65a31a6
Author: Esteban Mino <[email protected]>
Date:   Wed Nov 11 22:00:20 2020 -0300

    bumpcontrollers

commit 36a2289
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Wed Nov 11 19:18:40 2020 -0300

    Update Receiver Modal snapshot, it uses ModalHandler now

commit c69c414
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Wed Nov 11 19:13:31 2020 -0300

    Add tokens from SwapsController

commit 4f4e87f
Author: Esteban Mino <[email protected]>
Date:   Tue Nov 10 21:57:42 2020 -0300

    inception

commit 2367393
Author: Esteban Mino <[email protected]>
Date:   Tue Nov 10 19:09:15 2020 -0300

    package

commit 707b491
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Wed Nov 11 17:49:41 2020 -0300

    Add Initial Token Selector with dummy tokens

commit 8644be0
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Tue Nov 10 12:40:34 2020 -0300

    Switch Swaps feature flag to false

commit 0696f10
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Mon Nov 9 20:40:44 2020 -0300

    Add Keypad rules and swap token button

commit 3173290
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Fri Nov 6 17:08:56 2020 -0300

    Update snapshot for main nav

commit 5f03198
Author: Pedro Pablo Aste Kompen <[email protected]>
Date:   Fri Nov 6 12:41:01 2020 -0300

    Add SWAPS.ACTIVE flag

* Disable flag

* Remove console.log

* Fix linting

* bump and getch quotes

* bump

* bump

* fetchingcorrectly

* fetchQuotesfetchQuotes

* Use SwapsController state

* Add initial generic error view

* bumpcontroller

* Add swaps app utils

* Add ratio and values from top quote

* bump

* bump

* bump

* effect

* Add gas price

* Remove console.log

* Add quotes modal and i18n

* tradefees

* bump

* tradefees

* orderedtradesfees

* bump

* bumpcontrolker

* snaps

* walletaddress

* bump

* bump

* quotevalues

* Order quotes by overall quote value

* Add enable asset text row

* bump

* bump

* 500

* Swaps amount view: use max for tokens (#2052)

* Add slider button component (#2046)

* Add slider buttons and useBalance

useBalance should be used to show balance alerts

* detecting

* bump

* REVERTTHISVALIDATION

* Add Alert component (#2061)

* Add balance alert to quotes view

* fixsendto

* networkfix

* Fix use max handler usecallback deps

* Add Slippage Slider Component (#2068)

Co-authored-by: Pedro Pablo Aste Kompen <[email protected]>

* controllers

* circle

* circlerevert

* 9

* bumpcontrollers

* CURRENT_PROJECT_VERSION

* Refactor slider button

* Add visual feedback

- Nav title
- Spacing
- Text color and size

* Adjust token symbol text colors

* Update ios/MetaMask.xcodeproj/project.pbxproj

* Update ios/MetaMask.xcodeproj/project.pbxproj

* Fix SliderButton infinite effect

* Update ios/MetaMask.xcodeproj/project.pbxproj

* Update ios/MetaMask.xcodeproj/project.pbxproj

* gasprice

* 561

* Make onComplete optional

* averagegas

* 42

* Add touchable ratio switcher

* Add default 3% slippage constant

* Add fee variable to fee modal

* Add hitSlop area to modal close buttons

* Add quotes overview string

* Add error views styling

* merge

* networkupdated

Co-authored-by: Pedro Pablo Aste Kompen <[email protected]>
Co-authored-by: tlip <[email protected]>
Co-authored-by: tlip <[email protected]>
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.

3 participants