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

refactor: refactor widget configurator #3259

Merged
merged 51 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
51 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
7994ebf
refactor: split main.ts
shoom3301 Oct 21, 2023
913383a
refactor: use common linter config for configurator
shoom3301 Oct 21, 2023
42b3ed2
refactor: split general controls
shoom3301 Oct 21, 2023
4e34ae1
refactor: extract CurrencyInputControl
shoom3301 Oct 21, 2023
fd4896f
refactor: update EmbedDialog
shoom3301 Oct 21, 2023
d822f5f
chore: fix lint and tests
shoom3301 Oct 23, 2023
5526243
chore: fix build
shoom3301 Oct 23, 2023
b7bafa7
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 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
123 changes: 123 additions & 0 deletions .eslintrc-common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nx", "unused-imports"],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"no-prototype-builtins": "off",
"react/jsx-no-useless-fragment": "off",
"no-irregular-whitespace": "off",
"no-case-declarations": "off",
"no-dupe-else-if": "off",
"jsx-a11y/accessible-emoji": "off",
"no-async-promise-executor": "off",
"no-constant-condition": "off",
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "ethers",
"message": "Please import from '@ethersproject/module' directly to support tree-shaking."
},
{
"name": "styled-components",
"message": "Please import from styled-components/macro."
}
],
"patterns": [
{
"group": ["**/dist"],
"message": "Do not import from dist/ - this is an implementation detail, and breaks tree-shaking."
},
{
"group": ["!styled-components/macro"]
}
]
}
],
"no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"error",
{
"vars": "all",
"varsIgnorePattern": "^_",
"args": "after-used",
"argsIgnorePattern": "^_"
}
],
"import/order": [
"error",
{
"pathGroups": [
{
"pattern": "{react,jotai,jotai/*}",
"group": "external",
"position": "before"
},
{
"pattern": "{@cowprotocol,@cowprotocol,@uniswap,@safe-global,@ethersproject,@web3-react}/**",
"group": "external",
"position": "before"
},
{
"pattern": "legacy/**",
"group": "external",
"position": "after"
},
{
"pattern": "modules/**",
"group": "builtin",
"position": "after"
},
{
"pattern": "{api,abis,common,constants,legacy,lib,pages,types,utils}/**",
"group": "internal",
"position": "before"
}
],
"pathGroupsExcludedImportTypes": ["react"],
"groups": ["external", "builtin", "internal", "sibling", "parent", "object", "index", "type"],
"alphabetize": {
"order": "asc",
"caseInsensitive": true
},
"newlines-between": "always"
}
],
"prefer-const": "error",
"no-unneeded-ternary": "error",
"no-var": "error"
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nx/javascript"],
"rules": {}
}
]
}
90 changes: 2 additions & 88 deletions apps/cowswap-frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,94 +1,8 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"extends": ["plugin:@nx/react", "../../.eslintrc-common.json"],
"ignorePatterns": ["!**/*", "public/cosmos/*", "dev-dist/*"],
"plugins": ["unused-imports"],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"no-prototype-builtins": "off",
"react/jsx-no-useless-fragment": "off",
"no-irregular-whitespace": "off",
"no-case-declarations": "off",
"no-dupe-else-if": "off",
"jsx-a11y/accessible-emoji": "off",
"no-async-promise-executor": "off",
"no-constant-condition": "off",
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "ethers",
"message": "Please import from '@ethersproject/module' directly to support tree-shaking."
},
{
"name": "styled-components",
"message": "Please import from styled-components/macro."
}
],
"patterns": [
{
"group": ["**/dist"],
"message": "Do not import from dist/ - this is an implementation detail, and breaks tree-shaking."
},
{
"group": ["!styled-components/macro"]
}
]
}
],
"no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"error",
{
"vars": "all",
"varsIgnorePattern": "^_",
"args": "after-used",
"argsIgnorePattern": "^_"
}
],
"import/order": [
"error",
{
"pathGroups": [
{
"pattern": "{react,jotai,jotai/*}",
"group": "external",
"position": "before"
},
{
"pattern": "{@cowprotocol,@cowprotocol,@uniswap,@safe-global,@ethersproject,@web3-react}/**",
"group": "external",
"position": "before"
},
{
"pattern": "legacy/**",
"group": "external",
"position": "after"
},
{
"pattern": "modules/**",
"group": "builtin",
"position": "after"
},
{
"pattern": "{api,abis,common,constants,legacy,lib,pages,types,utils}/**",
"group": "internal",
"position": "before"
}
],
"pathGroupsExcludedImportTypes": ["react"],
"groups": ["external", "builtin", "internal", "sibling", "parent", "object", "index", "type"],
"alphabetize": {
"order": "asc",
"caseInsensitive": true
},
"newlines-between": "always"
}
],
"prefer-const": "error",
"no-unneeded-ternary": "error",
"no-var": "error"
"@typescript-eslint/no-explicit-any": "off"
},
"overrides": [
{
Expand Down
3 changes: 1 addition & 2 deletions apps/cowswap-frontend/src/common/updaters/ListsUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ export function ListsUpdater(): null {
throw new Error('unexpected no version bump')
case VersionUpgrade.PATCH:
case VersionUpgrade.MINOR:
const min = minVersionBump(list.current.tokens, list.pendingUpdate.tokens)
// automatically update minor/patch as long as bump matches the min update
if (bump >= min) {
if (bump >= minVersionBump(list.current.tokens, list.pendingUpdate.tokens)) {
dispatch(acceptListUpdate({ chainId, url: listUrl }))
} else {
console.error(
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
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 @@ -7,20 +7,23 @@ enum ValidationSchema {
TOKENS = 'tokens',
}

const validator = new Promise<Ajv>(async (resolve) => {
const [ajv, schema] = await Promise.all([import('ajv'), import('@uniswap/token-lists/src/tokenlist.schema.json')])
const validator = new ajv.default({ allErrors: true })
.addSchema(schema, ValidationSchema.LIST)
// Adds a meta scheme of Pick<TokenList, 'tokens'>
.addSchema(
{
...schema,
$id: schema.$id + '#tokens',
required: ['tokens'],
},
ValidationSchema.TOKENS
)
resolve(validator)
const validator = new Promise<Ajv>((resolve) => {
Promise.all([import('ajv'), import('@uniswap/token-lists/src/tokenlist.schema.json')]).then((res) => {
const [ajv, schema] = res

const validator = new ajv.default({ allErrors: true })
.addSchema(schema, ValidationSchema.LIST)
// Adds a meta scheme of Pick<TokenList, 'tokens'>
.addSchema(
{
...schema,
$id: schema.$id + '#tokens',
required: ['tokens'],
},
ValidationSchema.TOKENS
)
resolve(validator)
})
})

function getValidationErrors(validate: ValidateFunction | undefined): string {
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.

2 changes: 1 addition & 1 deletion apps/widget-configurator/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"extends": ["plugin:@nx/react", "../../.eslintrc-common.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
Expand Down
24 changes: 24 additions & 0 deletions apps/widget-configurator/src/app/WidgetIframe/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Box from '@mui/material/Box'
import Typography from '@mui/material/Typography'

import { ContentStyled, IframeInfo } from './styled'

import { EmbedDialog } from '../configurator/embedDialog'

export interface WidgetIframeProps {
id: string
src: string
}

export function WidgetIframe({ id, src }: WidgetIframeProps) {
return (
<Box sx={ContentStyled}>
<iframe id={id} src={src} width="400px" height="640px" title="widget" />

<Box sx={IframeInfo}>
<Typography variant="body2">URL: {src}</Typography>
<EmbedDialog iframeUrl={src} />
</Box>
</Box>
)
}
Loading
Loading