diff --git a/src/extensions/staking/src/App.tsx b/src/extensions/staking/src/App.tsx index bdad0c9..361d694 100644 --- a/src/extensions/staking/src/App.tsx +++ b/src/extensions/staking/src/App.tsx @@ -1,28 +1,27 @@ -import { Config } from './config' import React, { useEffect, useState } from 'react' import { useApp } from '../../../shared/hooks/useApp' import { DelegateSection } from './delegation/DelegateSection' import { OverviewSection } from './delegation/OverviewSection' import { DelegationInfo, DelegationProvider } from './types' -import { ApiNetworkProvider } from '@multiversx/sdk-network-providers' import { DelegationsSection } from './delegation/DelegationsSection' import { getDelegationInfoRequest, getDelegationProvidersRequest } from './api' export const App = () => { const app = useApp() - const delegationNetworkProvider = new ApiNetworkProvider(Config.Urls.Delegation(app.config.network)) const [providers, setProviders] = useState([]) const [delegations, setDelegations] = useState([]) useEffect(() => { - getDelegationProvidersRequest(delegationNetworkProvider).then((p) => setProviders(p)) - getDelegationInfoRequest(delegationNetworkProvider, app.config.entity.address).then((d) => setDelegations(d)) + getDelegationProvidersRequest(app.networkProvider).then((p) => setProviders(p)) + getDelegationInfoRequest(app.networkProvider, app.config.entity.address).then((d) => setDelegations(d)) }, []) return ( <> - + {delegations.length > 0 && ( + + )} ) diff --git a/src/extensions/staking/src/api.ts b/src/extensions/staking/src/api.ts index 8d16e17..602617f 100644 --- a/src/extensions/staking/src/api.ts +++ b/src/extensions/staking/src/api.ts @@ -3,24 +3,25 @@ import { DelegationInfo, DelegationProvider } from './types' import { ApiNetworkProvider } from '@multiversx/sdk-network-providers' export const getDelegationProvidersRequest = async (provider: ApiNetworkProvider): Promise => { - const res = await provider.doGetGeneric('providers?size=10000') - - return res.map( + const res = await provider.doGetGeneric('providers?withIdentityInfo=true&size=10000') + const providers: DelegationProvider[] = res.map( (r: any) => ({ ...r, - totalActiveStake: new BigNumber(res.totalActiveStake || 0), - maxDelegationCap: new BigNumber(res.maxDelegationCap || 0), - maxDelegateAmountAllowed: new BigNumber(res.maxDelegateAmountAllowed || 0), + contract: r.provider, + stake: new BigNumber(res.stake || 0), + delegationCap: new BigNumber(res.delegationCap || 0), } as DelegationProvider) ) + + return providers.filter((p) => !!p.identityInfo) } export const getDelegationInfoRequest = async ( provider: ApiNetworkProvider, address: string ): Promise => { - const res = await provider.doGetGeneric(`accounts/${address}/delegations?size=10000`) + const res = await provider.doGetGeneric(`accounts/${address}/delegation?size=10000`) return res.map( (r: any) => diff --git a/src/extensions/staking/src/config.ts b/src/extensions/staking/src/config.ts index fb436f9..1c7eee6 100644 --- a/src/extensions/staking/src/config.ts +++ b/src/extensions/staking/src/config.ts @@ -1,5 +1,3 @@ -import { Network } from '../../../shared/types' - export const Config = { Endpoints: { ClaimRewards: 'claimRewards', @@ -7,12 +5,4 @@ export const Config = { ReDelegateRewards: 'reDelegateRewards', UnDelegate: 'unDelegate', }, - - Urls: { - Delegation: (network: Network) => { - if (network === 'devnet') return 'https://devnet-delegation-api.multiversx.com' - if (network === 'testnet') return 'https://testnet-delegation-api.multiversx.com' - return 'https://delegation-api.multiversx.com' - }, - }, } diff --git a/src/extensions/staking/src/delegation/DelegateSection.tsx b/src/extensions/staking/src/delegation/DelegateSection.tsx index 6d15042..d7bfffa 100644 --- a/src/extensions/staking/src/delegation/DelegateSection.tsx +++ b/src/extensions/staking/src/delegation/DelegateSection.tsx @@ -44,7 +44,7 @@ export const DelegateSection = (props: Props) => { const filterProviders = (providers: DelegationProvider[], query: string) => providers - .filter((p) => p.identity.name && p.identity.url) - .filter((p) => p.identity.name.toLowerCase().includes(query.toLowerCase())) - .sort((a, b) => (a.identity.name > b.identity.name ? 1 : -1)) + .filter((p) => p.identityInfo.name && p.identityInfo.website) + .filter((p) => p.identityInfo.name.toLowerCase().includes(query.toLowerCase())) + .sort((a, b) => (a.identityInfo.name > b.identityInfo.name ? 1 : -1)) .sort((a, b) => (a.featured ? -1 : 1)) diff --git a/src/extensions/staking/src/delegation/_DelegateProviderList.tsx b/src/extensions/staking/src/delegation/_DelegateProviderList.tsx index 6cb63e4..8990760 100644 --- a/src/extensions/staking/src/delegation/_DelegateProviderList.tsx +++ b/src/extensions/staking/src/delegation/_DelegateProviderList.tsx @@ -42,33 +42,26 @@ export const _DelegateProviderList = (props: Props) => (
{provider.identity.name
-

{provider.identity.name}

- {provider.identity.url} +

{provider.identityInfo.name}

+ {provider.identityInfo.website}
{provider.apr}% {+provider.serviceFee / 100}% - {provider.maxDelegationCap.isZero() - ? 'Uncapped' - : calculateProviderFilledPercentage(provider).toFixed(2) + '%'} + {provider.delegationCap.isZero() ? 'Uncapped' : provider.identityInfo.stakePercent + '%'} - {provider.maxDelegateAmountAllowed.isZero() - ? 'Uncapped' - : toEgldDisplayAmount(provider.maxDelegateAmountAllowed)} + {provider.stake.isZero() ? 'Uncapped' : toEgldDisplayAmount(provider.stake)} ))} ) - -const calculateProviderFilledPercentage = (provider: DelegationProvider) => - provider.totalActiveStake.div(provider.maxDelegationCap).times(100) diff --git a/src/extensions/staking/src/delegation/_DelegationsRow.tsx b/src/extensions/staking/src/delegation/_DelegationsRow.tsx index ff2d90d..c2c7885 100644 --- a/src/extensions/staking/src/delegation/_DelegationsRow.tsx +++ b/src/extensions/staking/src/delegation/_DelegationsRow.tsx @@ -43,13 +43,13 @@ export const _DelegationsRow = (props: Props) => {
{props.provider.identity.name
-

{props.provider.identity.name}

+

{props.provider.identityInfo.name}

APR: {props.provider.apr}%
diff --git a/src/extensions/staking/src/delegation/_Delegator.tsx b/src/extensions/staking/src/delegation/_Delegator.tsx index 3ce7077..eac3c41 100644 --- a/src/extensions/staking/src/delegation/_Delegator.tsx +++ b/src/extensions/staking/src/delegation/_Delegator.tsx @@ -32,23 +32,23 @@ export const _Delegator = (props: Props) => { return (
-

Stake with {props.provider.identity.name}

+

Stake with {props.provider.identityInfo.name}

{props.provider.identity.name
-

{props.provider.identity.name}

- {props.provider.identity.url} +

{props.provider.identityInfo.name}

+ {props.provider.identityInfo.website}