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

Widget UI + configurator #3227

Merged
merged 28 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2a1111d
feat: widget init mods
Sep 28, 2023
d6e6a76
feat: widget menu links
Sep 29, 2023
fc0113f
feat: select menu
Oct 3, 2023
6962653
feat: select menu
Oct 3, 2023
cd00476
feat: select menu
Oct 3, 2023
26de84c
Update apps/cowswap-frontend/src/modules/trade/containers/TradeWidget…
fairlighteth Oct 3, 2023
bac8ade
feat: fix semicolons
fairlighteth Oct 3, 2023
07ea891
feat: menu styling
fairlighteth Oct 3, 2023
3b76433
feat: general styling
fairlighteth Oct 9, 2023
a343871
feat: connect wallet internal
fairlighteth Oct 10, 2023
fe89695
feat: connect wallet internal
fairlighteth Oct 10, 2023
f931b09
feat: connect wallet internal
fairlighteth Oct 10, 2023
9180d5e
feat: widget configurator app
fairlighteth Oct 10, 2023
d96c8c7
feat: widget configurator app
fairlighteth Oct 11, 2023
c23d531
feat: widget configurator app
fairlighteth Oct 12, 2023
30565eb
feat: widget configurator app
fairlighteth Oct 12, 2023
64c8533
feat: widget configurator app
fairlighteth Oct 12, 2023
d0b064e
feat: widget configurator app
fairlighteth Oct 12, 2023
6c39e14
feat: widget configurator app
fairlighteth Oct 12, 2023
8638950
feat: widget configurator app
fairlighteth Oct 12, 2023
790abd0
feat: widget configurator app
fairlighteth Oct 13, 2023
65c6f00
feat: widget configurator app
fairlighteth Oct 16, 2023
527108a
Merge branch 'develop' into widget-ui-6
fairlighteth Oct 16, 2023
a133ca5
feat: widget configurator app
fairlighteth Oct 16, 2023
0abd19e
refactor: extract AccountElement and AccountModalState
shoom3301 Oct 18, 2023
c7e94e0
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Oct 19, 2023
3e78f09
chore: update yarn.lock
shoom3301 Oct 19, 2023
7f5b699
chore: fix code style
shoom3301 Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/cowswap-frontend/src/assets/icon/carret.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion apps/cowswap-frontend/src/assets/icon/gas-free.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/cowswap-frontend/src/assets/icon/wallet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions apps/cowswap-frontend/src/common/constants/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export enum UI {

// Icons
ICON_SIZE_NORMAL = '--cow-icon-size-normal',
ICON_SIZE_SMALL = '--cow-icon-size-small',
ICON_SIZE_XSMALL = '--cow-icon-size-xsmall',
ICON_SIZE_LARGE = '--cow-icon-size-large',
ICON_COLOR_NORMAL = '--cow-icon-color-normal',

Expand Down
25 changes: 25 additions & 0 deletions apps/cowswap-frontend/src/common/hooks/useOrdersPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useState, useCallback } from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

creating a reusable hook to control the orders panel (user activity modal)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Refactored it into accountModalStateAtom


interface UseOrdersPanel {
isOrdersPanelOpen: boolean;
handleOpenOrdersPanel: () => void;
handleCloseOrdersPanel: () => void;
}

export const useOrdersPanel = (): UseOrdersPanel => {
const [isOrdersPanelOpen, setIsOrdersPanelOpen] = useState<boolean>(false);

const handleOpenOrdersPanel = useCallback(() => {
setIsOrdersPanelOpen(true);
}, []);

const handleCloseOrdersPanel = useCallback(() => {
setIsOrdersPanelOpen(false);
}, []);

return {
isOrdersPanelOpen,
handleOpenOrdersPanel,
handleCloseOrdersPanel,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,19 @@ export const StepsWrapper = styled.div`
margin: auto;
position: absolute;
width: 100%;
max-width: 162px;
max-width: 35%;
left: 0;
right: 0;
top: 32px;
z-index: 1;

${({ theme }) => theme.mediaWidth.upToSmall`
max-width: 25%;
`}

${({ theme }) => theme.mediaWidth.upToVerySmall`
max-width: 20%;
`}
}

> hr::before {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ReactComponent as DropDown } from '@cowprotocol/assets/images/dropdown.
import { lighten, transparentize } from 'polished'
import styled from 'styled-components/macro'

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

export const CurrencySelectWrapper = styled.button<{ isLoading: boolean; $stubbed: boolean; readonlyMode: boolean }>`
display: flex;
justify-content: space-between;
Expand All @@ -19,7 +21,7 @@ export const CurrencySelectWrapper = styled.button<{ isLoading: boolean; $stubbe
: `0px 4px 8px ${transparentize(0.96, theme.text1)}`};
opacity: ${({ isLoading }) => (isLoading ? 0.6 : 1)};
pointer-events: ${({ readonlyMode }) => (readonlyMode ? 'none' : '')};
border-radius: 16px;
border-radius: var(${UI.BORDER_RADIUS_NORMAL});
padding: 6px;
transition: background-color 0.15s ease-in-out;
max-width: 190px;
Expand Down
16 changes: 12 additions & 4 deletions apps/cowswap-frontend/src/cow-react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Provider as AtomProvider } from 'jotai'
import { StrictMode } from 'react'

import { BlockNumberProvider } from '@cowprotocol/common-hooks'
import { isInjectedWidget } from '@cowprotocol/common-utils'
import { nodeRemoveChildFix } from '@cowprotocol/common-utils'
import { jotaiStore } from '@cowprotocol/core'
import { SnackbarsWidget } from '@cowprotocol/snackbars'
Expand Down Expand Up @@ -41,6 +42,7 @@ if (window.ethereum) {
}

const root = createRoot(document.getElementById('root')!)
const isInjectedWidgetMode = isInjectedWidget()

root.render(
<StrictMode>
Expand All @@ -56,12 +58,18 @@ root.render(
<BlockNumberProvider>
<WithLDProvider>
<Updaters />
<FeatureGuard featureFlag="cowFortuneEnabled">
<FortuneWidget />
</FeatureGuard>

{!isInjectedWidgetMode && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't render Fortune Widget and Appzi button for Widget mode

<>
<FeatureGuard featureFlag="cowFortuneEnabled">
<FortuneWidget />
</FeatureGuard>
<AppziButton />
</>
)}

<Popups />
<SnackbarsWidget />
<AppziButton />
<App />
</WithLDProvider>
</BlockNumberProvider>
Expand Down
5 changes: 3 additions & 2 deletions apps/cowswap-frontend/src/legacy/components/Copy/CopyMod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { UI } from 'common/constants/theme'

// MOD imports
export const CopyIcon = styled(LinkStyledButton)`
--iconSize: var(${UI.ICON_SIZE_NORMAL});
color: ${({ theme }) => theme.text3};
flex-shrink: 0;
display: flex;
Expand All @@ -22,8 +23,8 @@ export const CopyIcon = styled(LinkStyledButton)`
font-size: 0.825rem;
border-radius: 50%;
background-color: transparent;
min-width: 20px;
min-height: 20px;
min-width: var(--iconSize);
min-height: var(--iconSize);
align-self: flex-end;
:hover,
:active,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { ErrorInfo, PropsWithChildren } from 'react'

import { sendError } from '@cowprotocol/analytics'
import { isInjectedWidget } from '@cowprotocol/common-utils'

import * as Sentry from '@sentry/react'
import styled from 'styled-components/macro'


import { ChunkLoadError } from 'legacy/components/ErrorBoundary/ChunkLoadError'
import { ErrorWithStackTrace } from 'legacy/components/ErrorBoundary/ErrorWithStackTrace'
import Footer from 'legacy/components/Footer'
Expand Down Expand Up @@ -128,6 +130,8 @@ export default class ErrorBoundary extends React.Component<PropsWithChildren, Er

return (
<AppWrapper>

{!isInjectedWidget() &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hide the normal header (logo/menu/etc) in Widget mode

<HeaderWrapper>
<HeaderRow marginRight="0">
<a href={Routes.HOME}>
Expand All @@ -137,6 +141,8 @@ export default class ErrorBoundary extends React.Component<PropsWithChildren, Er
</a>
</HeaderRow>
</HeaderWrapper>
}

<Wrapper>{isChunkLoadError ? <ChunkLoadError /> : <ErrorWithStackTrace error={error} />}</Wrapper>
<FooterWrapper>
<Footer />
Expand Down
56 changes: 28 additions & 28 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 { toggleDarkModeAnalytics } from '@cowprotocol/analytics'
import { isInjectedWidget } from '@cowprotocol/common-utils'
import { addBodyClass, removeBodyClass } from '@cowprotocol/common-utils'
import { SupportedChainId as ChainId, SupportedChainId } from '@cowprotocol/cow-sdk'
import { TokenAmount } from '@cowprotocol/ui'
Expand Down Expand Up @@ -29,6 +28,8 @@ import { Web3Status } from 'modules/wallet/containers/Web3Status'
import { Routes } from 'common/constants/routes'
import { useCategorizeRecentActivity } from 'common/hooks/useCategorizeRecentActivity'
import { useIsProviderNetworkUnsupported } from 'common/hooks/useIsProviderNetworkUnsupported'
import { useOrdersPanel } from 'common/hooks/useOrdersPanel'


import MobileMenuIcon from './MobileMenuIcon'
import {
Expand All @@ -49,16 +50,31 @@ const CHAIN_CURRENCY_LABELS: { [chainId in ChainId]?: string } = {
[ChainId.GNOSIS_CHAIN]: 'xDAI',
}

// Todo: fix 'any' types
shoom3301 marked this conversation as resolved.
Show resolved Hide resolved
export const AccountElementComponent = ({ isWidgetMode, pendingActivity, handleOpenOrdersPanel }: any) => {
const { account, chainId } = useWalletInfo()
const isChainIdUnsupported = useIsProviderNetworkUnsupported()
const nativeToken = CHAIN_CURRENCY_LABELS[chainId] || 'ETH'
const userEthBalance = useNativeCurrencyBalances(account ? [account] : [])?.[account ?? '']

return (
<AccountElement active={!!account} onClick={handleOpenOrdersPanel}>
{!isWidgetMode && account && !isChainIdUnsupported && userEthBalance && chainId && (
<BalanceText>
<TokenAmount amount={userEthBalance} tokenSymbol={{ symbol: nativeToken }} />
</BalanceText>
)}

<Web3Status pendingActivities={pendingActivity} />
</AccountElement>
)
}

export default function Header() {
const { account, chainId } = useWalletInfo()
const isInjectedWidgetMode = isInjectedWidget()
const injectedWidgetParams = useInjectedWidgetParams()

const isChainIdUnsupported = useIsProviderNetworkUnsupported()

const { pendingActivity } = useCategorizeRecentActivity()
const userEthBalance = useNativeCurrencyBalances(account ? [account] : [])?.[account ?? '']
const nativeToken = CHAIN_CURRENCY_LABELS[chainId] || 'ETH'
const [darkMode, toggleDarkModeAux] = useDarkModeManager()
const toggleDarkMode = useCallback(() => {
toggleDarkModeAnalytics(!darkMode)
Expand All @@ -67,14 +83,7 @@ export default function Header() {
const swapRawState = useSwapRawState()
const { state: tradeState } = useTradeState()

const [isOrdersPanelOpen, setIsOrdersPanelOpen] = useState<boolean>(false)
const handleOpenOrdersPanel = () => {
account && setIsOrdersPanelOpen(true)
}
const handleCloseOrdersPanel = () => {
setIsOrdersPanelOpen(false)
!isOrdersPanelOpen && removeBodyClass('noScroll')
}
const { isOrdersPanelOpen, handleOpenOrdersPanel, handleCloseOrdersPanel } = useOrdersPanel();

const navigate = useNavigate()

Expand Down Expand Up @@ -128,7 +137,7 @@ export default function Header() {
<HeaderModWrapper>
<HeaderRow>
{!injectedWidgetParams.hideLogo && (
<Title href={isInjectedWidgetMode ? undefined : Routes.HOME} isMobileMenuOpen={isMobileMenuOpen}>
<Title href={Routes.HOME} isMobileMenuOpen={isMobileMenuOpen}>
<UniIcon>
<LogoImage isMobileMenuOpen={isMobileMenuOpen}>
{injectedWidgetParams.logoUrl ? (
Expand All @@ -140,14 +149,14 @@ export default function Header() {
</UniIcon>
</Title>
)}
{!isInjectedWidgetMode && <MenuTree isMobileMenuOpen={isMobileMenuOpen} context={menuContext} />}
{<MenuTree isMobileMenuOpen={isMobileMenuOpen} context={menuContext} />}
</HeaderRow>

<HeaderControls>
{!injectedWidgetParams.hideNetworkSelector && <NetworkSelector />}

<HeaderElement>
{!isInjectedWidgetMode && !isChainIdUnsupported && (
{!isChainIdUnsupported && (
<CowBalanceButton
onClick={() => navigate('/account')}
account={account}
Expand All @@ -156,20 +165,11 @@ export default function Header() {
/>
)}

<AccountElement active={!!account} onClick={handleOpenOrdersPanel}>
{account && !isChainIdUnsupported && userEthBalance && chainId && (
<BalanceText>
<TokenAmount amount={userEthBalance} tokenSymbol={{ symbol: nativeToken }} />
</BalanceText>
)}
<Web3Status pendingActivities={pendingActivity} />
</AccountElement>
<AccountElementComponent pendingActivity={pendingActivity} handleOpenOrdersPanel={handleOpenOrdersPanel} />
</HeaderElement>
</HeaderControls>

{isUpToLarge && !isInjectedWidgetMode && (
<MobileMenuIcon isMobileMenuOpen={isMobileMenuOpen} onClick={handleMobileMenuOnClick} />
)}
{isUpToLarge && <MobileMenuIcon isMobileMenuOpen={isMobileMenuOpen} onClick={handleMobileMenuOnClick} />}
{isOrdersPanelOpen && <OrdersPanel handleCloseOrdersPanel={handleCloseOrdersPanel} />}
</HeaderModWrapper>
</Wrapper>
Expand Down
Loading
Loading