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

Iframe & configurator updates (widget-ui-9) #3255

Merged
merged 46 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
46 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
964aaa2
feat: update theme
fairlighteth Oct 18, 2023
9374bf8
feat: update modalheader
fairlighteth Oct 18, 2023
7e8aa60
feat: update modalheader
fairlighteth Oct 18, 2023
4047b4b
Merge branch 'widget-ui-6' into widget-ui-7
fairlighteth Oct 18, 2023
e47fcb6
feat: update modalheader
fairlighteth Oct 18, 2023
3833a91
feat: refactor code
fairlighteth Oct 19, 2023
6e1716c
feat: iframe resizer
fairlighteth Oct 19, 2023
95cb964
feat: powered by footer
fairlighteth Oct 19, 2023
cdc5f5a
feat: iframe WIP
fairlighteth Oct 19, 2023
aa56228
feat: revert tsconfig
fairlighteth Oct 20, 2023
146b508
feat: merge develop
fairlighteth Oct 20, 2023
dc1f1de
feat: fix import
fairlighteth Oct 20, 2023
bcf3e7a
feat: fix gap loading spinner
fairlighteth Oct 20, 2023
38615c6
feat: cleanup + optimize iframeresizer
fairlighteth Oct 20, 2023
be7c010
feat: add ENUM
fairlighteth Oct 20, 2023
dd900b3
feat: optimize iframeResizer script
fairlighteth Oct 20, 2023
840dda5
feat: fix height iframe
fairlighteth Oct 20, 2023
c3dcb7b
feat: configurator background
fairlighteth Oct 20, 2023
a50a5a4
feat: fix fav tokens styles
fairlighteth Oct 23, 2023
ec44b5a
Merge branch 'develop' into widget-ui-9
fairlighteth Oct 23, 2023
002c17f
feat: fix img alt
fairlighteth Oct 23, 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
8 changes: 0 additions & 8 deletions apps/cowswap-frontend/src/common/pure/CurrencyLogo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ export const StyledLogo = styled(Logo)<{ size: string; $native: boolean }>`
height: ${({ size }) => size};
min-width: ${({ size }) => size}; // MOD
min-height: ${({ size }) => size}; // MOD
/* background: radial-gradient(white 50%, #ffffff00 calc(75% + 1px), #ffffff00 100%);
border-radius: 50%;
-mox-box-shadow: 0 0 1px ${({ $native }) => ($native ? 'white' : 'black')};
-webkit-box-shadow: 0 0 1px ${({ $native }) => ($native ? 'white' : 'black')};
box-shadow: 0 0 1px ${({ $native }) => ($native ? 'white' : 'black')};
border: 0px solid rgba(255, 255, 255, 0); */
border-radius: ${({ size }) => size};
/* box-shadow: 0px 6px 10px rgba(0, 0, 0, 0.075); */
/* background-color: ${({ theme }) => theme.white}; */
background-color: ${({ theme }) => theme.white}; // MOD
color: ${({ theme }) => theme.black}!important; // MOD
`
Expand Down
3 changes: 1 addition & 2 deletions apps/cowswap-frontend/src/cow-react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { StrictMode } from 'react'
import { BlockNumberProvider } from '@cowprotocol/common-hooks'
import { isInjectedWidget } from '@cowprotocol/common-utils'
import { nodeRemoveChildFix } from '@cowprotocol/common-utils'
import { IframeResizer } from '@cowprotocol/common-utils'
import { jotaiStore } from '@cowprotocol/core'
import { SnackbarsWidget } from '@cowprotocol/snackbars'

Expand All @@ -30,11 +31,9 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import { CurrencyLogo } from 'common/pure/CurrencyLogo'

import { BaseWrapper, CommonBasesRow, MobileWrapper } from './index'

export const StyledScrollarea = styled.div`
overflow-y: auto; // fallback for 'overlay'
overflow-y: overlay;
padding: 0 20px 0;
overflow-y: hidden;
overflow-x: auto;
${({ theme }) => theme.colorScrollbar};
export const StyledTokenList = styled.div`
padding: 0 10px 16px;

${({ theme }) => theme.mediaWidth.upToSmall`
overflow-x: scroll;
`}
`

const MAX_LENGTH_OVERFLOW = 12
Expand All @@ -43,7 +42,7 @@ export default function CommonBases({
</Text>
<QuestionHelper text={<Trans>Your favourite saved tokens. Edit this list in your account page.</Trans>} />
</AutoRow>
<StyledScrollarea>
<StyledTokenList>
<CommonBasesRow gap="4px">
{tokens.map((currency: Currency) => {
const isSelected = selectedCurrency?.equals(currency)
Expand All @@ -58,15 +57,15 @@ export default function CommonBases({
key={currencyId(currency)}
>
<CurrencyLogoFromList currency={currency} />
<Text fontWeight={500} fontSize={16}>
<Text fontWeight={500} fontSize={13}>
<TokenSymbol token={currency} length={6} />
</Text>
</BaseWrapper>
</>
)
})}
</CommonBasesRow>
</StyledScrollarea>
</StyledTokenList>
</MobileWrapper>
) : null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,25 @@ export const AutoColumn = styled(AutoColumnUni)`
`}
`

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

${({ theme }) =>
theme.isInjectedWidgetMode &&
`
padding: 0 100px 0 10px;
flex-flow: row nowrap;
overflow-x: scroll;
`}

${({ theme }) => theme.mediaWidth.upToSmall`
padding: 0 100px 0 10px;
flex-flow: row nowrap;
overflow-x: scroll;
`}
`

export const MobileWrapper = styled(AutoColumn)<{ showOverflow?: boolean }>`
Expand All @@ -59,23 +71,18 @@ export const MobileWrapper = styled(AutoColumn)<{ showOverflow?: boolean }>`
margin: auto;
}
`}

overflow-y: auto; // fallback for 'overlay'
overflow-y: overlay;
max-height: 135px;
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;
padding: 6px 8px;
align-items: center;
color: ${({ theme, disable }) => disable && theme.text3};
background-color: ${({ theme, disable }) => disable && theme.bg3};
filter: ${({ disable }) => disable && 'grayscale(1)'};
flex: 0 0 calc(33% - 8px);
flex: 0 1 auto;
justify-content: center;

&:hover {
Expand Down
2 changes: 1 addition & 1 deletion apps/cowswap-frontend/src/legacy/theme/baseTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ export const UniThemedGlobalStyle = css`
color: var(${UI.COLOR_TEXT1});
}
body {
min-height: 100vh;
min-height: ${({ theme }) => (theme.isInjectedWidgetMode ? 'auto' : '100vh')};
scrollbar-color: ${({ theme }) => theme.colorScrollbar};
}
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const AppWrapper = styled.div<Partial<CSS.Properties>>`
display: flex;
flex-flow: column;
align-items: flex-start;
min-height: 100vh;
height: 100vh;
min-height: ${({ theme }) => (theme.isInjectedWidgetMode ? '400px' : '100vh')};
height: ${({ theme }) => (theme.isInjectedWidgetMode ? 'initial' : '100vh')};
`

export const HeaderWrapper = styled.div`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export function OrdersTableContainer({
pendingActivities,
ordersPermitStatus,
}: OrdersProps) {

const content = () => {
if (!isWalletConnected) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function Web3StatusInner(props: Web3StatusInnerProps) {
return (
<Web3StatusConnected id="web3-status-connected" pending={hasPendingTransactions}>
{hasPendingTransactions ? (
<RowBetween>
<RowBetween gap={'6px'}>
<FollowPendingTxPopup>
<Text>
<Trans>{pendingCount} Pending</Trans>
Expand Down
27 changes: 0 additions & 27 deletions apps/cowswap-frontend/src/utils/iframeResizer.ts

This file was deleted.

3 changes: 1 addition & 2 deletions apps/widget-configurator/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Box from '@mui/material/Box'
import { Configurator } from './configurator'
import { Theme } from '@mui/material/styles';
import { Theme } from '@mui/material/styles'

const WrapperStyled = (theme: Theme) => ({
display: 'flex',
flexDirection: 'column',
height: '100%',
width: '100%',
background: theme.palette.cow.background,
})

export function App() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// TODO: Move this to libs/common-utils/src/iframeResizer.ts as a helper function
// Adding the file here to avoid TS errors around environment variables

import { useEffect } from 'react'

interface IframeResizerProps {
iframeId: string
originCheck?: string
}

// A utility function to adjust iframe height based on postMessage from iframe content.
export function AttachIframeResizer({ iframeId, originCheck }: IframeResizerProps) {
useEffect(() => {
const iframeElement = document.getElementById(iframeId)

if (!iframeElement) {
console.error(`No iframe found with ID: ${iframeId}`)
return
}

const handleMessage = (event: MessageEvent) => {
// If an originCheck is provided, validate against it
if (originCheck && event.origin !== originCheck) return

const data = event.data

// Validate the data format and type before processing it
if (
typeof data === 'object' &&
data.type === 'iframeHeight' &&
Object.prototype.hasOwnProperty.call(data, 'height')
) {
console.log('got iframeHeight ====>', data.height)
iframeElement.style.height = 'auto' // Reset the iframe's height
iframeElement.style.height = `${data.height}px` // Adjust the height based on the content
}
}

window.addEventListener('message', handleMessage)

// Cleanup: Remove the event listener when the component is unmounted
return () => {
window.removeEventListener('message', handleMessage)
}
}, [iframeId, originCheck])

return null
}
19 changes: 14 additions & 5 deletions apps/widget-configurator/src/app/configurator/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react'
import { AttachIframeResizer } from './attachIframeResizer'
import { ColorModeContext } from '../../main'
// import { useTheme } from '@mui/material/styles'
import Box from '@mui/material/Box'
Expand Down Expand Up @@ -41,7 +42,12 @@ const TradeModeOptions = [
{ label: 'TWAP', value: TradeMode.TWAP },
]

const NetworkOptions = [
type NetworkOption = {
chainID: number
label: string
}

const NetworkOptions: NetworkOption[] = [
{ chainID: 1, label: 'Ethereum' },
{ chainID: 100, label: 'Gnosis Chain' },
]
Expand Down Expand Up @@ -169,7 +175,7 @@ export function Configurator({ title }: { title: string }) {
onChange={(event: SyntheticEvent, newValue: { chainID: number; label: string } | null) => {
setNetwork(newValue || NetworkOptions[0])
}}
getOptionLabel={(option) => option.label}
getOptionLabel={(option: { chainID: number; label: string }) => option.label}
id="controllable-states-network"
options={NetworkOptions}
size="small"
Expand All @@ -184,7 +190,7 @@ export function Configurator({ title }: { title: string }) {
setSellToken(newValue)
}}
inputValue={sellToken || ''}
onInputChange={(event, newInputValue) => {
onInputChange={(event: React.ChangeEvent<unknown>, newInputValue: string) => {
setSellToken(newInputValue)
}}
id="controllable-states-selling-token"
Expand All @@ -197,7 +203,7 @@ export function Configurator({ title }: { title: string }) {
id="input-sellTokenAmount"
label="Sell amount"
value={sellTokenAmount}
onChange={(e) => setSellTokenAmount(Number(e.target.value))}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSellTokenAmount(Number(e.target.value))}
size="small"
/>

Expand Down Expand Up @@ -235,7 +241,7 @@ export function Configurator({ title }: { title: string }) {
</Drawer>

<Box sx={ContentStyled}>
<iframe src={iframeURL} width="400px" height="640px" title="widget" />
<iframe id="cow-widget" src={iframeURL} width="400px" height="640px" title="widget" />

<Box
sx={{
Expand All @@ -245,12 +251,15 @@ export function Configurator({ title }: { title: string }) {
alignItems: 'center',
margin: '1.6rem 0 0',
gap: '2.4rem',
width: '100%',
}}
>
<Typography variant="body2">URL: {iframeURL}</Typography>
<EmbedDialog />
</Box>
</Box>

<AttachIframeResizer iframeId={'cow-widget'} />
</Box>
)
}
17 changes: 8 additions & 9 deletions apps/widget-configurator/src/app/configurator/styled.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Theme } from '@mui/material/styles';
import { Theme } from '@mui/material/styles'

export const WrapperStyled = { display: 'flex', flexFlow: 'column wrap', width: '100%' }

export const DrawerStyled = (theme: Theme) => ({
width: '29rem',
Expand All @@ -15,23 +17,20 @@ export const DrawerStyled = (theme: Theme) => ({
boxShadow: 'rgba(5, 43, 101, 0.06) 0 1.2rem 1.2rem',
padding: '1.6rem',
},
});
})

export const ContentStyled = {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
flexFlow: 'column wrap',
height: '100%',
width: 'auto',
flexFlow: 'column',
flex: '1 1 auto',
margin: '4.2rem auto',

'& > iframe': {
'> iframe': {
border: 0,
margin: '0 auto',
borderRadius: '1.6rem',
overflow: 'hidden',
overflow: 'auto',
},
}

export const WrapperStyled = { display: 'flex', flexFlow: 'row wrap', height: '100vh', width: '100%' }
Loading
Loading