Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into tron-new
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMasayoshi committed Sep 27, 2024
2 parents 516b540 + f9f3e6f commit 8c21606
Show file tree
Hide file tree
Showing 197 changed files with 2,991 additions and 1,706 deletions.
2 changes: 1 addition & 1 deletion apis/tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@wagmi/core": "2.13.5",
"drizzle-orm": "^0.29.5",
"postgres": "^3.4.3",
"sushi": "4.0.2",
"sushi": "4.0.5",
"viem": "2.21.4",
"zod": "3.23.8"
},
Expand Down
10 changes: 6 additions & 4 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"lint": "TIMING=1 next lint",
"lint:fix": "TIMING=1 next lint --fix",
"start": "next start",
"test": "npx playwright test -c test/playwright.config.ts"
"test": "npx playwright test -c test/playwright.config.ts",
"test:unit": "vitest --watch=false src"
},
"dependencies": {
"@aptos-labs/ts-sdk": "^1.22.1",
Expand Down Expand Up @@ -43,7 +44,6 @@
"@sushiswap/hooks": "workspace:*",
"@sushiswap/nextjs-config": "workspace:*",
"@sushiswap/notifications": "workspace:*",
"@sushiswap/react-query": "workspace:*",
"@sushiswap/steer-sdk": "workspace:*",
"@sushiswap/tailwindcss-config": "workspace:*",
"@sushiswap/telemetry": "workspace:*",
Expand Down Expand Up @@ -92,7 +92,7 @@
"react-virtualized-auto-sizer": "1.0.7",
"react-window": "1.8.7",
"strapi-sdk-js": "2.3.3",
"sushi": "4.0.2",
"sushi": "4.0.5",
"swr": "2.1.5",
"tiny-invariant": "1.3.1",
"tronweb": "5.3.2",
Expand Down Expand Up @@ -132,6 +132,8 @@
"schema-dts": "^1.1.2",
"tailwindcss": "3.3.2",
"tsx": "^4.16.5",
"typescript": "5.4.5"
"typescript": "5.4.5",
"unimported": "1.30.0",
"vitest": "2.0.5"
}
}
4 changes: 2 additions & 2 deletions apps/web/src/app/(cms)/academy/[article-slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
export default async function Page({ params }: Props) {
let article
let moreArticles
let body
let body: string

try {
const articleP = getAcademyArticles({
Expand All @@ -86,7 +86,7 @@ export default async function Page({ params }: Props) {
})

article = (await articleP).articles[0]
body = await getGhostBody(article.ghostSlug)
body = await getGhostBody(article.ghostSlug).then(({ html }) => html)
moreArticles = (await moreArticlesP).articles
} catch {
return notFound()
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(cms)/blog/[article-slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default async function Page({ params }: Props) {
})

article = (await articleP).articles[0]
body = await getGhostBody(article.ghostSlug)
body = await getGhostBody(article.ghostSlug).then(({ html }) => html)
moreArticles = (await moreArticlesP).articles
} catch {
return notFound()
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/app/(cms)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Header } from './header'
import { Providers } from './providers'

export const fetchCache = 'default-no-store'

export default function Layout({ children }: { children: React.ReactNode }) {
return (
<Providers>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(cms)/lib/ghost/addGhostBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function addGhostBody<T extends Record<string, unknown>>(
data: T,
ghostSlug: string,
) {
const ghostBody = await getGhostBody(ghostSlug)
const { html: ghostBody } = await getGhostBody(ghostSlug)

return {
...data,
Expand Down
16 changes: 4 additions & 12 deletions apps/web/src/app/(cms)/lib/ghost/ghost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,9 @@ function processVideos(html: string) {
export async function getGhostBody(slug: string) {
const ghostClient = getGhostClient()

let html
const { html, ...rest } = await ghostClient.posts.read({
slug,
})

try {
;({ html } = await ghostClient.posts.read({
slug,
}))
} catch {}

if (!html) {
return ''
}

return processVideos(html)
return { html: html ? processVideos(html) : '', ...rest }
}
2 changes: 1 addition & 1 deletion apps/web/src/app/(evm)/(trade)/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const Header: FC = () => {
const chainId = useChainId()
return (
<Navigation
leftElements={headerElements(chainId)}
leftElements={headerElements({ chainId })}
rightElement={<WagmiHeaderComponents chainIds={SUPPORTED_CHAIN_IDS} />}
/>
)
Expand Down
3 changes: 0 additions & 3 deletions apps/web/src/app/(evm)/(trade)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { HotJar } from '@sushiswap/ui'

import { Header } from './header'
import { Providers } from './providers'

Expand All @@ -12,7 +10,6 @@ export default function TradeLayout({
<Header />
<div className="lg:p-4 mt-16 mb-[86px]">{children}</div>
</Providers>
<HotJar />
</>
)
}
2 changes: 1 addition & 1 deletion apps/web/src/app/(evm)/[chainId]/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const Header: FC = () => {
const chainId = useChainId()
return (
<Navigation
leftElements={headerElements(chainId)}
leftElements={headerElements({ chainId })}
rightElement={<WagmiHeaderComponents chainIds={SUPPORTED_CHAIN_IDS} />}
/>
)
Expand Down
3 changes: 0 additions & 3 deletions apps/web/src/app/(evm)/[chainId]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { HotJar } from '@sushiswap/ui'

import { isSupportedChainId } from 'src/config'
import { Header } from './header'
import notFound from './not-found'
Expand All @@ -19,7 +17,6 @@ export default function PoolLayout({
<Header />
<div className="flex flex-col h-full flex-1">{children}</div>
</Providers>
<HotJar />
</>
)
}
2 changes: 1 addition & 1 deletion apps/web/src/app/(evm)/[chainId]/pool/incentivize/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client'

import { useAngleRewardTokens } from '@sushiswap/react-query'
import {
Button,
ChipInput,
Expand Down Expand Up @@ -30,6 +29,7 @@ import {
import format from 'date-fns/format'
import { useRouter } from 'next/navigation'
import { useMemo, useState } from 'react'
import { useAngleRewardTokens } from 'src/lib/hooks/react-query'
import { Web3Input } from 'src/lib/wagmi/components/web3-input'
import { useConcentratedLiquidityPool } from 'src/lib/wagmi/hooks/pools/hooks/useConcentratedLiquidityPool'
import {
Expand Down
21 changes: 15 additions & 6 deletions apps/web/src/app/(evm)/_common/header-elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ import {
import { ChainId, ChainKey } from 'sushi/chain'
import { isAggregatorOnlyChainId } from 'sushi/config'

export const headerElements = (chainId?: ChainId): NavigationElement[] => [
interface HeaderElements {
chainId?: ChainId
includeOnramper?: boolean
}

export const headerElements = (
{ chainId, includeOnramper }: HeaderElements = { includeOnramper: true },
): NavigationElement[] => [
{
title: 'Explore',
items: EXPLORE_NAVIGATION_LINKS(chainId),
Expand All @@ -34,11 +41,13 @@ export const headerElements = (chainId?: ChainId): NavigationElement[] => [
<NavigationListItem title={'Swap'} href={'/swap'}>
The easiest way to trade.
</NavigationListItem>
<OnramperButton>
<NavigationListItem title={'Buy Crypto'}>
Onramp with fiat.
</NavigationListItem>
</OnramperButton>
{includeOnramper ? (
<OnramperButton>
<NavigationListItem title={'Buy Crypto'}>
Onramp with fiat.
</NavigationListItem>
</OnramperButton>
) : null}
</ul>
</NavigationMenuContent>
</NavigationMenuItem>
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/app/(evm)/_common/ui/price-provider/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import ms from 'ms'

export const UPDATE_INTERVAL = ms('15s')
export const STALE_TIME = ms('60s')
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
'use client'

import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useReducer,
useState,
} from 'react'
import { ChainId } from 'sushi'
import { useChainId } from 'wagmi'
import {
PriceWorker,
PriceWorkerPostMessageType,
PriceWorkerReceiveMessage,
PriceWorkerReceiveMessageType,
} from '../price-worker/types'
import { Provider, ProviderActions, ProviderState } from './types'

function reducer(state: ProviderState, action: ProviderActions): ProviderState {
switch (action.type) {
case 'UPDATE_CHAIN_STATE': {
const currentChain = state.chains.get(action.payload.chainId)

if (currentChain) {
state.chains.set(action.payload.chainId, {
...currentChain,
...action.payload,
priceMap: action.payload.priceMap || currentChain.priceMap,
})
} else {
const { isError, isLoading, isUpdating, lastModified } = action.payload

if (
isError === undefined ||
isLoading === undefined ||
isUpdating === undefined ||
lastModified === undefined
) {
throw new Error('Invalid initial chain state')
}

state.chains.set(action.payload.chainId, {
chainId: action.payload.chainId,
isError,
isLoading,
isUpdating,
lastModified,
priceMap: action.payload.priceMap || undefined,
})
}

return {
...state,
}
}
default:
return state
}
}

const PriceProviderContext = createContext<Provider>({} as Provider)

interface PriceProviderContextProps {
children: React.ReactNode
}

export function PriceProvider({ children }: PriceProviderContextProps) {
const [worker, setWorker] = useState<PriceWorker>()
const [state, dispatch] = useReducer(reducer, {
chains: new Map(),
ready: false,
})

const chainId = useChainId()

useEffect(() => {
const worker = new Worker(
new URL('../price-worker/price-worker.ts', import.meta.url),
)

worker.postMessage({
type: PriceWorkerPostMessageType.Initialize,
canUseSharedArrayBuffer: false,
})

worker.onmessage = (event: MessageEvent<PriceWorkerReceiveMessage>) => {
switch (event.data.type) {
case PriceWorkerReceiveMessageType.ChainState:
dispatch({
type: 'UPDATE_CHAIN_STATE',
payload: event.data.payload,
})
break
}
}

setWorker(worker as unknown as PriceWorker)

return () => {
worker.terminate()
}
}, [])

const incrementChainId = useCallback(
(chainId: ChainId) => {
if (worker) {
worker.postMessage({
type: PriceWorkerPostMessageType.IncrementChainId,
chainId,
})
}
},
[worker],
)

const decrementChainId = useCallback(
(chainId: ChainId) => {
if (worker) {
worker.postMessage({
type: PriceWorkerPostMessageType.DecrementChainId,
chainId,
})
}
},
[worker],
)

useEffect(() => {
if (worker) {
incrementChainId(chainId)
}

return () => {
if (worker) {
decrementChainId(chainId)
}
}
}, [worker, chainId, decrementChainId, incrementChainId])

return (
<PriceProviderContext.Provider
value={{
state: useMemo(() => ({ ...state, ready: !!worker }), [state, worker]),
mutate: useMemo(
() => ({
incrementChainId,
decrementChainId,
}),
[incrementChainId, decrementChainId],
),
}}
>
{children}
</PriceProviderContext.Provider>
)
}

export function usePriceProvider() {
const context = useContext(PriceProviderContext)

if (!context) {
throw new Error('usePriceProvider must be used within a PriceProvider')
}

return context
}
Loading

0 comments on commit 8c21606

Please sign in to comment.