Skip to content

Commit

Permalink
refactor: replace swap slider with swap button (#12030)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Feedback was received suggesting that the "swipe to swap" UI was often
navigating back instead of executing the swap. This PR replaces the
swipe with a button to address this issue and simplify the interaction.

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to the swap page
2. Get quotes
3. See swap button

## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**
<img width="310" alt="Screenshot 2024-10-25 at 17 22 47"
src="https://github.com/user-attachments/assets/f93ba955-164e-4a6b-895b-400a56c8bda0">
<!-- [screenshots/recordings] -->

### **After**
<img width="309" alt="Screenshot 2024-10-25 at 17 24 04"
src="https://github.com/user-attachments/assets/3aacf0c1-1066-4dbd-ac62-bef8682c2660">
<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
bfullam authored Oct 28, 2024
1 parent 87e0c7d commit a2de45b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
31 changes: 9 additions & 22 deletions app/components/UI/Swaps/QuotesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import ScreenView from '../../Base/ScreenView';
import Text from '../../Base/Text';
import Alert, { AlertType } from '../../Base/Alert';
import StyledButton from '../StyledButton';
import SliderButton from '../SliderButton';

import LoadingAnimation from './components/LoadingAnimation';
import TokenIcon from './components/TokenIcon';
Expand Down Expand Up @@ -444,6 +443,7 @@ function SwapsQuotesView({
const [trackedError, setTrackedError] = useState(false);
const [animateOnGasChange, setAnimateOnGasChange] = useState(false);
const [isAnimating, setIsAnimating] = useState(false);
const [isHandlingSwap, setIsHandlingSwap] = useState(false);
const [multiLayerL1ApprovalFeeTotal, setMultiLayerL1ApprovalFeeTotal] =
useState(null);

Expand All @@ -460,8 +460,6 @@ function SwapsQuotesView({
const [customGasEstimate, setCustomGasEstimate] = useState(null);
const [customGasLimit, setCustomGasLimit] = useState(null);

const [isSwiping, setIsSwiping] = useState(false);

// TODO: use this variable in the future when calculating savings
const [isSaving] = useState(false);
const [isInFetch, setIsInFetch] = useState(false);
Expand Down Expand Up @@ -1072,7 +1070,10 @@ function SwapsQuotesView({
);

const handleCompleteSwap = useCallback(async () => {
setIsHandlingSwap(true);

if (!selectedQuote) {
setIsHandlingSwap(false);
return;
}

Expand All @@ -1088,6 +1089,7 @@ function SwapsQuotesView({
);

if (isHardwareAddress) {
setIsHandlingSwap(false);
navigation.dangerouslyGetParent()?.pop();
return;
}
Expand All @@ -1100,6 +1102,7 @@ function SwapsQuotesView({
await handleSwapTransaction(approvalTransactionMetaId);
}

setIsHandlingSwap(false);
navigation.dangerouslyGetParent()?.pop();
}, [
selectedQuote,
Expand Down Expand Up @@ -1720,7 +1723,6 @@ function SwapsQuotesView({
contentContainerStyle={styles.screen}
style={styles.container}
keyboardShouldPersistTaps="handled"
scrollEnabled={!isSwiping}
>
<View style={styles.topBar}>
{(!hasEnoughTokenBalance || !hasEnoughEthBalance) && (
Expand Down Expand Up @@ -2155,24 +2157,9 @@ function SwapsQuotesView({
</QuotesSummary.Body>
</QuotesSummary>
)}
<SliderButton
incompleteText={
<Text style={styles.sliderButtonText}>
{`${strings('swaps.swipe_to')} `}
<Text reset bold>
{strings('swaps.swap')}
</Text>
</Text>
}
onSwipeChange={setIsSwiping}
completeText={
<Text style={styles.sliderButtonText}>
{strings('swaps.completed_swap')}
</Text>
}
disabled={unableToSwap || isAnimating}
onComplete={handleCompleteSwap}
/>
<StyledButton type="confirm" onPress={handleCompleteSwap} disabled={unableToSwap || isHandlingSwap || isAnimating}>
{strings('swaps.swap')}
</StyledButton>
<TouchableOpacity onPress={handleTermsPress} style={styles.termsButton}>
<Text link centered>
{strings('swaps.terms_of_service')}
Expand Down
2 changes: 1 addition & 1 deletion locales/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2777,7 +2777,7 @@
"tap_to_swap": "Tap to Swap",
"swipe_to_swap": "Swipe to swap",
"swipe_to": "Swipe to",
"swap": "swap",
"swap": "Swap",
"completed_swap": "Swap!",
"metamask_swap_fee": "MetaMask Swap fee",
"fee_text": {
Expand Down

0 comments on commit a2de45b

Please sign in to comment.