-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: profile page lists NFTs by wallet
- Loading branch information
Showing
30 changed files
with
1,082 additions
and
446 deletions.
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
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,5 @@ | ||
import { createContext } from "react"; | ||
|
||
import { Erc721ContextType } from "./Erc721Context.types"; | ||
|
||
export const Erc721Context = createContext<Erc721ContextType | undefined>(undefined); |
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,11 @@ | ||
import { GetNFTsByWalletResult } from "api/evm/ERC721/types"; | ||
import { ReactNode } from "react"; | ||
|
||
export type Erc721ContextControllerProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
export type Erc721ContextType = { | ||
nftsByWallet: GetNFTsByWalletResult[][]; | ||
getNFTsByWallet: () => Promise<void>; | ||
}; |
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,51 @@ | ||
import React from "react"; | ||
import { useAccount } from "wagmi"; | ||
import axios from "axios"; | ||
import { GetNFTsByWalletRequest, GetNFTsByWalletResult } from "api/evm/ERC721/types"; | ||
import _ from "lodash"; | ||
|
||
import { useRoutes } from "hooks/useRoutes/useRoutes"; | ||
|
||
import { Erc721ContextControllerProps, Erc721ContextType } from "./Erc721Context.types"; | ||
import { Erc721Context } from "./Erc721Context"; | ||
|
||
const groupNFTsByContract = (nfts: GetNFTsByWalletResult[]) => { | ||
const group = _.groupBy(nfts, "tokenAddress"); | ||
|
||
console.log(_.map(group)); | ||
|
||
return _.map(group); | ||
}; | ||
|
||
export const Erc721ContextController = ({ children }: Erc721ContextControllerProps) => { | ||
const [nftsByWallet, setNftsByWallet] = React.useState<Erc721ContextType["nftsByWallet"]>([]); | ||
|
||
const { address, chainId } = useAccount(); | ||
const routes = useRoutes(); | ||
|
||
const getNFTsByWallet = async () => { | ||
try { | ||
const data: GetNFTsByWalletRequest = { | ||
chainId: chainId!, | ||
walletAddress: address!, | ||
}; | ||
|
||
const result = await axios.post<GetNFTsByWalletResult[]>(routes.api.evm.ERC721.getNFTsByWallet(), { | ||
data, | ||
}); | ||
|
||
console.log(result.data); | ||
|
||
setNftsByWallet(groupNFTsByContract(result.data)); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
const props: Erc721ContextType = { | ||
getNFTsByWallet, | ||
nftsByWallet, | ||
}; | ||
|
||
return <Erc721Context.Provider value={props}>{children}</Erc721Context.Provider>; | ||
}; |
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 { useContext } from "react"; | ||
|
||
import { Erc721Context } from "./Erc721Context"; | ||
|
||
export const useErc721Context = () => { | ||
const context = useContext(Erc721Context); | ||
|
||
if (context === undefined) { | ||
throw new Error("useErc721Context must be used within a Erc721Context"); | ||
} | ||
|
||
return context; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import logger from "providers/logger"; | ||
import moralis from "providers/moralis"; | ||
|
||
export default async function Fn(request: NextApiRequest, response: NextApiResponse) { | ||
try { | ||
await moralis.loadClient(); | ||
} catch (error) { | ||
logger.error(error); | ||
} | ||
|
||
try { | ||
const { data } = request.body; | ||
logger.info(`api/evm/ERC721/get-nfts-by-wallet: ${JSON.stringify(data)}`); | ||
|
||
const result = await moralis.client.EvmApi.nft.getWalletNFTs({ | ||
chain: data.chainId, | ||
format: "decimal", | ||
mediaItems: false, | ||
address: data.walletAddress, | ||
}); | ||
|
||
response.status(200).json(result.result); | ||
} catch (error) { | ||
logger.error(error); | ||
|
||
response.status(500).json({ error: (error as Error).message }); | ||
} | ||
} |
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,11 @@ | ||
import { EvmNft } from "@moralisweb3/common-evm-utils/lib"; | ||
import { MoralisDataObjectValue } from "@moralisweb3/common-core/lib"; | ||
|
||
export type GetNFTsByWalletResult = EvmNft & { | ||
metadata: MoralisDataObjectValue & Record<string, any>; | ||
}; | ||
|
||
export type GetNFTsByWalletRequest = { | ||
walletAddress: string; | ||
chainId: number; | ||
}; |
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,37 @@ | ||
import { GetServerSidePropsContext, NextPage } from "next"; | ||
import { i18n, useTranslation } from "next-i18next"; | ||
import { serverSideTranslations } from "next-i18next/serverSideTranslations"; | ||
import Head from "next/head"; | ||
|
||
import { HomeLayout } from "layouts/home-layout/HomeLayout"; | ||
import { Collections } from "ui/lease721/profile/collections/Collections"; | ||
|
||
const Index: NextPage = () => { | ||
const { t } = useTranslation("head"); | ||
|
||
return ( | ||
<HomeLayout> | ||
<Head> | ||
<title>{t("head.og.title")}</title> | ||
<meta name="description" content={t("head.og.description")} /> | ||
<meta property="og:title" content={t("head.og.title")} /> | ||
<meta property="og:description" content={t("head.og.description")} /> | ||
<meta property="og:url" content="https://lease721.com/" /> | ||
</Head> | ||
|
||
<Collections /> | ||
</HomeLayout> | ||
); | ||
}; | ||
|
||
export const getServerSideProps = async ({ locale }: GetServerSidePropsContext) => { | ||
await i18n?.reloadResources(); | ||
|
||
return { | ||
props: { | ||
...(await serverSideTranslations(locale!, ["common", "head", "chat", "prompt-wars"])), | ||
}, | ||
}; | ||
}; | ||
|
||
export default Index; |
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,11 @@ | ||
import Moralis from "moralis"; | ||
|
||
const loadClient = async () => | ||
await Moralis.start({ | ||
apiKey: process.env.MORALIS_API_KEY, | ||
}); | ||
|
||
export default { | ||
loadClient, | ||
client: Moralis, | ||
}; |
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 @@ | ||
@mixin hero { | ||
&__hero { | ||
@include atLargeTablet { | ||
height: 50vh; | ||
} | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
height: 100vh; | ||
text-align: left; | ||
background-color: var(--color-background); | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
app/src/ui/lease721/navbar/profile-dropdown/ProfileDropdown.module.scss
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,5 @@ | ||
@import "src/theme/base"; | ||
|
||
.profile-dropdown { | ||
display: block; | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/ui/lease721/navbar/profile-dropdown/ProfileDropdown.module.scss.d.ts
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,16 @@ | ||
export type Styles = { | ||
"profile-dropdown": string; | ||
"z-depth-0": string; | ||
"z-depth-1": string; | ||
"z-depth-1-half": string; | ||
"z-depth-2": string; | ||
"z-depth-3": string; | ||
"z-depth-4": string; | ||
"z-depth-5": string; | ||
}; | ||
|
||
export type ClassNames = keyof Styles; | ||
|
||
declare const styles: Styles; | ||
|
||
export default styles; |
13 changes: 13 additions & 0 deletions
13
app/src/ui/lease721/navbar/profile-dropdown/ProfileDropdown.test.tsx
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 { screen, render } from "tests"; | ||
|
||
import { ProfileDropdown } from "./ProfileDropdown"; | ||
|
||
describe("ProfileDropdown", () => { | ||
it("renders children correctly", () => { | ||
render(<ProfileDropdown>ProfileDropdown</ProfileDropdown>); | ||
|
||
const element = screen.getByText("ProfileDropdown"); | ||
|
||
expect(element).toBeInTheDocument(); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
app/src/ui/lease721/navbar/profile-dropdown/ProfileDropdown.tsx
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,20 @@ | ||
import clsx from "clsx"; | ||
|
||
import { Icon } from "ui/icon/Icon"; | ||
import { Typography } from "ui/typography/Typography"; | ||
import { useRoutes } from "hooks/useRoutes/useRoutes"; | ||
|
||
import { ProfileDropdownProps } from "./ProfileDropdown.types"; | ||
import styles from "./ProfileDropdown.module.scss"; | ||
|
||
export const ProfileDropdown: React.FC<ProfileDropdownProps> = ({ className }) => { | ||
const routes = useRoutes(); | ||
|
||
return ( | ||
<div className={clsx(styles["profile-dropdown"], className)}> | ||
<Typography.Link href={routes.profile.index()}> | ||
<Icon name="icon-user" /> | ||
</Typography.Link> | ||
</div> | ||
); | ||
}; |
6 changes: 6 additions & 0 deletions
6
app/src/ui/lease721/navbar/profile-dropdown/ProfileDropdown.types.ts
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,6 @@ | ||
import { ReactNode } from "react"; | ||
|
||
export type ProfileDropdownProps = { | ||
children?: ReactNode; | ||
className?: string; | ||
}; |
Oops, something went wrong.