Skip to content

Commit

Permalink
feat: enhance ScheduleTable with improved address display and central…
Browse files Browse the repository at this point in the history
…ized token info retrieval
  • Loading branch information
Ben-Rey committed Oct 11, 2024
1 parent 777caef commit 943fdbf
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 39 deletions.
64 changes: 35 additions & 29 deletions front/src/components/ScheduleTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import CheckBox from './CheckBox';
import useSchedule from '@/services/useSchedule';
import { MasToken, supportedTokens } from '../const/assets';
import ScheduleHistory from '@/components/ScheduleHistory';
import { getTokenInfo } from '@/utils/assets';

interface ScheduleTableProps {
schedules: Schedule[];
}

const CopyableAddress: React.FC<{ address: string; label: string }> = ({
address,
label,
}) => (
const CopyableAddress: React.FC<{
address: string;
label: string;
value: string;
}> = ({ value, address, label }) => (
<span
title={address}
className="hover:text-blue-500 cursor-pointer"
Expand All @@ -23,7 +25,7 @@ const CopyableAddress: React.FC<{ address: string; label: string }> = ({
toast.success(`${label} copied to clipboard`);
}}
>
{truncateAddress(address)}
{value}
</span>
);

Expand All @@ -47,7 +49,7 @@ const TableHeader: React.FC = () => (
].map((header, index) => (
<th
key={index}
className="px-6 py-6 text-left text-xs font-medium uppercase"
className="px-4 py-6 text-left text-xs font-medium uppercase"
>
{header}
</th>
Expand Down Expand Up @@ -75,55 +77,59 @@ const TableRow: React.FC<TableRowProps> = ({

return (
<tr>
<td className="px-6 py-4">
<td className="text-center px-2 py-4">
<CheckBox
isSelected={isSelected}
onChange={onCheckboxChange}
id={schedule.id}
/>
</td>
<td className="px-6 py-4 whitespace-nowrap">{schedule.id.toString()}</td>
<td className="px-6 py-4 whitespace-nowrap">
<CopyableAddress address={schedule.operationId} label="Operation ID" />
<td className="text-center px-2 py-4">{schedule.id.toString()}</td>
<td className="text-center px-2 py-4">
<CopyableAddress
address={schedule.operationId}
label="Operation ID"
value={truncateAddress(schedule.operationId)}
/>
</td>
<td className="px-6 py-4 whitespace-nowrap">
<td className="text-center px-2 py-4">
{schedule.isVesting ? 'Vesting' : 'Tips'}
</td>
<td className="px-6 py-4 whitespace-nowrap">
<td className="text-center px-2 py-4">
{isMas ? (
'MAS'
) : (
<CopyableAddress
address={schedule.tokenAddress}
label="Token address"
address={asset.address}
value={getTokenInfo(asset.address).symbol}
/>
)}
</td>
<td className="px-6 py-4 whitespace-nowrap">
<CopyableAddress address={schedule.spender} label="Spender address" />
<td className="text-center px-2 py-4">
<CopyableAddress
address={schedule.spender}
label="Spender address"
value={truncateAddress(schedule.spender)}
/>
</td>
<td className="px-6 py-4 whitespace-nowrap">
<td className="text-center px-2 py-4">
<CopyableAddress
address={schedule.recipient}
label="Recipient address"
value={truncateAddress(schedule.recipient)}
/>
</td>
<td className="px-6 py-4 whitespace-nowrap">
<td className="text-center px-2 py-4">
<span title={formattedAmount.full}>{formattedAmount.preview}</span>
</td>
<td className="px-6 py-4 whitespace-nowrap">
{schedule.interval.toString()}
</td>
<td className="px-6 py-4 whitespace-nowrap">
<td className="text-center px-2 py-4">{schedule.interval.toString()}</td>
<td className="text-center px-2 py-4">
{schedule.occurrences.toString()}
</td>
<td className="px-6 py-4 whitespace-nowrap">
{schedule.remaining.toString()}
</td>
<td className="px-6 py-4 whitespace-nowrap">
{schedule.tolerance.toString()}
</td>
<td className="px-6 py-4 whitespace-nowrap">
<td className="text-center px-2 py-4">{schedule.remaining.toString()}</td>
<td className="text-center px-2 py-4">{schedule.tolerance.toString()}</td>
<td className="text-center px-2 py-4">
<ScheduleHistory schedule={schedule} />
</td>
</tr>
Expand Down Expand Up @@ -172,7 +178,7 @@ const ScheduleTable: React.FC<ScheduleTableProps> = ({ schedules }) => {
<SelectedInfo count={selected.length} onCancel={handleCancel} />
)}

<table className="min-w-full overflow-hidden rounded-2xl shadow-lg bg-secondary">
<table className="overflow-hidden rounded-2xl shadow-lg bg-secondary w-full">
<TableHeader />
<tbody className="text-sm divide-y divide-zinc-300">
{schedules.map((schedule) => (
Expand Down
11 changes: 1 addition & 10 deletions front/src/store/store.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EventPoller, Provider, SCEvent } from '@massalabs/massa-web3';
import { schedulerAddress } from '../const/contracts';
import { Schedule } from '../serializable/Schedule';
import { supportedTokens } from '../const/assets';
import { truncateAddress } from '@/utils/address';
import { useAccountStore, formatAmount, toast } from '@massalabs/react-ui-kit';
import { useSchedulerStore } from './scheduler';
import { useTokenStore } from './token';
import { getTokenInfo } from '@/utils/assets';

export async function initApp() {
const { connectedAccount } = useAccountStore.getState();
Expand Down Expand Up @@ -80,12 +80,3 @@ function handleTransferEvents(data: SCEvent[], schedules: Schedule[]) {
}
}
}

function getTokenInfo(tokenAddress: string | null) {
if (!tokenAddress) return { decimals: 9, symbol: 'MAS' };

const token = supportedTokens.find((t) => t.address === tokenAddress);
return token
? { decimals: token.decimals, symbol: token.symbol }
: { decimals: 9, symbol: 'MAS' };
}
21 changes: 21 additions & 0 deletions front/src/utils/assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { MasToken, supportedTokens } from '@/const/assets';

export function getTokenInfo(tokenAddress: string | null) {
if (!tokenAddress) return MasToken;

const token = supportedTokens.find((t) => t.address === tokenAddress);

if (!token) {
return {
name: 'Unknown',
address: tokenAddress,
symbol: 'Unknown',
decimals: 18,
balance: 0n,
allowance: 0n,
chainId: 0,
};
}

return token;
}

0 comments on commit 943fdbf

Please sign in to comment.