use pledges collection in pledges table
This commit is contained in:
parent
3bee0c97d8
commit
304082ff21
|
@ -8,7 +8,7 @@ const createPledge = (pledge, data, profiles) => {
|
||||||
const profile = profiles.find(p => p.idProfile == owner)
|
const profile = profiles.find(p => p.idProfile == owner)
|
||||||
pledge.pledgeId = id
|
pledge.pledgeId = id
|
||||||
pledge.owner = Number(owner)
|
pledge.owner = Number(owner)
|
||||||
pledge.amount = Number(amount)
|
pledge.amount = amount
|
||||||
pledge.token = token
|
pledge.token = token
|
||||||
pledge.commitTime = Number(commitTime)
|
pledge.commitTime = Number(commitTime)
|
||||||
pledge.nDelegates = Number(nDelegates)
|
pledge.nDelegates = Number(nDelegates)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import React, { Fragment, PureComponent } from 'react'
|
import React, { Fragment, PureComponent } from 'react'
|
||||||
import MaterialTable from 'material-table'
|
import MaterialTable from 'material-table'
|
||||||
|
import withObservables from '@nozbe/with-observables'
|
||||||
|
import { withDatabase } from '@nozbe/watermelondb/DatabaseProvider'
|
||||||
import { toEther } from '../utils/conversions'
|
import { toEther } from '../utils/conversions'
|
||||||
import { getTokenLabel } from '../utils/currencies'
|
import { getTokenLabel } from '../utils/currencies'
|
||||||
import TransferDialog from './TransferDialog'
|
import TransferDialog from './TransferDialog'
|
||||||
|
@ -12,17 +14,17 @@ const pledgeStateMap = {
|
||||||
1: 'Paying',
|
1: 'Paying',
|
||||||
2: 'Paid'
|
2: 'Paid'
|
||||||
}
|
}
|
||||||
const convertToDatetime = (field, fundProfiles) => {
|
const convertToDatetime = field => {
|
||||||
const { commitTime, owner } = field
|
const { commitTime } = field
|
||||||
const profile = fundProfiles[Number(owner) - 1]
|
const profile = field.profile
|
||||||
if (!profile || Number(commitTime) === 0) return 0
|
if (!profile || Number(commitTime) === 0) return 0
|
||||||
const time = Number(commitTime) + Number(profile.commitTime)
|
const time = Number(commitTime) + Number(profile.commitTime)
|
||||||
const date = new Date(time * 1000)
|
const date = new Date(time * 1000)
|
||||||
return `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`
|
return `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`
|
||||||
}
|
}
|
||||||
const formatField = (field, fundProfiles) => ({
|
const formatField = field => ({
|
||||||
...field,
|
...field.getFields(),
|
||||||
commitTime: convertToDatetime(field, fundProfiles),
|
commitTime: convertToDatetime(field),
|
||||||
amount: toEther(field.amount),
|
amount: toEther(field.amount),
|
||||||
token: getTokenLabel(field.token),
|
token: getTokenLabel(field.token),
|
||||||
intendedProject: projectText(field.intendedProject),
|
intendedProject: projectText(field.intendedProject),
|
||||||
|
@ -44,7 +46,7 @@ class PledgesTable extends PureComponent {
|
||||||
clearRowData = () => this.setState({ rowData: null })
|
clearRowData = () => this.setState({ rowData: null })
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { data, transferPledgeAmounts, fundProfiles } = this.props
|
const { pledges, transferPledgeAmounts } = this.props
|
||||||
const { row, rowData } = this.state
|
const { row, rowData } = this.state
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
|
@ -55,7 +57,7 @@ class PledgesTable extends PureComponent {
|
||||||
/>
|
/>
|
||||||
<MaterialTable
|
<MaterialTable
|
||||||
columns={[
|
columns={[
|
||||||
{ title: 'Pledge Id', field: 'id', type: 'numeric' },
|
{ title: 'Pledge Id', field: 'pledgeId', type: 'numeric' },
|
||||||
{ title: 'Owner', field: 'owner' },
|
{ title: 'Owner', field: 'owner' },
|
||||||
{ title: 'Amount Funded', field: 'amount', type: 'numeric' },
|
{ title: 'Amount Funded', field: 'amount', type: 'numeric' },
|
||||||
{ title: 'Token', field: 'token' },
|
{ title: 'Token', field: 'token' },
|
||||||
|
@ -64,7 +66,7 @@ class PledgesTable extends PureComponent {
|
||||||
{ title: 'Intended Project', field: 'intendedProject' },
|
{ title: 'Intended Project', field: 'intendedProject' },
|
||||||
{ title: 'Pledge State', field: 'pledgeState' },
|
{ title: 'Pledge State', field: 'pledgeState' },
|
||||||
]}
|
]}
|
||||||
data={data.map((f) => formatField(f, fundProfiles))}
|
data={pledges.map(formatField)}
|
||||||
title="Pledges"
|
title="Pledges"
|
||||||
options={{ showEmptyDataSourceMessage: true }}
|
options={{ showEmptyDataSourceMessage: true }}
|
||||||
actions={[
|
actions={[
|
||||||
|
@ -91,4 +93,6 @@ class PledgesTable extends PureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PledgesTable
|
export default withDatabase(withObservables([], ({ database }) => ({
|
||||||
|
pledges: database.collections.get('pledges').query().observeWithColumns(['pledge_state']),
|
||||||
|
}))(PledgesTable))
|
||||||
|
|
|
@ -31,7 +31,7 @@ export default appSchema({
|
||||||
columns: [
|
columns: [
|
||||||
{ name: 'pledge_id', type: 'number' },
|
{ name: 'pledge_id', type: 'number' },
|
||||||
{ name: 'owner_id', type: 'number', isIndexed: true },
|
{ name: 'owner_id', type: 'number', isIndexed: true },
|
||||||
{ name: 'amount', type: 'number' },
|
{ name: 'amount', type: 'string' },
|
||||||
{ name: 'token', type: 'string' },
|
{ name: 'token', type: 'string' },
|
||||||
{ name: 'commit_time', type: 'number' },
|
{ name: 'commit_time', type: 'number' },
|
||||||
{ name: 'n_delegates', type: 'number' },
|
{ name: 'n_delegates', type: 'number' },
|
||||||
|
|
Loading…
Reference in New Issue