connexion to fetch validator urls
This commit is contained in:
@@ -1,47 +1,50 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { FormControl, InputLabel, ListItemText, MenuItem, Select, SelectChangeEvent, Typography } from '@mui/material';
|
||||
// import { getValidators } from '../requests';
|
||||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import { ListItemText, MenuItem, Select, SelectChangeEvent, Typography } from '@mui/material';
|
||||
import { ClientContext } from '../context/main';
|
||||
import { validatorUrls } from '../utils';
|
||||
|
||||
interface ValidatorDropdownProps {
|
||||
onChangeValidatorSelection: (validator: TValidatorOption) => void;
|
||||
}
|
||||
type TValidatorUrl = string;
|
||||
|
||||
type TValidatorOption = string;
|
||||
|
||||
export const ValidatorSelector: React.FC<ValidatorDropdownProps> = ({
|
||||
export const ValidatorSelector: React.FC<{ onChangeValidatorSelection: (validator: TValidatorUrl) => void }> = ({
|
||||
onChangeValidatorSelection,
|
||||
}) => {
|
||||
const [validators, setValidators] = useState<TValidatorOption[] | null>(null);
|
||||
const [selectedValidator, setSelectedValidator] = useState<TValidatorOption>('');
|
||||
|
||||
const [validators, setValidators] = useState<string[] | null>();
|
||||
const [selectedValidator, setSelectedValidator] = useState<TValidatorUrl>('');
|
||||
|
||||
const {
|
||||
network
|
||||
} = useContext(ClientContext);
|
||||
|
||||
useEffect(() => {
|
||||
// (async () => {
|
||||
// await getValidators();
|
||||
// })();
|
||||
setValidators(['aaa', 'bbb', 'ccc']);
|
||||
(async () => {
|
||||
if(network) {
|
||||
const validator = await validatorUrls(network);
|
||||
setValidators(validator?.urls);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
onChangeValidatorSelection(selectedValidator);
|
||||
}, [selectedValidator]);
|
||||
|
||||
return validators &&
|
||||
return (
|
||||
<Select
|
||||
labelId="validatorSelect_label"
|
||||
id="validatorSelect"
|
||||
value={selectedValidator}
|
||||
onChange={(e: SelectChangeEvent) => {
|
||||
setSelectedValidator(e.target.value as TValidatorOption);
|
||||
setSelectedValidator(e.target.value as TValidatorUrl);
|
||||
}}
|
||||
renderValue={(value) => <Typography sx={{ textTransform: 'capitalize' }}>{value}</Typography>}
|
||||
>
|
||||
{
|
||||
validators.map((validator) => (
|
||||
validators && validators.map((validator) => (
|
||||
<MenuItem value={validator} key={validator}>
|
||||
<ListItemText>{validator}</ListItemText>
|
||||
</MenuItem>
|
||||
))
|
||||
}
|
||||
</Select>
|
||||
};
|
||||
)};
|
||||
|
||||
@@ -5,4 +5,4 @@ export * from './contract';
|
||||
export * from './vesting';
|
||||
export * from './network';
|
||||
export * from './queries';
|
||||
// export * from './validators';
|
||||
export * from './validators';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//TODO once merge branch feature/wallet-expose-validator-urls
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { Network } from '../types';
|
||||
|
||||
// import {
|
||||
// ValidatorUrls
|
||||
// } from '../types';
|
||||
import {
|
||||
ValidatorUrls
|
||||
} from '../types';
|
||||
|
||||
// export const getValidators = async (): Promise<ValidatorUrls> => {
|
||||
// const ValidatorUrls: ValidatorUrls = await invoke('locked_coins');
|
||||
// const major = await minorToMajor(coin.amount);
|
||||
// return major;
|
||||
// };
|
||||
export const getValidatorUrls = async (network: Network): Promise<ValidatorUrls> => {
|
||||
const res: ValidatorUrls = await invoke('get_validator_nymd_urls', { network });
|
||||
return res;
|
||||
};
|
||||
|
||||
@@ -23,3 +23,4 @@ export * from './vestingperiod';
|
||||
export * from './pendingundelegate';
|
||||
export * from './delegationevent';
|
||||
export * from './epoch';
|
||||
export * from './validatorurls';
|
||||
|
||||
@@ -2,7 +2,7 @@ import { invoke } from '@tauri-apps/api';
|
||||
import { appWindow } from '@tauri-apps/api/window';
|
||||
import bs58 from 'bs58';
|
||||
import { minor, valid } from 'semver';
|
||||
import { userBalance, majorToMinor, getLockedCoins, getSpendableCoins } from '../requests';
|
||||
import { userBalance, majorToMinor, getLockedCoins, getSpendableCoins, getValidatorUrls } from '../requests';
|
||||
import { Coin, Network, TCurrency } from '../types';
|
||||
import { Console } from './console';
|
||||
|
||||
@@ -150,3 +150,13 @@ export const maximizeWindow = async () => {
|
||||
export function removeObjectDuplicates<T extends object, K extends keyof T>(arr: T[], id: K) {
|
||||
return arr.filter((v, i, a) => a.findIndex((v2) => v2[id] === v[id]) === i);
|
||||
}
|
||||
|
||||
export const validatorUrls = async (network: Network) => {
|
||||
try {
|
||||
const urls = await getValidatorUrls(network);
|
||||
return urls;
|
||||
} catch (e) {
|
||||
Console.error(e as string);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Reference in New Issue
Block a user