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

Update NavigationWrapper to use RaysCountSmall component + other fixes #436

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client'

import { type FC, useEffect, useState } from 'react'
import { type FC, useCallback, useEffect, useState } from 'react'
import { type NavigationMenuPanelType } from '@summerfi/app-types'
import { Navigation } from '@summerfi/app-ui'
import { Navigation, RaysCountSmall } from '@summerfi/app-ui'
import { useConnectWallet } from '@web3-onboard/react'
import dynamic from 'next/dynamic'
import { usePathname } from 'next/navigation'
Expand All @@ -13,9 +13,9 @@ import {
} from '@/components/layout/Navigation/NavigationModules'
import { BridgeSwapHandlerLoader } from '@/components/molecules/BridgeSwap/BridgeSwapLoader'
import { BridgeSwapWrapper } from '@/components/molecules/BridgeSwap/BridgeSwapWrapper'
import { RaysCountComponent } from '@/components/molecules/RaysCountComponent/RaysCountComponent'
import { WalletButtonFallback } from '@/components/molecules/WalletButton/WalletButtonFallback'
import { basePath } from '@/helpers/base-path'
import { formatCryptoBalance } from '@/helpers/formatters'

const WalletButton = dynamic(() => import('@/components/molecules/WalletButton/WalletButton'), {
ssr: false,
Expand Down Expand Up @@ -47,6 +47,16 @@ export const NavigationWrapper: FC<NavigationWrapperProps> = ({ panels }) => {
}
}, [showNavigationModule, onceLoaded])

const raysFetchFunction = useCallback(async () => {
if (wallet?.accounts[0].address) {
return await fetch(`${basePath}/api/rays?address=${wallet.accounts[0].address}`).then(
(resp) => resp.json(),
)
}

return {}
}, [wallet])

return (
<Navigation
currentPath={currentPath}
Expand Down Expand Up @@ -84,7 +94,13 @@ export const NavigationWrapper: FC<NavigationWrapperProps> = ({ panels }) => {
)}
</BridgeSwapWrapper>
}
raysCountComponent={<RaysCountComponent />}
raysCountComponent={
<RaysCountSmall
userAddress={wallet?.accounts[0].address}
formatter={formatCryptoBalance}
raysFetchFunction={raysFetchFunction}
/>
}
walletConnectionComponent={<WalletButton />}
onLogoClick={() => {
// because router will use base path...
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ export const RaysCountSmall = ({
}: RaysCountSmallProps) => {
const [loadingRaysCount, setLoadingRaysCount] = useState<boolean>(false)
const [raysCount, setRaysCount] = useState<number | null>(null)
const [raysAddresses, setRaysAddresses] = useState<string[]>([])

useEffect(() => {
if (userAddress) {
if (userAddress && !raysAddresses.includes(userAddress)) {
setLoadingRaysCount(true)
raysFetchFunction().then((response) => {
if (response.rays?.allPossiblePoints !== undefined) {
setLoadingRaysCount(false)
setRaysAddresses([...raysAddresses, userAddress])
setRaysCount(response.rays.allPossiblePoints)
}
})
Expand Down
Loading