Skip to content

Commit

Permalink
Widget UI 7 (#3251)
Browse files Browse the repository at this point in the history
* feat: widget init mods

* feat: widget menu links

* feat: select menu

* feat: select menu

* feat: select menu

* Update apps/cowswap-frontend/src/modules/trade/containers/TradeWidget/index.tsx

Co-authored-by: Alexandr Kazachenko <[email protected]>

* feat: fix semicolons

* feat: menu styling

* feat: general styling

* feat: connect wallet internal

* feat: connect wallet internal

* feat: connect wallet internal

* feat: widget configurator app

* feat: widget configurator app

* feat: widget configurator app

* feat: widget configurator app

* feat: widget configurator app

* feat: widget configurator app

* feat: widget configurator app

* feat: widget configurator app

* feat: widget configurator app

* feat: widget configurator app

* feat: widget configurator app

* refactor: extract AccountElement and AccountModalState

* feat: update theme

* feat: update modalheader

* feat: update modalheader

* feat: update modalheader

* feat: refactor code

* feat: iframe resizer

* feat: update

* feat: powered by footer (#3254)

---------

Co-authored-by: Michel <[email protected]>
Co-authored-by: Alexandr Kazachenko <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2023
1 parent 1a2c1de commit 6a36d1a
Show file tree
Hide file tree
Showing 24 changed files with 206 additions and 104 deletions.
1 change: 1 addition & 0 deletions apps/cowswap-frontend/src/assets/logo/cow-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ModalContentWrapper = styled.div`
padding: 24px;
color: var(${UI.COLOR_TEXT2});
background-color: var(${UI.COLOR_CONTAINER_BG_01});
border-radius: 24px;
border-radius: var(${UI.BORDER_RADIUS_NORMAL});
> p {
line-height: 1.4;
Expand Down
47 changes: 47 additions & 0 deletions apps/cowswap-frontend/src/common/pure/PoweredFooter/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { COW_PROTOCOL_LINK } from '@cowprotocol/common-const'
import { ExternalLink } from '@cowprotocol/ui'

import { Trans } from '@lingui/macro'
import cowIcon from 'assets/logo/cow-icon.svg'
import SVG from 'react-inlinesvg'
import styled from 'styled-components/macro'

import { UI } from 'common/constants/theme'

const Wrapper = styled.div`
display: flex;
flex-flow: row wrap;
align-items: center;
justify-content: center;
font-size: var(${UI.FONT_SIZE_SMALLER});
padding: 4px 0;
`

const StyledExternalLink = styled(ExternalLink)`
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
color: var(${UI.COLOR_TEXT2});
> svg {
--size: 14px;
width: var(--size);
height: var(--size);
}
> svg > g > path {
fill: var(${UI.COLOR_TEXT2});
}
`

export function PoweredFooter() {
return (
<Wrapper>
<StyledExternalLink href={COW_PROTOCOL_LINK}>
<SVG src={cowIcon} title="CoW Protocol" />
<Trans>Powered by CoW Protocol</Trans>
</StyledExternalLink>
</Wrapper>
)
}
4 changes: 4 additions & 0 deletions apps/cowswap-frontend/src/cow-react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ import { WithLDProvider } from 'modules/application/containers/WithLDProvider'
import { FortuneWidget } from 'modules/fortune/containers/FortuneWidget'

import { FeatureGuard } from 'common/containers/FeatureGuard'
import { IframeResizer } from 'utils/iframeResizer'

import { WalletUnsupportedNetworkBanner } from '../common/containers/WalletUnsupportedNetworkBanner'


// Node removeChild hackaround
// based on: https://github.com/facebook/react/issues/11538#issuecomment-417504600
nodeRemoveChildFix()
Expand Down Expand Up @@ -79,6 +81,8 @@ root.render(
</HashRouter>
</AtomProvider>
</Provider>

{isInjectedWidgetMode && <IframeResizer />}
</StrictMode>
)

Expand Down
15 changes: 2 additions & 13 deletions apps/cowswap-frontend/src/legacy/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react'
import React, { useCallback, useMemo, useState } from 'react'

import { toggleDarkModeAnalytics } from '@cowprotocol/analytics'
import { addBodyClass, removeBodyClass } from '@cowprotocol/common-utils'
import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { useWalletInfo } from '@cowprotocol/wallet'

Expand All @@ -10,11 +9,10 @@ import { useNavigate } from 'react-router-dom'

import CowBalanceButton from 'legacy/components/CowBalanceButton'
import { NetworkSelector } from 'legacy/components/Header/NetworkSelector'
import { LargeAndUp, upToLarge, upToMedium, upToSmall, useMediaQuery } from 'legacy/hooks/useMediaQuery'
import { upToLarge, upToSmall, useMediaQuery } from 'legacy/hooks/useMediaQuery'
import { useDarkModeManager } from 'legacy/state/user/hooks'
import { cowSwapLogo } from 'legacy/theme/cowSwapAssets'

import { useAccountModalState } from 'modules/account'
import { useInjectedWidgetParams } from 'modules/injectedWidget'
import { MainMenuContext } from 'modules/mainMenu'
import { MenuTree } from 'modules/mainMenu/pure/MenuTree'
Expand Down Expand Up @@ -52,14 +50,11 @@ export default function Header() {
}, [toggleDarkModeAux, darkMode])
const swapRawState = useSwapRawState()
const { state: tradeState } = useTradeState()
const { isOpen: isAccountModalOpen } = useAccountModalState()

const navigate = useNavigate()

const isUpToLarge = useMediaQuery(upToLarge)
const isUpToMedium = useMediaQuery(upToMedium)
const isUpToSmall = useMediaQuery(upToSmall)
const isLargeAndUp = useMediaQuery(LargeAndUp)

const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false)
const handleMobileMenuOnClick = useCallback(() => {
Expand Down Expand Up @@ -95,12 +90,6 @@ export default function Header() {
tradeContext: tradeMenuContext,
}

// Toggle the 'noScroll' class on body, whenever the mobile menu or orders panel is open.
// This removes the inner scrollbar on the page body, to prevent showing double scrollbars.
useEffect(() => {
isMobileMenuOpen || isAccountModalOpen ? addBodyClass('noScroll') : removeBodyClass('noScroll')
}, [isAccountModalOpen, isMobileMenuOpen, isUpToLarge, isUpToMedium, isUpToSmall, isLargeAndUp])

return (
<Wrapper isMobileMenuOpen={isMobileMenuOpen}>
<HeaderModWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const Fader = styled.div`
export const PopupWrapper = styled.div<{ css?: FlattenInterpolation<ThemeProps<DefaultTheme>> }>`
display: inline-block;
width: 100%;
//padding: 1em;
background-color: var(${UI.COLOR_CONTAINER_BG_01});
position: relative;
border-radius: 10px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ import { BaseWrapper, CommonBasesRow, MobileWrapper } from './index'
export const StyledScrollarea = styled.div`
overflow-y: auto; // fallback for 'overlay'
overflow-y: overlay;
padding: 0 20px;
padding: 0 20px 0;
overflow-y: hidden;
overflow-x: auto;
${({ theme }) => theme.colorScrollbar};
${({ theme }) => theme.mediaWidth.upToSmall`
overflow-y: hidden;
overflow-x: auto;
`}
`

const MAX_LENGTH_OVERFLOW = 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ export const AutoColumn = styled(AutoColumnUni)`
`

export const CommonBasesRow = styled(AutoRow)`
${({ theme }) => theme.mediaWidth.upToSmall`
flex-flow: row nowrap;
overflow-x: scroll;
padding: 0 100px 0 0;
position: relative;
${({ theme }) => theme.colorScrollbar};
`}
margin: 0;
flex-flow: row nowrap;
overflow-x: scroll;
padding: 0 100px 5px 0;
position: relative;
${({ theme }) => theme.colorScrollbar};
`

export const MobileWrapper = styled(AutoColumn)<{ showOverflow?: boolean }>`
Expand All @@ -50,7 +49,6 @@ export const MobileWrapper = styled(AutoColumn)<{ showOverflow?: boolean }>`
&::after {
content: '';
display: block;
// background: linear-gradient(to top, #163861 0%, rgba(22, 56, 97, 0) 100%);
pointer-events: none;
height: 40px;
width: 100%;
Expand All @@ -61,35 +59,30 @@ export const MobileWrapper = styled(AutoColumn)<{ showOverflow?: boolean }>`
margin: auto;
}
`}
${({ theme }) => theme.mediaWidth.upToSmall`
/* display: none; */
`};
overflow-y: auto; // fallback for 'overlay'
overflow-y: overlay;
max-height: 135px;
padding-bottom: 20px;
padding: 0;
`

export const BaseWrapperMod = styled.div<{ disable?: boolean }>`
border: 1px solid ${({ theme, disable }) => (disable ? 'transparent' : theme.bg3)};
border-radius: 10px;
display: flex;
padding: 6px;
align-items: center;
:hover {
cursor: ${({ disable }) => !disable && 'pointer'};
background-color: ${({ theme, disable }) => !disable && theme.bg4};
}
color: ${({ theme, disable }) => disable && theme.text3};
background-color: ${({ theme, disable }) => disable && theme.bg3};
filter: ${({ disable }) => disable && 'grayscale(1)'};
flex: 0 0 calc(33% - 8px);
justify-content: center;
&:hover {
cursor: ${({ disable }) => !disable && 'pointer'};
background-color: ${({ theme, disable }) => !disable && theme.bg4};
}
${({ theme }) => theme.mediaWidth.upToSmall`
flex: auto;
`}
Expand Down
4 changes: 3 additions & 1 deletion apps/cowswap-frontend/src/legacy/pages/AppBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import styled from 'styled-components/macro'

import { Z_INDEX } from 'legacy/theme'

import { UI } from 'common/constants/theme'

export const BodyWrapper = styled.main<{ margin?: string; maxWidth?: string }>`
position: relative;
margin-top: ${({ margin }) => margin ?? '0px'};
Expand All @@ -12,7 +14,7 @@ export const BodyWrapper = styled.main<{ margin?: string; maxWidth?: string }>`
background: ${({ theme }) => theme.bg0};
box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.01), 0px 4px 8px rgba(0, 0, 0, 0.04), 0px 16px 24px rgba(0, 0, 0, 0.04),
0px 24px 32px rgba(0, 0, 0, 0.01);
border-radius: 24px;
border-radius: var(${UI.BORDER_RADIUS_NORMAL});
margin-top: 1rem;
margin-left: auto;
margin-right: auto;
Expand Down
8 changes: 4 additions & 4 deletions apps/cowswap-frontend/src/legacy/theme/baseTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,9 @@ export const ThemedGlobalStyle = createGlobalStyle`
${UniThemedGlobalStyle}
html {
background-color: ${({ theme }) => theme.isInjectedWidgetMode ? 'transparent' : `var(${UI.COLOR_CONTAINER_BG_02})`};
${({ theme }) => theme.body.background};
background-color: ${({ theme }) =>
theme.isInjectedWidgetMode ? 'transparent' : `var(${UI.COLOR_CONTAINER_BG_02})`};
${({ theme }) => (theme.isInjectedWidgetMode ? 'transparent' : theme.body.background)};
}
*, *:after, *:before { box-sizing:border-box; }
Expand Down Expand Up @@ -533,8 +534,7 @@ export const ThemedGlobalStyle = createGlobalStyle`
body #wcm-modal.wcm-overlay {
${({ theme }) => theme.mediaWidth.upToSmall`
align-items: flex-start;
`
}
`}
a {
text-decoration: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const AppWrapper = styled.div<Partial<CSS.Properties>>`
flex-flow: column;
align-items: flex-start;
min-height: 100vh;
height: 100vh;
`

export const HeaderWrapper = styled.div`
Expand Down Expand Up @@ -36,10 +37,10 @@ export const BodyWrapper = styled.div`
justify-content: center;
flex: 1 1 auto;
z-index: 2;
padding: ${({ theme }) => theme.isInjectedWidgetMode ? '0' : '5vh 16px 0'};
padding: ${({ theme }) => (theme.isInjectedWidgetMode ? '16px 16px 0' : '5vh 16px 0')};
${({ theme }) => theme.mediaWidth.upToMedium`
padding: ${({ theme }) => theme.isInjectedWidgetMode ? '0' : '0 10px 16px'};
padding: ${({ theme }) => (theme.isInjectedWidgetMode ? '0 0 16px' : '0 10px 16px')};
flex: none;
`}
`
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import IMAGE_CARRET from 'assets/icon/carret.svg'
import SVG from 'react-inlinesvg'
import { matchPath, useLocation } from 'react-router-dom'

import { ModalHeader } from 'modules/tokensList/pure/ModalHeader'
import { useTradeRouteContext } from 'modules/trade/hooks/useTradeRouteContext'
import { parameterizeTradeRoute } from 'modules/trade/utils/parameterizeTradeRoute'

Expand Down Expand Up @@ -50,7 +51,7 @@ export function TradeWidgetLinks({
const location = useLocation()
const [isDropdownVisible, setDropdownVisible] = useState(false)

const handleMenuItemClick = (_item: MenuItemConfig) => {
const handleMenuItemClick = (_item?: MenuItemConfig) => {
if (menuItems.length === 1) return
setDropdownVisible(false)
}
Expand Down Expand Up @@ -81,23 +82,32 @@ export function TradeWidgetLinks({
)
})

const singleMenuItem = menuItems.length === 1;
const singleMenuItem = menuItems.length === 1

return isDropdown ? (
<>
<styledEl.MenuItem onClick={() => !singleMenuItem && setDropdownVisible(!isDropdownVisible)} isDropdownVisible={isDropdownVisible}>
<styledEl.MenuItem
onClick={() => !singleMenuItem && setDropdownVisible(!isDropdownVisible)}
isDropdownVisible={isDropdownVisible}
>
<styledEl.Link to={menuItems.find((item) => item.props.isActive)?.props.routePath || '#'}>
<Trans>
{menuItems.find((item) => item.props.isActive)?.props.item.label}
{!singleMenuItem ? <SVG src={IMAGE_CARRET} title="select" /> : null}
</Trans>
</styledEl.Link>
</styledEl.MenuItem>
{isDropdownVisible && <styledEl.SelectMenu>{menuItems}</styledEl.SelectMenu>}

{isDropdownVisible && (
<styledEl.SelectMenu>
<ModalHeader onBack={handleMenuItemClick}>Trading mode</ModalHeader>
{menuItems}
</styledEl.SelectMenu>
)}
</>
) : (
<styledEl.Wrapper>{menuItems}</styledEl.Wrapper>
);
)
}

const MenuItem = ({
Expand Down
Loading

0 comments on commit 6a36d1a

Please sign in to comment.