-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: main
Are you sure you want to change the base?
Conversation
b95d766
to
72b6ec6
Compare
72b6ec6
to
885174e
Compare
async _initialize(){ | ||
|
||
} |
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
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 use the OwnedTraitIDs class and have that class provide all the information about NFT traits;"NFTTraitsManager"
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) |
There was a problem hiding this comment.
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' }) |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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;
This PR helps with wallet integration and supports manifest collection definition