Skip to content

Commit d1efce7

Browse files
committed
Add fetching status to EVM Proposals lists
1 parent 77cbd4a commit d1efce7

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

src/components/EVMProposalsTable.tsx

+9-8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface EVMProposalsPageProps {
3434
proposal_data: Proposal[];
3535
limit: number;
3636
offset: number;
37+
loading?: boolean;
3738
handleOffsetChange: (offset: number) => void;
3839
approveAction?: (hash: string) => void;
3940
executeAction?: (hash: string) => void;
@@ -43,6 +44,7 @@ const EVMProposalsTable: React.FC<EVMProposalsPageProps> = ({
4344
proposal_data,
4445
limit,
4546
offset,
47+
loading = false,
4648
handleOffsetChange,
4749
approveAction,
4850
executeAction,
@@ -77,8 +79,12 @@ const EVMProposalsTable: React.FC<EVMProposalsPageProps> = ({
7779
</tr>
7880
</thead>
7981
<tbody>
80-
{proposal_data.length > 0 ? (
81-
proposal_data.map((proposal: Proposal, index: number) => (
82+
<tr className="data-loading-details text-center font-semibold">
83+
{loading && <td colSpan={7}>Loading...</td>}
84+
{!loading && proposal_data.length === 0 && <td colSpan={7}>No proposals to display.</td>}
85+
</tr>
86+
87+
{proposal_data.map((proposal: Proposal, index: number) => (
8288
<tr key={index} className="">
8389
<td className=" ">{proposal.proposal}</td>
8490

@@ -104,12 +110,7 @@ const EVMProposalsTable: React.FC<EVMProposalsPageProps> = ({
104110
</Link>
105111
</td>
106112
</tr>
107-
))
108-
) : (
109-
<tr>
110-
<td className="text-center">No proposals</td>
111-
</tr>
112-
)}
113+
))}
113114
</tbody>
114115
</table>
115116
</div>

src/pages/EVM/EVMApproveProposalsPage.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const EVMApproveProposalsPage = () => {
4848
const [proposal_data, setProposalData] = useState<Proposal[]>([]);
4949
const [thres, setThresh] = useState<number>(0);
5050
const [owner, setOwner] = useState<string[]>([]);
51+
const [fetchingData, setFetchingData] = useState(false);
5152

5253
function generateSignature() {
5354
if (!signer || !signer._address) {
@@ -135,6 +136,7 @@ const EVMApproveProposalsPage = () => {
135136
};
136137
const fetchData = async () => {
137138
try {
139+
setFetchingData(true);
138140
const data = await loadProposalData();
139141
let filteredData = data;
140142
if (chainId !== 0) {
@@ -145,6 +147,8 @@ const EVMApproveProposalsPage = () => {
145147
setProposalData(paginatedData);
146148
} catch (error) {
147149
console.error('Error fetching proposal data:', error);
150+
} finally {
151+
setFetchingData(false);
148152
}
149153
};
150154

@@ -192,6 +196,7 @@ const EVMApproveProposalsPage = () => {
192196
proposal_data={proposal_data}
193197
limit={itemsPerPageLimit}
194198
offset={itemsListOffset}
199+
loading={fetchingData}
195200
handleOffsetChange={handlePaginationChanges}
196201
approveAction={handleApprove}
197202
/>

src/pages/EVM/EVMExecuteProposals.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const EVMExecuteProposals = () => {
2727
const itemsPerPageLimit = 5;
2828
const [itemsListOffset, setItemsListOffset] = useState(0);
2929
let contract = new ethers.Contract(contractAddress, abi, signer);
30+
const [fetchingData, setFetchingData] = useState(false);
3031

3132
const handleExecute = async (proposal: any) => {
3233
setLoading(true);
@@ -44,13 +45,16 @@ const EVMExecuteProposals = () => {
4445
};
4546
const fetchFilteredData = async () => {
4647
try {
48+
setFetchingData(true);
4749
const data = await loadProposalData();
4850

4951
let filteredData = data.filter((proposal: any) => proposal.status === 'Passed');
5052
const paginatedData = filteredData.slice(itemsListOffset, itemsListOffset + itemsPerPageLimit);
5153
setProposalData(paginatedData);
5254
} catch (error) {
5355
console.error('Error fetching proposal data:', error);
56+
} finally {
57+
setFetchingData(false);
5458
}
5559
};
5660
const handlePaginationChanges = (offset: number) => {
@@ -86,6 +90,7 @@ const EVMExecuteProposals = () => {
8690
proposal_data={proposal_data}
8791
limit={itemsPerPageLimit}
8892
offset={itemsListOffset}
93+
loading={fetchingData}
8994
handleOffsetChange={handlePaginationChanges}
9095
approveAction={handleExecute}
9196
/>

src/pages/EVM/EVMExecutedProposals.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@ const EVMExecutedProposals = () => {
1717

1818
const itemsPerPageLimit = 5;
1919
const [itemsListOffset, setItemsListOffset] = useState(0);
20+
const [fetchingData, setFetchingData] = useState(false);
2021

2122
const fetchFilteredData = async () => {
2223
try {
24+
setFetchingData(true);
2325
const data = await loadProposalData();
2426

2527
let filteredData = data.filter((proposal: any) => proposal.status === 'Executed');
2628
const paginatedData = filteredData.slice(itemsListOffset, itemsListOffset + itemsPerPageLimit);
2729
setProposalData(paginatedData);
2830
} catch (error) {
2931
console.error('Error fetching proposal data:', error);
32+
} finally {
33+
setFetchingData(false);
3034
}
3135
};
3236
const handlePaginationChanges = (offset: number) => {
@@ -50,6 +54,7 @@ const EVMExecutedProposals = () => {
5054
proposal_data={proposal_data}
5155
limit={itemsPerPageLimit}
5256
offset={itemsListOffset}
57+
loading={fetchingData}
5358
handleOffsetChange={handlePaginationChanges}
5459
/>
5560
</div>

0 commit comments

Comments
 (0)