React TypeScript client implementation to interact with the Safient protocol
Install dependencies and start the client:
npm install | yarn install
npm start
Open http://localhost:3000 with your browser to see the result.
Build the client:
npm install | yarn install
npm build
You are welcome to submit issues and enhancement requests and work on any of the existing issues. Follow this simple guide to contribute to the repository.
- Create or pick an existing issue to work on
- Fork the repo on GitHub
- Clone the forked project to your own machine
- Commit changes to your own branch
- Push your work back up to your forked repo
- Submit a Pull request from the forked repo to our repo so that we can review your changes
- Add the screen name in RouteName enum in src/navigation/route-name.ts
- Add the screen path in the RoutePath enum in src/navigation/route-path.ts
- Add the screen route object to the routes array in src/navigation/routes.ts
- If the screen contains params then define it to route-param-list else make it undefined in src/navigation/route-param-list.ts
- If the screen contains query strings then define it to route-query-list else make it undefined in src/navigation/route-query-list.ts
RouteName:
home = 'home',
RoutePath:
home = '/',
Route object:
{
path: RoutePath.home,
name: RouteName.home,
exact: true,
component: HomeScreen,
props: { name: 'HomeScreen' },
},
RouteParam:
[RouteName.home]: undefined; // If does not have any params
[RouteName.claimDetails]: { id: string }; // If there are some params
RouteQuery:
[RouteName.home]: undefined; // If does not have any params
[RouteName.example]: {username: string}; // If there are some params
There are two ways to navigate one is using Link which is equivalent to a tag and other is programmatically using Redirect
<link to={RoutePath.example} />
<Redirect to={RoutePath.example} />
All route params are defined in the RouteParamList interface where key is the name of the route and value is the param object. We can use useParam() hook provided by the react-router-dom.
[RouteName.home]: undefined; // If the route does not have any params
[RouteName.claimDetails]: { id: string }; // If the screen have any param
const param = useParams<RouteParamsList[RouteName.home]>();
All route query strings are defined in the RouteQueryList interface where key is the name of the route and value is the query string object. We can use useQuery() hook to access the query object. useQuery() is a custom hook which takes the screen name as argument and returns a object with typecasts value (We need the typecast only if the data type of the value is not string as query strings are always string value)
[RouteName.home]: undefined; // If the route does not have any query string
[RouteName.example]: { number1: number, number2: number }; // If the screen have any query string
Query string definition in RouteQueryList:
[RouteName.home]: { number1: number; number2: number };
Using the useQuery() hook
const query = useQuery<RouteQueryList[RouteName.home]>(RouteName.home);
As the datatype of the values are not string then we need to type case the string to number. To do that you have to add query string object in src/navigation/route-query-list.ts and if there are any type casting then have to do that in typecast() function in src/hooks/useQuery.ts
const _data = { ...data };
switch (routeName) {
case RouteName.home:
{
_data.number1 = Number(_data.number1);
_data.number2 = Number(_data.number2);
}
break;
}
return _data;