-
Notifications
You must be signed in to change notification settings - Fork 5
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 #143 from NetSepio/main
Merging Main with prod
- Loading branch information
Showing
9 changed files
with
2,371 additions
and
617 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,58 @@ | ||
import { Connection, PublicKey } from '@solana/web3.js'; | ||
import { Metaplex } from '@metaplex-foundation/js'; | ||
|
||
const fetchUserNFTs = async (userAddress: string, chainSymbol: string) => { | ||
if (!userAddress) { | ||
console.log('No user address provided'); | ||
return []; | ||
} | ||
|
||
console.log('Fetching NFTs for address:', userAddress); | ||
console.log('Chain symbol:', chainSymbol); | ||
|
||
try { | ||
if (chainSymbol === 'sol') { | ||
const connection = new Connection(process.env.NEXT_PUBLIC_SOLANA_RPC_URL); | ||
console.log('Connected to Solana network'); | ||
|
||
let ownerPublicKey; | ||
try { | ||
ownerPublicKey = new PublicKey(userAddress); | ||
} catch (err) { | ||
console.error('Invalid Solana address:', userAddress); | ||
return []; | ||
} | ||
|
||
const metaplex = new Metaplex(connection); | ||
|
||
console.log('Fetching all NFTs for owner...'); | ||
const userNFTs = await metaplex.nfts().findAllByOwner({ owner: ownerPublicKey }); | ||
console.log('All user NFTs:', userNFTs); | ||
|
||
const erebrusNFTs = userNFTs.filter(nft => nft.name === "Erebrus VPN NFT").map(nft => ({ | ||
amount: 1, | ||
current_token_data: { | ||
token_name: nft.name, | ||
token_uri: nft.uri, | ||
description: nft.json?.description || '', | ||
token_data_id: nft.address.toString(), | ||
cdn_asset_uris: { | ||
cdn_image_uri: nft.json?.image || '', | ||
}, | ||
}, | ||
})); | ||
|
||
console.log('Filtered Erebrus NFTs:', erebrusNFTs); | ||
|
||
return erebrusNFTs; | ||
} else { | ||
console.log('NFT fetching for this chain not implemented yet'); | ||
return []; | ||
} | ||
} catch (err) { | ||
console.error('Error fetching NFTs:', err); | ||
return []; | ||
} | ||
}; | ||
|
||
export default fetchUserNFTs; |
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
Oops, something went wrong.