-
Notifications
You must be signed in to change notification settings - Fork 13
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
a97bddb
commit 02c7f33
Showing
17 changed files
with
357 additions
and
150 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { encode } from "url-safe-base64"; | ||
|
||
import { isValidUrl } from "@/utils/url"; | ||
|
||
import { Pagination } from "../types/api"; | ||
import { | ||
FinalityProviderState, | ||
FinalityProviderV2, | ||
} from "../types/finalityProviders"; | ||
|
||
import { apiWrapper } from "./apiWrapper"; | ||
|
||
export interface PaginatedFinalityProvidersV2 { | ||
finalityProviders: FinalityProviderV2[]; | ||
pagination: Pagination; | ||
} | ||
|
||
interface FinalityProvidersAPIResponse { | ||
data: FinalityProviderAPI[]; | ||
pagination: Pagination; | ||
} | ||
|
||
interface FinalityProviderAPI { | ||
description: DescriptionAPI; | ||
state: FinalityProviderState; | ||
commission: string; | ||
btc_pk: string; | ||
active_tvl: number; | ||
total_tvl: number; | ||
active_delegations: number; | ||
total_delegations: number; | ||
} | ||
|
||
interface DescriptionAPI { | ||
moniker: string; | ||
identity: string; | ||
website: string; | ||
security_contact: string; | ||
details: string; | ||
} | ||
|
||
export const getFinalityProvidersV2 = async ({ | ||
key, | ||
pk, | ||
sortBy, | ||
order, | ||
name, | ||
}: { | ||
key: string; | ||
name?: string; | ||
sortBy?: string; | ||
order?: "asc" | "desc"; | ||
pk?: string; | ||
}): Promise<PaginatedFinalityProvidersV2> => { | ||
// const limit = 100; | ||
// const reverse = false; | ||
|
||
const params = { | ||
pagination_key: encode(key), | ||
finality_provider_pk: pk, | ||
sort_by: sortBy, | ||
order, | ||
name, | ||
// "pagination_reverse": reverse, | ||
// "pagination_limit": limit, | ||
}; | ||
|
||
const response = await apiWrapper( | ||
"GET", | ||
"/v2/finality-providers", | ||
"Error getting finality providers", | ||
params, | ||
); | ||
|
||
const finalityProvidersAPIResponse: FinalityProvidersAPIResponse = | ||
response.data; | ||
const finalityProvidersAPI: FinalityProviderAPI[] = | ||
finalityProvidersAPIResponse.data; | ||
|
||
const finalityProviders = finalityProvidersAPI.map( | ||
(fp: FinalityProviderAPI): FinalityProviderV2 => ({ | ||
description: { | ||
moniker: fp.description.moniker, | ||
identity: fp.description.identity, | ||
website: isValidUrl(fp.description.website) | ||
? fp.description.website | ||
: "", | ||
securityContact: fp.description.security_contact, | ||
details: fp.description.details, | ||
}, | ||
state: fp.state, | ||
commission: fp.commission, | ||
btcPk: fp.btc_pk, | ||
activeTVLSat: fp.active_tvl, | ||
totalTVLSat: fp.total_tvl, | ||
activeDelegations: fp.active_delegations, | ||
totalDelegations: fp.total_delegations, | ||
}), | ||
); | ||
|
||
const pagination: Pagination = { | ||
next_key: finalityProvidersAPIResponse.pagination.next_key, | ||
}; | ||
|
||
return { finalityProviders, pagination }; | ||
}; |
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.