Skip to content

Commit

Permalink
fix: failing network requests
Browse files Browse the repository at this point in the history
  • Loading branch information
cgilbe27 committed Dec 31, 2024
1 parent 9148894 commit a74d06a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
17 changes: 10 additions & 7 deletions src/libs/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
type RequestRegistry,
adapter,
} from './registry';
import { type RequestRegistry, adapter } from './registry';

export const DEFAULT: RequestRegistry = {
auth_params: { url: '/cosmos/auth/v1beta1/params', adapter },
Expand All @@ -10,7 +7,10 @@ export const DEFAULT: RequestRegistry = {
url: '/cosmos/auth/v1beta1/accounts/{address}',
adapter,
},
params: { url: '/cosmos/params/v1beta1/params?subspace={subspace}&key={key}', adapter },
params: {
url: '/cosmos/params/v1beta1/params?subspace={subspace}&key={key}',
adapter,
},
bank_params: { url: '/cosmos/bank/v1beta1/params', adapter },
bank_balances_address: {
url: '/cosmos/bank/v1beta1/balances/{address}',
Expand All @@ -21,7 +21,10 @@ export const DEFAULT: RequestRegistry = {
adapter,
},
bank_supply: { url: '/cosmos/bank/v1beta1/supply', adapter },
bank_supply_by_denom: { url: '/cosmos/bank/v1beta1/supply/{denom}', adapter },
bank_supply_by_denom: {
url: '/cosmos/bank/v1beta1/supply/by_denom?denom={denom}',
adapter,
},
distribution_params: { url: '/cosmos/distribution/v1beta1/params', adapter },
distribution_community_pool: {
url: '/cosmos/distribution/v1beta1/community_pool',
Expand Down Expand Up @@ -138,7 +141,7 @@ export const DEFAULT: RequestRegistry = {
tx_txs_block: { url: '/cosmos/tx/v1beta1/txs/block/{height}', adapter },
tx_hash: { url: '/cosmos/tx/v1beta1/txs/{hash}', adapter },

mint_inflation: { url: '/cosmos/mint/v1beta1/inflation', adapter },
mint_inflation: { url: '/nibiru/inflation/v1/params', adapter },
mint_params: { url: '/cosmos/mint/v1beta1/params', adapter },
mint_annual_provisions: {
url: '/cosmos/mint/v1beta1/annual_provisions',
Expand Down
44 changes: 26 additions & 18 deletions src/libs/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import type {
Validator,
} from '@/types/staking';
import type { PaginatedTxs, Tx, TxResponse } from '@/types';
import semver from 'semver'
import semver from 'semver';
export interface Request<T> {
url: string;
adapter: (source: any) => Promise<T>;
Expand Down Expand Up @@ -75,13 +75,15 @@ export interface RequestRegistry extends AbstractRegistry {
distribution_community_pool: Request<{ pool: Coin[] }>;
distribution_delegator_rewards: Request<{
rewards: {
validator_address: string,
reward: Coin[]
}[],
total: Coin[]
validator_address: string;
reward: Coin[];
}[];
total: Coin[];
}>;

mint_inflation: Request<{ inflation: string }>;
mint_inflation: Request<{
params: { inflation_distribution: { staking_rewards: string } };
}>;
mint_params: Request<{
params: {
mint_denom: string;
Expand All @@ -90,7 +92,7 @@ export interface RequestRegistry extends AbstractRegistry {
}>;
mint_annual_provisions: Request<{ annual_provisions: string }>;

slashing_params: Request<{params: SlashingParam}>;
slashing_params: Request<{ params: SlashingParam }>;
slashing_signing_info: Request<PaginatedSigningInfo>;

gov_params_voting: Request<GovParams>;
Expand Down Expand Up @@ -124,7 +126,7 @@ export interface RequestRegistry extends AbstractRegistry {
base_tendermint_validatorsets_latest: Request<PaginatedTendermintValidator>;
base_tendermint_validatorsets_height: Request<PaginatedTendermintValidator>;

params: Request<{param: any}>;
params: Request<{ param: any }>;

tx_txs: Request<PaginatedTxs>;
tx_txs_block: Request<Tx>;
Expand All @@ -151,7 +153,9 @@ export interface RequestRegistry extends AbstractRegistry {
ibc_core_connection_connections: Request<PaginatedIBCConnections>;
ibc_core_connection_connections_connection_id: Request<ConnectionWithProof>;
ibc_core_connection_connections_connection_id_client_state: Request<ClientStateWithProof>;
interchain_security_ccv_provider_validator_consumer_addr: Request<{consumer_address: string}>
interchain_security_ccv_provider_validator_consumer_addr: Request<{
consumer_address: string;
}>;
}

export function adapter<T>(source: any): Promise<T> {
Expand All @@ -174,16 +178,20 @@ export const VERSION_REGISTRY: ApiProfileRegistry = {};
// ChainName Profile Registory
export const NAME_REGISTRY: ApiProfileRegistry = {};

export function registryVersionProfile(version: string, requests: RequestRegistry) {
VERSION_REGISTRY[version] = requests
export function registryVersionProfile(
version: string,
requests: RequestRegistry
) {
VERSION_REGISTRY[version] = requests;
}

export function registryChainProfile(version: string, requests: RequestRegistry) {
NAME_REGISTRY[version] = requests
export function registryChainProfile(
version: string,
requests: RequestRegistry
) {
NAME_REGISTRY[version] = requests;
}
export function findApiProfileByChain(
name: string,
): RequestRegistry {
export function findApiProfileByChain(name: string): RequestRegistry {
const url = NAME_REGISTRY[name];
// if (!url) {
// throw new Error(`Unsupported version or name: ${name}`);
Expand All @@ -192,12 +200,12 @@ export function findApiProfileByChain(
}

export function findApiProfileBySDKVersion(
version: string,
version: string
): RequestRegistry | undefined {
let closestVersion: string | null = null;

for (const k in VERSION_REGISTRY) {
const key = k.replace('v', "")
const key = k.replace('v', '');
// console.log(semver.gt(key, version), semver.gte(version, key), key, version)
if (semver.lte(key, version)) {
if (!closestVersion || semver.gt(key, closestVersion)) {
Expand Down
2 changes: 1 addition & 1 deletion src/stores/useMintStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useMintStore = defineStore('mintStore', {
this.inflation = '0';
});
if (res) {
this.inflation = res.inflation;
this.inflation = res.params.inflation_distribution.staking_rewards;
}
} catch (e) {
console.log(e);
Expand Down

0 comments on commit a74d06a

Please sign in to comment.