-
Notifications
You must be signed in to change notification settings - Fork 24
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
e14ca07
commit f3e08f6
Showing
2 changed files
with
70 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { mbjs } from '@mintbase-js/sdk'; | ||
import { META_SERVICE_HOST, META_SERVICE_HOST_TESTNET, MINTBASE_API_KEY_HEADER } from '../../constants'; | ||
import { ParsedDataReturn } from '../../types'; | ||
import { parseData } from '../../utils'; | ||
import { ORDER_BY_VALUE, UserTokensQueryResult } from './userOwnedTokens.types'; | ||
|
||
|
||
export const getUserOwnedTokens = async ( | ||
accountId: string, | ||
limit: number, | ||
offset: number, | ||
orderBy: ORDER_BY_VALUE, | ||
listedFilter: boolean, | ||
): Promise<ParsedDataReturn<UserTokensQueryResult>> => { | ||
|
||
let data; | ||
let error: string; | ||
|
||
const useHost = mbjs.keys.network === 'testnet' | ||
? META_SERVICE_HOST_TESTNET | ||
: META_SERVICE_HOST; | ||
|
||
try { | ||
const res = await fetch(`${useHost}/human/${accountId}/owned?offset=${offset}&limit=${limit}&orderBy=${orderBy}&listedFilter=${listedFilter}`, { | ||
method: 'GET', | ||
headers: { 'Content-type': 'application/json', | ||
[MINTBASE_API_KEY_HEADER]: mbjs.keys.apiKey, | ||
}, | ||
}); | ||
|
||
if (!res.ok) { | ||
error = 'Error fetching human owned nfts'; | ||
throw new Error(error); | ||
} | ||
|
||
data = await res.json(); | ||
} catch (err) { | ||
error = `Error fetching human owned nfts, ${err}`; | ||
} | ||
|
||
|
||
return parseData<UserTokensQueryResult>( | ||
data, | ||
error, | ||
error, | ||
); | ||
}; |
23 changes: 23 additions & 0 deletions
23
packages/data/src/api/userOwnedTokens/userOwnedTokens.types.ts
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,23 @@ | ||
export enum ORDER_BY_VALUE { | ||
PRICE_DESC = 'price desc nulls last', | ||
PRICE_ASC = 'price asc', | ||
LATEST = 'latest', | ||
OLDEST = 'oldest', | ||
} | ||
|
||
export interface UserTokensQueryResult { | ||
nft_contract_id: string; | ||
token_id: string; | ||
minter: string; | ||
owner: string; | ||
base_uri: string; | ||
metadata_id: string; | ||
title: string; | ||
media: string; | ||
reference: string; | ||
reference_blob: null; | ||
minted_timestamp: string; | ||
last_transfer_timestamp: string; | ||
price: string; | ||
currency: string; | ||
} |