Skip to content

Commit

Permalink
Merge pull request #784 from alexstotsky/actualize-export-methods
Browse files Browse the repository at this point in the history
(improvements) Actualize reports generation flow
  • Loading branch information
ezewer authored Mar 19, 2024
2 parents ab0d309 + e52f8bc commit 3fdd23c
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 99 deletions.
8 changes: 4 additions & 4 deletions src/components/ExportDialog/ExportDialog.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { toggleExportDialog } from 'state/ui/actions'
import { getTimestamp } from 'state/wallets/selectors'
import { getTimeFrame } from 'state/timeRange/selectors'
import { getIsExportDialogOpen } from 'state/ui/selectors'
import { exportCsv, prepareExport } from 'state/query/actions'
import { exportReport, prepareExport } from 'state/query/actions'
import { getFullTime, getTimezone } from 'state/base/selectors'
import { getExportEmail, getIsCsvExporting } from 'state/query/selectors'
import { getExportEmail, getIsReportExporting } from 'state/query/selectors'

import ExportDialog from './ExportDialog'

Expand All @@ -20,11 +20,11 @@ const mapStateToProps = state => ({
timestamp: getTimestamp(state),
getFullTime: getFullTime(state),
isOpen: getIsExportDialogOpen(state),
isExporting: getIsCsvExporting(state),
isExporting: getIsReportExporting(state),
})

const mapDispatchToProps = {
exportCsv,
exportReport,
prepareExport,
toggleDialog: toggleExportDialog,
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ExportDialog/ExportDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ExportDialog extends PureComponent {
end: PropTypes.number,
email: PropTypes.string,
toggleDialog: PropTypes.func.isRequired,
exportCsv: PropTypes.func.isRequired,
exportReport: PropTypes.func.isRequired,
location: PropTypes.shape({
pathname: PropTypes.string.isRequired,
}).isRequired,
Expand Down Expand Up @@ -78,15 +78,15 @@ class ExportDialog extends PureComponent {
}

startExport = () => {
const { exportCsv, location } = this.props
const { exportReport, location } = this.props
const { currentTargets } = this.state
tracker.trackEvent('Export')
const target = getTarget(location.pathname)
const targets = queryConstants.MENU_POSITIONS_AUDIT !== target
? currentTargets
: [queryConstants.MENU_POSITIONS_AUDIT]

exportCsv(targets)
exportReport(targets)
}

toggleTarget = (target) => {
Expand Down
20 changes: 10 additions & 10 deletions src/state/query/actions.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import types from './constants'

/**
* Create an action to export CSV.
* Create an action to export report.
* @param {string[]} targets array of export types
*/
export function exportCsv(targets) {
export function exportReport(targets) {
return {
type: types.EXPORT_CSV,
type: types.EXPORT_REPORT,
payload: targets,
}
}

/**
* Create an action to set path to local export CSV folder.
* Create an action to set path to local export folder.
* @param {string} path to local export folder
*/
export function setLocalExportPath(path) {
Expand All @@ -23,12 +23,12 @@ export function setLocalExportPath(path) {
}

/**
* Create an action to set remote CSV URN.
* Create an action to set remote report URN.
* @param {string} urn to generated report.
*/
export function setRemoteUrn(urn) {
return {
type: types.SET_REMOTE_CSV_URN,
type: types.SET_REMOTE_REPORT_URN,
payload: urn,
}
}
Expand All @@ -53,9 +53,9 @@ export function setExportEmail(email) {
}
}

export function setIsCsvExporting(isExporting) {
export function setIsReportExporting(isExporting) {
return {
type: types.SET_IS_CSV_EXPORTING,
type: types.SET_IS_REPORT_EXPORTING,
payload: isExporting,
}
}
Expand All @@ -68,11 +68,11 @@ export function setIsPdfRequired(isPdfRequired) {
}

export default {
exportCsv,
exportReport,
setRemoteUrn,
prepareExport,
setExportEmail,
setIsPdfRequired,
setIsCsvExporting,
setIsReportExporting,
setLocalExportPath,
}
8 changes: 4 additions & 4 deletions src/state/query/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export default {
TIME_TYPE_LOCALTIME: 'local',
DEFAULT_QUERY_LIMIT: 500,
DEFAULT_RANGE: '2w',
EXPORT_CSV: 'BITFINEX/EXPORT/CSV',
SET_LOCAL_EXPORT_PATH: 'BITFINEX/EXPORT/CSV_FOLDER_PATH',
SET_REMOTE_CSV_URN: 'BITFINEX/EXPORT/CSV_REMOTE_URN',
SET_IS_CSV_EXPORTING: 'BITFINEX/EXPORT/IS_CSV_EXPORTING',
EXPORT_REPORT: 'BITFINEX/EXPORT/REPORT',
SET_LOCAL_EXPORT_PATH: 'BITFINEX/EXPORT/REPORT_FOLDER_PATH',
SET_REMOTE_REPORT_URN: 'BITFINEX/EXPORT/REPORT_REMOTE_URN',
SET_IS_REPORT_EXPORTING: 'BITFINEX/EXPORT/IS_REPORT_EXPORTING',
SET_IS_PDF_REQUIRED: 'BITFINEX/EXPORT/IS_PDF_REQUIRED',
PREPARE_EXPORT: 'BITFINEX/EXPORT/PREPARE',
SET_EXPORT_EMAIL: 'BITFINEX/EMAIL/EXPORT',
Expand Down
8 changes: 4 additions & 4 deletions src/state/query/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const initialState = {
exportEmail: '',
localExportPath: null,
remoteUrn: null,
isCsvExporting: false,
isReportExporting: false,
isPDFRequired: true,
}

Expand All @@ -23,15 +23,15 @@ export function queryReducer(state = initialState, action) {
...state,
localExportPath: payload || null,
}
case types.SET_REMOTE_CSV_URN:
case types.SET_REMOTE_REPORT_URN:
return {
...state,
remoteUrn: payload || null,
}
case types.SET_IS_CSV_EXPORTING:
case types.SET_IS_REPORT_EXPORTING:
return {
...state,
isCsvExporting: payload,
isReportExporting: payload,
}
case types.SET_IS_PDF_REQUIRED:
return {
Expand Down
108 changes: 41 additions & 67 deletions src/state/query/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,7 @@ const {
MENU_WIN_LOSS,
} = types

/**
{
"auth": {
"apiKey": "fake",
"apiSecret": "fake"
},
"method": "getMultipleCsv",
"params": {
"email": "[email protected]",
"multiExport": [
{
"method": "getTradesCsv",
"symbol": "tBTCUSD",
"end": 1546765168000
},
{
"method": "getLedgersCsv",
"symbol": "BTC",
"end": 1546765168000,
"timezone": "America/Los_Angeles"
}
]
}
}
*/

const getMultipleCsv = params => makeFetchCall('getMultipleFile', params)
const getMultipleFile = params => makeFetchCall('getMultipleFile', params)

function getSelector(target) {
switch (target) {
Expand Down Expand Up @@ -309,114 +283,114 @@ function* getOptions({ target }) {

switch (target) {
case MENU_ACCOUNT_BALANCE:
options.method = 'getBalanceHistoryCsv'
options.method = 'getBalanceHistoryFile'
break
case MENU_AFFILIATES_EARNINGS:
options.method = 'getLedgersCsv'
options.method = 'getLedgersFile'
options.category = LEDGERS_CATEGORIES.AFFILIATE_REBATE
break
case MENU_CANDLES:
options.method = 'getCandlesCsv'
options.method = 'getCandlesFile'
break
case MENU_CHANGE_LOGS:
options.method = 'getChangeLogsCsv'
options.method = 'getChangeLogsFile'
break
case MENU_DERIVATIVES:
options.method = 'getStatusMessagesCsv'
options.method = 'getStatusMessagesFile'
break
case MENU_FCREDIT:
options.method = 'getFundingCreditHistoryCsv'
options.method = 'getFundingCreditHistoryFile'
break
case MENU_FLOAN:
options.method = 'getFundingLoanHistoryCsv'
options.method = 'getFundingLoanHistoryFile'
break
case MENU_FOFFER:
options.method = 'getFundingOfferHistoryCsv'
options.method = 'getFundingOfferHistoryFile'
break
case MENU_FPAYMENT:
options.method = 'getLedgersCsv'
options.method = 'getLedgersFile'
options.category = LEDGERS_CATEGORIES.FUNDING_PAYMENT
break
case MENU_INVOICES:
options.method = 'getPayInvoiceListCsv'
options.method = 'getPayInvoiceListFile'
break
case MENU_LEDGERS:
options.method = 'getLedgersFile'
options.isPDFRequired = isPdfExportRequired
options.category = yield select(getLedgersCategory)
break
case MENU_LOAN_REPORT:
options.method = 'getPerformingLoanCsv'
options.method = 'getPerformingLoanFile'
break
case MENU_LOGINS:
options.method = 'getLoginsCsv'
options.method = 'getLoginsFile'
break
case MENU_ORDERS:
options.method = 'getOrdersCsv'
options.method = 'getOrdersFile'
break
case MENU_ORDER_TRADES:
options.method = 'getOrderTradesCsv'
options.method = 'getOrderTradesFile'
break
case MENU_SPAYMENTS:
options.method = 'getLedgersCsv'
options.method = 'getLedgersFile'
options.category = LEDGERS_CATEGORIES.STAKING_PAYMENT
break
case MENU_TICKERS:
options.method = 'getTickersHistoryCsv'
options.method = 'getTickersHistoryFile'
break
case MENU_TRADES:
options.method = 'getTradesCsv'
options.method = 'getTradesFile'
break
case MENU_MOVEMENTS:
options.method = 'getMovementsCsv'
options.method = 'getMovementsFile'
break
case MENU_POSITIONS:
options.method = 'getPositionsHistoryCsv'
options.method = 'getPositionsHistoryFile'
break
case MENU_POSITIONS_ACTIVE:
options.method = 'getActivePositionsCsv'
options.method = 'getActivePositionsFile'
break
case MENU_POSITIONS_AUDIT:
options.method = 'getPositionsAuditCsv'
options.method = 'getPositionsAuditFile'
break
case MENU_PUBLIC_FUNDING:
options.method = 'getPublicTradesCsv'
options.method = 'getPublicTradesFile'
break
case MENU_PUBLIC_TRADES:
options.method = 'getPublicTradesCsv'
options.method = 'getPublicTradesFile'
break
case MENU_SNAPSHOTS:
options.method = 'getFullSnapshotReportCsv'
options.method = 'getFullSnapshotReportFile'
break
case MENU_TAX_REPORT:
options.method = 'getFullTaxReportFile'
break
case MENU_TRADED_VOLUME:
options.method = 'getTradedVolumeCsv'
options.method = 'getTradedVolumeFile'
break
case MENU_FEES_REPORT:
options.method = 'getTotalFeesReportCsv'
options.method = 'getTotalFeesReportFile'
break
case MENU_WALLETS:
options.method = 'getWalletsCsv'
options.method = 'getWalletsFile'
break
case MENU_WEIGHTED_AVERAGES:
options.method = 'getWeightedAveragesReportCsv'
options.method = 'getWeightedAveragesReportFile'
break
case MENU_WIN_LOSS:
options.method = isVsAccountBalanceSelected
? 'getWinLossVSAccountBalanceCsv'
: 'getWinLossCsv'
? 'getWinLossVSAccountBalanceFile'
: 'getWinLossFile'
break
default:
options.method = 'getLedgersCsv'
options.method = 'getLedgersFile'
break
}

return options
}

function* exportCSV({ payload: targets }) {
function* exportReport({ payload: targets }) {
try {
const exportEmail = yield select(getExportEmail)
const multiExport = []
Expand Down Expand Up @@ -448,15 +422,15 @@ function* exportCSV({ payload: targets }) {
}

if (showFrameworkMode) {
yield put(actions.setIsCsvExporting(true))
yield put(actions.setIsReportExporting(true))
}

const { result, error } = yield call(getMultipleCsv, params)
const { result, error } = yield call(getMultipleFile, params)

if (result) {
const { localCsvFolderPath, remoteCsvUrn = null } = result
yield put(actions.setRemoteUrn(remoteCsvUrn))
yield put(actions.setLocalExportPath(localCsvFolderPath))
const { localReportFolderPath, remoteReportUrn = null } = result
yield put(actions.setRemoteUrn(remoteReportUrn))
yield put(actions.setLocalExportPath(localReportFolderPath))
if (!showFrameworkMode) {
yield put(toggleExportDialog())
yield put(toggleExportSuccessDialog())
Expand All @@ -465,7 +439,7 @@ function* exportCSV({ payload: targets }) {

if (error) {
if (showFrameworkMode) {
yield put(actions.setIsCsvExporting(false))
yield put(actions.setIsReportExporting(false))
}
yield put(updateErrorStatus({
id: 'status.fail',
Expand All @@ -475,7 +449,7 @@ function* exportCSV({ payload: targets }) {
}
} catch (fail) {
if (showFrameworkMode) {
yield put(actions.setIsCsvExporting(false))
yield put(actions.setIsReportExporting(false))
}
yield put(updateErrorStatus({
id: 'status.request.error',
Expand Down Expand Up @@ -510,5 +484,5 @@ function* prepareExport() {

export default function* exportSaga() {
yield takeLatest(types.PREPARE_EXPORT, prepareExport)
yield takeLatest(types.EXPORT_CSV, exportCSV)
yield takeLatest(types.EXPORT_REPORT, exportReport)
}
Loading

0 comments on commit 3fdd23c

Please sign in to comment.