1+ import { apiDelete , apiGet , apiPost } from "./apiRequest" ;
2+ import {
3+ getGatewayApplicationsPath ,
4+ getGatewayApplicationWalletsPath ,
5+ } from "../utils/apiPathes" ;
6+ import {
7+ FETCH_GATEWAY_APPLICATION_WALLET ,
8+ FETCH_GATEWAY_APPLICATIONS , SET_ETHEREUM_SCAFFOLD_SET , SET_GATEWAY_APPLICATION_SET ,
9+ SHOW_MODAL
10+ } from "./types" ;
11+ import { parseApiError } from "../utils/parseApiError" ;
12+
13+
14+ export const fetchGatewayApplications = ( offset = 0 , limit = 10 ) => async dispatch => {
15+ const params = { offset, limit } ;
16+
17+ try {
18+ const data = await dispatch ( apiGet ( getGatewayApplicationsPath ( ) , params ) ) ;
19+ dispatch ( { type : FETCH_GATEWAY_APPLICATIONS , payload : data } ) ;
20+ } catch ( err ) {
21+ const error = parseApiError ( err ) ;
22+ dispatch ( {
23+ type : SHOW_MODAL ,
24+ payload : { showLoader : false , showModal : true , error : error . message }
25+ } ) ;
26+ throw error ;
27+ }
28+ } ;
29+
30+ export const saveGatewayApplication = formValues => async ( dispatch ) => {
31+ await dispatch ( apiPost ( getGatewayApplicationsPath ( ) , formValues ) ) ;
32+ } ;
33+
34+ export const fetchGatewayApplicationDetails = ( id ) => async dispatch => {
35+ dispatch ( { type : SET_GATEWAY_APPLICATION_SET , payload : { id, loading : true } } ) ;
36+
37+ try {
38+ const gateway = await dispatch ( apiGet ( getGatewayApplicationsPath ( id ) ) ) ;
39+ const wallets = await dispatch ( getGatewayApplicationWallet ( id ) ) ;
40+ const error = '' ;
41+ const payload = { id, gateway, wallets, error, loading : false } ;
42+ dispatch ( { type : SET_GATEWAY_APPLICATION_SET , payload } ) ;
43+
44+ } catch ( e ) {
45+ const response = e . response || { } ;
46+ const error = `${ response . status } : ${ response . message || response . statusText } ` ;
47+ const payload = { id, error, loading : false } ;
48+ dispatch ( { type : SET_GATEWAY_APPLICATION_SET , payload } ) ;
49+ throw e ;
50+ }
51+ } ;
52+
53+ export const removeGatewayApplication = ( id ) => async dispatch => {
54+ try {
55+ await dispatch ( apiDelete ( getGatewayApplicationsPath ( ) + "?id=" + id , { } ) ) ;
56+ await dispatch ( fetchGatewayApplications ( ) )
57+ } catch ( e ) {
58+ throw parseApiError ( e ) ;
59+ }
60+ } ;
61+
62+ export const getGatewayApplicationWallet = ( gatewayId ) => async dispatch => {
63+ const wallets = await dispatch ( apiGet ( getGatewayApplicationWalletsPath ( gatewayId ) , { } ) ) ;
64+ const error = '' ;
65+ dispatch ( { type : SET_GATEWAY_APPLICATION_SET , payload : { gatewayId, wallets, error, loading : false } } ) ;
66+ return wallets ;
67+ } ;
68+
69+ export const generateGatewayApplicationWallet = ( wallet , blockchain ) => async ( dispatch ) => {
70+ await dispatch ( apiPost ( getGatewayApplicationWalletsPath ( ) , { applicationId : wallet . applicationId , webHook : wallet . webHook , blockchainType : blockchain . blockchain } ) ) ;
71+ dispatch ( fetchGatewayApplicationDetails ( wallet . applicationId ) )
72+ } ;
73+
74+ export const removeGatewayApplicationWallet = ( gatewayId , address ) => async dispatch => {
75+ try {
76+ await dispatch ( apiDelete ( getGatewayApplicationWalletsPath ( ) + "?applicationId=" + gatewayId + "&address=" + address , { } ) ) ;
77+ await dispatch ( fetchGatewayApplicationDetails ( gatewayId ) )
78+ } catch ( e ) {
79+ throw parseApiError ( e ) ;
80+ }
81+ } ;
0 commit comments