Skip to content

Commit

Permalink
feat(swap): Initial Swap screen redesign (#5409)
Browse files Browse the repository at this point in the history
### Description

First part of
[RET-1065](https://linear.app/valora/issue/RET-1065/[wallet]-swap-screen-redesign).
Updates the design of swap screen to match the [designs in
Figma](https://www.figma.com/design/fjpfHZdVSLazv330kT2sQz/Cross-chain-swaps?node-id=606-1653&t=Bq4e7bCLkjpGu4D0-4).
The rest of the behavior outlined in the ticket will come in followup
PRs.

### Test plan

Unit and manual tested. See video below:



https://github.com/valora-inc/wallet/assets/569401/c078eb34-4cd2-4fe9-a9a2-f5eba85c0c47



### Related issues

- Part of
[RET-1065](https://linear.app/valora/issue/RET-1065/[wallet]-swap-screen-redesign).

### Backwards compatibility

Yes.

### Network scalability

If a new NetworkId and/or Network are added in the future, the changes
in this PR will:

- [x] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)
  • Loading branch information
jophish committed May 21, 2024
1 parent 3a4fd74 commit ea65cbc
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 180 deletions.
3 changes: 3 additions & 0 deletions locales/base/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,9 @@
"swapToTokenSelection": "SWAP TO",
"tokenUsdValueUnknown": "-",
"unsupportedSwapTokens": "The selected tokens aren't supported by our swap providers.",
"selectTokenLabel": "Select token",
"tokenBottomSheetTitle": "Select Token",
"onNetwork": "on {{networkName}}",
"switchedToNetworkWarning": {
"title": "You switched to the {{networkName}} network",
"body_swapFrom": "Select a token to swap from on the {{networkName}} network to continue.",
Expand Down
1 change: 1 addition & 0 deletions src/analytics/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ export enum SwapEvents {
swap_show_info = 'swap_show_info',
swap_show_fund_your_wallet = 'swap_show_fund_your_wallet',
swap_add_funds = 'swap_add_funds',
swap_switch_tokens = 'swap_switch_tokens',
}

export enum CeloNewsEvents {
Expand Down
4 changes: 4 additions & 0 deletions src/analytics/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,10 @@ interface SwapEventsProperties {
}
[SwapEvents.swap_show_fund_your_wallet]: undefined
[SwapEvents.swap_add_funds]: undefined
[SwapEvents.swap_switch_tokens]: {
fromTokenId: string | undefined
toTokenId: string | undefined
}
}

interface CeloNewsEventsProperties {
Expand Down
1 change: 1 addition & 0 deletions src/analytics/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ export const eventDocs: Record<AnalyticsEventType, string> = {
[SwapEvents.swap_show_info]: `When a user taps an info icon to show more information on the swap screen`,
[SwapEvents.swap_show_fund_your_wallet]: `When "Fund your wallet" bottom sheet is displayed`,
[SwapEvents.swap_add_funds]: `When user taps "Add funds" button is "Fund your wallet" bottom sheet`,
[SwapEvents.swap_switch_tokens]: `When a user taps the button to switch the to and from tokens`,
[CeloNewsEvents.celo_news_screen_open]: `When the screen is mounted`,
[CeloNewsEvents.celo_news_article_tap]: `When a user taps on a news article`,
[CeloNewsEvents.celo_news_bottom_read_more_tap]: `When a user taps on the read more button at the bottom of the screen`,
Expand Down
33 changes: 27 additions & 6 deletions src/components/Touchable.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
import * as React from 'react'
import { TouchableWithoutFeedbackProps, View } from 'react-native'
import { TouchableWithoutFeedbackProps, View, ViewStyle } from 'react-native'
import PlatformTouchable from 'react-native-platform-touchable'

type BorderRadiusStyle = Pick<
ViewStyle,
| 'borderTopLeftRadius'
| 'borderTopRightRadius'
| 'borderBottomLeftRadius'
| 'borderBottomRightRadius'
>

export interface Props extends TouchableWithoutFeedbackProps {
borderless?: boolean
children: React.ReactNode // must only have one direct child. see https://github.com/react-native-community/react-native-platform-touchable#touchable
borderRadius?: number
borderRadius?: number | BorderRadiusStyle
shouldRenderRippleAbove?: boolean
}

/**
* @param borderless - If true, the touchable has a borderless ripple effect.
* @param borderRadius - should be added if the touchable component has rounded corners, to prevent the ripple effect from going outside the component on tap (Android)
* @param borderRadius - should be added if the touchable component has rounded corners, to prevent the ripple effect from going outside the component on tap (Android). Can either be a number
* representing a single border radius, or an object individually specifying each corner's radius.
* @param shouldRenderRippleAbove - If present, ensures that the ripple effect will render above the touchable component. See https://github.com/facebook/react-native/issues/17200
* @returns A touchable component
*/
export default function Touchable({ borderless, borderRadius = 0, ...passThroughProps }: Props) {
export default function Touchable({
shouldRenderRippleAbove,
borderless,
borderRadius = 0,
...passThroughProps
}: Props) {
const background = borderless
? PlatformTouchable.SelectableBackgroundBorderless()
: PlatformTouchable.SelectableBackground()
const borderStyle = typeof borderRadius === 'number' ? { borderRadius } : borderRadius
return borderRadius === 0 ? (
<PlatformTouchable {...passThroughProps} background={background} />
) : (
<View style={[{ borderRadius }, !borderless && { overflow: 'hidden' }]}>
<PlatformTouchable {...passThroughProps} background={background} />
<View style={[borderStyle, !borderless && { overflow: 'hidden' }]}>
<PlatformTouchable
{...passThroughProps}
background={shouldRenderRippleAbove ? undefined : background}
foreground={shouldRenderRippleAbove ? background : undefined}
/>
</View>
)
}
5 changes: 3 additions & 2 deletions src/icons/DownIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import Svg, { Path } from 'svgs'
export interface Props {
color?: string
testID?: string
size?: number
}

function DownIndicator({ color = colors.error, testID }: Props) {
function DownIndicator({ color = colors.error, testID, size = 10 }: Props) {
return (
<Svg width="10" height="10" viewBox="0 0 10 10" fill="none" testID={testID}>
<Svg width={size} height={size} viewBox="0 0 10 10" fill="none" testID={testID}>
<Path
fill={color}
d="M4.369 0H5.63v7.576l3.473-3.472L10 5l-5 5-5-5 .896-.896L4.37 7.576V0Z"
Expand Down
Loading

0 comments on commit ea65cbc

Please sign in to comment.