generated from well-known-components/template-server
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfb40a4
commit 449d72f
Showing
31 changed files
with
1,144 additions
and
174 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules/ | |
**/.DS_Store | ||
coverage | ||
.env | ||
third-party-contracts-*.json |
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,58 @@ | ||
import { AppComponents } from '../types' | ||
import { ContractNetwork } from '@dcl/schemas' | ||
|
||
export type AlchemyNftFetcher = { | ||
getNFTsForOwner(owner: string, contractsByNetwork: Record<string, Set<string>>): Promise<string[]> | ||
} | ||
|
||
export async function createAlchemyNftFetcher({ | ||
config, | ||
logs, | ||
fetch | ||
}: Pick<AppComponents, 'config' | 'logs' | 'fetch'>): Promise<AlchemyNftFetcher> { | ||
const logger = logs.getLogger('alchemy-nft-fetcher') | ||
const nftWorkerBaseUrl = (await config.getString('NFT_WORKER_BASE_URL')) || 'https://nfts.decentraland.org' | ||
|
||
async function getNFTsForOwnerForNetwork( | ||
owner: string, | ||
network: string, | ||
contractAddresses: Set<string> | ||
): Promise<string[]> { | ||
if (!Object.values(ContractNetwork).includes(network as ContractNetwork)) { | ||
logger.warn(`Network ${network} not supported for LinkedWearables`) | ||
return [] | ||
} | ||
|
||
const response = await fetch.fetch(`${nftWorkerBaseUrl}/wallets/${owner}/networks/${network}/nfts`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json' | ||
}, | ||
body: JSON.stringify(Array.from(contractAddresses)) | ||
}) | ||
|
||
if (!response.ok) { | ||
logger.error(`Error fetching NFTs from Alchemy: ${response.status} - ${response.statusText}`) | ||
return [] | ||
} | ||
|
||
const nfts = await response.json() | ||
|
||
return nfts.data as string[] | ||
} | ||
|
||
async function getNFTsForOwner(owner: string, contractsByNetwork: Record<string, Set<string>>): Promise<string[]> { | ||
const all = await Promise.all( | ||
Object.entries(contractsByNetwork).map(([network, contractAddresses]) => | ||
getNFTsForOwnerForNetwork(owner, network, contractAddresses) | ||
) | ||
) | ||
|
||
return all.flat(1) | ||
} | ||
|
||
return { | ||
getNFTsForOwner | ||
} | ||
} |
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
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
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.