Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PE-7517: quick wins v1.8.0 #140

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Applications Settings: use new sidebar Settings option to open modal to
configure ARIO Process ID and AO CU URL
- Added copy button for domain name columns in tables
- Show Delegate EAY for gateways in Active Stakes table

### Changed

Expand Down
11 changes: 8 additions & 3 deletions src/pages/Gateways/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mARIOToken } from '@ar.io/sdk/web';
import AddressCell from '@src/components/AddressCell';
import CopyButton from '@src/components/CopyButton';
import Header from '@src/components/Header';
import Streak from '@src/components/Streak';
import TableView from '@src/components/TableView';
Expand Down Expand Up @@ -54,7 +55,9 @@ const Gateways = () => {
totalDelegatedStake: new mARIOToken(gateway.totalDelegatedStake)
.toARIO()
.valueOf(),
operatorStake: new mARIOToken(gateway.operatorStake).toARIO().valueOf(),
operatorStake: new mARIOToken(gateway.operatorStake)
.toARIO()
.valueOf(),
totalStake: new mARIOToken(
gateway.totalDelegatedStake + gateway.operatorStake,
)
Expand Down Expand Up @@ -92,17 +95,19 @@ const Gateways = () => {
header: 'Domain',
sortDescFirst: false,
cell: ({ row }) => (
<div className="text-gradient">
<div className="flex items-center gap-2">
<a
href={`https://${row.getValue('domain')}`}
target="_blank"
rel="noreferrer"
onClick={(e) => {
e.stopPropagation();
}}
className="text-gradient"
>
{row.getValue('domain')}
</a>{' '}
</a>
<CopyButton textToCopy={row.getValue('domain')} />
</div>
),
}),
Expand Down
11 changes: 8 additions & 3 deletions src/pages/Observers/ObserversTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AddressCell from '@src/components/AddressCell';
import CopyButton from '@src/components/CopyButton';
import Dropdown from '@src/components/Dropdown';
import TableView from '@src/components/TableView';
import useEpochs from '@src/hooks/useEpochs';
Expand Down Expand Up @@ -98,15 +99,19 @@ const ObserversTable = () => {
header: 'Domain',
sortDescFirst: false,
cell: ({ row }) => (
<div className="text-gradient">
<div className="flex items-center gap-2">
<a
href={`https://${row.getValue('domain')}`}
target="_blank"
rel="noreferrer"
onClick={(e) => e.stopPropagation()}
onClick={(e) => {
e.stopPropagation();
}}
className="text-gradient"
>
{row.getValue('domain')}
</a>{' '}
</a>
<CopyButton textToCopy={row.getValue('domain')} />
</div>
),
}),
Expand Down
11 changes: 8 additions & 3 deletions src/pages/Staking/DelegateStakeTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mARIOToken } from '@ar.io/sdk/web';
import AddressCell from '@src/components/AddressCell';
import Button, { ButtonType } from '@src/components/Button';
import CopyButton from '@src/components/CopyButton';
import Streak from '@src/components/Streak';
import TableView from '@src/components/TableView';
import Tooltip from '@src/components/Tooltip';
Expand Down Expand Up @@ -125,15 +126,19 @@ const DelegateStake = () => {
header: 'Domain',
sortDescFirst: false,
cell: ({ row }) => (
<div className="text-gradient">
<div className="flex items-center gap-2">
<a
href={`https://${row.getValue('domain')}`}
target="_blank"
rel="noreferrer"
onClick={(e) => e.stopPropagation()}
onClick={(e) => {
e.stopPropagation();
}}
className="text-gradient"
>
{row.getValue('domain')}
</a>{' '}
</a>
<CopyButton textToCopy={row.getValue('domain')} />
</div>
),
}),
Expand Down
58 changes: 52 additions & 6 deletions src/pages/Staking/MyStakesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { AoGatewayWithAddress, AoVaultData, mARIOToken } from '@ar.io/sdk/web';
import * as DropdownMenu from '@radix-ui/react-dropdown-menu';
import AddressCell from '@src/components/AddressCell';
import Button, { ButtonType } from '@src/components/Button';
import CopyButton from '@src/components/CopyButton';
import Dropdown from '@src/components/Dropdown';
import Streak from '@src/components/Streak';
import TableView from '@src/components/TableView';
import { ThreeDotsIcon } from '@src/components/icons';
import Tooltip from '@src/components/Tooltip';
import { InfoIcon, ThreeDotsIcon } from '@src/components/icons';
import CancelWithdrawalModal from '@src/components/modals/CancelWithdrawalModal';
import InstantWithdrawalModal from '@src/components/modals/InstantWithdrawalModal';
import RedelegateModal, {
Expand All @@ -14,10 +16,15 @@ import RedelegateModal, {
import StakeWithdrawalModal from '@src/components/modals/StakeWithdrawalModal';
import StakingModal from '@src/components/modals/StakingModal';
import WithdrawAllModal from '@src/components/modals/WithdrawAllModal';
import { EAY_TOOLTIP_FORMULA, EAY_TOOLTIP_TEXT } from '@src/constants';
import useDelegateStakes from '@src/hooks/useDelegateStakes';
import useGateways from '@src/hooks/useGateways';
import useProtocolBalance from '@src/hooks/useProtocolBalance';
import { useGlobalState } from '@src/store';
import { formatWithCommas } from '@src/utils';
import { calculateGatewayRewards } from '@src/utils/rewards';
import { ColumnDef, createColumnHelper } from '@tanstack/react-table';
import { MathJax } from 'better-react-mathjax';
import dayjs from 'dayjs';
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
Expand All @@ -28,6 +35,7 @@ interface ActiveStakesTableData {
gateway: AoGatewayWithAddress;
pendingWithdrawals: number;
streak: number;
eay: number;
}

interface PendingWithdrawalsTableData {
Expand Down Expand Up @@ -79,10 +87,12 @@ const MyStakesTable = () => {

const { data: delegateStakes } = useDelegateStakes(walletAddress?.toString());

const { data: protocolBalance } = useProtocolBalance();

useEffect(() => {
const activeStakes: Array<ActiveStakesTableData> | undefined = isFetching
? undefined
: !delegateStakes || !gateways
: !delegateStakes || !gateways || !protocolBalance
? []
: delegateStakes.stakes
.filter((stake) => stake.balance > 0)
Expand All @@ -101,6 +111,12 @@ const MyStakesTable = () => {
: gateway.stats.failedConsecutiveEpochs > 0
? -gateway.stats.failedConsecutiveEpochs
: gateway.stats.passedConsecutiveEpochs,
eay: calculateGatewayRewards(
new mARIOToken(protocolBalance).toARIO(),
Object.values(gateways).filter((g) => g.status == 'joined')
.length,
gateway,
).EAY,
};
});

Expand All @@ -125,7 +141,7 @@ const MyStakesTable = () => {

setActiveStakes(activeStakes);
setPendingWithdrawals(pendingWithdrawals);
}, [delegateStakes, gateways, isFetching]);
}, [delegateStakes, gateways, isFetching, protocolBalance]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels like its worth a useQuery hook with the dependencies as keys

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's alright here as it's not going to be re-used elsewhere. Perhaps there's an opportunity to further optimize but for now I think it's okay to keep this as-is.


// Define columns for the active stakes table
const activeStakesColumns: ColumnDef<ActiveStakesTableData, any>[] = [
Expand All @@ -139,15 +155,19 @@ const MyStakesTable = () => {
header: 'Domain',
sortDescFirst: false,
cell: ({ row }) => (
<div className="text-gradient">
<div className="flex items-center gap-2">
<a
href={`https://${row.getValue('domain')}`}
target="_blank"
rel="noreferrer"
onClick={(e) => e.stopPropagation()}
onClick={(e) => {
e.stopPropagation();
}}
className="text-gradient"
>
{row.getValue('domain')}
</a>{' '}
</a>
<CopyButton textToCopy={row.getValue('domain')} />
</div>
),
}),
Expand All @@ -165,6 +185,32 @@ const MyStakesTable = () => {
return `${new mARIOToken(row.original.delegatedStake).toARIO().valueOf()}`;
},
}),
columnHelper.accessor('eay', {
id: 'eay',
header: () => (
<div className="flex gap-1">
Delegate EAY
<Tooltip
message={
<div>
<p>{EAY_TOOLTIP_TEXT}</p>
<MathJax className="mt-4">{EAY_TOOLTIP_FORMULA}</MathJax>
</div>
}
>
<InfoIcon className="h-full" />
</Tooltip>
</div>
),
sortDescFirst: true,
cell: ({ row }) => (
<div>
{row.original.eay < 0
? 'N/A'
: `${formatWithCommas(row.original.eay * 100)}%`}
</div>
),
}),
columnHelper.accessor('streak', {
id: 'streak',
header: 'Streak',
Expand Down
Loading