-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: init useNFT hook and Web3ConfigProvider getNFTMetadata (#23)
* feat: init useNFT hook and Web3ConfigProvider getNFTMetadata * docs: add NFTCarrd zh-CN doc --------- Co-authored-by: yutingzhao1991 <[email protected]>
- Loading branch information
1 parent
710b175
commit 1725d7a
Showing
8 changed files
with
144 additions
and
0 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 { NFTCard } from '@ant-design/web3'; | ||
|
||
export default () => { | ||
return <NFTCard address="0xEcd0D12E21805803f70de03B72B1C162dB0898d9" id={42} />; | ||
}; |
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,12 @@ | ||
--- | ||
group: | ||
title: Components | ||
--- | ||
|
||
# NFTCard | ||
|
||
Components used to display NFT images more conveniently and simply. | ||
|
||
## Simple Usage | ||
|
||
<code src="./demos/simple.tsx"></code> |
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,14 @@ | ||
import React from 'react'; | ||
import { Image } from 'antd'; | ||
import useNFT from '../hooks/useNFT'; | ||
|
||
export interface NFTCardProps { | ||
address: string; | ||
id: number; | ||
} | ||
|
||
export const NFTCard: React.FC<NFTCardProps> = ({ address, id }) => { | ||
const { metadata } = useNFT(address, id); | ||
|
||
return <Image src={metadata.image} />; | ||
}; |
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,12 @@ | ||
--- | ||
group: | ||
title: Components | ||
--- | ||
|
||
# NFTCard | ||
|
||
更简单地展示 NFT 图片的组件。 | ||
|
||
## Simple Usage | ||
|
||
<code src="./demos/simple.tsx"></code> |
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,26 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { NFTMetadata } from '@ant-design/web3'; | ||
import useProvider from './useProvider'; | ||
|
||
export default function useNFT(address: string, id: number) { | ||
const [metadata, setMetadata] = useState<NFTMetadata>({}); | ||
const [error, setError] = useState<Error>(); | ||
const { provider } = useProvider(); | ||
|
||
useEffect(() => { | ||
if (provider) { | ||
provider | ||
.getNFTMetadata(address, id) | ||
.then((data) => { | ||
setMetadata(data); | ||
}) | ||
.catch((err) => { | ||
setError(err); | ||
}); | ||
} | ||
}, [address, id, provider]); | ||
return { | ||
metadata, | ||
error, | ||
}; | ||
} |
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