diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 938370e..668ede1 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -49,6 +49,7 @@ jobs: VITE_SENTRY_DSN_PROJECT_URI: ${{ secrets.SENTRY_DSN_PROJECT_URI }} VITE_SENTRY_DSN_PROJECT_ID: ${{ secrets.SENTRY_DSN_PROJECT_ID }} VITE_GITHUB_HASH: ${{ github.sha }} + VITE_IO_PROCESS_ID: ${{ secrets.IO_PROCESS_ID }} # ao infra settings VITE_AO_CU_URL: ${{ vars.VITE_AO_CU_URL }} - name: Add CNAME Record diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 142f564..c3d94d7 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -34,7 +34,7 @@ const Header = () => { {gatewaysLoading ? ( ) : gateways ? ( - Object.keys(gateways).length + Object.values(gateways).filter((g) => g.status === "joined").length ) : ( NBSP )} diff --git a/src/hooks/useRewardsInfo.ts b/src/hooks/useRewardsInfo.ts index ff5528f..3bdefdb 100644 --- a/src/hooks/useRewardsInfo.ts +++ b/src/hooks/useRewardsInfo.ts @@ -7,17 +7,22 @@ import { import useGateways from './useGateways'; import useProtocolBalance from './useProtocolBalance'; -const useRewardsInfo = ( - gateway: AoGateway | undefined, - userStake: number -) => { +const useRewardsInfo = (gateway: AoGateway | undefined, userStake: number) => { const { data: gateways } = useGateways(); const { data: protocolBalance } = useProtocolBalance(); let res: UserRewards | undefined = undefined; - if (gateways && gateway && protocolBalance && protocolBalance > 0 && !isNaN(userStake)) { - const numGateways = gateways ? Object.keys(gateways).length : 0; + if ( + gateways && + gateway && + protocolBalance && + protocolBalance > 0 && + !isNaN(userStake) + ) { + const numGateways = gateways + ? Object.values(gateways).filter((g) => g.status == 'joined').length + : 0; const gatewayRewards = calculateGatewayRewards( new mIOToken(protocolBalance).toIO(), numGateways, @@ -27,7 +32,7 @@ const useRewardsInfo = ( const userRewards = calculateUserRewards( gatewayRewards, new IOToken(Math.abs(userStake)), - userStake < 0 + userStake < 0, ); res = userRewards; } diff --git a/src/pages/Gateway/PropertyDisplayPanel.tsx b/src/pages/Gateway/PropertyDisplayPanel.tsx index b51b565..db973a1 100644 --- a/src/pages/Gateway/PropertyDisplayPanel.tsx +++ b/src/pages/Gateway/PropertyDisplayPanel.tsx @@ -13,16 +13,14 @@ const DisplayRow = ({ rightComponent, }: { label: string; - value: string | number | boolean | undefined; + value: React.ReactNode | string | number | boolean | undefined; type?: string; rightComponent?: React.ReactNode; }) => { return ( <>
-
- {label} -
+
{label}
{value === undefined ? ( @@ -79,17 +77,23 @@ const PropertyDisplayPanel = ({ ? `${gateway.settings.protocol}://${gateway.settings.fqdn}:${gateway.settings.port}` : undefined; + const gatewayLeaving = gateway?.status == 'leaving'; + const conditionalRows = gateway?.settings.allowDelegatedStaking ? [ { label: 'Reward Share Ratio:', - value: `${gateway?.settings.delegateRewardShareRatio}%`, + value: gatewayLeaving + ? 'N/A' + : `${gateway?.settings.delegateRewardShareRatio}%`, }, { label: `Minimum Delegated Stake (${ticker}):`, - value: new mIOToken(gateway?.settings.minDelegatedStake || 0) - .toIO() - .valueOf(), + value: gatewayLeaving + ? 'N/A' + : new mIOToken(gateway?.settings.minDelegatedStake || 0) + .toIO() + .valueOf(), }, ] : []; @@ -109,21 +113,37 @@ const PropertyDisplayPanel = ({ type: 'tx', }, { - label: `Gateway Stake (${ticker}):`, - value: gateway?.operatorStake - ? new mIOToken(gateway?.operatorStake).toIO().valueOf() - : undefined, + label: `Gateway Stake abc (${ticker}):`, + value: + gateway?.operatorStake != undefined + ? new mIOToken(gateway?.operatorStake).toIO().valueOf() + : undefined, + }, + { + label: 'Status:', + value: + gateway?.status == 'leaving' ? ( +
leaving
+ ) : ( + gateway?.status + ), }, - { label: 'Status:', value: gateway?.status }, { label: 'Note:', value: gateway?.settings.note }, { label: `Total Delegated Stake (${ticker}):`, - value: new mIOToken(gateway?.totalDelegatedStake || 0).toIO().valueOf(), + value: gatewayLeaving + ? 'N/A' + : gateway?.totalDelegatedStake == undefined + ? undefined + : new mIOToken(gateway.totalDelegatedStake).toIO().valueOf(), + }, + { + label: 'Reward Auto Stake:', + value: gatewayLeaving ? 'N/A' : gateway?.settings.autoStake, }, - { label: 'Reward Auto Stake:', value: gateway?.settings.autoStake }, { label: 'Delegated Staking:', - value: gateway?.settings.allowDelegatedStaking, + value: gatewayLeaving ? 'N/A' : gateway?.settings.allowDelegatedStaking, rightComponent: gateway?.settings.allowDelegatedStaking ? (
- } - > - - - - } - value={ - operatorRewards - ? `${(operatorRewards.EAY * 100).toFixed(2)}%` - : undefined - } - /> + + {gateway?.status === 'joined' && ( + + Operator EAY{' '} + +

{EAY_TOOLTIP_TEXT}

+ + {OPERATOR_EAY_TOOLTIP_FORMULA} + + + } + > + +
+ + } + value={ + operatorRewards != undefined + ? `${(operatorRewards.EAY * 100).toFixed(2)}%` + : undefined + } + /> + )} {/* */} - {gateway?.weights && ( + {gateway?.weights && gateway?.status === 'joined' && (
Weights
@@ -486,7 +489,7 @@ const Gateway = () => { >
{title}:
- {value ? value.toFixed(3) : } + {value !== undefined ? value.toFixed(3) : }
))} diff --git a/src/pages/Gateways/index.tsx b/src/pages/Gateways/index.tsx index 127cdf1..a0e8dc2 100644 --- a/src/pages/Gateways/index.tsx +++ b/src/pages/Gateways/index.tsx @@ -69,6 +69,8 @@ const Gateways = () => { passedEpochCount, totalEpochCount, streak: + gateway.status == "leaving" ? + Number.NEGATIVE_INFINITY : gateway.stats.failedConsecutiveEpochs > 0 ? -gateway.stats.failedConsecutiveEpochs : gateway.stats.passedConsecutiveEpochs, @@ -180,6 +182,10 @@ const Gateways = () => { return ''; } + if (streak === Number.NEGATIVE_INFINITY) { + return 'N/A'; + } + const colorClasses = streak > 0 ? 'border-streak-up/[.56] bg-streak-up/[.1] text-streak-up' diff --git a/src/pages/Staking/DelegateStakeTable.tsx b/src/pages/Staking/DelegateStakeTable.tsx index 34f6e90..edf9b73 100644 --- a/src/pages/Staking/DelegateStakeTable.tsx +++ b/src/pages/Staking/DelegateStakeTable.tsx @@ -60,53 +60,57 @@ const DelegateStake = () => { const stakeableGateways: Array = !gateways || !protocolBalance ? [] - : Object.entries(gateways).reduce((acc, [owner, gateway]) => { - if (gateway.settings.allowDelegatedStaking) { - const passedEpochCount = gateway.stats.passedEpochCount; - const totalEpochCount = (gateway.stats as any).totalEpochCount; + : Object.entries(gateways) + .filter((g) => g[1].status === 'joined') + .reduce((acc, [owner, gateway]) => { + if (gateway.settings.allowDelegatedStaking) { + const passedEpochCount = gateway.stats.passedEpochCount; + const totalEpochCount = (gateway.stats as any).totalEpochCount; - return [ - ...acc, - { - label: gateway.settings.label, - domain: gateway.settings.fqdn, - owner, - streak: - gateway.stats.failedConsecutiveEpochs > 0 - ? -gateway.stats.failedConsecutiveEpochs - : gateway.stats.passedConsecutiveEpochs, + return [ + ...acc, + { + label: gateway.settings.label, + domain: gateway.settings.fqdn, + owner, + streak: + gateway.stats.failedConsecutiveEpochs > 0 + ? -gateway.stats.failedConsecutiveEpochs + : gateway.stats.passedConsecutiveEpochs, - rewardShareRatio: gateway.settings.allowDelegatedStaking - ? gateway.settings.delegateRewardShareRatio - : -1, - performance: - totalEpochCount > 0 - ? gateway.stats.passedEpochCount / totalEpochCount + rewardShareRatio: gateway.settings.allowDelegatedStaking + ? gateway.settings.delegateRewardShareRatio : -1, - passedEpochCount, - totalEpochCount, - totalDelegatedStake: new mIOToken(gateway.totalDelegatedStake) - .toIO() - .valueOf(), - operatorStake: new mIOToken(gateway.operatorStake) - .toIO() - .valueOf(), - totalStake: new mIOToken( - gateway.totalDelegatedStake + gateway.operatorStake, - ) - .toIO() - .valueOf(), + performance: + totalEpochCount > 0 + ? gateway.stats.passedEpochCount / totalEpochCount + : -1, + passedEpochCount, + totalEpochCount, + totalDelegatedStake: new mIOToken( + gateway.totalDelegatedStake, + ) + .toIO() + .valueOf(), + operatorStake: new mIOToken(gateway.operatorStake) + .toIO() + .valueOf(), + totalStake: new mIOToken( + gateway.totalDelegatedStake + gateway.operatorStake, + ) + .toIO() + .valueOf(), - eay: calculateGatewayRewards( - new mIOToken(protocolBalance).toIO(), - Object.keys(gateways).length, - gateway, - ).EAY, - }, - ]; - } - return acc; - }, [] as Array); + eay: calculateGatewayRewards( + new mIOToken(protocolBalance).toIO(), + Object.values(gateways).filter(g => g.status == "joined").length, + gateway, + ).EAY, + }, + ]; + } + return acc; + }, [] as Array); setStakeableGateways(stakeableGateways); }, [gateways, protocolBalance, walletAddress]);