Skip to content

Commit

Permalink
Merge pull request #852 from alexstotsky/rm-query-btns
Browse files Browse the repository at this point in the history
(improvements) Remove duplicate buttons with the same functionality
  • Loading branch information
ezewer authored Sep 9, 2024
2 parents 4cbb06a + 82b4e5c commit b145026
Show file tree
Hide file tree
Showing 17 changed files with 22 additions and 215 deletions.
25 changes: 0 additions & 25 deletions src/components/AccountBalance/AccountBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import NoData from 'ui/NoData'
import Loading from 'ui/Loading'
import Chart from 'ui/Charts/Chart'
import TimeRange from 'ui/TimeRange'
import QueryButton from 'ui/QueryButton'
import RefreshButton from 'ui/RefreshButton'
import TimeFrameSelector from 'ui/TimeFrameSelector'
import parseChartData from 'ui/Charts/Charts.helpers'
Expand All @@ -36,7 +35,6 @@ class AccountBalance extends PureComponent {
mts: PropTypes.number,
USD: PropTypes.number,
})),
fetchData: PropTypes.func.isRequired,
isUnrealizedProfitExcluded: PropTypes.bool.isRequired,
pageLoading: PropTypes.bool.isRequired,
refresh: PropTypes.func.isRequired,
Expand All @@ -58,11 +56,6 @@ class AccountBalance extends PureComponent {
checkFetch(prevProps, this.props, TYPE)
}

handleQuery = () => {
const { fetchData } = this.props
fetchData()
}

handleTimeframeChange = (timeframe) => {
const { setParams } = this.props
setParams({ timeframe })
Expand All @@ -73,19 +66,6 @@ class AccountBalance extends PureComponent {
setParams({ isUnrealizedProfitExcluded })
}

hasChanges = () => {
const {
currentFetchParams: {
timeframe: currTimeframe,
isUnrealizedProfitExcluded: currUnrealizedProfitState,
},
isUnrealizedProfitExcluded,
timeframe,
} = this.props
return currTimeframe !== timeframe
|| currUnrealizedProfitState !== isUnrealizedProfitExcluded
}

render() {
const {
currentFetchParams: { timeframe: currTimeframe },
Expand All @@ -97,7 +77,6 @@ class AccountBalance extends PureComponent {
t,
timeframe,
} = this.props
const hasChanges = this.hasChanges()

const { chartData, presentCurrencies } = parseChartData({
data: _sortBy(entries, ['mts']),
Expand Down Expand Up @@ -151,10 +130,6 @@ class AccountBalance extends PureComponent {
onChange={this.handleUnrealizedProfitChange}
/>
</SectionHeaderItem>
<QueryButton
disabled={!hasChanges}
onClick={this.handleQuery}
/>
<RefreshButton onClick={refresh} />
</SectionHeaderRow>
</SectionHeader>
Expand Down
18 changes: 1 addition & 17 deletions src/components/AverageWinLoss/AverageWinLoss.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { Card, Elevation } from '@blueprintjs/core'
import _sortBy from 'lodash/sortBy'
import { isEmpty, isEqual } from '@bitfinex/lib-js-util-base'
import { isEmpty } from '@bitfinex/lib-js-util-base'

import {
SectionHeader,
Expand All @@ -15,7 +15,6 @@ import NoData from 'ui/NoData'
import Loading from 'ui/Loading'
import Chart from 'ui/Charts/Chart'
import TimeRange from 'ui/TimeRange'
import QueryButton from 'ui/QueryButton'
import RefreshButton from 'ui/RefreshButton'
import SectionSwitch from 'ui/SectionSwitch'
import TimeFrameSelector from 'ui/TimeFrameSelector'
Expand Down Expand Up @@ -75,7 +74,6 @@ class AverageWinLoss extends PureComponent {
mts: PropTypes.number,
USD: PropTypes.number,
})),
fetchData: PropTypes.func.isRequired,
pageLoading: PropTypes.bool.isRequired,
params: PropTypes.shape({
timeframe: PropTypes.string,
Expand Down Expand Up @@ -103,11 +101,6 @@ class AverageWinLoss extends PureComponent {
checkFetch(prevProps, this.props, TYPE)
}

handleQuery = () => {
const { fetchData } = this.props
fetchData()
}

handleTimeframeChange = (timeframe) => {
const { setParams } = this.props
setParams({ timeframe })
Expand All @@ -125,11 +118,6 @@ class AverageWinLoss extends PureComponent {
setParams(params)
}

hasChanges = () => {
const { currentFetchParams, params } = this.props
return !isEqual(currentFetchParams, params)
}

render() {
const {
t,
Expand Down Expand Up @@ -210,10 +198,6 @@ class AverageWinLoss extends PureComponent {
onChange={this.handleReportTypeChange}
/>
</SectionHeaderItem>
<QueryButton
onClick={this.handleQuery}
disabled={!this.hasChanges()}
/>
<RefreshButton onClick={refresh} />
</SectionHeaderRow>
</SectionHeader>
Expand Down
18 changes: 0 additions & 18 deletions src/components/Candles/Candles.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { Card, Elevation } from '@blueprintjs/core'
import { isEqual } from '@bitfinex/lib-js-util-base'

import {
SectionHeader,
Expand All @@ -14,7 +13,6 @@ import NoData from 'ui/NoData'
import Loading from 'ui/Loading'
import TimeRange from 'ui/TimeRange'
import GoToButton from 'ui/GoToButton'
import QueryButton from 'ui/QueryButton'
import PairSelector from 'ui/PairSelector'
import Timeframe from 'ui/CandlesTimeframe'
import RefreshButton from 'ui/RefreshButton'
Expand Down Expand Up @@ -73,17 +71,6 @@ class Candles extends PureComponent {
checkFetch(prevProps, this.props, TYPE)
}

hasChanges = () => {
const { currentFetchParams, params } = this.props
return !isEqual(currentFetchParams, params)
}

handleQuery = () => {
const { refresh, fetchData } = this.props
refresh()
fetchData()
}

onPairSelect = (pair) => {
const { setParams } = this.props
setParams({ pair })
Expand All @@ -107,7 +94,6 @@ class Candles extends PureComponent {
toggleGoToRangeDialog,
} = this.props
const { pair, timeframe } = params
const hasChanges = this.hasChanges()
const chartClassName = isChartLoading ? 'candlestick--loading' : ''

let showContent
Expand Down Expand Up @@ -160,10 +146,6 @@ class Candles extends PureComponent {
value={timeframe}
onChange={this.onTimeframeChange}
/>
<QueryButton
disabled={!hasChanges}
onClick={this.handleQuery}
/>
<RefreshButton onClick={refresh} />
<CandlesSyncPref />
<GoToButton onClick={toggleGoToRangeDialog} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { withTranslation } from 'react-i18next'

import { fetchWallets, refresh } from 'state/wallets/actions'
import { fetchWallets, refresh, setTimestamp } from 'state/wallets/actions'
import {
getEntries,
getTimestamp,
Expand All @@ -25,6 +25,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = {
refresh,
fetchWallets,
setTimestamp,
}

export default compose(
Expand Down
17 changes: 3 additions & 14 deletions src/components/ConcentrationRisk/ConcentrationRisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from 'ui/SectionHeader'
import DataTable from 'ui/DataTable'
import DateInput from 'ui/DateInput'
import QueryButton from 'ui/QueryButton'
import PieChart from 'ui/Charts/PieChart'
import RefreshButton from 'ui/RefreshButton'
import SectionSwitch from 'ui/SectionSwitch'
Expand All @@ -38,6 +37,7 @@ class ConcentrationRisk extends PureComponent {
pageLoading: PropTypes.bool.isRequired,
isSyncRequired: PropTypes.bool.isRequired,
refresh: PropTypes.func.isRequired,
setTimestamp: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
}

Expand Down Expand Up @@ -108,32 +108,25 @@ class ConcentrationRisk extends PureComponent {
}

handleDateChange = (time) => {
const { setTimestamp } = this.props
const end = time && time.getTime()
if (isValidTimeStamp(end) || time === null) {
this.setState({ timestamp: time })
setTimestamp(end)
}
}

handleQuery = () => {
const { fetchWallets } = this.props
const { timestamp } = this.state
const time = timestamp ? timestamp.getTime() : null
fetchWallets(time)
}

render() {
const {
t,
entries,
refresh,
pageLoading,
currentTime,
dataReceived,
} = this.props
const isNoData = isEmpty(entries)
const isLoading = !dataReceived && pageLoading
const { timestamp } = this.state
const hasNewTime = timestamp ? currentTime !== timestamp.getTime() : !!currentTime !== !!timestamp

const filteredData = entries.filter(entry => entry.balanceUsd)

Expand Down Expand Up @@ -192,10 +185,6 @@ class ConcentrationRisk extends PureComponent {
onChange={this.handleDateChange}
/>
</SectionHeaderItem>
<QueryButton
disabled={!hasNewTime}
onClick={this.handleQuery}
/>
<RefreshButton onClick={refresh} />
</SectionHeaderRow>
</SectionHeader>
Expand Down
18 changes: 1 addition & 17 deletions src/components/FeesReport/FeesReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { Card, Elevation } from '@blueprintjs/core'
import _sortBy from 'lodash/sortBy'
import { isEmpty, isEqual } from '@bitfinex/lib-js-util-base'
import { isEmpty } from '@bitfinex/lib-js-util-base'

import {
SectionHeader,
Expand All @@ -15,7 +15,6 @@ import NoData from 'ui/NoData'
import Loading from 'ui/Loading'
import Chart from 'ui/Charts/Chart'
import TimeRange from 'ui/TimeRange'
import QueryButton from 'ui/QueryButton'
import RefreshButton from 'ui/RefreshButton'
import SectionSwitch from 'ui/SectionSwitch'
import TimeFrameSelector from 'ui/TimeFrameSelector'
Expand Down Expand Up @@ -57,7 +56,6 @@ class FeesReport extends PureComponent {
entries: PropTypes.arrayOf(PropTypes.shape({
mts: PropTypes.number.isRequired,
})),
fetchData: PropTypes.func.isRequired,
pageLoading: PropTypes.bool.isRequired,
params: PropTypes.shape({
timeframe: PropTypes.string,
Expand Down Expand Up @@ -86,21 +84,11 @@ class FeesReport extends PureComponent {
checkFetch(prevProps, this.props, TYPE)
}

handleQuery = () => {
const { fetchData } = this.props
fetchData()
}

handleTimeframeChange = (timeframe) => {
const { setParams } = this.props
setParams({ timeframe })
}

hasChanges = () => {
const { currentFetchParams, params } = this.props
return !isEqual(currentFetchParams, params)
}

toggleSymbol = symbol => toggleSymbol(TYPE, this.props, symbol)

clearSymbols = () => clearAllSymbols(TYPE, this.props)
Expand Down Expand Up @@ -189,10 +177,6 @@ class FeesReport extends PureComponent {
onChange={this.handleReportTypeChange}
/>
</SectionHeaderItem>
<QueryButton
onClick={this.handleQuery}
disabled={!this.hasChanges()}
/>
<RefreshButton onClick={refresh} />
</SectionHeaderRow>
</SectionHeader>
Expand Down
19 changes: 1 addition & 18 deletions src/components/LoanReport/LoanReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { Card, Elevation } from '@blueprintjs/core'
import _sortBy from 'lodash/sortBy'
import { isEmpty, isEqual } from '@bitfinex/lib-js-util-base'
import { isEmpty } from '@bitfinex/lib-js-util-base'

import {
SectionHeader,
Expand All @@ -15,7 +15,6 @@ import NoData from 'ui/NoData'
import Loading from 'ui/Loading'
import Chart from 'ui/Charts/Chart'
import TimeRange from 'ui/TimeRange'
import QueryButton from 'ui/QueryButton'
import RefreshButton from 'ui/RefreshButton'
import SectionSwitch from 'ui/SectionSwitch'
import TimeFrameSelector from 'ui/TimeFrameSelector'
Expand Down Expand Up @@ -50,7 +49,6 @@ class LoanReport extends PureComponent {
timeframe: PropTypes.string,
targetSymbols: PropTypes.arrayOf(PropTypes.string),
}),
fetchData: PropTypes.func.isRequired,
setParams: PropTypes.func.isRequired,
}

Expand All @@ -69,21 +67,11 @@ class LoanReport extends PureComponent {
checkFetch(prevProps, this.props, TYPE)
}

handleQuery = () => {
const { fetchData } = this.props
fetchData()
}

handleTimeframeChange = (timeframe) => {
const { setParams } = this.props
setParams({ timeframe })
}

hasChanges = () => {
const { currentFetchParams, params } = this.props
return !isEqual(currentFetchParams, params)
}

toggleSymbol = symbol => toggleSymbol(TYPE, this.props, symbol)

clearSymbols = () => clearAllSymbols(TYPE, this.props)
Expand All @@ -102,7 +90,6 @@ class LoanReport extends PureComponent {
},
} = this.props
const { timeframe } = params
const hasChanges = this.hasChanges()

const { chartData, dataKeys } = parseLoanReportChartData({
data: _sortBy(entries, ['mts']),
Expand Down Expand Up @@ -159,10 +146,6 @@ class LoanReport extends PureComponent {
onChange={this.handleTimeframeChange}
/>
</SectionHeaderItem>
<QueryButton
disabled={!hasChanges}
onClick={this.handleQuery}
/>
<RefreshButton onClick={refresh} />
</SectionHeaderRow>
</SectionHeader>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Snapshots/Snapshots.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { withRouter } from 'react-router-dom'
import {
fetchSnapshots,
refresh,
setTimestamp,
} from 'state/snapshots/actions'
import {
getDataReceived,
Expand Down Expand Up @@ -36,6 +37,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = {
fetchData: fetchSnapshots,
refresh,
setTimestamp,
}

const SnapshotsContainer = withRouter(connect(mapStateToProps, mapDispatchToProps)(Snapshots))
Expand Down
Loading

0 comments on commit b145026

Please sign in to comment.