Skip to content

Commit

Permalink
Merge pull request #4976 from cowprotocol/release/2024-10-10
Browse files Browse the repository at this point in the history
chore(release): 2024 10 10
  • Loading branch information
alfetopito authored Oct 10, 2024
2 parents 3bf24c7 + 64e58c6 commit 5c70d49
Show file tree
Hide file tree
Showing 121 changed files with 2,533 additions and 912 deletions.
103 changes: 40 additions & 63 deletions apps/cow-fi/next-sitemap.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,100 +20,77 @@ module.exports = {
transform: async (config, url) => {
// Handle /learn/* pages with lastmod from CMS
if (url.startsWith('/learn/')) {
const articles = await getAllArticleSlugsWithDates()
const article = articles.find(({ slug }) => `/learn/${slug}` === url)
if (article) {
return {
loc: url,
changefreq: 'weekly',
priority: 0.6,
lastmod: article.lastModified,
try {
console.log(`Transforming learn page: ${url}`)
const articles = await getAllArticleSlugsWithDates()
const article = articles.find(({ slug }) => `/learn/${slug}` === url)

if (article) {
console.log(`Found matching article for ${url}`)
return {
loc: url,
changefreq: config.changefreq,
priority: config.priority,
lastmod: article.updatedAt,
}
} else {
console.log(`No matching article found for ${url}`)
}
} catch (error) {
console.error(`Error processing ${url}:`, error)
}
}

// Handle /tokens/* pages
if (url.startsWith('/tokens/')) {
return {
loc: url,
changefreq: 'daily',
priority: 0.6,
lastmod: new Date().toISOString(), // Assume updated daily
}
}

// Default transformation for all other pages
console.log(`Applying default transformation for: ${url}`)
return {
loc: url,
changefreq: 'weekly',
priority: 0.5,
changefreq: config.changefreq,
priority: config.priority,
lastmod: new Date().toISOString(),
}
},
}

/**
* Function to fetch all article slugs with lastModified dates from the CMS API
* Implements caching to avoid redundant network requests
* Implements pagination to fetch all pages of articles
*/
async function getAllArticleSlugsWithDates() {
// Check if articles are already cached
if (getAllArticleSlugsWithDates.cachedArticles) {
return getAllArticleSlugsWithDates.cachedArticles
}

const articles = []
const cmsBaseUrl = process.env.NEXT_PUBLIC_CMS_BASE_URL || 'https://cms.cow.fi/api'
const cmsApiUrl = `${cmsBaseUrl}/articles`

let allArticles = []
let page = 1
const pageSize = 100
let totalPages = 1
let hasMorePages = true

while (page <= totalPages) {
while (hasMorePages) {
try {
console.log(`Fetching page ${page} of articles from CMS...`)

const params = new URLSearchParams({
'query[fields]': 'slug,updatedAt', // Fetch both slug and updatedAt
'query[pagination][page]': page,
'query[pagination][pageSize]': pageSize,
})

const response = await fetch(`${cmsApiUrl}?${params.toString()}`, {
headers: {
// Include Authorization header if required
// Authorization: `Bearer ${process.env.CMS_API_KEY}`,
},
})
const url = `${cmsApiUrl}?pagination[page]=${page}&pagination[pageSize]=100`
console.log(`Fetching articles from: ${url}`)
const response = await fetch(url)

if (!response.ok) {
throw new Error(`Failed to fetch articles: ${response.statusText}`)
throw new Error(`HTTP error! status: ${response.status}`)
}

const data = await response.json()
const articles = data.data
allArticles = allArticles.concat(articles)

// Adjust based on your actual CMS API response structure
data.data.forEach((article) => {
articles.push({
slug: article.attributes.slug, // Ensure 'slug' is the correct field
lastModified: article.attributes.updatedAt, // Ensure 'updatedAt' is the correct field
})
})
console.log(`Fetched ${articles.length} articles from page ${page}`)

const pagination = data.meta.pagination
totalPages = pagination.pageCount
page += 1
// Check if there are more pages
hasMorePages = data.meta.pagination.page < data.meta.pagination.pageCount
page++
} catch (error) {
console.error('Error fetching articles for sitemap:', error)
throw error
hasMorePages = false // Stop trying if there's an error
}
}

console.log(`Total articles fetched: ${articles.length}`)

// Cache the fetched articles
getAllArticleSlugsWithDates.cachedArticles = articles
console.log(`Total articles fetched: ${allArticles.length}`)

return articles
return allArticles.map((article) => ({
slug: article.attributes.slug,
updatedAt: article.attributes.updatedAt,
}))
}
31 changes: 24 additions & 7 deletions apps/cow-fi/pages/cow-swap.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'react'
import { useEffect, useRef } from 'react'

import { GetStaticProps } from 'next'
import { Color, ProductLogo, ProductVariant } from '@cowprotocol/ui'
Expand Down Expand Up @@ -49,12 +49,29 @@ interface PageProps {
}

export default function Page({ tweets }: PageProps) {
// Load Twitter script
const tweetSectionRef = useRef<HTMLDivElement>(null)

useEffect(() => {
const script = document.createElement('script')
script.src = 'https://platform.twitter.com/widgets.js'
script.async = true
document.head.appendChild(script)
const observer = new IntersectionObserver(
(entries) => {
if (entries[0].isIntersecting) {
const script = document.createElement('script')
script.src = 'https://platform.twitter.com/widgets.js'
script.async = true
document.head.appendChild(script)
observer.disconnect()
}
},
{ rootMargin: '100px' },
)

if (tweetSectionRef.current) {
observer.observe(tweetSectionRef.current)
}

return () => {
observer.disconnect()
}
}, [])

return (
Expand Down Expand Up @@ -341,7 +358,7 @@ export default function Page({ tweets }: PageProps) {
</ContainerCardSection>
</ContainerCard>

<ContainerCard bgColor={'transparent'}>
<ContainerCard bgColor={'transparent'} ref={tweetSectionRef}>
<ContainerCardSection>
<SectionTitleWrapper maxWidth={1100}>
<SectionTitleText textAlign="center">Don't take our word for it</SectionTitleText>
Expand Down
14 changes: 7 additions & 7 deletions apps/cowswap-frontend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
# To set your own `AppData`, change `REACT_APP_FULL_APP_DATA_<environment>`

# AppData, build yours at https://explorer.cow.fi/appdata
REACT_APP_FULL_APP_DATA_PRODUCTION='{"version":"1.2.0","appCode":"CoW Swap","environment":"production","metadata":{}}'
REACT_APP_FULL_APP_DATA_ENS='{"version":"1.2.0","appCode":"CoW Swap","environment":"ens","metadata":{}}'
REACT_APP_FULL_APP_DATA_BARN='{"version":"1.2.0","appCode":"CoW Swap","environment":"barn","metadata":{}}'
REACT_APP_FULL_APP_DATA_STAGING='{"version":"1.2.0","appCode":"CoW Swap","environment":"staging","metadata":{}}'
REACT_APP_FULL_APP_DATA_PR='{"version":"1.2.0","appCode":"CoW Swap","environment":"pr","metadata":{}}'
REACT_APP_FULL_APP_DATA_DEVELOPMENT='{"version":"1.2.0","appCode":"CoW Swap","environment":"development","metadata":{}}'
REACT_APP_FULL_APP_DATA_LOCAL='{"version":"1.2.0","appCode":"CoW Swap","environment":"local","metadata":{}}'
REACT_APP_FULL_APP_DATA_PRODUCTION='{"version":"1.3.0","appCode":"CoW Swap","environment":"production","metadata":{}}'
REACT_APP_FULL_APP_DATA_ENS='{"version":"1.3.0","appCode":"CoW Swap","environment":"ens","metadata":{}}'
REACT_APP_FULL_APP_DATA_BARN='{"version":"1.3.0","appCode":"CoW Swap","environment":"barn","metadata":{}}'
REACT_APP_FULL_APP_DATA_STAGING='{"version":"1.3.0","appCode":"CoW Swap","environment":"staging","metadata":{}}'
REACT_APP_FULL_APP_DATA_PR='{"version":"1.3.0","appCode":"CoW Swap","environment":"pr","metadata":{}}'
REACT_APP_FULL_APP_DATA_DEVELOPMENT='{"version":"1.3.0","appCode":"CoW Swap","environment":"development","metadata":{}}'
REACT_APP_FULL_APP_DATA_LOCAL='{"version":"1.3.0","appCode":"CoW Swap","environment":"local","metadata":{}}'



Expand Down
1 change: 0 additions & 1 deletion apps/cowswap-frontend/public/emergency.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ if (window.location.pathname !== '/') {
for (let i = 0; i < version; i++) {
localStorage.removeItem(`${name}:v${i}`)
}
console.log(name, version)
})
})()

Expand Down
4 changes: 1 addition & 3 deletions apps/cowswap-frontend/src/api/cowProtocol/priceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function _getPriceStrategyApiBaseUrl(chainId: SupportedChainId): string {
new Error(
`Unsupported Network. The ${API_NAME} strategy API is not deployed in the Network ` +
chainId +
'. Defaulting to using Mainnet strategy.'
'. Defaulting to using Mainnet strategy.',
)
}
return baseUrl
Expand All @@ -34,8 +34,6 @@ function _fetchPriceStrategy(chainId: SupportedChainId): Promise<Response> {
}

export async function getPriceStrategy(chainId: SupportedChainId): Promise<PriceStrategy> {
console.log(`[api:${API_NAME}] Get GP price strategy for`, chainId)

const response = await _fetchPriceStrategy(chainId)

if (!response.ok) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { useState } from 'react'

import { HookToDappMatch } from '@cowprotocol/hook-dapp-lib'

import { ChevronDown, ChevronUp } from 'react-feather'

import { clickOnHooks } from 'modules/analytics'

import * as styledEl from './styled'

export function HookItem({ item, index }: { item: HookToDappMatch; index: number }) {
const [isOpen, setIsOpen] = useState(false)

const handleLinkClick = () => {
clickOnHooks(item.dapp?.name || 'Unknown hook dapp')
}

return (
<styledEl.HookItemWrapper as="li">
<styledEl.HookItemHeader onClick={() => setIsOpen(!isOpen)}>
<styledEl.HookItemInfo>
<styledEl.HookNumber>{index + 1}</styledEl.HookNumber>
{item.dapp ? (
<>
<img src={item.dapp.image} alt={item.dapp.name} />
<span>{item.dapp.name}</span>
</>
) : (
<span>Unknown hook dapp</span>
)}
</styledEl.HookItemInfo>
<styledEl.ToggleIcon isOpen={isOpen}>
{isOpen ? <ChevronUp size={16} /> : <ChevronDown size={16} />}
</styledEl.ToggleIcon>
</styledEl.HookItemHeader>
{isOpen && (
<styledEl.HookItemContent>
{item.dapp && (
<>
<p>
<b>Description:</b> {item.dapp.descriptionShort}
</p>
<p>
<b>Version:</b> {item.dapp.version}
</p>
<p>
<b>Website:</b>{' '}
<a href={item.dapp.website} target="_blank" rel="noopener noreferrer" onClick={handleLinkClick}>
{item.dapp.website}
</a>
</p>
</>
)}
<p>
<b>calldata:</b> {item.hook.callData}
</p>
<p>
<b>target:</b> {item.hook.target}
</p>
<p>
<b>gasLimit:</b> {item.hook.gasLimit}
</p>
</styledEl.HookItemContent>
)}
</styledEl.HookItemWrapper>
)
}
Loading

0 comments on commit 5c70d49

Please sign in to comment.