Skip to content

Commit

Permalink
fix: changed the api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
samwel141 committed May 21, 2024
1 parent 6102d32 commit 9844373
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/api/trust_relationships.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const getTrustRelationships = async (
{ pagination, filter, sorting }
) => {
const { sort_by, order } = sorting;
const wallet = JSON.parse(localStorage.getItem('wallet') || '{}');

try {
const where = filter.getWhereObj();
Expand All @@ -20,7 +21,7 @@ export const getTrustRelationships = async (
const queryString = makeQueryString(trustRelationshipsFilter);
const response = await apiClient
.setAuthHeader(token)
.get(`/trust_relationships?${queryString}`);
.get(`/wallets/${wallet.id}/trust_relationships?${queryString}`);
return response.data;
} catch (error) {
console.error(error);
Expand Down
33 changes: 17 additions & 16 deletions src/pages/TrustRelationship/TrustRelationshipTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const FilterDialog = ({
setFilter={setFilter}
defaultFilter={defaultFilter}
/>
<button
{/* <button
style={{
color: 'black',
border: 'none',
Expand All @@ -120,7 +120,7 @@ const FilterDialog = ({
onClick={handleFilterClose}
>
<h4> Apply</h4>
</button>
</button> */}
</Grid>
</Grid>
</Menu>
Expand Down Expand Up @@ -262,16 +262,16 @@ const TrustRelationshipTableBody = ({
}) => {
// state to track if side panel is open when you click the row on table
const [isSidePanelOpen, setIsSidePanelOpen] = useState(false);
const [sortedTableRows, setSortedTableRows] = useState([]);
const stateOrder = ['requested', 'trusted', 'cancelled_by_originator', 'cancelled_by_target'];
useEffect(() => {
const sortData = (data) => {
return data.sort((a, b) => stateOrder.indexOf(a.state) - stateOrder.indexOf(b.state));
};

setSortedTableRows(sortData([...tableRows]));
}, [tableRows]);

// let sortedTableRows = [...tableRows].sort(
// (a, b) => new Date(b.created_at) - new Date(a.created_at)
// );
// sortedTableRows = [...sortedTableRows].sort(
// (a, b) => new Date(b.updated_at) - new Date(a.updated_at)
// );
// let sortedTableRows = [...tableRows].sort((a, b) =>
// a.state.localeCompare(b.state)
// );
//function to close side panel
const handleClosePanel = () => {
setIsSidePanelOpen(false);
Expand All @@ -286,6 +286,7 @@ const TrustRelationshipTableBody = ({
setIsSidePanelOpen(true);
};

const wallet = JSON.parse(localStorage.getItem('wallet') || '{}');
const { isLoading, searchString } = useTrustRelationshipsContext();
if (isLoading)
return (
Expand All @@ -312,8 +313,8 @@ const TrustRelationshipTableBody = ({
return (
<>
<TableBody>
{tableRows &&
tableRows
{sortedTableRows &&
sortedTableRows
.filter(
(row) =>
row.actor_wallet
Expand All @@ -332,11 +333,11 @@ const TrustRelationshipTableBody = ({
sx={{ transition: 'all 0.3s ease' }}
style={{
backgroundColor:
isSelected && row.state == 'requested'
isSelected && row.state == 'requested' && wallet.name === row.target_wallet
? 'rgba(135, 195, 46, .4)'
: isSelected
? 'rgba(135, 195, 46, .4)'
: row.state == 'requested'
: row.state == 'requested' && wallet.name === row.target_wallet
? 'rgba(135, 195, 46, .1)'
: null,
}}
Expand Down Expand Up @@ -405,7 +406,7 @@ function TrustRelationshipTable({ tableTitle, tableRows, totalRowCount }) {
};

//sorting
const [sortBy, setSortBy] = useState('created_at');
const [sortBy, setSortBy] = useState('updated_at');
const [order, setOrder] = useState('desc');

const getColumnNames = (columnName) => {
Expand Down
5 changes: 3 additions & 2 deletions src/pages/TrustRelationship/trustRelationshipSidePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function TrustRelationshipSidePanel({ open, onClose, rowInfo }) {

const { setRefetch } = useTrustRelationshipsContext();
const authContext = useContext(AuthContext);
const wallet = JSON.parse(localStorage.getItem('wallet') || '{}');

const token = authContext.token;

Expand Down Expand Up @@ -131,7 +132,7 @@ function TrustRelationshipSidePanel({ open, onClose, rowInfo }) {
</TallTypography>
</Grid>
</Grid>
{rowInfo.state === 'requested' && rowInfo.originating_wallet === rowInfo.target_wallet && (
{rowInfo.state === 'requested' && wallet.name === rowInfo.target_wallet && (
<Grid sx={3} style={{ margin: '5rem 4rem' }}>
<AcceptButton
variant="contained"
Expand All @@ -145,7 +146,7 @@ function TrustRelationshipSidePanel({ open, onClose, rowInfo }) {
</DeclineButton>
</Grid>
)}
{(rowInfo.state === 'trusted' || rowInfo.originating_wallet !== rowInfo.target_wallet) && (
{(rowInfo.state === 'trusted' || wallet.name !== rowInfo.target_wallet) && (
<Grid sx={3} style={{ margin: '5rem 7.2rem', backgroundColor: 'red', borderRadius: 8, padding: '10px' }}>
<DeleteButton onClick={() => handleDelete(rowInfo.id)}>
Delete
Expand Down
31 changes: 29 additions & 2 deletions src/store/TrustRelationshipsContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const TrustRelationshipsProvider = ({ children }) => {

// sorting
const defaultSorting = {
sort_by: 'created_at',
sort_by: 'updated_at',
order: 'desc',
};

Expand All @@ -42,6 +42,8 @@ const TrustRelationshipsProvider = ({ children }) => {
// Loader
const [isLoading, setIsLoading] = useState(false);

const wallet = JSON.parse(localStorage.getItem('wallet') || '{}');
console.log(wallet);
// trust relationships table columns

const tableColumns = [
Expand Down Expand Up @@ -131,6 +133,16 @@ const TrustRelationshipsProvider = ({ children }) => {
value: 'trusted',
color: 'black',
},
{
label: 'Cancelled_by_originator',
value: 'cancelled_by_originator',
color: 'black',
},
{
label: 'Cancelled_by_target',
value: 'cancelled_by_target',
color: 'black',
},
];

const requestTypeList = [
Expand All @@ -149,6 +161,21 @@ const TrustRelationshipsProvider = ({ children }) => {
value: 'deduct',
color: 'black',
},
{
label: 'Receive',
value: 'receive',
color: 'black',
},
{
label: 'Release',
value: 'release',
color: 'black',
},
{
label: 'Yield',
value: 'yield',
color: 'black',
},
];

const typeList = [
Expand Down Expand Up @@ -191,7 +218,7 @@ const TrustRelationshipsProvider = ({ children }) => {

let local_count = 0;
for (const item of data.trust_relationships) {
if (item.state === 'requested') {
if (item.state === 'requested' && wallet.name === item.target_wallet) {
local_count++;
}
}
Expand Down

0 comments on commit 9844373

Please sign in to comment.