Skip to content

Commit

Permalink
Merge pull request #650 from liquality/fix/infura-nft-provider
Browse files Browse the repository at this point in the history
feat: fixed infura nft provider
  • Loading branch information
bradleySuira committed May 2, 2023
2 parents 2848770 + fad1035 commit 0046cd8
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 98 deletions.
10 changes: 10 additions & 0 deletions .changeset/twenty-lemons-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@chainify/bitcoin': minor
'@chainify/evm': minor
'@chainify/evm-contracts': minor
'@chainify/terra': minor
'@chainify/types': minor
'@chainify/utils': minor
---

Updated Infura nft provider with fixes
2 changes: 1 addition & 1 deletion packages/bitcoin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"bitcoinjs-lib": "5.2.0",
"bitcoinjs-message": "2.2.0",
"coinselect": "^3.1.12",
"lodash": "^4.17.21",
"lodash": "4.17.21",
"memoizee": "^0.4.15"
}
}
2 changes: 1 addition & 1 deletion packages/evm-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"hardhat-gas-reporter": "^1.0.7",
"husky": "^7.0.4",
"lint-staged": "^12.3.3",
"lodash": "^4.17.21",
"lodash": "4.17.21",
"mocha": "^9.2.0",
"pinst": "^2.1.6",
"prettier": "^2.5.1",
Expand Down
68 changes: 36 additions & 32 deletions packages/evm/lib/nft/InfuraNftProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,45 @@ export class InfuraNftProvider extends EvmNftProvider {

async fetch(): Promise<NFTAsset[]> {
const [userAddress, network] = await Promise.all([this.walletProvider.getAddress(), this.walletProvider.getConnectedNetwork()]);

const chainId = Number(network.chainId);
const { data } = await this._httpClient.nodeGet(`/networks/${chainId}/accounts/${userAddress.toString()}/assets/nfts`);
return data.reduce((result: NFTAsset[], nft: { contract: any; tokenId: any; supply: any; type: any; metadata: any }) => {
const { contract, tokenId, supply, type, metadata } = nft;
if (type in NftTypes && contract) {
this.cache[contract] = {
contract: this.schemas[type].attach(contract),
schema: type as NftTypes,
};
const _image = metadata?.image?.replace('ipfs://', 'https://ipfs.io/ipfs/') || '';
const nftAsset: NFTAsset = {
asset_contract: {
address: contract,
name: metadata?.name,
symbol: '',
},
collection: {
const response = await this._httpClient.nodeGet(`/networks/${chainId}/accounts/${userAddress.toString()}/assets/nfts`);

return (
response?.assets?.reduce((result: NFTAsset[], nft: { contract: any; tokenId: any; supply: any; type: any; metadata: any }) => {
const { contract, tokenId, supply, type, metadata } = nft;
if (type in NftTypes && contract) {
this.cache[contract] = {
contract: this.schemas[type].attach(contract),
schema: type as NftTypes,
};
const _image = metadata?.image?.replace('ipfs://', 'https://ipfs.io/ipfs/') || '';
const description =
metadata?.attributes?.find((i: any) => i.trait_type === 'Description')?.value || metadata?.description;
const nftAsset: NFTAsset = {
asset_contract: {
address: contract,
name: metadata?.name,
symbol: '',
},
collection: {
name: metadata?.name,
},
token_id: tokenId,
amount: supply,
standard: type,
name: metadata?.name,
},
token_id: tokenId,
amount: supply,
standard: type,
name: metadata?.name,
description: metadata?.attributes.find((i: any) => i.trait_type === 'Description')?.value,
image_original_url: _image,
image_preview_url: _image,
image_thumbnail_url: _image,
external_link: '',
};
description,
image_original_url: _image,
image_preview_url: _image,
image_thumbnail_url: _image,
external_link: '',
};

result.push(nftAsset);
}
result.push(nftAsset);
}

return result;
}, []);
return result;
}, []) || []
);
}
}
4 changes: 2 additions & 2 deletions packages/terra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"@chainify/logger": "workspace:*",
"@chainify/types": "workspace:*",
"@chainify/utils": "workspace:*",
"@terra-money/terra.js": "3.1.3",
"@terra-money/terra.js": "3.1.6",
"@types/luxon": "^2.0.9",
"lodash": "^4.17.21",
"lodash": "4.17.21",
"luxon": "^2.3.1"
}
}
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"@ethersproject/bignumber": "5.7.0",
"@liquality/cryptoassets": "^1.13.3",
"@liquality/cryptoassets": "1.6.0",
"bignumber.js": "^9.0.2"
}
}
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@chainify/types": "workspace:*",
"@ethersproject/sha2": "5.7.0",
"bech32": "^2.0.0",
"bs58": "^5.0.0",
"bs58": "5.0.0",
"crypto-hashing": "^1.0.0",
"setimmediate": "^1.0.5"
},
Expand Down

0 comments on commit 0046cd8

Please sign in to comment.