2018-12-02 13:24:31 +00:00
|
|
|
import React, { Fragment, memo } from 'react'
|
|
|
|
import MaterialTable from 'material-table'
|
2018-12-21 19:31:46 +00:00
|
|
|
import LiquidPledging from 'Embark/contracts/LiquidPledging'
|
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 => ({
|
|
|
|
...field,
|
|
|
|
commitTime: convertToHours(field.commitTime),
|
|
|
|
canceled: cancelText(field.canceled)
|
|
|
|
})
|
2018-12-07 14:47:00 +00:00
|
|
|
const FunderProfilesTable = ({ data, cancelFundProfile }) => (
|
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' }
|
|
|
|
]}
|
|
|
|
data={data.map(formatField)}
|
|
|
|
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',
|
|
|
|
disabled: rowData.addr.toLowerCase() != account.toLowerCase(),
|
|
|
|
tooltip: 'Cancel',
|
|
|
|
onClick: (event, rowData) => {
|
|
|
|
cancelProject(rowData.idProject || rowData.idProfile)
|
|
|
|
.send()
|
|
|
|
.then(res => {
|
|
|
|
console.log({res})
|
|
|
|
cancelFundProfile(rowData.idProfile)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</Fragment>
|
|
|
|
}
|
|
|
|
</FundingContext.Consumer>
|
2018-12-02 13:24:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
export default memo(FunderProfilesTable)
|