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

pondjs implementation #90

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/stakinghistory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Test_GetStakingHistory(t *testing.T) {

connectWallet(endpoint)

history, err := GetStakingHistory()
history, err := GetStakingHistory(-1, 0)

if err != nil {
fmt.Printf("Missing endpoint in config")
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/@types/pondjs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ declare module "pondjs" {
import { List, Map } from "immutable";
import { Moment } from "moment";

function sum(): number
function count(filter?: any): number

// =======================================================================================================
// TimeRange
// =======================================================================================================
Expand Down Expand Up @@ -1031,7 +1034,7 @@ declare module "pondjs" {

export class TimeSeries {
static timeSeriesListMerge(options: { name: string, seriesList: TimeSeries[] }): TimeSeries

constructor(
arg:
| {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/containers/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type Props = OwnProps & DispatchProps & RouteChildrenProps<any>

const mapStateToProps = (state: IApplicationState): OwnProps => {
return {
txList: getWalletTransactions(state),
txList: getWalletTransactions(state).value(),
accounts: getVisibleAccounts(state),
balances: getWalletBalances(state),
walletTotals: getWalletTotals(state),
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/app/fixtures/AppSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ interface StatusBarProps {
class StatusBar extends React.Component<StatusBarProps> {
render() {
return (
<Navbar bg="light" expand="lg">
<Navbar bg="light" expand="sm">
<Nav className="">
<Nav.Link onClick={() => this.props.onMenuToggle()}>
<FontAwesomeIcon icon={faBars} />
Expand Down
126 changes: 126 additions & 0 deletions frontend/src/features/balances/BalanceHistoryChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import React, { PureComponent } from "react"
import { connect } from "react-redux"

import { Card } from "react-bootstrap"

import { TimeSeries, sum, TimeEvent } from "pondjs"
import {
Charts,
ChartContainer,
ChartRow,
YAxis,
LineChart,
Resizable,
BarChart,
styler,
} from "react-timeseries-charts"

import { WalletTotals } from "../../middleware/models"
import { IApplicationState } from "../../store/types"
import { makeTxHistoryChartSeries } from "../transactions/transactionsSlice"
import { timeframes, ChartTimeframe } from "../../components/Shared/IntervalChooser"
import { colorScheme } from "../staking/StakingHistory/StakingHistoryChart"
import { sprintf } from "sprintf-js"


const style = styler([
{ key: "credit", color: colorScheme[3], width: 5 },
{ key: "debit", color: colorScheme[1] },
{ key: "credit_sum", color: colorScheme[3], width: 5 },
{ key: "value_sum", color: colorScheme[1] },
])

function f(n: number) {
return sprintf("%.6f", n || 0)
}

class BalanceHistoryChart extends PureComponent<Props> {
render() {
const series = this.props.series
return (
<div>
{series != undefined && (
<Resizable>
<ChartContainer
timeRange={series.timerange()}
// showGrid={true}
padding={0}
timeAxisTickCount={5}
timeAxisHeight={0}
hideTimeAxis={true}
timeAxisStyle={{ axis: { display: "none" } }}
enablePanZoom={false}
>
<ChartRow height="100">
<YAxis
id="y"
label="Amount"
min={series.min("value_sum")}
max={series.max("value_sum")}
width={0}
type="linear"
hideAxisLine={true}
visible={false}
// format="d"
format=",.0f"

/>
<Charts>
{/* <BarChart
axis="y"
style={style}
series={series}
columns={["debit_sum"]}

/> */}
<BarChart
axis="y"
style={style}
series={series}
columns={["value_sum"]}
/>
</Charts>
</ChartRow>
</ChartContainer>
</Resizable>
)}
</div>
)
}
}

interface OwnProps {
}


interface StateProps {
series: TimeSeries | undefined
loading: boolean
timeframe: ChartTimeframe
}

type Props = OwnProps & StateProps

const mapStateToProps = (state: IApplicationState): StateProps => {
const timeframe = timeframes[1]
const series = makeTxHistoryChartSeries(state, timeframe)
const rollup = series?.map((event: TimeEvent) => {
const data = event.data()
// @ts-ignore
return event.setData(data.set("value", data.get("credit") - data.get("debit")))
})
.fixedWindowRollup({
windowSize: "3d",//this.props.timeframe.windowSize,
toTimeEvents: false,
aggregation: {
value_sum: { value: sum() },
},
})
return {
series: rollup,
loading: state.accounts.getAccountsAttempting,
timeframe: timeframe,
}
}

export default connect(mapStateToProps)(BalanceHistoryChart)
54 changes: 54 additions & 0 deletions frontend/src/features/balances/WalletAvailableBalanceCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { PureComponent } from "react"
import { WalletTotals } from "../../middleware/models"
import { Row, Col, Card } from "react-bootstrap"
import ComponentPlaceHolder from "../../components/Shared/ComponentPlaceholder"
import { Amount, FiatAmount } from "../../components/Shared/Amount"
import SparklineChart from "../market/charts/SparklineChart"
import BalanceHistoryChart from "./BalanceHistoryChart"

export default class WalletAvailableBalanceCard extends PureComponent<OwnProps> {
render() {
const totals = this.props.totals
return (
<Card className="h-100">
<Card.Body>
<Row>
<Col>
<ComponentPlaceHolder
type="text"
rows={3}
ready={!this.props.loading}
>
<div>
<div className="text-muted">
Available balance
</div>
<h1 className="mb-0">
<Amount
amount={totals.total}
showCurrency
rounding={2}
/>
</h1>
<h4 className="text-muted mb-2">
<FiatAmount
amount={totals.total}
showCurrency
currency="USD"
/>
</h4>
</div>
</ComponentPlaceHolder>
</Col>
</Row>
</Card.Body>
<BalanceHistoryChart />
</Card>
)
}
}

interface OwnProps {
totals: WalletTotals
loading: boolean
}
121 changes: 121 additions & 0 deletions frontend/src/features/balances/WalletCreditDebitCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import React, { PureComponent } from "react"
import { connect } from "react-redux"

import { Card } from "react-bootstrap"

import { TimeSeries, sum } from "pondjs"
import {
Charts,
ChartContainer,
ChartRow,
YAxis,
LineChart,
Resizable,
BarChart,
styler,
} from "react-timeseries-charts"

import { WalletTotals } from "../../middleware/models"
import { IApplicationState } from "../../store/types"
import { makeTxHistoryChartSeries } from "../transactions/transactionsSlice"
import { timeframes, ChartTimeframe } from "../../components/Shared/IntervalChooser"
import { colorScheme } from "../staking/StakingHistory/StakingHistoryChart"
import { sprintf } from "sprintf-js"


const style = styler([
{ key: "credit", color: colorScheme[3], width: 5 },
{ key: "debit", color: colorScheme[1] },
{ key: "credit_sum", color: colorScheme[3], width: 5 },
{ key: "debit_sum", color: colorScheme[1] },
])

function f(n: number) {
return sprintf("%.6f", n || 0)
}

class WalletCreditDebitCard extends PureComponent<Props> {
render() {
const series = this.props.series
return (
<Card className="h-100">
<Card.Body className="">
{series != undefined && (
<Resizable>
<ChartContainer
timeRange={series.timerange()}
// showGrid={true}
timeAxisTickCount={5}
// timeAxisStyle={{axis:{strokeWidth:0}}}
enablePanZoom={true}
>
<ChartRow height="160">
<YAxis
id="y"
label="Amount"
min={series.min("debit_sum")}
max={series.max("credit_sum")}
width="60"
type="linear"
hideAxisLine={true}
visible={false}
// format="d"
format=",.0f"

/>
<Charts>
<BarChart
axis="y"
style={style}
series={series}
columns={["debit_sum"]}

/>
<BarChart
axis="y"
style={style}
series={series}
columns={["credit_sum"]}
/>
</Charts>
</ChartRow>
</ChartContainer>
</Resizable>
)}
</Card.Body>
</Card>
)
}
}

interface OwnProps {
}


interface StateProps {
loading: boolean
timeframe: ChartTimeframe
series: TimeSeries | undefined
}

type Props = OwnProps & StateProps

const mapStateToProps = (state: IApplicationState): StateProps => {
const timeframe = timeframes[1]
const series = makeTxHistoryChartSeries(state, timeframe)
const rollup = series?.fixedWindowRollup({
windowSize: "3d",//this.props.timeframe.windowSize,
toTimeEvents: false,
aggregation: {
debit_sum: { debit: sum() },
credit_sum: { credit: sum() },
},
})
return {
series: rollup,
loading: state.accounts.getAccountsAttempting,
timeframe: timeframe,
}
}

export default connect(mapStateToProps)(WalletCreditDebitCard)
Loading