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

Rooms nft #125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Rooms nft #125

wants to merge 3 commits into from

Conversation

tanerdurmaz
Copy link
Collaborator

  • Room ownership changed, now it is nft based
  • I used some gas price and gaslimit but not sure how clever was it.

@tanerdurmaz tanerdurmaz requested a review from LeoTheG August 29, 2021 20:27
Comment on lines +13 to +14
const HDWalletProvider = require("@truffle/hdwallet-provider");
const web3 = require( 'web3');
Copy link
Member

Choose a reason for hiding this comment

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

should use import instead of require whenever possible in typescript projects for proper type checking

might have to install @types/... to get it working

@@ -72,8 +98,54 @@ roomRouter.post("/:roomId", async (req, res) => {

await collection
.doc(roomId)
.set({ name: roomId, isLocked, lockedOwnerAddress: address ?? undefined , contractAddress: contractAddress ?? undefined});
.set({ name: roomId, isLocked, lockedOwnerAddress: "dynamic" , contractAddress: contractAddress ?? undefined});
Copy link
Member

Choose a reason for hiding this comment

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

if lockedOwnerAddress is dynamic every time from now on, do we need to set it as dynamic? Seems redundant

.set({ name: roomId, isLocked, lockedOwnerAddress: "dynamic" , contractAddress: contractAddress ?? undefined});

// get token count then add new metadata to database using it
const tokenCount = await nftRooms.doc("token-count").get();
Copy link
Member

Choose a reason for hiding this comment

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

Don't want to store this in the database, the database can get out of sync for whatever reason. We can instead query the blockchain directly for token balance using total supply https://docs.openzeppelin.com/contracts/3.x/api/token/erc721#IERC721Enumerable-totalSupply--

Comment on lines +109 to +115
await nftRooms
.doc(tokenId.toString())
.set({ name: roomId });

await nftRooms
.doc("token-count")
.set({ count: tokenId});
Copy link
Member

Choose a reason for hiding this comment

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

do we need nftRooms? Why not store the data in the room itself in the chatrooms collection?

Comment on lines +119 to +120
const provider = new HDWalletProvider(MNEMONIC, "https://rpc-mainnet.maticvigil.com/v1/41b386d43bd3cfdf37a0fdef86b801ef9836fa7b");
const web3Instance = new web3(provider);
Copy link
Member

Choose a reason for hiding this comment

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

Since provider and web3Instance don't change, these should be declared outside the function instead of being redeclared each time the function is called

Comment on lines +123 to +129
const nftContract = new web3Instance.eth.Contract(
NFT_ABI,
NFT_CONTRACT_ADDRESS,
{ gasLimit: "1000000",
gasPrice: 15000000000
}
);
Copy link
Member

Choose a reason for hiding this comment

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

this can be declared outside the function too since its value doesn't change whenever you recall the function


const reciever = address ? address : OWNER_ADDRESS;
Copy link
Member

Choose a reason for hiding this comment

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

receiver not reciever

Copy link
Member

Choose a reason for hiding this comment

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

Also, you can just do const receiver = address || OWNER_ADDRESS

Comment on lines +138 to +142
} catch (e) {
await nftRooms
.doc("token-count")
.set({ count: parseInt(tokenCount.data()!.count) - 1 });
console.log(e);
Copy link
Member

Choose a reason for hiding this comment

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

we shouldn't need to manually keep track of count since we can query the blockchain at any time for token supply. If we want to do this, you should increase token count on success instead of always increasing token count and decreasing on failure

Comment on lines +374 to +388
await axios.get('https://api.covalenthq.com/v1/137/address/' + address + '/balances_v2/?nft=true&key=ckey_c35e2c388e1b4efea8490fb8c83').then( async (result) => {
let permission = false;
for(let i = 0; i < result.data.data.items.length; i++){
if(NFT_CONTRACT_ADDRESS!.toLowerCase() === result.data.data.items[i].contract_address.toLowerCase()){
if(result.data.data.items[i].nft_data){
for(let j = 0; j < result.data.data.items[i].nft_data.length; j++){
const doc = await nftRooms.doc(result.data.data.items[i].nft_data[j].token_id).get();
const name = await doc.get("name");
if(name === roomId){
permission = true;
}
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer if this were a separate method with a clear name explaining what it's doing. Currently it's very hard to read and understand what's happening, especially with nested for loops and very nested objects like result.data.data.items[i].nft_data

I'm not actually sure what this function is doing, can you explain it?

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