2019-01-18 17:03:17 +00:00
|
|
|
import React, { Fragment } from 'react'
|
2018-12-02 13:24:31 +00:00
|
|
|
import MaterialTable from 'material-table'
|
2018-12-21 19:31:46 +00:00
|
|
|
import LiquidPledging from 'Embark/contracts/LiquidPledging'
|
2019-01-18 17:03:17 +00:00
|
|
|
import withObservables from '@nozbe/with-observables'
|
|
|
|
import { withDatabase } from '@nozbe/watermelondb/DatabaseProvider'
|
2018-12-13 20:41:40 +00:00
|
|
|
import { FundingContext } from '../context'
|
2018-12-07 14:47:00 +00:00
|
|
|
|
2018-12-21 19:31:46 +00:00
|
|
|
const { cancelProject } = LiquidPledging.methods
|
2018-12-02 13:24:31 +00:00
|
|
|
|
|
|
|
const convertToHours = seconds => seconds / 60 / 60
|
|
|
|
const cancelText = canceled => canceled ? 'Yes' : 'No'
|
|
|
|
const formatField = field => ({
|
2019-01-18 17:03:17 +00:00
|
|
|
...field.getFields(),
|
2018-12-02 13:24:31 +00:00
|
|
|
commitTime: convertToHours(field.commitTime),
|
|
|
|
canceled: cancelText(field.canceled)
|
|
|
|
})
|
2019-01-18 21:14:33 +00:00
|
|
|
const FunderProfilesTable = ({ profiles }) => (
|
2018-12-13 20:41:40 +00:00
|
|
|
<FundingContext.Consumer>
|
|
|
|
{({ account }) =>
|
|
|
|
<Fragment>
|
|
|
|
<MaterialTable
|
|
|
|
columns={[
|
|
|
|
{ title: 'Profile Id', field: 'idProfile', type: 'numeric' },
|
|
|
|
{ title: 'Name', field: 'name' },
|
|
|
|
{ title: 'Url', field: 'url' },
|
|
|
|
{ title: 'Admin Address', field: 'addr'},
|
|
|
|
{ title: 'Commit Time', field: 'commitTime', type: 'numeric' },
|
|
|
|
{ title: 'Type', field: 'type' },
|
|
|
|
{ title: 'Canceled', field: 'canceled' }
|
|
|
|
]}
|
2019-01-18 17:03:17 +00:00
|
|
|
data={profiles.map(formatField)}
|
2018-12-13 20:41:40 +00:00
|
|
|
title="Funding Profiles"
|
2019-01-10 19:37:23 +00:00
|
|
|
options={{ showEmptyDataSourceMessage: true }}
|
2018-12-13 20:41:40 +00:00
|
|
|
actions={[
|
2019-01-10 19:37:23 +00:00
|
|
|
rowData => ({
|
2018-12-13 20:41:40 +00:00
|
|
|
icon: 'cancel',
|
2019-01-18 17:03:17 +00:00
|
|
|
disabled: !account || rowData.addr.toLowerCase() != account.toLowerCase(),
|
2018-12-13 20:41:40 +00:00
|
|
|
tooltip: 'Cancel',
|
|
|
|
onClick: (event, rowData) => {
|
|
|
|
cancelProject(rowData.idProject || rowData.idProfile)
|
|
|
|
.send()
|
2019-01-18 21:14:33 +00:00
|
|
|
.then(async res => {
|
2018-12-13 20:41:40 +00:00
|
|
|
console.log({res})
|
2019-01-18 21:14:33 +00:00
|
|
|
const profile = profiles.find(p => p.idProfile == rowData.idProfile)
|
|
|
|
await profile.markAsCanceled()
|
2018-12-13 20:41:40 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</Fragment>
|
|
|
|
}
|
|
|
|
</FundingContext.Consumer>
|
2018-12-02 13:24:31 +00:00
|
|
|
)
|
|
|
|
|
2019-01-18 17:03:17 +00:00
|
|
|
export default withDatabase(withObservables([], ({ database }) => ({
|
2019-01-18 21:14:33 +00:00
|
|
|
profiles: database.collections.get('profiles').query().observeWithColumns(['canceled']),
|
2019-01-18 17:03:17 +00:00
|
|
|
}))(FunderProfilesTable))
|