Skip to content
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

Fix trending apps chips, update metaport dependency #354

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@mdx-js/rollup": "^2.3.0",
"@mui/icons-material": "^5.15.14",
"@mui/material": "^5.15.14",
"@skalenetwork/metaport": "3.0.0-develop.3",
"@skalenetwork/metaport": "3.0.0-develop.4",
"@skalenetwork/skale-contracts-ethers-v6": "1.0.1",
"@transak/transak-sdk": "^3.1.1",
"@types/react-copy-to-clipboard": "^5.0.4",
Expand Down
9 changes: 8 additions & 1 deletion src/LikedAppsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface LikedAppsContextType {
getAppId: (chainName: string, appName: string) => string
getAppInfoById: (appId: string) => types.IAppId
getTrendingApps: () => string[]
getTrendingRank: (trendingAppIds: string[], appId: string) => number | undefined
}

const LikedAppsContext = createContext<LikedAppsContextType | undefined>(undefined)
Expand Down Expand Up @@ -139,6 +140,11 @@ export const LikedAppsProvider: React.FC<{ children: React.ReactNode }> = ({ chi
.map(([appId]) => appId)
}, [appLikes])

const getTrendingRank = (trendingAppIds: string[], appId: string): number | undefined => {
const idx = trendingAppIds.indexOf(appId)
return idx === -1 ? undefined : idx + 1
}

return (
<LikedAppsContext.Provider
value={{
Expand All @@ -150,7 +156,8 @@ export const LikedAppsProvider: React.FC<{ children: React.ReactNode }> = ({ chi
refreshLikedApps: fetchLikedApps,
getAppId,
getAppInfoById,
getTrendingApps
getTrendingApps,
getTrendingRank
}}
>
{children}
Expand Down
4 changes: 3 additions & 1 deletion src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import './App.scss'

import { useState, useEffect } from 'react'
import { WalletClient } from 'viem'

import { Helmet } from 'react-helmet'
import { useLocation, Routes, Route, useSearchParams } from 'react-router-dom'
import { TransitionGroup, CSSTransition } from 'react-transition-group'
Expand Down Expand Up @@ -132,7 +134,7 @@ export default function Router() {
const { chainId } = await mpc.mainnet().provider.getNetwork()
await enforceNetwork(
chainId,
walletClient,
walletClient as WalletClient,
switchChainAsync!,
mpc.config.skaleNetwork,
MAINNET_CHAIN_NAME
Expand Down
9 changes: 7 additions & 2 deletions src/components/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ const Chip: React.FC<{
)
}

export const ChipTrending: React.FC<{}> = ({}) => {
return <Chip label="Trending" className={cls(cmn.mleft5, 'chipTrending', 'chipXs')} />
export const ChipTrending: React.FC<{ trending?: number }> = ({ trending }) => {
return (
<Chip
label={trending ? `#${trending} on Trending` : 'Trending'}
className={cls(cmn.mleft5, 'chipTrending', 'chipXs')}
/>
)
}

export const ChipNew: React.FC<{}> = ({}) => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/TokenBalanceTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

import { Contract } from 'ethers'
import { WalletClient } from 'viem'
import { useState, useEffect } from 'react'

import {
Expand Down Expand Up @@ -85,7 +86,7 @@ export default function TokenBalanceTile(props: { mpc: MetaportCore; chain: stri
const { chainId } = await props.mpc.provider(props.chain).getNetwork()
await enforceNetwork(
chainId,
walletClient,
walletClient as WalletClient,
switchChainAsync!,
props.mpc.config.skaleNetwork,
props.chain
Expand Down
5 changes: 2 additions & 3 deletions src/components/ecosystem/AllApps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface AllAppsProps {
}

const AllApps: React.FC<AllAppsProps> = ({ skaleNetwork, chainsMeta, apps, newApps, loaded }) => {
const { getTrendingApps, getAppId } = useLikedApps()
const { getTrendingApps, getAppId, getTrendingRank } = useLikedApps()

const trendingAppIds = useMemo(() => getTrendingApps(), [getTrendingApps])

Expand All @@ -59,7 +59,6 @@ const AllApps: React.FC<AllAppsProps> = ({ skaleNetwork, chainsMeta, apps, newAp
<Grid container spacing={2}>
{apps.map((app: types.AppWithChainAndName) => {
const appId = getAppId(app.chain, app.appName)
const isTrending = trendingAppIds.includes(appId)
const isNew = isNewApp({ chain: app.chain, app: app.appName }, newApps)
return (
<Grid key={appId} item xs={12} sm={6} md={4} lg={4}>
Expand All @@ -68,7 +67,7 @@ const AllApps: React.FC<AllAppsProps> = ({ skaleNetwork, chainsMeta, apps, newAp
schainName={app.chain}
appName={app.appName}
chainsMeta={chainsMeta}
isTrending={isTrending}
trending={getTrendingRank(trendingAppIds, appId)}
isNew={isNew}
/>
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ecosystem/AppCardV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export default function AppCard(props: {
chainsMeta: types.ChainsMetadataMap
transactions?: number
newApps?: types.AppWithChainAndName[]
isTrending?: boolean
isNew?: boolean
trending?: number
}) {
const shortAlias = getChainShortAlias(props.chainsMeta, props.schainName)
const url = `/ecosystem/${shortAlias}/${props.appName}`
Expand Down Expand Up @@ -81,7 +81,7 @@ export default function AppCard(props: {
<p className={cls(cmn.p, cmn.pPrim, cmn.p600, cmn.p1, 'shortP', cmn.flexg, cmn.mri5)}>
{getChainAlias(props.chainsMeta, props.schainName, props.appName)}
</p>
{props.isTrending && <ChipTrending />}
{props.trending !== undefined && <ChipTrending />}
{props.isNew && <ChipNew />}
{appMeta.tags?.includes('pretge') && <ChipPreTge />}
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/ecosystem/FavoriteApps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export default function FavoriteApps(props: {
isSignedIn: boolean
error: string | null
}) {
const { getTrendingApps } = useLikedApps()
const { getTrendingApps, getAppId, getTrendingRank } = useLikedApps()
const trendingAppIds = useMemo(() => getTrendingApps(), [getTrendingApps])

if (!props.isSignedIn) return <ConnectWallet customText="Sign in to see your favorite dApps" />
if (props.error) return <div>Error: {props.error}</div>

const appCards = props.filteredApps.map((app) => {
const isTrending = trendingAppIds.includes(`${app.chain}-${app.appName}`)
const trendingRank = getTrendingRank(trendingAppIds, getAppId(app.chain, app.appName))
const isNew = isNewApp({ chain: app.chain, app: app.appName }, props.newApps)
return (
<Grid
Expand All @@ -67,7 +67,7 @@ export default function FavoriteApps(props: {
skaleNetwork={props.skaleNetwork}
chainsMeta={props.chainsMeta}
isNew={isNew}
isTrending={isTrending}
trending={trendingRank}
/>
</Grid>
)
Expand Down
5 changes: 2 additions & 3 deletions src/components/ecosystem/NewApps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,19 @@ const NewApps: React.FC<NewAppsProps> = ({
chainsMeta,
useCarousel = false
}) => {
const { getTrendingApps, getAppId } = useLikedApps()
const { getTrendingApps, getAppId, getTrendingRank } = useLikedApps()
const trendingAppIds = useMemo(() => getTrendingApps(), [getTrendingApps])

const renderAppCard = (app: types.AppWithChainAndName) => {
const appId = getAppId(app.chain, app.appName)
const isTrending = trendingAppIds.includes(appId)
return (
<AppCard
key={`${app.chain}-${app.appName}`}
skaleNetwork={skaleNetwork}
schainName={app.chain}
appName={app.appName}
chainsMeta={chainsMeta}
isTrending={isTrending}
trending={getTrendingRank(trendingAppIds, appId)}
/>
)
}
Expand Down
14 changes: 11 additions & 3 deletions src/pages/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,15 @@ export default function App(props: {
chainsMeta: types.ChainsMetadataMap
}) {
let { chain, app } = useParams()
const { likedApps, appLikes, toggleLikedApp, getAppId, getTrendingApps, refreshLikedApps } =
useLikedApps()
const {
likedApps,
appLikes,
toggleLikedApp,
getAppId,
getTrendingApps,
refreshLikedApps,
getTrendingRank
} = useLikedApps()
const { isSignedIn, handleSignIn } = useAuth()

const { address } = useWagmiAccount()
Expand Down Expand Up @@ -124,6 +131,7 @@ export default function App(props: {
const likesCount = appLikes[appId] || 0

const trendingAppIds = useMemo(() => getTrendingApps(), [getTrendingApps])
const trendingIndex = getTrendingRank(trendingAppIds, appId)
const isNew = isNewApp({ chain, app }, newApps)

const handleToggleLike = async () => {
Expand Down Expand Up @@ -234,7 +242,7 @@ export default function App(props: {
<div className={cls(cmn.flex, cmn.flexcv)}>
<h2 className={cls(cmn.nom, cmn.p1)}>{appAlias}</h2>
<div className={cls(cmn.flex, cmn.mleft10)}>
{trendingAppIds.includes(appId) && <ChipTrending />}
{trendingIndex !== undefined && <ChipTrending trending={trendingIndex} />}
{isNew && <ChipNew />}
{appMeta.tags?.includes('pretge') && <ChipPreTge />}
</div>
Expand Down
1 change: 0 additions & 1 deletion src/styles/chip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
overflow-x: auto;
white-space: nowrap;
gap: 8px;
// border-radius: 25px;
position: relative;
}

Expand Down
Loading