-
Notifications
You must be signed in to change notification settings - Fork 154
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
feat: add dynamic swap page #1575
Open
dennyscode
wants to merge
30
commits into
develop
Choose a base branch
from
LF-11128-jumper-create-how-to-swap-on-x-seo-cluster-pages
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
bfb94fd
chore: setup dynamic swap page
dennyscode d15891f
fix: clean up img urls
dennyscode ccd1048
Merge branch 'develop' into LF-11128-jumper-create-how-to-swap-on-x-s…
dennyscode 7b0573f
fix: meta title, dark-theme issues, welcomeScreenClosed,..
dennyscode 11703f3
Merge branch 'develop' into LF-11128-jumper-create-how-to-swap-on-x-s…
dennyscode 75bd05d
fix: use chain-name as segment param
dennyscode 40f56c8
refactor: cleanup
dennyscode ce99aaf
refactor: cleanup
dennyscode 575952d
Merge branch 'develop' into LF-11128-jumper-create-how-to-swap-on-x-s…
dennyscode fbc23a2
Merge branch 'develop' into LF-11128-jumper-create-how-to-swap-on-x-s…
dennyscode 3e4425a
chore: add swap-quote-images
dennyscode adf04ce
fix: update yarn.lock
dennyscode 5a21272
Merge branch 'develop' into LF-11128-jumper-create-how-to-swap-on-x-s…
dennyscode e6b65ac
chore: rename styled component
dennyscode 079376d
refactor: remove duplicate
dennyscode fe6cb7d
fix: sitemap and segments with empty space
dennyscode 4e8a64f
chore: cleanup and fix token explorer links
dennyscode 9cdc859
refactor: remove comment
dennyscode 74d1de0
Merge branch 'develop' into LF-11128-jumper-create-how-to-swap-on-x-s…
dennyscode 0fddf0a
fix: yarn.lock
dennyscode 074e91c
Merge branch 'develop' into LF-11128-jumper-create-how-to-swap-on-x-s…
dennyscode a5aee59
fix: Label
dennyscode 195e9e8
style: fix table cell bottom border color
dennyscode b5c5cc1
chore: replace next/image in favor of img tag
dennyscode e455783
refactor: create re-usable util function
dennyscode f6f3140
refactor: remove commented code
dennyscode 40b845a
Merge branch 'develop' into LF-11128-jumper-create-how-to-swap-on-x-s…
dennyscode 8e0e803
Merge branch 'develop' into LF-11128-jumper-create-how-to-swap-on-x-s…
dennyscode b4b90e6
Merge branch 'develop' into LF-11128-jumper-create-how-to-swap-on-x-s…
dennyscode a8c284d
chore: add faq questions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { siteName } from '@/app/lib/metadata'; | ||
import { getSiteUrl } from '@/const/urls'; | ||
import { getChainsQuery } from '@/hooks/useChains'; | ||
import { getTokensQuery } from '@/hooks/useTokens'; | ||
import { getChainByName } from '@/utils/tokenAndChain'; | ||
import type { Metadata } from 'next'; | ||
import { notFound } from 'next/navigation'; | ||
import SwapPage from 'src/app/ui/swap/SwapPage'; | ||
|
||
export async function generateMetadata({ | ||
params, | ||
}: { | ||
params: { segments: string }; | ||
}): Promise<Metadata> { | ||
const { chains } = await getChainsQuery(); | ||
const sourceChain = getChainByName(chains, params.segments); | ||
const title = `Jumper | How To Swap on ${sourceChain?.name} | A Complete Guide`; | ||
|
||
const openGraph: Metadata['openGraph'] = { | ||
title: title, | ||
description: `Jumper offers the best way to swap tokens on ${sourceChain?.name} with the fastest speeds, lowest costs, and most secure swap providers available.`, | ||
siteName: siteName, | ||
url: `${getSiteUrl()}/swap/${params.segments.replace('-', ' ').toLowerCase()}`, | ||
type: 'article', | ||
}; | ||
|
||
return { | ||
title, | ||
description: title, | ||
twitter: openGraph, | ||
openGraph, | ||
alternates: { | ||
canonical: `${getSiteUrl()}/swap/${params.segments}`, | ||
}, | ||
}; | ||
} | ||
|
||
export const revalidate = 86400; | ||
export const dynamicParams = true; // or false, to 404 on unknown paths | ||
export const dynamic = 'force-dynamic'; | ||
|
||
export async function generateStaticParams() { | ||
return []; | ||
} | ||
|
||
export default async function Page({ | ||
params: { segments }, | ||
}: { | ||
params: { segments: string }; | ||
}) { | ||
try { | ||
const chainName = decodeURIComponent( | ||
segments.replace('-', ' ').toLowerCase(), | ||
); | ||
const { chains } = await getChainsQuery(); | ||
const { tokens } = await getTokensQuery(); | ||
const sourceChain = getChainByName(chains, chainName); | ||
if (!sourceChain) { | ||
return notFound(); | ||
} | ||
|
||
const chainTokens = tokens[sourceChain.id]; | ||
let sourceToken, destinationToken; | ||
if (chainTokens) { | ||
sourceToken = chainTokens[0]; | ||
destinationToken = chainTokens[1]; | ||
} | ||
|
||
return ( | ||
<SwapPage | ||
sourceChain={sourceChain} | ||
sourceToken={sourceToken} | ||
destinationChain={sourceChain} | ||
chainName={chainName} | ||
destinationToken={destinationToken} | ||
tokens={tokens} | ||
/> | ||
); | ||
} catch (e) { | ||
notFound(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Metadata } from 'next'; | ||
import type { PropsWithChildren } from 'react'; | ||
import { Layout } from 'src/Layout'; | ||
|
||
export const metadata: Metadata = { | ||
other: { | ||
'partner-theme': 'default', | ||
}, | ||
}; | ||
|
||
export default async function InfosLayout({ children }: PropsWithChildren) { | ||
return <Layout>{children}</Layout>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* eslint-disable @next/next/no-img-element */ | ||
|
||
/** | ||
* Image Generation of Widget for SEO pages | ||
* Step 4 - Route execution | ||
* | ||
* Example: | ||
* ``` | ||
* http://localhost:3000/api/widget-amounts?chainName=arbitrum&amount=1&theme=light | ||
* ``` | ||
* | ||
* @typedef {Object} SearchParams | ||
* @property {number} chainId - The chain ID to send from. | ||
* @property {number} amount - The amount of tokens. | ||
* @property {'light'|'dark'} [theme] - The theme for the widget (optional). | ||
* | ||
*/ | ||
|
||
import { ImageResponse } from 'next/og'; | ||
import type { CSSProperties } from 'react'; | ||
import type { HighlightedAreas } from 'src/components/ImageGeneration/ImageGeneration.types'; | ||
import { imageResponseOptions } from 'src/components/ImageGeneration/imageResponseOptions'; | ||
import { imageFrameStyles } from 'src/components/ImageGeneration/style'; | ||
import WidgetAmountsImage from 'src/components/ImageGeneration/WidgetAmountImage'; | ||
import { getChainsQuery } from 'src/hooks/useChains'; | ||
import { getTokensQuery } from 'src/hooks/useTokens'; | ||
import { parseSearchParams } from 'src/utils/image-generation/parseSearchParams'; | ||
import { sortChainsBySpecificName } from 'src/utils/image-generation/sortChains'; | ||
|
||
const WIDGET_IMAGE_WIDTH = 416; | ||
const WIDGET_IMAGE_HEIGHT = 536; | ||
const WIDGET_IMAGE_SCALING_FACTOR = 2; | ||
|
||
export async function GET(request: Request) { | ||
const { chainName, theme, amount, highlighted } = parseSearchParams( | ||
request.url, | ||
); | ||
|
||
if (!chainName) { | ||
return; | ||
} | ||
|
||
// Fetch data asynchronously before rendering | ||
const { chains } = await getChainsQuery(); | ||
const sortedChains = sortChainsBySpecificName(chains, chainName); | ||
const { tokens } = await getTokensQuery(); | ||
const sortedTokensByChainId = | ||
sortedChains[0]?.id && tokens[sortedChains[0]?.id].slice(0, 4); | ||
const options = await imageResponseOptions({ | ||
width: WIDGET_IMAGE_WIDTH, | ||
height: WIDGET_IMAGE_HEIGHT, | ||
scalingFactor: WIDGET_IMAGE_SCALING_FACTOR, | ||
}); | ||
|
||
const imageFrameStyle = imageFrameStyles({ | ||
width: WIDGET_IMAGE_WIDTH, | ||
height: WIDGET_IMAGE_HEIGHT, | ||
scalingFactor: WIDGET_IMAGE_SCALING_FACTOR, | ||
}) as CSSProperties; | ||
|
||
const imageStyle = imageFrameStyles({ | ||
width: WIDGET_IMAGE_WIDTH, | ||
height: WIDGET_IMAGE_HEIGHT, | ||
scalingFactor: WIDGET_IMAGE_SCALING_FACTOR, | ||
}) as CSSProperties; | ||
|
||
return new ImageResponse( | ||
( | ||
<div style={imageFrameStyle}> | ||
<img | ||
alt="Widget Amount Example" | ||
width={'100%'} | ||
height={'100%'} | ||
style={imageStyle} | ||
src={`${process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL}` : process.env.NEXT_PUBLIC_SITE_URL}/widget/widget-swap-amounts-${theme === 'dark' ? 'dark' : 'light'}.png`} //${theme === 'dark' ? 'dark' : 'light'} | ||
/> | ||
<WidgetAmountsImage | ||
height={WIDGET_IMAGE_WIDTH} | ||
width={WIDGET_IMAGE_HEIGHT} | ||
theme={theme as 'light' | 'dark'} | ||
chains={sortedChains} | ||
amount={amount} | ||
tokens={sortedTokensByChainId || undefined} | ||
highlighted={highlighted as HighlightedAreas} | ||
/> | ||
</div> | ||
), | ||
options, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ export async function GET(request: Request) { | |
width={'100%'} | ||
height={'100%'} | ||
style={imageStyle} | ||
src={`${process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL}` : process.env.NEXT_PUBLIC_SITE_URL}/widget/widget-quotes-${theme === 'dark' ? 'dark' : 'light'}.png`} | ||
src={`${process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL}` : process.env.NEXT_PUBLIC_SITE_URL}/widget/widget${isSwap ? '-swap' : ''}-quotes-${theme === 'dark' ? 'dark' : 'light'}.png`} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to use getSiteUrl() instead |
||
/> | ||
<WidgetQuoteImage | ||
theme={theme as 'light' | 'dark'} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to use getSiteUrl() instead