Skip to content

Commit

Permalink
fix(validator): fix validator page after upgrade, refactor lcd reques…
Browse files Browse the repository at this point in the history
…ts (#1328)
  • Loading branch information
happylolonly authored Oct 9, 2024
1 parent abd1e40 commit f5d15fa
Show file tree
Hide file tree
Showing 29 changed files with 633 additions and 608 deletions.
3 changes: 1 addition & 2 deletions src/containers/Search/ActionBarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {
ButtonImgText,
} from '../../components';

import { getTxs } from '../../utils/search/utils';

import { LEDGER } from '../../utils/config';
import { PATTERN_IPFS_HASH } from 'src/constants/patterns';
import { trimString } from '../../utils/utils';
Expand All @@ -22,6 +20,7 @@ import { DefaultAccount } from 'src/types/defaultAccount';
import { BackgroundWorker } from 'src/services/backend/workers/background/worker';
import { SenseApi } from 'src/contexts/backend/services/senseApi';
import { sendCyberlink } from 'src/services/neuron/neuronApi';
import { getTxs } from 'src/services/transactions/lcd';

const imgKeplr = require('../../image/keplr-icon.svg');
const imgLedger = require('../../image/ledger.svg');
Expand Down
4 changes: 3 additions & 1 deletion src/containers/Validators/Validators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ import { useParams } from 'react-router-dom';
import { useDevice } from 'src/contexts/device';
import { useQueryClient } from 'src/contexts/queryClient';
import { useAdviser } from 'src/features/adviser/context';
import { getDelegatorDelegations } from 'src/utils/search/utils';

import {
BondStatus,
Validator,
} from 'cosmjs-types/cosmos/staking/v1beta1/staking';
import { DenomArr, MainContainer, Loading } from 'src/components';
import { BASE_DENOM, DENOM_LIQUID } from 'src/constants/config';
import useStakingParams from 'src/features/staking/useStakingParams';

import { fromBech32, formatNumber, asyncForEach } from '../../utils/utils';
import ActionBarContainer from './ActionBarContainer';
import { TableHeroes, TableItem, InfoBalance } from './components';
import getHeroes from './getHeroesHook';
import { useGetBalance } from '../../pages/robot/_refactor/account/hooks';
import useSetActiveAddress from '../../hooks/useSetActiveAddress';
import styles from './Validators.module.scss';
import { getDelegatorDelegations } from 'src/features/staking/getDelegatorDelegations';

function Validators({ defaultAccount }) {
const { isMobile: mobile } = useDevice();
Expand Down
2 changes: 1 addition & 1 deletion src/containers/application/notFound.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styles from './notFound.module.scss';

function NotFound({ text }) {
return <div className={styles.container} />;
return <div className={styles.container}>{text || 'not found'}</div>;
}

export default NotFound;
2 changes: 1 addition & 1 deletion src/containers/energy/component/actionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Link } from 'react-router-dom';
import { useSigningClient } from 'src/contexts/signerClient';
import { PATTERN_CYBER, PATTERN_CYBER_CONTRACT } from 'src/constants/patterns';
import { DEFAULT_GAS_LIMITS } from 'src/constants/config';
import { getTxs } from 'src/services/transactions/lcd';
import {
Dots,
ActionBarContentText,
Expand All @@ -17,7 +18,6 @@ import {
Input,
} from '../../../components';
import { LEDGER } from '../../../utils/config';
import { getTxs } from '../../../utils/search/utils';
import { ValueImg } from '../ui';
import { routes } from '../../../routes';

Expand Down
3 changes: 1 addition & 2 deletions src/containers/governance/actionBarDatail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
MEMO_KEPLR,
} from 'src/constants/config';
import useCurrentAddress from 'src/hooks/useCurrentAddress';
import { getTxs } from 'src/services/transactions/lcd';
import {
TransactionSubmitted,
Confirmed,
Expand All @@ -28,7 +29,6 @@ import {
Select,
} from '../../components';

import { getTxs } from '../../utils/search/utils';
// import styles from './ActionBarDetail.module.scss';

import { LEDGER } from '../../utils/config';
Expand All @@ -51,7 +51,6 @@ type Props = {
};

function ActionBarDetail({ proposals, id, update }: Props) {
const queryClient = useQueryClient();
const { signer, signingClient } = useSigningClient();
const [stage, setStage] = useState(STAGE_INIT);
const [txHash, setTxHash] = useState(null);
Expand Down
2 changes: 1 addition & 1 deletion src/containers/ipfs/hooks/useGetCommunity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQuery } from '@tanstack/react-query';
import { getToLink, getFromLink } from '../../../utils/search/utils';
import { getFromLink, getToLink } from 'src/services/transactions/lcd';

const reduceParticleArr = (data) => {
return data.reduce((acc, item) => {
Expand Down
48 changes: 47 additions & 1 deletion src/containers/ipfs/hooks/useGetCreator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,53 @@
import { useQuery } from '@tanstack/react-query';
import { CreatorCyberLink } from 'src/types/cyberLink';
import { Option } from 'src/types';
import { getCreator } from '../../../utils/search/utils';
import { getTransactions } from 'src/services/transactions/lcd';

// TODO: refactor this
const getCreator = async (cid) => {
try {
const response = await getTransactions({
events: [
{
key: 'cyberlink.particleTo',
value: cid,
},
],
pagination: {
limit: 1,
offset: 0,
},
});

const response2 = await getTransactions({
events: [
{
key: 'cyberlink.particleFrom',
value: cid,
},
],
pagination: {
limit: 1,
offset: 0,
},
});

const h1 = Number(response.txResponses?.[0]?.height || 0);
const h2 = Number(response2.txResponses?.[0]?.height || 0);

if (h1 === 0) {
return response2;
}
if (h2 === 0) {
return response;
}

return h1 < h2 ? response : response2;
} catch (error) {
console.log(error);
return null;
}
};

function useGetCreator(cid: string) {
const { data } = useQuery(
Expand Down
Loading

0 comments on commit f5d15fa

Please sign in to comment.