return governance schemas (#210)

This commit is contained in:
Dmitry
2023-11-15 14:03:46 +03:00
committed by GitHub
parent 30512d7500
commit 093c57ccdc
7 changed files with 117 additions and 6 deletions

View File

@@ -18,6 +18,12 @@ import { makePartial } from '../../utils';
import type { networkCodes } from '../../constants/index.js';
import { fetchWithValidation } from 'simple-typed-fetch';
import type { BasicAuthCredentials } from '../../types.js';
import {
governanceChainsInfoSchema,
governanceContractsSchema,
governancePoolSchema,
governancePoolsSchema
} from './schemas';
type IAdminAuthHeaders = {
auth: string
@@ -62,6 +68,7 @@ type PlatformFees = {
walletAddress?: string | undefined
fromWidget?: string | undefined
}
class BlockchainService {
private readonly apiUrl: string;
@@ -109,6 +116,10 @@ class BlockchainService {
this.getBlockNumber = this.getBlockNumber.bind(this);
this.getRedeemOrderBySecretHash = this.getRedeemOrderBySecretHash.bind(this);
this.claimOrder = this.claimOrder.bind(this);
this.getGovernanceContracts = this.getGovernanceContracts.bind(this);
this.getGovernancePools = this.getGovernancePools.bind(this);
this.getGovernancePool = this.getGovernancePool.bind(this);
this.getGovernanceChainsInfo = this.getGovernanceChainsInfo.bind(this);
}
get basicAuthHeaders() {
@@ -222,8 +233,8 @@ class BlockchainService {
);
/**
* @deprecated In favor of getPlatformFees
*/
* @deprecated In favor of getPlatformFees
*/
getTokensFee = () => fetchWithValidation(
`${this.apiUrl}/api/tokensFee`,
z.record(z.string()).transform(makePartial),
@@ -420,9 +431,9 @@ class BlockchainService {
);
/**
* Sender is user address in source BlockchainService instance \
* Receiver is user address in target BlockchainService instance
*/
* Sender is user address in source BlockchainService instance \
* Receiver is user address in target BlockchainService instance
*/
getAtomicSwapHistory = (query: AtomicSwapHistorySourceQuery | AtomicSwapHistoryTargetQuery) => {
const url = new URL(`${this.apiUrl}/api/atomic/history/`);
@@ -476,6 +487,30 @@ class BlockchainService {
body: JSON.stringify(secretHashes),
},
);
getGovernanceContracts = () => fetchWithValidation(
`${this.apiUrl}/api/governance/info`,
governanceContractsSchema,
{ headers: this.basicAuthHeaders },
);
getGovernancePools = () => fetchWithValidation(
`${this.apiUrl}/api/governance/pools`,
governancePoolsSchema,
{ headers: this.basicAuthHeaders },
);
getGovernancePool = (address: string) => fetchWithValidation(
`${this.apiUrl}/api/governance/pools/${address}`,
governancePoolSchema,
{ headers: this.basicAuthHeaders },
);
getGovernanceChainsInfo = () => fetchWithValidation(
`${this.apiUrl}/api/governance/chains-info`,
governanceChainsInfoSchema,
{ headers: this.basicAuthHeaders },
);
}
export * as schemas from './schemas/index.js';