Browse Source

Minor adjustments

Leszek Wiesner 4 years ago
parent
commit
ccbdfbab41

+ 3 - 4
pioneer/packages/joy-proposals/src/Proposal/ProposalTypePreview.tsx

@@ -5,7 +5,7 @@ import { Item, Icon, Button, Label } from "semantic-ui-react";
 
 import { Category } from "./ChooseProposalType";
 import { ProposalType } from "@polkadot/joy-utils/types/proposals";
-import { slugify, splitOnUpperCase } from "@polkadot/joy-utils/functions/misc";
+import _ from 'lodash';
 import styled from 'styled-components';
 import useVoteStyles from './useVoteStyles';
 import { formatBalance } from "@polkadot/util";
@@ -46,7 +46,6 @@ const CreateButton = styled(Button)`
 export type ProposalTypeInfo = {
   type: ProposalType;
   category: Category;
-  image: string;
   description: string;
   stake: number;
   cancellationFee?: number;
@@ -88,7 +87,7 @@ export default function ProposalTypePreview(props: ProposalTypePreviewProps) {
 
   const handleClick = () => {
     if (!props.history) return;
-    props.history.push(`/proposals/new/${slugify(type)}`);
+    props.history.push(`/proposals/new/${_.kebabCase(type)}`);
   };
 
   return (
@@ -98,7 +97,7 @@ export default function ProposalTypePreview(props: ProposalTypePreviewProps) {
         <Item.Image size="tiny" src={image} />
       */}
       <Item.Content>
-        <Item.Header>{splitOnUpperCase(type).join(" ")}</Item.Header>
+        <Item.Header>{_.startCase(type)}</Item.Header>
         <Item.Description>{description}</Item.Description>
         <div className="proposal-details">
           <ProposalTypeDetail

+ 2 - 2
pioneer/packages/joy-proposals/src/forms/GenericProposalForm.tsx

@@ -14,7 +14,7 @@ import { CallProps } from "@polkadot/react-api/types";
 import { Balance, Event } from "@polkadot/types/interfaces";
 import { RouteComponentProps } from "react-router";
 import { ProposalType } from "@polkadot/joy-utils/types/proposals";
-import { calculateStake } from "@polkadot/joy-utils/functions/proposals";
+import proposalsConsts from "@polkadot/joy-utils/consts/proposals";
 import { formatBalance } from "@polkadot/util"
 import "./forms.css";
 import { ProposalId } from "@joystream/types/proposals";
@@ -125,7 +125,7 @@ export const GenericProposalForm: React.FunctionComponent<GenericFormInnerProps>
   const requiredStake: number | undefined =
     balances_totalIssuance &&
     proposalType &&
-    calculateStake(proposalType);
+    proposalsConsts[proposalType].stake;
 
   return (
     <div className="Forms">

+ 2 - 2
pioneer/packages/joy-proposals/src/forms/SetCouncilParamsForm.tsx

@@ -18,7 +18,7 @@ import { withFormContainer } from "./FormContainer";
 import { createType } from "@polkadot/types";
 import "./forms.css";
 import { useTransport, usePromise } from "@polkadot/joy-utils/react/hooks";
-import { snakeCaseToCamelCase } from "@polkadot/joy-utils/functions/misc";
+import _ from "lodash";
 import { ElectionParameters } from "@joystream/types/proposals";
 import { PromiseComponent } from "@polkadot/joy-utils/react/components";
 
@@ -84,7 +84,7 @@ const SetCouncilParamsForm: React.FunctionComponent<FormInnerProps> = props => {
         "council_size"
       ] as const;
       fieldsToPopulate.forEach(field => {
-        const camelCaseField = snakeCaseToCamelCase(field) as keyof FormValues;
+        const camelCaseField = _.camelCase(field) as keyof FormValues;
         setFieldValue(camelCaseField, councilParams[field].toString());
         fetchedPlaceholders[camelCaseField] = councilParams[field].toString();
       });

+ 0 - 9
pioneer/packages/joy-proposals/src/stories/data/ProposalTypesInfo.mock.ts

@@ -5,7 +5,6 @@ const MockProposalTypesInfo: ProposalTypeInfo[] = [
   {
     type: "Text",
     category: Categories.other,
-    image: "https://react.semantic-ui.com/images/wireframe/image.png",
     description:
         "Change the total reward across all validators in a given block."+
         "This is not the direct reward, but base reward for Pallet staking module."+
@@ -22,7 +21,6 @@ const MockProposalTypesInfo: ProposalTypeInfo[] = [
   {
     type: "Spending",
     category: Categories.other,
-    image: "https://react.semantic-ui.com/images/wireframe/image.png",
     description:
         "Change the total reward across all validators in a given block."+
         "This is not the direct reward, but base reward for Pallet staking module."+
@@ -39,7 +37,6 @@ const MockProposalTypesInfo: ProposalTypeInfo[] = [
   {
     type: "RuntimeUpgrade",
     category: Categories.other,
-    image: "https://react.semantic-ui.com/images/wireframe/image.png",
     description:
         "Change the total reward across all validators in a given block."+
         "This is not the direct reward, but base reward for Pallet staking module."+
@@ -56,7 +53,6 @@ const MockProposalTypesInfo: ProposalTypeInfo[] = [
   {
     type: "EvictStorageProvider",
     category: Categories.storage,
-    image: "https://react.semantic-ui.com/images/wireframe/image.png",
     description:
         "Change the total reward across all validators in a given block."+
         "This is not the direct reward, but base reward for Pallet staking module."+
@@ -73,7 +69,6 @@ const MockProposalTypesInfo: ProposalTypeInfo[] = [
   {
     type: "SetStorageRoleParameters",
     category: Categories.storage,
-    image: "https://react.semantic-ui.com/images/wireframe/image.png",
     description:
         "Change the total reward across all validators in a given block."+
         "This is not the direct reward, but base reward for Pallet staking module."+
@@ -90,7 +85,6 @@ const MockProposalTypesInfo: ProposalTypeInfo[] = [
   {
     type: "SetValidatorCount",
     category: Categories.validators,
-    image: "https://react.semantic-ui.com/images/wireframe/image.png",
     description:
         "Change the total reward across all validators in a given block."+
         "This is not the direct reward, but base reward for Pallet staking module."+
@@ -107,7 +101,6 @@ const MockProposalTypesInfo: ProposalTypeInfo[] = [
   {
     type: "SetContentWorkingGroupMintCapacity",
     category: Categories.cwg,
-    image: "https://react.semantic-ui.com/images/wireframe/image.png",
     description:
         "Change the total reward across all validators in a given block."+
         "This is not the direct reward, but base reward for Pallet staking module."+
@@ -124,7 +117,6 @@ const MockProposalTypesInfo: ProposalTypeInfo[] = [
   {
     type: "SetLead",
     category: Categories.cwg,
-    image: "https://react.semantic-ui.com/images/wireframe/image.png",
     description:
         "Change the total reward across all validators in a given block."+
         "This is not the direct reward, but base reward for Pallet staking module."+
@@ -141,7 +133,6 @@ const MockProposalTypesInfo: ProposalTypeInfo[] = [
   {
     type: "SetElectionParameters",
     category: Categories.council,
-    image: "https://react.semantic-ui.com/images/wireframe/image.png",
     description:
         "Change the total reward across all validators in a given block."+
         "This is not the direct reward, but base reward for Pallet staking module."+

+ 87 - 0
pioneer/packages/joy-utils/src/consts/proposals.ts

@@ -0,0 +1,87 @@
+import { ProposalType, ProposalMeta } from "../types/proposals";
+
+const metadata: { [k in ProposalType]: ProposalMeta } = {
+  EvictStorageProvider: {
+      description: "Evicting Storage Provider Proposal",
+      category: "Storage",
+      stake: 25000,
+      approvalQuorum: 50,
+      approvalThreshold: 75,
+      slashingQuorum: 60,
+      slashingThreshold: 80
+  },
+  Text: {
+      description: "Signal Proposal",
+      category: "Other",
+      stake: 25000,
+      approvalQuorum: 60,
+      approvalThreshold: 80,
+      slashingQuorum: 60,
+      slashingThreshold: 80
+  },
+  SetStorageRoleParameters: {
+      description: "Set Storage Role Params Proposal",
+      category: "Storage",
+      stake: 100000,
+      approvalQuorum: 66,
+      approvalThreshold: 80,
+      slashingQuorum: 60,
+      slashingThreshold: 80
+  },
+  SetValidatorCount: {
+      description: "Set Max Validator Count Proposal",
+      category: "Validators",
+      stake: 100000,
+      approvalQuorum: 66,
+      approvalThreshold: 80,
+      slashingQuorum: 60,
+      slashingThreshold: 80
+  },
+  SetLead: {
+      description: "Set Lead Proposal",
+      category: "Content Working Group",
+      stake: 50000,
+      approvalQuorum: 60,
+      approvalThreshold: 75,
+      slashingQuorum: 60,
+      slashingThreshold: 80
+  },
+  SetContentWorkingGroupMintCapacity: {
+      description: "Set WG Mint Capacity Proposal",
+      category: "Content Working Group",
+      stake: 50000,
+      approvalQuorum: 60,
+      approvalThreshold: 75,
+      slashingQuorum: 60,
+      slashingThreshold: 80
+  },
+  Spending: {
+      description: "Spending Proposal",
+      category: "Other",
+      stake: 25000,
+      approvalQuorum: 60,
+      approvalThreshold: 80,
+      slashingQuorum: 60,
+      slashingThreshold: 80
+  },
+  SetElectionParameters: {
+      description: "Set Election Parameters Proposal",
+      category: "Council",
+      stake: 200000,
+      approvalQuorum: 66,
+      approvalThreshold: 80,
+      slashingQuorum: 60,
+      slashingThreshold: 80
+  },
+  RuntimeUpgrade: {
+      description: "Runtime Upgrade Proposal",
+      category: "Other",
+      stake: 1000000,
+      approvalQuorum: 80,
+      approvalThreshold: 100,
+      slashingQuorum: 60,
+      slashingThreshold: 80
+  },
+}
+
+export default metadata;

+ 0 - 24
pioneer/packages/joy-utils/src/functions/misc.ts

@@ -6,27 +6,3 @@ export function includeKeys<T extends { [k: string]: any }>(obj: T, ...allowedKe
     );
   });
 }
-
-export function splitOnUpperCase(str: string) {
-  return str.split(/(?=[A-Z])/);
-}
-
-export function slugify(str: string) {
-  return splitOnUpperCase(str)
-    .map(w => w.toLowerCase())
-    .join("-")
-    .trim();
-}
-
-export function snakeCaseToCamelCase(str: string) {
-  return str
-    .split('_')
-    .map((w, i) => i ? w[0].toUpperCase() + w.substr(1) : w)
-    .join('');
-}
-
-export function camelCaseToSnakeCase(str: string) {
-  return splitOnUpperCase(str)
-    .map(w => w[0].toLocaleLowerCase() + w.substr(1))
-    .join('_');
-}

+ 0 - 152
pioneer/packages/joy-utils/src/functions/proposals.ts

@@ -1,152 +0,0 @@
-import { ProposalType, ProposalMeta } from "../types/proposals";
-
-// TODO: Those may actually be const objects (now that we don't need total issuance etc.)
-
-export function calculateStake(type: ProposalType) {
-  let stake = NaN;
-  switch (type) {
-    case "EvictStorageProvider": {
-      stake = 25000;
-      break;
-    }
-    case "Text":
-      stake = 25000;
-      break;
-    case "SetStorageRoleParameters":
-      stake = 100000;
-      break;
-    case "SetValidatorCount":
-      stake = 100000;
-      break;
-    case "SetLead":
-      stake = 50000;
-      break;
-    case "SetContentWorkingGroupMintCapacity":
-      stake = 50000;
-      break;
-    case "Spending": {
-      stake = 25000;
-      break;
-    }
-    case "SetElectionParameters": {
-      stake = 200000;
-      break;
-    }
-    case "RuntimeUpgrade": {
-      stake = 1000000;
-      break;
-    }
-    default: {
-      throw new Error(`Proposal Type is invalid. Got ${type}.`);
-    }
-  }
-  return stake;
-}
-
-export function calculateMetaFromType(type: ProposalType): ProposalMeta {
-  const image = "";
-  switch (type) {
-    case "EvictStorageProvider": {
-      return {
-        description: "Evicting Storage Provider Proposal",
-        category: "Storage",
-        image,
-        approvalQuorum: 50,
-        approvalThreshold: 75,
-        slashingQuorum: 60,
-        slashingThreshold: 80,
-      }
-    }
-    case "Text": {
-      return {
-        description: "Signal Proposal",
-        category: "Other",
-        image,
-        approvalQuorum: 60,
-        approvalThreshold: 80,
-        slashingQuorum: 60,
-        slashingThreshold: 80,
-      }
-    }
-    case "SetStorageRoleParameters": {
-      return {
-        description: "Set Storage Role Params Proposal",
-        category: "Storage",
-        image,
-        approvalQuorum: 66,
-        approvalThreshold: 80,
-        slashingQuorum: 60,
-        slashingThreshold: 80,
-      }
-    }
-    case "SetValidatorCount": {
-      return {
-        description: "Set Max Validator Count Proposal",
-        category: "Validators",
-        image,
-        approvalQuorum: 66,
-        approvalThreshold: 80,
-        slashingQuorum: 60,
-        slashingThreshold: 80,
-      }
-    }
-    case "SetLead": {
-      return {
-        description: "Set Lead Proposal",
-        category: "Content Working Group",
-        image,
-        approvalQuorum: 60,
-        approvalThreshold: 75,
-        slashingQuorum: 60,
-        slashingThreshold: 80,
-      }
-    }
-    case "SetContentWorkingGroupMintCapacity": {
-      return {
-        description: "Set WG Mint Capacity Proposal",
-        category: "Content Working Group",
-        image,
-        approvalQuorum: 60,
-        approvalThreshold: 75,
-        slashingQuorum: 60,
-        slashingThreshold: 80,
-      }
-    }
-    case "Spending": {
-      return {
-        description: "Spending Proposal",
-        category: "Other",
-        image,
-        approvalQuorum: 60,
-        approvalThreshold: 80,
-        slashingQuorum: 60,
-        slashingThreshold: 80,
-      }
-    }
-    case "SetElectionParameters": {
-      return {
-        description: "Set Election Parameters Proposal",
-        category: "Council",
-        image,
-        approvalQuorum: 66,
-        approvalThreshold: 80,
-        slashingQuorum: 60,
-        slashingThreshold: 80,
-      }
-    }
-    case "RuntimeUpgrade": {
-      return {
-        description: "Runtime Upgrade Proposal",
-        category: "Other",
-        image,
-        approvalQuorum: 80,
-        approvalThreshold: 100,
-        slashingQuorum: 60,
-        slashingThreshold: 80,
-      }
-    }
-    default: {
-      throw new Error("'Proposal Type is invalid. Can't calculate metadata.");
-    }
-  }
-}

+ 5 - 7
pioneer/packages/joy-utils/src/transport/proposals.ts

@@ -13,8 +13,9 @@ import { MemberId } from "@joystream/types/members";
 import { u32 } from "@polkadot/types/";
 import { BalanceOf } from "@polkadot/types/interfaces";
 
-import { includeKeys, splitOnUpperCase } from "../functions/misc";
-import { calculateStake, calculateMetaFromType } from "../functions/proposals"
+import { includeKeys } from "../functions/misc";
+import _ from 'lodash';
+import proposalsConsts from "../consts/proposals"
 
 import { ApiPromise } from "@polkadot/api";
 import MembersTransport from "./members";
@@ -135,7 +136,7 @@ export default class ProposalsTransport extends BaseTransport {
       const obj = await prevProm;
       const period = (await this.proposalsCodex[method]()) as u32;
       // setValidatorCountProposalVotingPeriod to SetValidatorCount
-      const key = splitOnUpperCase(method)
+      const key = _.words(_.startCase(method))
         .slice(0, -3)
         .map((w, i) => (i === 0 ? w.slice(0, 1).toUpperCase() + w.slice(1) : w))
         .join("") as ProposalType;
@@ -155,17 +156,14 @@ export default class ProposalsTransport extends BaseTransport {
   async parametersFromProposalType(type: ProposalType) {
     const votingPeriod = (await this.proposalTypesVotingPeriod())[type];
     const gracePeriod = (await this.proposalTypesGracePeriod())[type];
-    const stake = calculateStake(type);
-    const meta = calculateMetaFromType(type);
     // Currently it's same for all types, but this will change soon
     const cancellationFee = await this.cancellationFee();
     return {
       type,
       votingPeriod,
       gracePeriod,
-      stake,
       cancellationFee,
-      ...meta
+      ...proposalsConsts[type]
     };
   }
 

+ 1 - 1
pioneer/packages/joy-utils/src/types/proposals.ts

@@ -58,7 +58,7 @@ export type Category = typeof Categories[keyof typeof Categories];
 export type ProposalMeta = {
   description: string;
   category: Category;
-  image: string;
+  stake: number;
   approvalQuorum: number;
   approvalThreshold: number;
   slashingQuorum: number;