-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
7 changed files
with
69 additions
and
4 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { getArbitrumWalletAssets } from './targets/arbitrum/client'; | ||
export { getCrossmintWalletAssets } from './targets/crossmint/client'; | ||
export { getUniqueWalletAssets } from './targets/unique/client'; |
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,32 @@ | ||
import { DeepAsset, ExternalApiError } from '@sni/types'; | ||
import { getUniqueAsset } from '../../../assets-client/targets/unique/client'; //TODO: Add path aliases | ||
import { AccountTokensResponseSchema } from './schemas'; | ||
|
||
//TODO: Cover with tests | ||
export async function getUniqueWalletAssets( | ||
network: 'unique' | 'opal', | ||
walletAddress: string, | ||
collectionId: number | ||
): Promise<DeepAsset[]> { | ||
const response = await fetch( | ||
`https://rest.unique.network/${network}/v1/tokens/account-tokens?address=${walletAddress.toLowerCase()}&collectionId=${collectionId}`, | ||
{ | ||
method: 'GET', | ||
headers: { Accept: 'application/json' }, | ||
} | ||
); | ||
|
||
if (response.status !== 200) { | ||
throw new ExternalApiError( | ||
`Failed to fetch wallet data from ${network} network. ${response.statusText}` | ||
); | ||
} | ||
|
||
const nfts = AccountTokensResponseSchema.parse(await response.json()).tokens; | ||
|
||
const deepAssets = await Promise.all( | ||
nfts.map((nft) => getUniqueAsset(network, nft.collectionId, nft.tokenId)) | ||
); | ||
|
||
return deepAssets; | ||
} |
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,10 @@ | ||
import { z } from 'zod'; | ||
|
||
export const AccountTokensResponseSchema = z.object({ | ||
tokens: z.array( | ||
z.object({ | ||
collectionId: z.number(), | ||
tokenId: z.number(), | ||
}) | ||
), | ||
}); |
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