-
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: NFTCard support address and tokenId (#177)
* feat: NFTCard support address and tokenId * fix: ts type for ci * feat: support getNFTMetadata and add test case --------- Co-authored-by: yutingzhao1991 <[email protected]>
- Loading branch information
1 parent
05ca67a
commit 884a222
Showing
7 changed files
with
127 additions
and
17 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
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,43 @@ | ||
import { NFTCard } from '@ant-design/web3'; | ||
import { render } from '@testing-library/react'; | ||
import { describe, it, expect, vi } from 'vitest'; | ||
|
||
describe('NFTImage', () => { | ||
it('renders correctly with valid address and tokenId', () => { | ||
const address = '0x21CDf0974d53a6e96eF05d7B324a9803735fFd3B'; | ||
const tokenId = 123; | ||
|
||
expect(() => render(<NFTCard address={address} tokenId={tokenId} />)).not.toThrow(); | ||
}); | ||
|
||
it('renders correctly with valid address and bigint tokenId', () => { | ||
const address = '0x21CDf0974d53a6e96eF05d7B324a9803735fFd3B'; | ||
const tokenId = BigInt(123); | ||
|
||
expect(() => render(<NFTCard address={address} tokenId={tokenId} />)).not.toThrow(); | ||
}); | ||
|
||
it('getNFTMetadata', async () => { | ||
const address = '0x21CDf0974d53a6e96eF05d7B324a9803735fFd3B'; | ||
const tokenId = 123; | ||
|
||
const { baseElement } = render( | ||
<NFTCard | ||
address={address} | ||
tokenId={tokenId} | ||
getNFTMetadata={async () => { | ||
return { | ||
name: 'NFT Name', | ||
description: 'NFT Description', | ||
image: 'ipfs://QmXVH2TsfCXJ5pDM3cabHKW1Z7M6fAtu5yV6LuifVWPsoP', | ||
}; | ||
}} | ||
/>, | ||
); | ||
await vi.waitFor(() => { | ||
expect(baseElement.querySelector('.ant-image-img')?.getAttribute('src')).toBe( | ||
'https://ipfs.io/ipfs/QmXVH2TsfCXJ5pDM3cabHKW1Z7M6fAtu5yV6LuifVWPsoP', | ||
); | ||
}); | ||
}); | ||
}); |
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,27 @@ | ||
import { createConfig, configureChains, mainnet } from 'wagmi'; | ||
import { infuraProvider } from 'wagmi/providers/infura'; | ||
import { WagmiWeb3ConfigProvider } from '@ant-design/web3-wagmi'; | ||
import { NFTCard } from '@ant-design/web3'; | ||
|
||
const { publicClient } = configureChains( | ||
[mainnet], | ||
[ | ||
infuraProvider({ | ||
apiKey: YOUR_INFURA_API_KEY, | ||
}), | ||
], | ||
); | ||
|
||
const config = createConfig({ | ||
publicClient, | ||
}); | ||
|
||
const App: React.FC = () => { | ||
return ( | ||
<WagmiWeb3ConfigProvider config={config}> | ||
<NFTCard address="0x79fcdef22feed20eddacbb2587640e45491b757f" tokenId={42n} /> | ||
</WagmiWeb3ConfigProvider> | ||
); | ||
}; | ||
|
||
export default App; |
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