-
Notifications
You must be signed in to change notification settings - Fork 78
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 #645 from liquality/feat/nft-providers
Feat/nft providers
- Loading branch information
Showing
6 changed files
with
133 additions
and
223 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { HttpClient } from '@chainify/client'; | ||
import { NFTAsset } from '@chainify/types'; | ||
import { BaseProvider } from '@ethersproject/providers'; | ||
import { NftProviderConfig, NftTypes } from '../types'; | ||
import { EvmBaseWalletProvider } from '../wallet/EvmBaseWalletProvider'; | ||
import { EvmNftProvider } from './EvmNftProvider'; | ||
|
||
export class InfuraNftProvider extends EvmNftProvider { | ||
private readonly _config: NftProviderConfig; | ||
private readonly _httpClient: HttpClient; | ||
|
||
constructor(walletProvider: EvmBaseWalletProvider<BaseProvider>, config: NftProviderConfig) { | ||
super(walletProvider); | ||
this._config = config; | ||
|
||
this._httpClient = new HttpClient({ | ||
baseURL: config.url, | ||
transformResponse: undefined, | ||
headers: { Authorization: `Basic ${this._config.apiKey}` }, | ||
}); | ||
} | ||
|
||
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: { | ||
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: '', | ||
}; | ||
|
||
result.push(nftAsset); | ||
} | ||
|
||
return result; | ||
}, []); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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.