-
Notifications
You must be signed in to change notification settings - Fork 40
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
f45ac5f
commit d366fa6
Showing
26 changed files
with
628 additions
and
34 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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { AccountSearchResult, CollectionSearchResult } from "@/types/ark"; | ||
import type { ArkClient } from "./client"; | ||
|
||
interface CollectionSearchApiResponse { | ||
data: { | ||
collections: CollectionSearchResult[]; | ||
accounts: AccountSearchResult[]; | ||
}; | ||
} | ||
interface GetCollectionSearchParams { | ||
client: ArkClient; | ||
query: string; | ||
} | ||
|
||
export async function getCollectionSearch({ client, query }: GetCollectionSearchParams): Promise<CollectionSearchApiResponse> { | ||
const queryParams = [`q=${query}`]; | ||
|
||
try { | ||
return await client.fetch(`/collections/search?${queryParams.join("&")}`); | ||
} catch (error) { | ||
console.error(error) | ||
return { | ||
data: { collections: [], accounts: [] }, | ||
} as CollectionSearchApiResponse; | ||
} | ||
} |
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,53 @@ | ||
import type { CollectionToken } from "@/types/ark" | ||
import type { ArkClient } from "./client"; | ||
|
||
import { createSearchParamsCache, parseAsStringLiteral } from "nuqs/server"; | ||
|
||
export const collectionSortDirectionKey = "direction"; | ||
export const collectionSortDirectionsValues = ["asc", "desc"] as const; | ||
export const collectionSortDirectionsParser = parseAsStringLiteral( | ||
collectionSortDirectionsValues, | ||
).withDefault("asc"); | ||
export type CollectionSortDirection = | ||
(typeof collectionSortDirectionsValues)[number]; | ||
|
||
export const collectionSortByKey = "sort"; | ||
export const collectionSortByValues = ["price"] as const; | ||
export const collectionSortByParser = parseAsStringLiteral( | ||
collectionSortByValues, | ||
).withDefault("price"); | ||
export type CollectionSortBy = (typeof collectionSortByValues)[number]; | ||
|
||
export const collectionPageSearchParamsCache = createSearchParamsCache({ | ||
[collectionSortDirectionKey]: collectionSortDirectionsParser, | ||
[collectionSortByKey]: collectionSortByParser, | ||
}); | ||
|
||
interface CollectionTokensApiResponse { | ||
data: CollectionToken[]; | ||
next_page: number | null; | ||
token_count: number; | ||
} | ||
interface GetCollectionTokensParams { | ||
client: ArkClient; | ||
collectionAddress: string; | ||
page?: number; | ||
itemsPerPage?: number; | ||
sortBy?: string; | ||
sortDirection?: string; | ||
} | ||
|
||
export async function getCollectionTokens({ client, collectionAddress, page = 1, itemsPerPage = 50, sortBy = "price", sortDirection = "asc" }: GetCollectionTokensParams): Promise<CollectionTokensApiResponse> { | ||
const queryParams = [`items_per_page=${itemsPerPage}`, `sort=${sortBy}`, `direction=${sortDirection}`, `page=${page}`]; | ||
|
||
try { | ||
return await client.fetch(`/collections/${collectionAddress}/0x534e5f4d41494e/tokens?${queryParams.join("&")}`); | ||
} catch (error) { | ||
console.error(error) | ||
return { | ||
data: [], | ||
next_page: null, | ||
token_count: 0, | ||
} as CollectionTokensApiResponse; | ||
} | ||
} |
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,26 @@ | ||
import type { PortfolioActivity } from "@/types/ark"; | ||
import type { ArkClient } from "./client" | ||
|
||
|
||
export interface PortfolioActivityApiResponse { | ||
count: number; | ||
data: PortfolioActivity[]; | ||
next_page: number; | ||
} | ||
|
||
interface GetPortfolioActivityParams { | ||
client: ArkClient | ||
walletAddress: string | ||
page?: number | ||
itemsPerPage?: number | ||
} | ||
|
||
export async function getPortfolioActivity({ client, walletAddress, page = 1, itemsPerPage = 10 }: GetPortfolioActivityParams): Promise<PortfolioActivityApiResponse> { | ||
const queryParams = [`items_per_page=${itemsPerPage}`, `page=${page}`]; | ||
|
||
try { | ||
return await client.fetch(`/portfolio/${walletAddress}/activity?${queryParams.join("&")}`); | ||
} catch (error) { | ||
throw new Error("failed to fetch portfolio activity : " + (error as string)) | ||
} | ||
} |
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,33 @@ | ||
import type { PortfolioCollection } from "@/types/ark"; | ||
import type { ArkClient } from "./client" | ||
|
||
|
||
export interface PortfolioCollectionApiResponse { | ||
collection_count: number; | ||
token_count: number; | ||
data: PortfolioCollection[]; | ||
next_page: number | null; | ||
|
||
} | ||
|
||
interface GetPortfolioActivityParams { | ||
client: ArkClient | ||
walletAddress: string | ||
page?: number | ||
itemsPerPage?: number | ||
} | ||
|
||
export async function getPortfolioCollections({ client, walletAddress, page = 1, itemsPerPage = 10 }: GetPortfolioActivityParams): Promise<PortfolioCollectionApiResponse> { | ||
const queryParams = [`items_per_page=${itemsPerPage}`, `page=${page}`]; | ||
|
||
try { | ||
return await client.fetch(`/portfolio/${walletAddress}/collections?${queryParams.join("&")}`); | ||
} catch (_) { | ||
return { | ||
data: [], | ||
next_page: null, | ||
collection_count: 0, | ||
token_count: 0, | ||
}; | ||
} | ||
} |
Oops, something went wrong.