diff --git a/app/actions/pledges.js b/app/actions/pledges.js index 4803e1b..f4dba15 100644 --- a/app/actions/pledges.js +++ b/app/actions/pledges.js @@ -8,7 +8,7 @@ const createPledge = (pledge, data, profiles) => { const profile = profiles.find(p => p.idProfile == owner) pledge.pledgeId = id pledge.owner = Number(owner) - pledge.amount = Number(amount) + pledge.amount = amount pledge.token = token pledge.commitTime = Number(commitTime) pledge.nDelegates = Number(nDelegates) diff --git a/app/components/PledgesTable.jsx b/app/components/PledgesTable.jsx index 02d40db..97a2d64 100644 --- a/app/components/PledgesTable.jsx +++ b/app/components/PledgesTable.jsx @@ -1,5 +1,7 @@ import React, { Fragment, PureComponent } from 'react' import MaterialTable from 'material-table' +import withObservables from '@nozbe/with-observables' +import { withDatabase } from '@nozbe/watermelondb/DatabaseProvider' import { toEther } from '../utils/conversions' import { getTokenLabel } from '../utils/currencies' import TransferDialog from './TransferDialog' @@ -12,17 +14,17 @@ const pledgeStateMap = { 1: 'Paying', 2: 'Paid' } -const convertToDatetime = (field, fundProfiles) => { - const { commitTime, owner } = field - const profile = fundProfiles[Number(owner) - 1] +const convertToDatetime = field => { + const { commitTime } = field + const profile = field.profile if (!profile || Number(commitTime) === 0) return 0 const time = Number(commitTime) + Number(profile.commitTime) const date = new Date(time * 1000) return `${date.toLocaleDateString()} ${date.toLocaleTimeString()}` } -const formatField = (field, fundProfiles) => ({ - ...field, - commitTime: convertToDatetime(field, fundProfiles), +const formatField = field => ({ + ...field.getFields(), + commitTime: convertToDatetime(field), amount: toEther(field.amount), token: getTokenLabel(field.token), intendedProject: projectText(field.intendedProject), @@ -44,7 +46,7 @@ class PledgesTable extends PureComponent { clearRowData = () => this.setState({ rowData: null }) render() { - const { data, transferPledgeAmounts, fundProfiles } = this.props + const { pledges, transferPledgeAmounts } = this.props const { row, rowData } = this.state return ( @@ -55,7 +57,7 @@ class PledgesTable extends PureComponent { /> formatField(f, fundProfiles))} + data={pledges.map(formatField)} title="Pledges" options={{ showEmptyDataSourceMessage: true }} 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)) diff --git a/app/model/schema.js b/app/model/schema.js index b7f75db..f0015b4 100644 --- a/app/model/schema.js +++ b/app/model/schema.js @@ -31,7 +31,7 @@ export default appSchema({ columns: [ { name: 'pledge_id', type: 'number' }, { name: 'owner_id', type: 'number', isIndexed: true }, - { name: 'amount', type: 'number' }, + { name: 'amount', type: 'string' }, { name: 'token', type: 'string' }, { name: 'commit_time', type: 'number' }, { name: 'n_delegates', type: 'number' },