-
Notifications
You must be signed in to change notification settings - Fork 4
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
Trello 19 #31
Open
ZiyedB
wants to merge
11
commits into
paralink-network:master
Choose a base branch
from
ZiyedB:TRELLO-19
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Trello 19 #31
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a6f822b
feat(table): add a simple table component with tailwind
ZiyedB c1262ba
pr feedback
ZiyedB bc3ad16
feat(card): add card component + extend tailwind instead of overwrite
ZiyedB 0a51551
pr feedback
ZiyedB e8dc5aa
feat(tracked-contracts): ability to search through the chain to selec…
ZiyedB ac912e7
pr feedback
ZiyedB a3f1135
basic ui implementation
ZiyedB 6463125
hook with the BE
ZiyedB ba28515
setup correclty the ref
ZiyedB 492fb9e
update with latest model
ZiyedB 99f7eca
integrate with errors
ZiyedB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,70 @@ | ||
import axios from 'axios'; | ||
|
||
// const OBTAIN_TOKEN = '/token/obtain/'; | ||
// const REFRESH_TOKEN_URL = '/token/refresh/'; | ||
|
||
export const ACCESS_TOKEN = 'access_token'; | ||
export const REFRESH_TOKEN = 'refresh_token'; | ||
|
||
// interface JWTTokenResponse { | ||
// refresh: string; | ||
// access: string; | ||
// } | ||
|
||
export const axiosInstance = axios.create({ | ||
baseURL: 'http://127.0.0.1:7424/api/', | ||
timeout: 5000, | ||
headers: { | ||
// 'Authorization': localStorage.getItem('access_token') ? 'JWT ' + localStorage.getItem('access_token') : null, | ||
'Content-Type': 'application/json', | ||
accept: 'application/json', | ||
}, | ||
}); | ||
|
||
// export const saveTokens = (jwtToken: JWTTokenResponse): JWTTokenResponse => { | ||
// localStorage.setItem(ACCESS_TOKEN, jwtToken.access); | ||
// localStorage.setItem(REFRESH_TOKEN, jwtToken.refresh); | ||
// return jwtToken; | ||
// }; | ||
|
||
const localGet = (key: string, defaultValue = ''): string => { | ||
const value = localStorage.getItem(key); | ||
if (value === null) return defaultValue; | ||
return value; | ||
}; | ||
|
||
export const getAccessToken = (): string => localGet(ACCESS_TOKEN); | ||
export const getRefreshToken = (): string => localGet(REFRESH_TOKEN); | ||
|
||
axiosInstance.interceptors.response.use( | ||
(res) => res, | ||
(err) => { | ||
// const originalRequest = err.config; | ||
// If refresh tokens is expired redirect to login page | ||
// if (err.response.status === 401 && originalRequest.url === REFRESH_TOKEN_URL) { | ||
// window.location.href = '/login/'; | ||
// return Promise.reject(err); | ||
// } | ||
|
||
// // If access token is expired update it | ||
// if (err.response.status === 401 && err.response.statusText === 'Unauthorized') { | ||
// return axiosInstance | ||
// .post<JWTTokenResponse>(REFRESH_TOKEN_URL, {refresh: localStorage.getItem(REFRESH_TOKEN)}) | ||
// .then(res => res.data) | ||
// .then(saveTokens) | ||
// .then(res => { | ||
// axiosInstance.defaults.headers['Authorization'] = 'JWT ' + res.access; | ||
// originalRequest.headers['Authorization'] = 'JWT ' + res.access; | ||
|
||
// return axiosInstance(originalRequest); | ||
// }) | ||
// } | ||
|
||
return Promise.reject(err); | ||
}, | ||
); | ||
|
||
// export const obtainTokenApi = async (email: string, password: string): Promise<JWTTokenResponse> => | ||
// axiosInstance | ||
// .post<JWTTokenResponse>(OBTAIN_TOKEN, { email, password }) | ||
// .then((res) => res.data); |
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,14 @@ | ||
import { Chain } from '../interfaces'; | ||
import { axiosInstance } from './api'; | ||
|
||
// Let it be implicit here to avoid importing AxiosResponse etc. | ||
|
||
/* eslint-disable @typescript-eslint/explicit-function-return-type */ | ||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
const chainsApi = '/chains'; | ||
|
||
const getAllChains = () => axiosInstance.get<Chain[]>(`${chainsApi}`); | ||
const getChain = (chain: string) => axiosInstance.get<Chain>(`${chainsApi}/${chain}`); | ||
const setChainStatus = (chain: string) => axiosInstance.put<any>(`${chainsApi}/${chain}`); | ||
|
||
export default { getAllChains, getChain, setChainStatus }; |
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,17 @@ | ||
import { Contract } from '../interfaces'; | ||
import { axiosInstance } from './api'; | ||
|
||
const contractsApi = '/contracts'; | ||
|
||
/* eslint-disable @typescript-eslint/explicit-function-return-type */ | ||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
|
||
// Implementation : https://github.com/paralink-network/paralink-node/blob/master/src/api/contracts.py | ||
const getAllContracts = () => axiosInstance.get<Contract[]>(`${contractsApi}`); | ||
const getChainContracts = (chain: string) => axiosInstance.get<Contract>(`${contractsApi}/${chain}`); | ||
const createContract = (contract: Omit<Contract, 'id'>) => axiosInstance.post<any>(`${contractsApi}`, contract); | ||
const setContractStatus = (id: number, contract: Pick<Contract, 'active'>) => | ||
axiosInstance.put<any>(`${contractsApi}/${id}`, contract); | ||
const deleteContract = (id: number) => axiosInstance.delete<any>(`${contractsApi}/${id}`); | ||
|
||
export default { getAllContracts, getChainContracts, createContract, setContractStatus, deleteContract }; |
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,28 @@ | ||
import React from 'react'; | ||
|
||
const BLUE_COLOR = 'blue'; | ||
const GREEN_COLOR = 'green'; | ||
const GRAY_COLOR = 'gray'; | ||
const RED_COLOR = 'red'; | ||
|
||
type Color = typeof BLUE_COLOR | typeof GREEN_COLOR | typeof GRAY_COLOR | typeof RED_COLOR; | ||
|
||
interface Button { | ||
onClick?: () => void; | ||
color?: Color; | ||
className?: string; | ||
disabled?: boolean; | ||
} | ||
|
||
const Button: React.FC<Button> = ({ children, onClick, color = GRAY_COLOR, className = '', disabled = false }) => ( | ||
<button | ||
type="button" | ||
disabled={disabled} | ||
className={`focus:outline-none text-${color}-600 text-sm py-1.5 px-3 rounded-md border border-${color}-600 hover:bg-${color}-50 ${className} disabled:opacity-50`} | ||
onClick={onClick} | ||
> | ||
{children} | ||
</button> | ||
); | ||
|
||
export default Button; |
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,3 @@ | ||
import Button from './Buttons'; | ||
|
||
export default Button; |
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,7 @@ | ||
import React from 'react'; | ||
|
||
const Card: React.FC<{ className?: string }> = ({ className = '', children }) => { | ||
return <div className={`inline-block bg-light shadow-lg overflow-hidden sm:rounded-lg ${className}`}>{children}</div>; | ||
}; | ||
|
||
export default Card; |
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,7 @@ | ||
import React from 'react'; | ||
|
||
const CardBody: React.FC<{}> = ({ children }) => { | ||
return <div className="px-4 py-5 sm:px-6">{children}</div>; | ||
}; | ||
|
||
export default CardBody; |
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,7 @@ | ||
import React from 'react'; | ||
|
||
const CardFooter: React.FC<{}> = ({ children }) => { | ||
return <div className="px-4 py-3 bg-gray-50 text-right sm:px-6">{children}</div>; | ||
}; | ||
|
||
export default CardFooter; |
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,7 @@ | ||
import React from 'react'; | ||
|
||
const CardHeader: React.FC<{}> = ({ children }) => { | ||
return <div className="mx-4 px-4 py-3 text-left text-2xl border-b border-gray-200">{children}</div>; | ||
}; | ||
|
||
export default CardHeader; |
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,4 @@ | ||
export { default as Card } from './Card'; | ||
export { default as CardBody } from './CardBody'; | ||
export { default as CardFooter } from './CardFooter'; | ||
export { default as CardHeader } from './CardHeader'; |
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,46 @@ | ||
import React from 'react'; | ||
import { FaSearch, FaTimes } from 'react-icons/fa'; | ||
|
||
interface SearchInput { | ||
value: any; | ||
onChange: (value: string) => void; | ||
name?: string; | ||
id?: string; | ||
className?: string; | ||
placeholder?: string; | ||
} | ||
|
||
const SearchInput: React.FC<SearchInput> = ({ | ||
value, | ||
onChange, | ||
name = 'search', | ||
id = 'search', | ||
className = '', | ||
placeholder = '', | ||
}): JSX.Element => { | ||
return ( | ||
<div className="mt-1 relative"> | ||
<div className="absolute inset-y-0 right-0 p-3 text-gray-600 flex items-center"> | ||
{/** TODO: Remove this and actually use the other icons library once we get the query manager merged in */} | ||
{value ? ( | ||
<button type="button" onClick={() => onChange('')}> | ||
<FaTimes size={12} /> | ||
</button> | ||
) : ( | ||
<FaSearch size={12} /> | ||
)} | ||
</div> | ||
<input | ||
type="text" | ||
name={name} | ||
id={id} | ||
value={value} | ||
placeholder={placeholder} | ||
className={`focus:outline-none focus:ring-2 focus:ring-opacity-20 focus:ring-primary block w-full pl-7 pr-12 sm:text-sm border-gray-200 bg-gray-200 text-gray-600 rounded-full ${className}`} | ||
onChange={(event) => onChange(event.target.value)} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SearchInput; |
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,3 @@ | ||
import SearchInput from './SearchInput'; | ||
|
||
export default SearchInput; |
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,7 @@ | ||
import React from 'react'; | ||
|
||
const Table: React.FC<{ className?: string }> = ({ className = '', children }): JSX.Element => { | ||
return <table className={`min-w-full divide-y divide-gray-200 ${className}`}>{children}</table>; | ||
}; | ||
|
||
export default Table; |
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,7 @@ | ||
import React from 'react'; | ||
|
||
const TableBody: React.FC<{ className?: string }> = ({ className = '', children }): JSX.Element => { | ||
return <tbody className={`bg-white divide-y divide-gray-200 ${className}`}>{children}</tbody>; | ||
}; | ||
|
||
export default TableBody; |
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,7 @@ | ||
import React from 'react'; | ||
|
||
const TableCell: React.FC<{ className?: string }> = ({ className = '', children }): JSX.Element => { | ||
return <td className={`px-6 py-4 whitespace-nowrap ${className}`}>{children}</td>; | ||
}; | ||
|
||
export default TableCell; |
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,7 @@ | ||
import React from 'react'; | ||
|
||
const TableHeader: React.FC<{ className?: string }> = ({ className = '', children }): JSX.Element => { | ||
return <thead className={`bg-gray-50 ${className}`}>{children}</thead>; | ||
}; | ||
|
||
export default TableHeader; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI @frisitano @jbargu I've tried some of the BE Apis and had some feedback :
https://github.com/paralink-network/paralink-node/blob/master/src/api/contracts.py#L47 POST & PUT should return the contract response instead of just OK ( we'd need the latest from the DB, especially in the POST to have the ID without refreshing the page or refetching all of the contracts )
Error when trying to update the status of an address, we might want to fix that
Should we be able to edit an address after it was created or saved ? cause we don't have a "setAddress" or a modify endpoint. Also if we were to add one, let's just do it as "updateContract" endpoint and remove the status one.
Error when deleting. It actually works, but return a 500 as there is an error after deleting :
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ZiyedB
I have made some modifications to the API contract on this development branch - refactor_models .
This refactor modifies the API such that contracts are identified by a unique (chain, address) tuple.
Under this new API you should not need any additional information returned by the API as the contract id has been removed.
I am not experiencing the same issue as you. I suspect your
.env
file may be referencing the celery broker incorrectly. Could you ensure it containsCELERY_BROKER_URL=amqp://guest:guest@rabbitmq:5672
please?No we should not be able to update the address. A different address would represent a different contract.
Fixed.
Could you take a look at the API and let me know your feedback. I will hold fire on raising a PR to see if we need to make any modifications to the API for the front end. In any case I still need to develop some tests for the REST endpoints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to mention that you will have to delete the docker volume associated with the paralink Postgres container before executing the dev branch above.