-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from nezz0746/feat/add-nft-fetching
Feat: add nft fetching
- Loading branch information
Showing
16 changed files
with
108 additions
and
3 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
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 @@ | ||
import useSWR from "swr"; | ||
import { useAccount } from "wagmi"; | ||
import { getOwnerNFTsPerChainId } from "../services/alchemy"; | ||
|
||
const useOwnedNFTs = (chainId: number) => { | ||
const { address } = useAccount(); | ||
const { data, isLoading, error } = useSWR( | ||
["/api/owned-nfts", address, chainId], | ||
([, address, chainId]) => getOwnerNFTsPerChainId(address, chainId), | ||
{} | ||
); | ||
|
||
return { data, isLoading, error }; | ||
}; | ||
|
||
export default useOwnedNFTs; |
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,19 @@ | ||
import { Address } from "wagmi"; | ||
import { OwnedNft as AlchemyOwnedNFT } from "alchemy-sdk"; | ||
import { getAlchemyNFT } from "shared-config"; | ||
|
||
export interface OwnedNft extends AlchemyOwnedNFT { | ||
chainId: number; | ||
} | ||
|
||
export const getOwnerNFTsPerChainId = async ( | ||
owner: Address | undefined, | ||
chainId: number | ||
) => { | ||
if (!owner) return; | ||
const nft = getAlchemyNFT(chainId); | ||
|
||
const { ownedNfts: response } = await nft.getNftsForOwner(owner); | ||
|
||
return response.map((nft) => ({ ...nft, chainId })); | ||
}; |
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,24 @@ | ||
import op from "./icons/op.svg"; | ||
import polygon from "./icons/polygon.svg"; | ||
import ethereum from "./icons/ethereum.svg"; | ||
import base from "./icons/base.svg"; | ||
import opensea from "./icons/os.svg"; | ||
|
||
export const chainIdToIcon: Record<number, any> = { | ||
1: ethereum, | ||
5: ethereum, | ||
137: polygon, | ||
80001: polygon, | ||
10: op, | ||
420: op, | ||
8453: base, | ||
84531: base, | ||
}; | ||
|
||
export const icons = { | ||
op, | ||
polygon, | ||
ethereum, | ||
base, | ||
opensea, | ||
}; |
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,4 @@ | ||
declare module "*.svg" { | ||
const content: any; | ||
export default content; | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./nfts"; | ||
export * from "./variables"; | ||
export * from "./assets"; |
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 |
---|---|---|
|
@@ -9,6 +9,6 @@ | |
"lint": "echo 'Add lint script here'" | ||
}, | ||
"dependencies": { | ||
"alchemy-sdk": "^3.1.0" | ||
"alchemy-sdk": "3.1.0" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3716,7 +3716,7 @@ ajv@^6.12.3, ajv@^6.12.4, ajv@~6.12.6: | |
json-schema-traverse "^0.4.1" | ||
uri-js "^4.2.2" | ||
|
||
alchemy-sdk@^3.1.0: | ||
[email protected]: | ||
version "3.1.0" | ||
resolved "https://registry.yarnpkg.com/alchemy-sdk/-/alchemy-sdk-3.1.0.tgz#cd4a03215d7502ea4c3e7548f7b837e25b461864" | ||
integrity sha512-KMzBo0Dq+cEqXegn4fh2sP74dhAngr9twIv2pBTyPq3/ZJs+aiXXlFzVrVUYaa6x9L7iQtqhz3YKFCuN5uvpAg== | ||
|
@@ -4569,6 +4569,11 @@ cli-width@^3.0.0: | |
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6" | ||
integrity sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw== | ||
|
||
client-only@^0.0.1: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/client-only/-/client-only-0.0.1.tgz#38bba5d403c41ab150bff64a95c85013cf73bca1" | ||
integrity sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA== | ||
|
||
clipboardy@^3.0.0: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/clipboardy/-/clipboardy-3.0.0.tgz#f3876247404d334c9ed01b6f269c11d09a5e3092" | ||
|
@@ -9433,6 +9438,14 @@ swap-case@^2.0.2: | |
dependencies: | ||
tslib "^2.0.3" | ||
|
||
swr@^2.2.4: | ||
version "2.2.4" | ||
resolved "https://registry.yarnpkg.com/swr/-/swr-2.2.4.tgz#03ec4c56019902fbdc904d78544bd7a9a6fa3f07" | ||
integrity sha512-njiZ/4RiIhoOlAaLYDqwz5qH/KZXVilRLvomrx83HjzCWTfa+InyfAjv05PSFxnmLzZkNO9ZfvgoqzAaEI4sGQ== | ||
dependencies: | ||
client-only "^0.0.1" | ||
use-sync-external-store "^1.2.0" | ||
|
||
[email protected]: | ||
version "6.1.0" | ||
resolved "https://registry.yarnpkg.com/sync-request/-/sync-request-6.1.0.tgz#e96217565b5e50bbffe179868ba75532fb597e68" | ||
|