return (dispatch: Redux.Dispatch<any, IState>, getState: () => IState) => { dispatch(startLoading("wallets")); const query = WALLETS_GET_QUERY; const variables = queryData; clientAccess.query({query, variables}) .then(response => { const answer = response.data as any; clientAccess.cache.reset(); if (!answer || !answer.wallets) { throw Error("Server returns empty response"); } else { dispatch(endLoading("wallets")); dispatch(walletsLoadSuccess(answer.wallets as any)); } }) .catch((err: any) => { if (err.graphQLErrors && err.graphQLErrors.length) { err.graphQLErrors.forEach((e: any) => dispatch(this.fetchFailed.execute(e.message))); } else { dispatch(this.fetchFailed.execute(err.message)); } } ); };
return (dispatch: Redux.Dispatch<any, IState>, getState: () => IState) => { dispatch(startLoading("transactions")); const mutation = TRANSACTION_DELETE_MUTATION; const variables = {id}; clientAccess.mutate({mutation, variables}) .then(response => { const answer = (response.data as any); clientAccess.cache.reset(); if (!answer) { throw Error("Server returns empty response"); } else { dispatch(endLoading("transactions")); dispatch(removeTransactionFromSelectedWallet(id)); dispatch(transactionDeleteSuccess(id)); } }) .catch((err: any) => { if (err.graphQLErrors && err.graphQLErrors.length) { err.graphQLErrors.forEach((e: any) => dispatch(this.fetchFailed.execute(e.message, "transactions"))); } else { dispatch(this.fetchFailed.execute(err.message, "transactions")); } } ); };
return (dispatch: Redux.Dispatch<any, IState>, getState: () => IState) => { dispatch(startLoading("wallet")); const mutation = WALLET_CREATE_MUTATION; const variables = data; clientAccess.mutate({mutation, variables}) .then(response => { dispatch(endLoading("wallet")); if (!response.data) { throw Error("Server returns empty response"); } else { const w = (response.data.createWallet as IWalletCreateMutationResponse); const wallet = { ...w, ownerId: (w.owner.id as string) }; dispatch(walletCreationSuccess(wallet as any)); } }) .catch((err: any) => { if (err.graphQLErrors) { err.graphQLErrors.forEach((e: any) => dispatch(this.fetchFailed.execute(e.message))); } else { dispatch(this.fetchFailed.execute(err.message)); } } ); };
return (dispatch: Redux.Dispatch<any, IState>, getState: () => IState) => { dispatch(startLoading("transactions")); const mutation = TRANSACTION_CREATE_MUTATION; const variables = data; clientAccess.mutate({mutation, variables}) .then(response => { dispatch(endLoading("transactions")); if (!response.data) { throw Error("Server returns empty response"); } else { const w = (response.data.createTransaction as ITransactionCreateMutationResponse); const transaction = { ...w, }; dispatch(transactionCreationSuccess(transaction as any)); } }) .catch((err: any) => { if (err.graphQLErrors) { err.graphQLErrors.forEach((e: any) => dispatch(this.fetchFailed.execute(e.message))); } else { dispatch(this.fetchFailed.execute(err.message)); } } ); };