@hypernetlabs/web-ui
Version:
Web ui react components for hypernet protocol
237 lines • 8.5 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PushPaymentList = void 0;
const objects_1 = require("@hypernetlabs/objects");
const contexts_1 = require("../../contexts");
const components_1 = require("../../components");
const react_1 = __importStar(require("react"));
const hooks_1 = require("../../hooks");
const PushPaymentList_style_1 = require("../../components/PushPaymentList/PushPaymentList.style");
const PUSH_PAYMENTS_PER_PAGE = 5;
const tableColumns = [
{
cellValue: "Gateway",
tableCellProps: {
align: "left",
},
},
{
cellValue: "Payment Amount",
tableCellProps: {
align: "left",
},
},
{
cellValue: "Created",
tableCellProps: {
align: "left",
},
},
{
cellValue: "State",
tableCellProps: {
align: "left",
},
},
{
cellValue: "Payment ID",
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: "From",
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: "To",
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: "Payment Token",
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: "Required Stake",
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: "Amount Staked",
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: "Expiration Date",
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: "Updated",
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: "Action",
mobileCellValue: " ",
tableCellProps: {
align: "left",
},
},
];
const PushPaymentList = (props) => {
const { pushPayments, publicIdentifier, tokenInformationList, onAcceptPushPaymentClick, onRepairPaymentClick, } = props;
const classes = (0, PushPaymentList_style_1.useStyles)();
const { viewUtils, dateUtils } = (0, contexts_1.useStoreContext)();
const { loading } = (0, hooks_1.useLinks)();
const [page, setPage] = (0, react_1.useState)(1);
const initialValue = [];
const paginatedPushPayments = (0, react_1.useMemo)(() => (0, components_1.extractDataByPage)(pushPayments, PUSH_PAYMENTS_PER_PAGE, page), [JSON.stringify(pushPayments), page]);
const rows = (0, react_1.useMemo)(() => paginatedPushPayments.reduce((acc, item) => {
acc.push([
{
cellValue: item.gatewayUrl,
tableCellProps: {
align: "left",
},
},
{
cellValue: viewUtils.convertToEther(item.paymentAmount),
tableCellProps: {
align: "left",
},
},
{
cellValue: dateUtils.fromTimestampToUI(item.createdTimestamp),
tableCellProps: {
align: "left",
},
},
{
cellValue: (react_1.default.createElement(components_1.GovernanceTag, { text: viewUtils.fromPaymentState(item.state), color: components_1.ETagColor.BLUE })),
tableCellProps: {
align: "left",
},
},
{
cellValue: item.id,
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: `${item.from} ${item.from === publicIdentifier ? "(You)" : ""}`,
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: item.to,
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: (react_1.default.createElement(components_1.GovernancePaymentTokenCell, { paymentTokenAddress: item.paymentToken, tokenInformationList: tokenInformationList })),
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: viewUtils.convertToEther(item.requiredStake),
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: viewUtils.convertToEther(item.amountStaked),
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: dateUtils.fromTimestampToUI(item.expirationDate),
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: dateUtils.fromTimestampToUI(item.updatedTimestamp),
tableCellProps: {
align: "left",
},
onlyVisibleInExpandedState: true,
},
{
cellValue: (react_1.default.createElement(react_1.default.Fragment, null,
item.state !== objects_1.EPaymentState.Finalized && (react_1.default.createElement(components_1.GovernanceButton, { size: "small", variant: "outlined", color: "primary", className: classes.actionButton, onClick: () => onRepairPaymentClick(item.id) }, "Repair")),
publicIdentifier === item.to &&
item.state === objects_1.EPaymentState.Proposed && (react_1.default.createElement(components_1.GovernanceButton, { size: "small", variant: "outlined", color: "primary", onClick: () => onAcceptPushPaymentClick(item.id) }, "Accept")))),
tableCellProps: {
align: "right",
},
},
]);
return acc;
}, initialValue), [
JSON.stringify(paginatedPushPayments),
JSON.stringify(tokenInformationList),
]);
if (!loading && !rows.length) {
return (react_1.default.createElement(components_1.GovernanceEmptyState, { title: "No results!", description: "You don\u2019t have any payments yet." }));
}
return (react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement(components_1.GovernanceTable, { isExpandable: true, columns: tableColumns, rows: rows }),
pushPayments.length > 0 && (react_1.default.createElement(components_1.GovernancePagination, { className: classes.pagination, customPageOptions: {
itemsPerPage: PUSH_PAYMENTS_PER_PAGE,
totalItems: pushPayments.length,
}, onChange: (_, page) => {
setPage(page);
} }))));
};
exports.PushPaymentList = PushPaymentList;
//# sourceMappingURL=PushPaymentList.js.map