Skip to content
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

(improvements) Tax report generation progress #837

Merged
merged 21 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3fff5b4
Improve tax report initial fetch flow
alexstotsky Jul 23, 2024
a22fd5d
Add report generation success key/description
alexstotsky Jul 23, 2024
5d7197f
Implement notification on tax report generation success
alexstotsky Jul 23, 2024
3ccc683
Add ws tax report generation progress const
alexstotsky Jul 24, 2024
9008d18
Add pogress setter action and constant
alexstotsky Jul 24, 2024
75b6c51
Implement handleTaxTrxReportGenerationProgress saga
alexstotsky Jul 24, 2024
e42350a
Add progress handling reducer cases, update init state
alexstotsky Jul 24, 2024
852f4a2
Implement getTransactionsGenerationProgress selector
alexstotsky Jul 24, 2024
a83d5e3
[wip] Tax report loader section
alexstotsky Jul 24, 2024
d311d0d
Add tax report loader styling
alexstotsky Jul 24, 2024
659a54a
Add loading section to the tax report
alexstotsky Jul 24, 2024
e91b828
Implement progress value handling and providing
alexstotsky Jul 24, 2024
f47c3d1
Improve spinner content validation check
alexstotsky Jul 24, 2024
e503e62
Adjust loader content styling and positioning
alexstotsky Jul 24, 2024
729d139
Add tax gen notice keys/descriptions
alexstotsky Jul 25, 2024
ca9f192
Implement tax report generation note
alexstotsky Jul 25, 2024
48b4711
Improve spinner elements composition
alexstotsky Jul 25, 2024
b3db6f6
Adjust loading section styling
alexstotsky Jul 25, 2024
a7b5f43
Minor fix
alexstotsky Jul 25, 2024
d5b4fce
Improve init generation flow
alexstotsky Jul 25, 2024
40f0ecd
Minor tweak
alexstotsky Jul 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions public/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,11 @@
"disclaimer": {
"title": "Disclaimer",
"message": "The tax reports generated by this app are for informational purposes only. We do not guarantee accuracy or completeness. Always consult a qualified tax advisor to ensure compliance with current tax laws and personalized advice. Your reliance on the generated reports is at your own risk."
},
"generation": {
"success": "Tax Report generated",
"title": "Your tax report is being generated. This process can take a while.",
"note": "If you have a large history it's recommended to keep the window open in the background until it's completed."
}
},
"theme": {
Expand Down
10 changes: 7 additions & 3 deletions src/components/TaxReport/TaxReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { getFullTime as getFullTimeSelector } from 'state/base/selectors'

import queryConstants from 'state/query/constants'

import Loader from './TaxReport.loader'
import Disclaimer from './TaxReport.disclaimer'
import { getColumns } from './TaxReport.columns'

Expand All @@ -45,10 +46,11 @@ const TaxReport = () => {
const columnsWidth = useSelector((state) => getColumnsWidth(state, TYPE))
const isNoData = isEmpty(entries)
const isLoading = !dataReceived && pageLoading
const shouldFetchTaxReport = !isSyncRequired && !dataReceived && !isLoading

useEffect(() => {
if (!isSyncRequired && isNoData) dispatch(fetchTaxReportTransactions())
}, [isSyncRequired])
if (shouldFetchTaxReport) dispatch(fetchTaxReportTransactions())
}, [shouldFetchTaxReport])

const onRefresh = useCallback(
() => dispatch(fetchTaxReportTransactions()),
Expand All @@ -63,7 +65,9 @@ const TaxReport = () => {
)

let showContent
if (isNoData) {
if (isLoading) {
showContent = <Loader />
} else if (isNoData) {
showContent = (
<div className='data-table-wrapper'>
<DataTable
Expand Down
33 changes: 33 additions & 0 deletions src/components/TaxReport/TaxReport.loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'
import { useSelector } from 'react-redux'
import { useTranslation } from 'react-i18next'
import { Spinner } from '@blueprintjs/core'
import { isNil } from '@bitfinex/lib-js-util-base'

import { getTransactionsGenerationProgress } from 'state/taxReport/selectors'

export const Loader = () => {
const { t } = useTranslation()
const progress = useSelector(getTransactionsGenerationProgress)
const spinnerContent = isNil(progress) ? '' : `${progress}%`

return (
<div className='loading-container'>
<div className='spinner-wrapper'>
<div className='loading-progress'>
{spinnerContent}
</div>
<Spinner
className='loading'
size={Spinner.SIZE_STANDARD}
/>
</div>
<div className='loading-note'>
<p>{t('taxreport.generation.title')}</p>
<p>{t('taxreport.generation.note')}</p>
</div>
</div>
)
}

export default Loader
35 changes: 35 additions & 0 deletions src/components/TaxReport/_TaxReport.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,41 @@
margin-top: 10px;
}
}

.loading {
&.bp3-spinner {
margin: auto;
display: block;
}

&-container {
height: 60%;
display: flex;
position: relative;
align-items: center;
flex-direction: column;
justify-content: center;

.spinner-wrapper {
display: flex;
position: relative;
margin-bottom: 20px;
}
}

&-progress {
top: 50%;
left: 50%;
position: absolute;
line-height: initial;
transform: translate(-50%, -50%);
}

&-note {
min-width: 340px;
text-align: center;
}
}
}

.disclaimer {
Expand Down
8 changes: 8 additions & 0 deletions src/state/taxReport/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ export function setShowDisclaimer(payload) {
}
}

export function setGenerationProgress(payload) {
return {
type: types.SET_GENERATION_PROGRESS,
payload,
}
}

export default {
fetchFail,
setShowDisclaimer,
setGenerationProgress,
setTransactionsStrategy,
fetchTaxReportTransactions,
updateTaxReportTransactions,
Expand Down
2 changes: 2 additions & 0 deletions src/state/taxReport/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ export default {
UPDATE_TRANSACTIONS: 'BITFINEX/TAX_REPORT_TRANSACTIONS/UPDATE',
SET_TRANSACTIONS_STRATEGY: 'BITFINEX/TAX_REPORT_TRANSACTIONS/STRATEGY/SET',
SET_SHOW_DISCLAIMER: 'BITFINEX/TAX_REPORT_TRANSACTIONS/SHOW_DISCLAIMER/SET',
SET_GENERATION_PROGRESS: 'BITFINEX/TAX_REPORT_TRANSACTIONS/GENERATION_PROGRESS/SET',

STRATEGY_LIFO: 'LIFO',
STRATEGY_FIFO: 'FIFO',
WS_TAX_TRANSACTION_REPORT_GENERATION_PROGRESS: 'ws_emitTrxTaxReportGenerationProgressToOne',
WS_TAX_TRANSACTION_REPORT_GENERATION_COMPLETED: 'ws_emitTrxTaxReportGenerationInBackgroundToOne',
}
18 changes: 15 additions & 3 deletions src/state/taxReport/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import types from './constants'

const transactionsInitState = {
data: [],
progress: null,
pageLoading: false,
dataReceived: false,
showDisclaimer: true,
Expand All @@ -30,9 +31,10 @@ export function taxReportReducer(state = initialState, action) {
return {
...state,
transactions: {
dataReceived: true,
pageLoading: false,
data: payload,
progress: null,
pageLoading: false,
dataReceived: true,
strategy: state.transactions.strategy,
showDisclaimer: state.transactions.showDisclaimer,
},
Expand All @@ -56,13 +58,23 @@ export function taxReportReducer(state = initialState, action) {
},
}
}
case types.SET_GENERATION_PROGRESS: {
return {
...state,
transactions: {
...state.transactions,
progress: payload,
},
}
}
case types.FETCH_FAIL:
return {
...state,
transactions: {
...state.transactions,
dataReceived: false,
progress: null,
pageLoading: false,
dataReceived: true,
},
}
case authTypes.LOGOUT:
Expand Down
12 changes: 11 additions & 1 deletion src/state/taxReport/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'redux-saga/effects'

import { makeFetchCall } from 'state/utils'
import { updateErrorStatus } from 'state/status/actions'
import { updateSuccessStatus, updateErrorStatus } from 'state/status/actions'
import { getTimeFrame } from 'state/timeRange/selectors'

import types from './constants'
Expand Down Expand Up @@ -46,6 +46,7 @@ function* handleTaxTrxReportGenerationCompleted({ payload }) {
const { result, error } = payload
if (result) {
yield put(actions.updateTaxReportTransactions(result))
yield put(updateSuccessStatus({ id: 'taxreport.generation.success' }))
}
if (error) {
yield put(actions.fetchFail({
Expand All @@ -56,8 +57,17 @@ function* handleTaxTrxReportGenerationCompleted({ payload }) {
}
}

function* handleTaxTrxReportGenerationProgress({ payload }) {
const { result } = payload
if (result) {
const { progress } = result
yield put(actions.setGenerationProgress(progress))
}
}

export default function* taxReportSaga() {
yield takeLatest(types.FETCH_FAIL, fetchTaxReportFail)
yield takeLatest([types.FETCH_TRANSACTIONS], fetchTaxReport)
yield takeLatest(types.WS_TAX_TRANSACTION_REPORT_GENERATION_PROGRESS, handleTaxTrxReportGenerationProgress)
yield takeLatest(types.WS_TAX_TRANSACTION_REPORT_GENERATION_COMPLETED, handleTaxTrxReportGenerationCompleted)
}
2 changes: 2 additions & 0 deletions src/state/taxReport/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const getTransactionsPageLoading = state => getTaxTransactions(state)?.pa
export const getTransactionsDataReceived = state => getTaxTransactions(state)?.dataReceived ?? false
export const getTransactionsStrategy = state => getTaxTransactions(state)?.strategy ?? types.STRATEGY_LIFO
export const getTransactionsShowDisclaimer = state => getTaxTransactions(state)?.showDisclaimer ?? false
export const getTransactionsGenerationProgress = state => getTaxTransactions(state)?.progress ?? null

export default {
getTaxReport,
Expand All @@ -17,4 +18,5 @@ export default {
getTransactionsPageLoading,
getTransactionsDataReceived,
getTransactionsShowDisclaimer,
getTransactionsGenerationProgress,
}