-
Notifications
You must be signed in to change notification settings - Fork 17
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
8 changed files
with
74 additions
and
39 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import axios from "axios"; | ||
|
||
import { zResourcesResponseLcd } from "lib/services/types"; | ||
import type { | ||
ResourceResponse, | ||
ResourceResponseItem, | ||
} from "lib/services/types"; | ||
import type { Addr, Nullable } from "lib/types"; | ||
import { parseWithError } from "lib/utils"; | ||
|
||
export const getAccountResourcesLcd = async ( | ||
endpoint: string, | ||
address: Addr | ||
): Promise<ResourceResponse> => { | ||
const result: ResourceResponseItem[] = []; | ||
|
||
const fetchFn = async (paginationKey: Nullable<string>) => { | ||
const res = await axios | ||
.get( | ||
`${endpoint}/initia/move/v1/accounts/${encodeURI(address)}/resources`, | ||
{ | ||
params: { | ||
"pagination.key": paginationKey, | ||
}, | ||
} | ||
) | ||
.then(({ data }) => parseWithError(zResourcesResponseLcd, data)); | ||
result.push(...res.resources); | ||
if (res.pagination.nextKey) await fetchFn(res.pagination.nextKey); | ||
}; | ||
|
||
await fetchFn(null); | ||
|
||
return { | ||
items: result.sort((a, b) => a.structTag.localeCompare(b.structTag)), | ||
total: result.length, | ||
}; | ||
}; |
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 +1,2 @@ | ||
export * from "./module"; | ||
export * from "./resource"; |
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,25 @@ | ||
import { z } from "zod"; | ||
|
||
import { zHexAddr, zPagination } from "lib/types"; | ||
import { snakeToCamel } from "lib/utils"; | ||
|
||
const zResourcesResponseItem = z | ||
.object({ | ||
address: zHexAddr, | ||
move_resource: z.string(), | ||
raw_bytes: z.string(), | ||
struct_tag: z.string(), | ||
}) | ||
.transform(snakeToCamel); | ||
export type ResourceResponseItem = z.infer<typeof zResourcesResponseItem>; | ||
|
||
export const zResourcesResponseLcd = z.object({ | ||
resources: z.array(zResourcesResponseItem), | ||
pagination: zPagination, | ||
}); | ||
|
||
export const zResourcesResponse = z.object({ | ||
items: z.array(zResourcesResponseItem), | ||
total: z.number().nonnegative(), | ||
}); | ||
export type ResourceResponse = z.infer<typeof zResourcesResponse>; |