Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Nexus API as a backend option for Wallet #2076

Merged
merged 19 commits into from
Nov 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Nexus validators API
buberdds committed Nov 6, 2024

Verified

This commit was signed with the committer’s verified signature.
commit 7e6b632d9d0bc6099bc28ebab5aeecc9c1766175
45 changes: 41 additions & 4 deletions src/vendors/nexus.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
import { Configuration } from 'vendors/nexus/index'

import { Configuration, DefaultApi as NexusApi, Validator as NexusValidator } from 'vendors/nexus/index'
import { StringifiedBigInt } from 'types/StringifiedBigInt'
import { Validator } from 'app/state/staking/types'
import { throwAPIErrors } from './helpers'

export function getNexusAPIs(url: string | 'https://nexus.oasis.io/v1/consensus/') {
export function getNexusAPIs(url: string | 'https://nexus.oasis.io/v1/') {
const explorerConfig = new Configuration({
basePath: url,
...throwAPIErrors,
})

return {}
const api = new NexusApi(explorerConfig)

async function getAllValidators(): Promise<Validator[]> {
const validatorsResponse = await api.consensusValidatorsGet({})
if (!validatorsResponse) throw new Error('Wrong response code')

return parseValidatorsList(validatorsResponse.validators)
}

async function getTransactionsList(params: { accountId: string; limit: number }) {
return []
}

return {
getAllValidators,
getTransactionsList,
}
}

function parseValidatorsList(validators: NexusValidator[]): Validator[] {
return validators.map(v => {
const parsed: Validator = {
address: v.entity_address,
name: v.media?.name ?? undefined,
escrow: v.escrow.active_balance as StringifiedBigInt,
current_rate: v.current_rate / 100000,
status: v.active ? 'active' : 'inactive',
media: {
email_address: v.media?.email ?? undefined,
logotype: v.media?.logoUrl ?? undefined,
twitter_acc: v.media?.twitter ?? undefined,
website_link: v.media?.url ?? undefined,
},
rank: v.rank,
}
return parsed
})
}