Skip to content

Commit

Permalink
feat: widget skeleton (#3393)
Browse files Browse the repository at this point in the history
  • Loading branch information
fairlighteth authored and anxolin committed Nov 17, 2023
1 parent c07a25f commit af1add9
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 49 deletions.
134 changes: 130 additions & 4 deletions apps/cowswap-frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@
<meta name="twitter:site" content="@CoWSwap" />
<meta name="twitter:title" content="CoW Swap | The smartest way to trade cryptocurrencies" />
<meta name="twitter:image" content="https://swap.cow.fi/images/og-meta-cowswap.png?v=3" />

</head>

<body>
<noscript>
<style>
main {
max-width: 35em;
max-width: 350px;
margin: 0 auto;
}

Expand All @@ -51,9 +50,9 @@
}

.banner {
padding: 1em;
padding: 10px;
background-color: #fdfda8;
border-radius: 0.5em;
border-radius: 16px;
}
</style>
<main>
Expand All @@ -75,6 +74,133 @@
</ul>
</main>
</noscript>

<style>
#skeleton {
--borderRadius: 24px;
--containerBG: #fff;
--colorGrey: #ecf1f8;
--colorBorder: rgb(236 241 248);
--colorBlue: #052b65;
--colorShimmerColor1: rgba(236, 241, 248, 0) 0;
--colorShimmerColor2: rgba(236, 241, 248, 0.2) 20%;
--colorShimmerColor3: rgba(255, 255, 255, 0.5) 50%;
--colorShimmerColor4: rgba(236, 241, 248, 0.2) 80%;
--colorShimmerColor5: rgba(236, 241, 248, 0) 100%;
--colorShimmer: linear-gradient(
90deg,
var(--colorShimmerColor1),
var(--colorShimmerColor2),
var(--colorShimmerColor3),
var(--colorShimmerColor4),
var(--colorShimmerColor5)
);
display: flex;
justify-content: center;
align-items: center;
width: 100%;
margin: 16px auto 0;
flex-flow: column wrap;
}

@media (prefers-color-scheme: dark) {
#skeleton {
--colorBorder: rgb(236 241 248 / 15%);
--colorShimmerColor1: rgba(236, 241, 248, 0) 0;
--colorShimmerColor2: rgba(236, 241, 248, 0.1) 20%;
--colorShimmerColor3: rgba(255, 255, 255, 0.2) 50%;
--colorShimmerColor4: rgba(236, 241, 248, 0.1) 80%;
--colorShimmerColor5: rgba(236, 241, 248, 0) 100%;
}
}

#swap-skeleton {
display: flex;
width: 100%;
max-width: 470px;
border-radius: var(--borderRadius);
height: 400px;
}

.cowprotocol-logo {
display: block;
height: 80px;
width: 80px;
object-fit: contain;
margin: auto;
animation: pulse 1s infinite ease-in-out;
transform-style: preserve-3d;
backface-visibility: visible;
opacity: 0.5;
z-index: 5;
}

@media (prefers-color-scheme: light) {
.cowprotocol-logo {
background: url('/images/cowprotocol-dark.svg') no-repeat 100% / contain;
}
}

@media (prefers-color-scheme: dark) {
.cowprotocol-logo {
background: url('/images/cowprotocol-light.svg') no-repeat 100% / contain;
}
}

@keyframes pulse {
0% {
transform: scale(1);
}
20% {
transform: scale(1.05);
}
30% {
transform: scale(1);
}
40% {
transform: scale(1.05);
}
50% {
transform: scale(1);
}
100% {
transform: scale(1);
}
}

.skeleton-box {
display: inline-block;
height: 100%;
position: relative;
overflow: hidden;
border: 1px solid var(--colorBorder);
}

.skeleton-box::after {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
transform: translateX(-100%);
background-image: var(--colorShimmer);
animation: shimmer 2s infinite;
content: '';
}

@keyframes shimmer {
100% {
transform: translateX(100%);
}
}
</style>

<div id="skeleton">
<div id="swap-skeleton" class="skeleton-box">
<span class="cowprotocol-logo"></span>
</div>
</div>

<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
Expand Down
1 change: 1 addition & 0 deletions apps/cowswap-frontend/public/images/cowprotocol-dark.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/public/images/cowprotocol-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 57 additions & 41 deletions apps/cowswap-frontend/src/cow-react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'inter-ui'
import '@cowprotocol/analytics'
import './sentry'
import { Provider as AtomProvider } from 'jotai'
import { StrictMode } from 'react'
import { useEffect, StrictMode } from 'react'

import { BlockNumberProvider } from '@cowprotocol/common-hooks'
import { isInjectedWidget } from '@cowprotocol/common-utils'
Expand Down Expand Up @@ -41,46 +41,62 @@ if (window.ethereum) {
window.ethereum.autoRefreshOnNetworkChange = false
}

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

root.render(
<StrictMode>
<FixedGlobalStyle />
<Provider store={cowSwapStore}>
<AtomProvider store={jotaiStore}>
<HashRouter>
<LanguageProvider>
<Web3Provider>
<ThemeProvider>
<ThemedGlobalStyle />
<WalletUnsupportedNetworkBanner />
<BlockNumberProvider>
<WithLDProvider>
<Updaters />

{!isInjectedWidgetMode && (
<>
<FeatureGuard featureFlag="cowFortuneEnabled">
<FortuneWidget />
</FeatureGuard>
<AppziButton />
</>
)}

<Popups />
<SnackbarsWidget />
<App />
</WithLDProvider>
</BlockNumberProvider>
</ThemeProvider>
</Web3Provider>
</LanguageProvider>
</HashRouter>
</AtomProvider>
</Provider>
</StrictMode>
)
function Main() {
const isInjectedWidgetMode = isInjectedWidget()

useEffect(() => {
const skeleton = document.getElementById('skeleton')
if (skeleton) {
skeleton.parentNode?.removeChild(skeleton)
}
}, [])

return (
<StrictMode>
<FixedGlobalStyle />
<Provider store={cowSwapStore}>
<AtomProvider store={jotaiStore}>
<HashRouter>
<LanguageProvider>
<Web3Provider>
<ThemeProvider>
<ThemedGlobalStyle />
<WalletUnsupportedNetworkBanner />
<BlockNumberProvider>
<WithLDProvider>
<Updaters />

{!isInjectedWidgetMode && (
<>
<FeatureGuard featureFlag="cowFortuneEnabled">
<FortuneWidget />
</FeatureGuard>
<AppziButton />
</>
)}

<Popups />
<SnackbarsWidget />
<App />
</WithLDProvider>
</BlockNumberProvider>
</ThemeProvider>
</Web3Provider>
</LanguageProvider>
</HashRouter>
</AtomProvider>
</Provider>
</StrictMode>
)
}

const container = document.getElementById('root')
if (container !== null) {
const root = createRoot(container)
root.render(<Main />)
} else {
console.error('Failed to find the root element')
}

if (process.env.REACT_APP_SERVICE_WORKER !== 'false') {
serviceWorkerRegistration.register()
Expand Down
6 changes: 5 additions & 1 deletion apps/widget-configurator/src/app/embedDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@ export function EmbedDialog({ params, open, handleClose }: EmbedDialogProps) {
<Tabs
value={currentTab}
onChange={(event: SyntheticEvent, newValue: number) => setCurrentTab(newValue)}
aria-label="basic tabs example"
aria-label="configuration tabs"
sx={{
'& .MuiTab-iconWrapper': {
height: '16px',
width: '16px',
opacity: 0.75,
},
'& .Mui-selected .MuiTab-iconWrapper': {
opacity: 1,
},
}}
>
Expand Down
2 changes: 1 addition & 1 deletion libs/assets/src/cow-swap/html.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 libs/assets/src/cow-swap/js.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

2 comments on commit af1add9

@vercel
Copy link

@vercel vercel bot commented on af1add9 Nov 17, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on af1add9 Nov 17, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

cosmos – ./

cosmos-git-main-cowswap.vercel.app
cosmos.cow.fi
cowswap-seven.vercel.app
cosmos-cowswap.vercel.app

Please sign in to comment.