UNPKG

@hypernetlabs/web-ui

Version:
73 lines 4.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ViewUtils = void 0; const objects_1 = require("@hypernetlabs/objects"); const interfaces_1 = require("../interfaces"); const ethers_1 = require("ethers"); const theme_1 = require("../theme"); class ViewUtils { convertToWei(value) { return ethers_1.utils.formatUnits(value, "wei"); } convertToEther(value) { return ethers_1.utils.formatUnits(value, "ether"); } convertToBigNumber(value) { return ethers_1.BigNumber.from(value); } isZeroAddress(address) { return ethers_1.BigNumber.from(address).isZero(); } fromPaymentState(state) { return this._factoryPaymentStatusViewModel(state).state; } fromPaymentStateColor(state) { switch (state) { case objects_1.EPaymentState.Finalized || objects_1.EPaymentState.Accepted || objects_1.EPaymentState.Approved: return (0, theme_1.getColorFromStatus)(theme_1.EStatusColor.SUCCESS); case objects_1.EPaymentState.Proposed || objects_1.EPaymentState.Staked: return (0, theme_1.getColorFromStatus)(theme_1.EStatusColor.PRIMARY); case objects_1.EPaymentState.InvalidFunds || objects_1.EPaymentState.InvalidProposal || objects_1.EPaymentState.InvalidStake || objects_1.EPaymentState.Rejected: return (0, theme_1.getColorFromStatus)(theme_1.EStatusColor.DANGER); default: return (0, theme_1.getColorFromStatus)(theme_1.EStatusColor.IDLE); } } getPaymentStateOptions() { return [ new interfaces_1.PaymentStateOption("All", "all"), new interfaces_1.PaymentStateOption(this._factoryPaymentStatusViewModel(objects_1.EPaymentState.Accepted).state, objects_1.EPaymentState.Accepted), new interfaces_1.PaymentStateOption(this._factoryPaymentStatusViewModel(objects_1.EPaymentState.Approved).state, objects_1.EPaymentState.Approved), new interfaces_1.PaymentStateOption(this._factoryPaymentStatusViewModel(objects_1.EPaymentState.Borked).state, objects_1.EPaymentState.Borked), new interfaces_1.PaymentStateOption(this._factoryPaymentStatusViewModel(objects_1.EPaymentState.Canceled).state, objects_1.EPaymentState.Canceled), new interfaces_1.PaymentStateOption(this._factoryPaymentStatusViewModel(objects_1.EPaymentState.Finalized).state, objects_1.EPaymentState.Finalized), new interfaces_1.PaymentStateOption(this._factoryPaymentStatusViewModel(objects_1.EPaymentState.InsuranceReleased).state, objects_1.EPaymentState.InsuranceReleased), new interfaces_1.PaymentStateOption(this._factoryPaymentStatusViewModel(objects_1.EPaymentState.InvalidFunds).state, objects_1.EPaymentState.InvalidFunds), new interfaces_1.PaymentStateOption(this._factoryPaymentStatusViewModel(objects_1.EPaymentState.InvalidProposal).state, objects_1.EPaymentState.InvalidProposal), new interfaces_1.PaymentStateOption(this._factoryPaymentStatusViewModel(objects_1.EPaymentState.InvalidStake).state, objects_1.EPaymentState.InvalidStake), new interfaces_1.PaymentStateOption(this._factoryPaymentStatusViewModel(objects_1.EPaymentState.Proposed).state, objects_1.EPaymentState.Proposed), new interfaces_1.PaymentStateOption(this._factoryPaymentStatusViewModel(objects_1.EPaymentState.Rejected).state, objects_1.EPaymentState.Rejected), new interfaces_1.PaymentStateOption(this._factoryPaymentStatusViewModel(objects_1.EPaymentState.Staked).state, objects_1.EPaymentState.Staked), ]; } getProposalName(description) { const seperatorIndex = description.lastIndexOf(":"); const proposalName = description.substring(0, seperatorIndex); return proposalName; } getProposalDescriptionHash(description) { const seperatorIndex = description.lastIndexOf(":"); const descriptionHash = description.substring(seperatorIndex + 1, description.length); return descriptionHash; } _factoryPaymentStatusViewModel(state) { return new objects_1.PaymentStatusViewModel(new objects_1.PaymentStatusParams(state)); } } exports.ViewUtils = ViewUtils; //# sourceMappingURL=ViewUtils.js.map