-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
760 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* eslint-disable no-debugger */ | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import { Grid } from '@mui/material'; | ||
import WalletsTable from './WalletsTable'; | ||
import Message from '../../components/UI/components/Message/Message'; | ||
import { getWallets } from '../../api/wallets'; | ||
import AuthContext from '../../store/auth-context'; | ||
import { useWalletsContext } from '../../store/WalletsContext'; | ||
|
||
/**@function | ||
* @name ListWallets | ||
* @description Renders the List Wallets page | ||
* | ||
* @returns {JSX.Element} - List Wallets page component | ||
* */ | ||
const ListWallets = () => { | ||
// get data from context | ||
const { pagination, setIsLoading, prepareRows } = useWalletsContext(); | ||
// error | ||
const [message, setMessage] = useState(''); | ||
// data to be displayed in the table | ||
const [tableRows, setTableRows] = useState([]); | ||
// total rows count for pagination | ||
const [totalRowCount, setTotalRowCount] = useState(null); | ||
|
||
const authContext = useContext(AuthContext); | ||
|
||
// load data | ||
useEffect(() => { | ||
const loadData = async () => { | ||
try { | ||
setIsLoading(true); | ||
debugger; | ||
const data = await getWallets(authContext.token, '', { | ||
pagination, | ||
}); | ||
const preparedRows = prepareRows(await data.wallets); | ||
|
||
setTableRows(preparedRows); | ||
setTotalRowCount(data.total); | ||
} catch (error) { | ||
console.error(error); | ||
setMessage('An error occurred while fetching the table data'); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
loadData(); | ||
}, [pagination]); | ||
|
||
return ( | ||
<div | ||
style={{ | ||
marginTop: '5rem', | ||
marginLeft: '1rem', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
marginRight: '1rem', | ||
width: '100%', | ||
}} | ||
> | ||
{message && <Message message={message} onClose={() => setMessage('')} />} | ||
<Grid container direction="column" sx={{ flexGrow: '1' }}> | ||
<WalletsTable | ||
tableTitle={'Managed Wallets List'} | ||
tableRows={tableRows} | ||
totalRowCount={totalRowCount} | ||
/> | ||
</Grid> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ListWallets; |
Oops, something went wrong.