Skip to content

Commit 5c70d49

Browse files
authored
Merge pull request #4976 from cowprotocol/release/2024-10-10
chore(release): 2024 10 10
2 parents 3bf24c7 + 64e58c6 commit 5c70d49

File tree

121 files changed

+2533
-912
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+2533
-912
lines changed

apps/cow-fi/next-sitemap.config.js

Lines changed: 40 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,100 +20,77 @@ module.exports = {
2020
transform: async (config, url) => {
2121
// Handle /learn/* pages with lastmod from CMS
2222
if (url.startsWith('/learn/')) {
23-
const articles = await getAllArticleSlugsWithDates()
24-
const article = articles.find(({ slug }) => `/learn/${slug}` === url)
25-
if (article) {
26-
return {
27-
loc: url,
28-
changefreq: 'weekly',
29-
priority: 0.6,
30-
lastmod: article.lastModified,
23+
try {
24+
console.log(`Transforming learn page: ${url}`)
25+
const articles = await getAllArticleSlugsWithDates()
26+
const article = articles.find(({ slug }) => `/learn/${slug}` === url)
27+
28+
if (article) {
29+
console.log(`Found matching article for ${url}`)
30+
return {
31+
loc: url,
32+
changefreq: config.changefreq,
33+
priority: config.priority,
34+
lastmod: article.updatedAt,
35+
}
36+
} else {
37+
console.log(`No matching article found for ${url}`)
3138
}
39+
} catch (error) {
40+
console.error(`Error processing ${url}:`, error)
3241
}
3342
}
3443

35-
// Handle /tokens/* pages
36-
if (url.startsWith('/tokens/')) {
37-
return {
38-
loc: url,
39-
changefreq: 'daily',
40-
priority: 0.6,
41-
lastmod: new Date().toISOString(), // Assume updated daily
42-
}
43-
}
44-
45-
// Default transformation for all other pages
44+
console.log(`Applying default transformation for: ${url}`)
4645
return {
4746
loc: url,
48-
changefreq: 'weekly',
49-
priority: 0.5,
47+
changefreq: config.changefreq,
48+
priority: config.priority,
5049
lastmod: new Date().toISOString(),
5150
}
5251
},
5352
}
5453

5554
/**
5655
* Function to fetch all article slugs with lastModified dates from the CMS API
57-
* Implements caching to avoid redundant network requests
56+
* Implements pagination to fetch all pages of articles
5857
*/
5958
async function getAllArticleSlugsWithDates() {
60-
// Check if articles are already cached
61-
if (getAllArticleSlugsWithDates.cachedArticles) {
62-
return getAllArticleSlugsWithDates.cachedArticles
63-
}
64-
65-
const articles = []
6659
const cmsBaseUrl = process.env.NEXT_PUBLIC_CMS_BASE_URL || 'https://cms.cow.fi/api'
6760
const cmsApiUrl = `${cmsBaseUrl}/articles`
68-
61+
let allArticles = []
6962
let page = 1
70-
const pageSize = 100
71-
let totalPages = 1
63+
let hasMorePages = true
7264

73-
while (page <= totalPages) {
65+
while (hasMorePages) {
7466
try {
75-
console.log(`Fetching page ${page} of articles from CMS...`)
76-
77-
const params = new URLSearchParams({
78-
'query[fields]': 'slug,updatedAt', // Fetch both slug and updatedAt
79-
'query[pagination][page]': page,
80-
'query[pagination][pageSize]': pageSize,
81-
})
82-
83-
const response = await fetch(`${cmsApiUrl}?${params.toString()}`, {
84-
headers: {
85-
// Include Authorization header if required
86-
// Authorization: `Bearer ${process.env.CMS_API_KEY}`,
87-
},
88-
})
67+
const url = `${cmsApiUrl}?pagination[page]=${page}&pagination[pageSize]=100`
68+
console.log(`Fetching articles from: ${url}`)
69+
const response = await fetch(url)
8970

9071
if (!response.ok) {
91-
throw new Error(`Failed to fetch articles: ${response.statusText}`)
72+
throw new Error(`HTTP error! status: ${response.status}`)
9273
}
9374

9475
const data = await response.json()
76+
const articles = data.data
77+
allArticles = allArticles.concat(articles)
9578

96-
// Adjust based on your actual CMS API response structure
97-
data.data.forEach((article) => {
98-
articles.push({
99-
slug: article.attributes.slug, // Ensure 'slug' is the correct field
100-
lastModified: article.attributes.updatedAt, // Ensure 'updatedAt' is the correct field
101-
})
102-
})
79+
console.log(`Fetched ${articles.length} articles from page ${page}`)
10380

104-
const pagination = data.meta.pagination
105-
totalPages = pagination.pageCount
106-
page += 1
81+
// Check if there are more pages
82+
hasMorePages = data.meta.pagination.page < data.meta.pagination.pageCount
83+
page++
10784
} catch (error) {
10885
console.error('Error fetching articles for sitemap:', error)
109-
throw error
86+
hasMorePages = false // Stop trying if there's an error
11087
}
11188
}
11289

113-
console.log(`Total articles fetched: ${articles.length}`)
114-
115-
// Cache the fetched articles
116-
getAllArticleSlugsWithDates.cachedArticles = articles
90+
console.log(`Total articles fetched: ${allArticles.length}`)
11791

118-
return articles
92+
return allArticles.map((article) => ({
93+
slug: article.attributes.slug,
94+
updatedAt: article.attributes.updatedAt,
95+
}))
11996
}

apps/cow-fi/pages/cow-swap.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect } from 'react'
1+
import { useEffect, useRef } from 'react'
22

33
import { GetStaticProps } from 'next'
44
import { Color, ProductLogo, ProductVariant } from '@cowprotocol/ui'
@@ -49,12 +49,29 @@ interface PageProps {
4949
}
5050

5151
export default function Page({ tweets }: PageProps) {
52-
// Load Twitter script
52+
const tweetSectionRef = useRef<HTMLDivElement>(null)
53+
5354
useEffect(() => {
54-
const script = document.createElement('script')
55-
script.src = 'https://platform.twitter.com/widgets.js'
56-
script.async = true
57-
document.head.appendChild(script)
55+
const observer = new IntersectionObserver(
56+
(entries) => {
57+
if (entries[0].isIntersecting) {
58+
const script = document.createElement('script')
59+
script.src = 'https://platform.twitter.com/widgets.js'
60+
script.async = true
61+
document.head.appendChild(script)
62+
observer.disconnect()
63+
}
64+
},
65+
{ rootMargin: '100px' },
66+
)
67+
68+
if (tweetSectionRef.current) {
69+
observer.observe(tweetSectionRef.current)
70+
}
71+
72+
return () => {
73+
observer.disconnect()
74+
}
5875
}, [])
5976

6077
return (
@@ -341,7 +358,7 @@ export default function Page({ tweets }: PageProps) {
341358
</ContainerCardSection>
342359
</ContainerCard>
343360

344-
<ContainerCard bgColor={'transparent'}>
361+
<ContainerCard bgColor={'transparent'} ref={tweetSectionRef}>
345362
<ContainerCardSection>
346363
<SectionTitleWrapper maxWidth={1100}>
347364
<SectionTitleText textAlign="center">Don't take our word for it</SectionTitleText>

apps/cowswap-frontend/.env

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
# To set your own `AppData`, change `REACT_APP_FULL_APP_DATA_<environment>`
5757

5858
# AppData, build yours at https://explorer.cow.fi/appdata
59-
REACT_APP_FULL_APP_DATA_PRODUCTION='{"version":"1.2.0","appCode":"CoW Swap","environment":"production","metadata":{}}'
60-
REACT_APP_FULL_APP_DATA_ENS='{"version":"1.2.0","appCode":"CoW Swap","environment":"ens","metadata":{}}'
61-
REACT_APP_FULL_APP_DATA_BARN='{"version":"1.2.0","appCode":"CoW Swap","environment":"barn","metadata":{}}'
62-
REACT_APP_FULL_APP_DATA_STAGING='{"version":"1.2.0","appCode":"CoW Swap","environment":"staging","metadata":{}}'
63-
REACT_APP_FULL_APP_DATA_PR='{"version":"1.2.0","appCode":"CoW Swap","environment":"pr","metadata":{}}'
64-
REACT_APP_FULL_APP_DATA_DEVELOPMENT='{"version":"1.2.0","appCode":"CoW Swap","environment":"development","metadata":{}}'
65-
REACT_APP_FULL_APP_DATA_LOCAL='{"version":"1.2.0","appCode":"CoW Swap","environment":"local","metadata":{}}'
59+
REACT_APP_FULL_APP_DATA_PRODUCTION='{"version":"1.3.0","appCode":"CoW Swap","environment":"production","metadata":{}}'
60+
REACT_APP_FULL_APP_DATA_ENS='{"version":"1.3.0","appCode":"CoW Swap","environment":"ens","metadata":{}}'
61+
REACT_APP_FULL_APP_DATA_BARN='{"version":"1.3.0","appCode":"CoW Swap","environment":"barn","metadata":{}}'
62+
REACT_APP_FULL_APP_DATA_STAGING='{"version":"1.3.0","appCode":"CoW Swap","environment":"staging","metadata":{}}'
63+
REACT_APP_FULL_APP_DATA_PR='{"version":"1.3.0","appCode":"CoW Swap","environment":"pr","metadata":{}}'
64+
REACT_APP_FULL_APP_DATA_DEVELOPMENT='{"version":"1.3.0","appCode":"CoW Swap","environment":"development","metadata":{}}'
65+
REACT_APP_FULL_APP_DATA_LOCAL='{"version":"1.3.0","appCode":"CoW Swap","environment":"local","metadata":{}}'
6666

6767

6868

apps/cowswap-frontend/public/emergency.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ if (window.location.pathname !== '/') {
4646
for (let i = 0; i < version; i++) {
4747
localStorage.removeItem(`${name}:v${i}`)
4848
}
49-
console.log(name, version)
5049
})
5150
})()
5251

apps/cowswap-frontend/src/api/cowProtocol/priceApi.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function _getPriceStrategyApiBaseUrl(chainId: SupportedChainId): string {
2222
new Error(
2323
`Unsupported Network. The ${API_NAME} strategy API is not deployed in the Network ` +
2424
chainId +
25-
'. Defaulting to using Mainnet strategy.'
25+
'. Defaulting to using Mainnet strategy.',
2626
)
2727
}
2828
return baseUrl
@@ -34,8 +34,6 @@ function _fetchPriceStrategy(chainId: SupportedChainId): Promise<Response> {
3434
}
3535

3636
export async function getPriceStrategy(chainId: SupportedChainId): Promise<PriceStrategy> {
37-
console.log(`[api:${API_NAME}] Get GP price strategy for`, chainId)
38-
3937
const response = await _fetchPriceStrategy(chainId)
4038

4139
if (!response.ok) {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { useState } from 'react'
2+
3+
import { HookToDappMatch } from '@cowprotocol/hook-dapp-lib'
4+
5+
import { ChevronDown, ChevronUp } from 'react-feather'
6+
7+
import { clickOnHooks } from 'modules/analytics'
8+
9+
import * as styledEl from './styled'
10+
11+
export function HookItem({ item, index }: { item: HookToDappMatch; index: number }) {
12+
const [isOpen, setIsOpen] = useState(false)
13+
14+
const handleLinkClick = () => {
15+
clickOnHooks(item.dapp?.name || 'Unknown hook dapp')
16+
}
17+
18+
return (
19+
<styledEl.HookItemWrapper as="li">
20+
<styledEl.HookItemHeader onClick={() => setIsOpen(!isOpen)}>
21+
<styledEl.HookItemInfo>
22+
<styledEl.HookNumber>{index + 1}</styledEl.HookNumber>
23+
{item.dapp ? (
24+
<>
25+
<img src={item.dapp.image} alt={item.dapp.name} />
26+
<span>{item.dapp.name}</span>
27+
</>
28+
) : (
29+
<span>Unknown hook dapp</span>
30+
)}
31+
</styledEl.HookItemInfo>
32+
<styledEl.ToggleIcon isOpen={isOpen}>
33+
{isOpen ? <ChevronUp size={16} /> : <ChevronDown size={16} />}
34+
</styledEl.ToggleIcon>
35+
</styledEl.HookItemHeader>
36+
{isOpen && (
37+
<styledEl.HookItemContent>
38+
{item.dapp && (
39+
<>
40+
<p>
41+
<b>Description:</b> {item.dapp.descriptionShort}
42+
</p>
43+
<p>
44+
<b>Version:</b> {item.dapp.version}
45+
</p>
46+
<p>
47+
<b>Website:</b>{' '}
48+
<a href={item.dapp.website} target="_blank" rel="noopener noreferrer" onClick={handleLinkClick}>
49+
{item.dapp.website}
50+
</a>
51+
</p>
52+
</>
53+
)}
54+
<p>
55+
<b>calldata:</b> {item.hook.callData}
56+
</p>
57+
<p>
58+
<b>target:</b> {item.hook.target}
59+
</p>
60+
<p>
61+
<b>gasLimit:</b> {item.hook.gasLimit}
62+
</p>
63+
</styledEl.HookItemContent>
64+
)}
65+
</styledEl.HookItemWrapper>
66+
)
67+
}

0 commit comments

Comments
 (0)