Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Wallet Integration #152

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

[wip] Wallet Integration #152

wants to merge 23 commits into from

Conversation

memelotsqui
Copy link
Collaborator

This PR helps with wallet integration and supports manifest collection definition

@memelotsqui memelotsqui marked this pull request as ready for review December 6, 2024 21:38
Comment on lines +133 to +135
async _initialize(){

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete?

@@ -638,12 +669,21 @@ class TraitTexturesGroup{
}
});
}
createCollection(itemCollection, replaceExisting = false){
createCollection(itemCollection, replaceExisting = false, ownedTraitsArray = null){
Copy link
Contributor

@Benjythebee Benjythebee Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of always passing ownedTraitsArray = null to every functions, maybe it would be cleaner to create a new class "NFTTraitsManager" use the OwnedTraitIDs class and have that class provide all the information about NFT traits;

logic would become something like

//    if (ownedTraitsArray == null){
//      getAsArray(itemCollection).forEach(item => {
//        this.collection.push(new TextureTrait(this, item))
//      });
//    }
//    else{
//      getAsArray(itemCollection).forEach(item => {
//        if (ownedTraitsArray.includes(item.id)){
//          this.collection.push(new TextureTrait(this, item))
//        }
//      });
//    }



      getAsArray(itemCollection).forEach(item => {
          if( !OwnedTraitIDs.isNFT(item) || OwnedTraitIDs.isOwned(item) ) {
                  this.collection.push(new TextureTrait(this, item))
           }

      });

isOwned could just be something like

 class  OwnedTraitIDs {
 
     ....

     
       isOwned (n) {
          this.nftTraits has i = n.tokenID && has n.collection.name; idk
          }
          
      // I realize this function is redundant         
     isNFT(n){
       return this.Owned(n)
     }
          

// Returning a Promise
return new Promise((resolve, reject) => {
fetch('https://api.opensea.io/api/v2/chain/ethereum/account/' + address + '/nfts?collection=' + collection, options)
fetch('https://api.opensea.io/api/v2/chain/ethereum/account/' + address + '/nfts?limit=200&collection=' + collection, options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are some collections on polygon but this fetches collection on ethereum?

}

export async function currentWallet(){
const chain = await window.ethereum.request({ method: 'eth_chainId' })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window.ethereum is not necessarily defined sadly, need to check if wallet exist

function browserProviderExists(){
   
    try{
         return typeof window.ethereum !== 'undefined'
         }catch(){}
      return false
   }


export async function currentWallet(){
const chain = await window.ethereum.request({ method: 'eth_chainId' })
if (parseInt(chain, 16) == parseInt(chainId, 16)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chainID is hardcoded to polygon at the moment, is that on purpose?

/**
* Represents owned traits and IDs extracted from NFT metadata.
*/
export class OwnedTraitIDs {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rename this to something like OwnedNFTTraitsIds ? just to clarify we're talking about NFTs

* @param {string} chainName - The blockchain name (`"ethereum"` or `"polygon"`).
* @returns {Promise<string>} A promise resolving to the active wallet address, or an empty string on error.
*/
switchWallet(chainName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this function should be in mint-utils with the other window.ethereum related functions;

You can get the wallet address regardless of the chain; but we need to be on the right chain for minting; so it's relevant there!

return {
name:c.name,
image:c.portrait,
description: c.description,
manifest: c.manifest,
icon:c.icon,
format:c.format,
disabled:false
disabled:enabled,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this made me chuckle

Maybe change let enabled = c.collectionLock == null ? false : true; to let disabled= c.collectionLock == null ? true : false;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants