Explorar o código

Merge pull request #722 from mnaamani/fix-followin-working-group-refactor-dropping-actors-module

Fix Pioneer and types - following buraucracy renaming and update to working-group module
Mokhtar Naamani %!s(int64=4) %!d(string=hai) anos
pai
achega
835c942654

+ 2 - 2
cli/src/Api.ts

@@ -18,7 +18,7 @@ import {
 import { DerivedFees, DerivedBalances } from '@polkadot/api-derive/types';
 import { CLIError } from '@oclif/errors';
 import ExitCodes from './ExitCodes';
-import { Worker, Lead as WorkerLead, WorkerId, WorkerRoleStakeProfile } from '@joystream/types/lib/bureaucracy';
+import { Worker, Lead as WorkerLead, WorkerId, WorkerRoleStakeProfile } from '@joystream/types/lib/working-group';
 import { MemberId, Profile } from '@joystream/types/lib/members';
 import { RewardRelationship, RewardRelationshipId } from '@joystream/types/lib/recurring-rewards';
 import { Stake, StakeId } from '@joystream/types/lib/stake';
@@ -29,7 +29,7 @@ const DEFAULT_DECIMALS = new u32(12);
 
 // Mapping of working group to api module
 const apiModuleByGroup: { [key in WorkingGroups]: string } = {
-    [WorkingGroups.StorageProviders]: 'storageBureaucracy'
+    [WorkingGroups.StorageProviders]: 'storageWorkingGroup'
 };
 
 // Api wrapper for handling most common api calls and allowing easy API implementation switch in the future

+ 1 - 1
cli/src/Types.ts

@@ -4,7 +4,7 @@ import { Option } from '@polkadot/types';
 import { BlockNumber, Balance, AccountId } from '@polkadot/types/interfaces';
 import { DerivedBalances } from '@polkadot/api-derive/types';
 import { KeyringPair } from '@polkadot/keyring/types';
-import { WorkerId, Lead } from '@joystream/types/lib/bureaucracy';
+import { WorkerId, Lead } from '@joystream/types/lib/working-group';
 import { Profile, MemberId } from '@joystream/types/lib/members';
 
 // KeyringPair type extended with mandatory "meta.name"

+ 2 - 1
pioneer/packages/apps-routing/src/joy-roles.ts

@@ -7,7 +7,8 @@ export default ([
     Component: Roles,
     display: {
       needsApi: [
-        'query.actors.actorAccountIds'
+        'query.contentWorkingGroup.mint',
+        'query.storageWorkingGroup.mint'
       ]
     },
     i18n: {

+ 1 - 1
pioneer/packages/joy-media/src/DiscoveryProvider.tsx

@@ -2,7 +2,7 @@ import React, { useState, useEffect, useContext, createContext } from 'react';
 import { Message } from 'semantic-ui-react';
 import axios, { CancelToken } from 'axios';
 
-import { StorageProviderId } from '@joystream/types/bureaucracy';
+import { StorageProviderId } from '@joystream/types/working-group';
 import { Vec } from '@polkadot/types';
 import { Url } from '@joystream/types/discovery';
 import ApiContext from '@polkadot/react-api/ApiContext';

+ 8 - 8
pioneer/packages/joy-media/src/Upload.tsx

@@ -15,7 +15,7 @@ import { formatNumber } from '@polkadot/util';
 import translate from './translate';
 import { fileNameWoExt } from './utils';
 import { ContentId, DataObject } from '@joystream/types/media';
-import { withMembershipRequired } from '@polkadot/joy-utils/MyAccount';
+import { withOnlyMembers, MyAccountProps } from '@polkadot/joy-utils/MyAccount';
 import { DiscoveryProviderProps, withDiscoveryProvider } from './DiscoveryProvider';
 import TxButton from '@polkadot/joy-utils/TxButton';
 import IpfsHash from 'ipfs-only-hash';
@@ -23,12 +23,12 @@ import { ChannelId } from '@joystream/types/content-working-group';
 import { EditVideoView } from './upload/EditVideo.view';
 import { JoyInfo } from '@polkadot/joy-utils/JoyStatus';
 import { IterableFile } from './IterableFile';
-import { StorageProviderId } from '@joystream/types/bureaucracy';
+import { StorageProviderId } from '@joystream/types/working-group';
 
 const MAX_FILE_SIZE_MB = 500;
 const MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024;
 
-type Props = ApiProps & I18nProps & DiscoveryProviderProps & {
+type Props = ApiProps & I18nProps & DiscoveryProviderProps & MyAccountProps & {
   channelId: ChannelId;
   history?: History;
   match: {
@@ -62,7 +62,7 @@ const defaultState = (): State => ({
   cancelSource: axios.CancelToken.source()
 });
 
-class Component extends React.PureComponent<Props, State> {
+class Upload extends React.PureComponent<Props, State> {
   state = defaultState();
 
   componentWillUnmount () {
@@ -248,8 +248,8 @@ class Component extends React.PureComponent<Props, State> {
 
     // TODO get corresponding data type id based on file content
     const dataObjectTypeId = new BN(1);
-
-    return [newContentId, dataObjectTypeId, new BN(file.size), ipfs_cid];
+    const { myMemberId } = this.props;
+    return [myMemberId, newContentId, dataObjectTypeId, new BN(file.size), ipfs_cid];
   }
 
   private onDataObjectCreated = async (_txResult: SubmittableResult) => {
@@ -349,9 +349,9 @@ class Component extends React.PureComponent<Props, State> {
 }
 
 export const UploadWithRouter = withMulti(
-  Component,
+  Upload,
   translate,
   withApi,
-  withMembershipRequired,
+  withOnlyMembers,
   withDiscoveryProvider
 );

+ 3 - 3
pioneer/packages/joy-media/src/common/MediaPlayerWithResolver.tsx

@@ -6,7 +6,7 @@ import { ApiProps } from '@polkadot/react-api/types';
 import { I18nProps } from '@polkadot/react-components/types';
 import { withMulti } from '@polkadot/react-api/with';
 import { Option } from '@polkadot/types/codec';
-import { StorageProviderId, Worker } from '@joystream/types/bureaucracy';
+import { StorageProviderId, Worker } from '@joystream/types/working-group';
 
 import translate from '../translate';
 import { DiscoveryProviderProps, withDiscoveryProvider } from '../DiscoveryProvider';
@@ -31,7 +31,7 @@ function InnerComponent (props: Props) {
   const [cancelSource, setCancelSource] = useState<CancelTokenSource>(newCancelSource());
 
   const getActiveStorageProviderIds = async (): Promise<StorageProviderId[]> => {
-    const nextId = await api.query.storageBureaucracy.nextWorkerId() as StorageProviderId;
+    const nextId = await api.query.storageWorkingGroup.nextWorkerId() as StorageProviderId;
     // This is chain specfic, but if next id is still 0, it means no workers have been added,
     // so the workerById is empty
     if (nextId.eq(0)) {
@@ -41,7 +41,7 @@ function InnerComponent (props: Props) {
     const workers = new MultipleLinkedMapEntry<StorageProviderId, Worker>(
       StorageProviderId,
       Worker,
-      await api.query.storageBureaucracy.workerById()
+      await api.query.storageWorkingGroup.workerById()
     );
 
     return workers.linked_keys;

+ 0 - 84
pioneer/packages/joy-roles/src/elements.stories.tsx

@@ -1,84 +0,0 @@
-// @ts-nocheck
-import React from 'react';
-import { boolean, number, text, withKnobs } from '@storybook/addon-knobs';
-import { Table } from 'semantic-ui-react';
-
-import { u128, Text } from '@polkadot/types';
-
-import { Actor } from '@joystream/types/roles';
-
-import { BalanceView, GroupMemberView, HandleView, MemberView, MemoView } from './elements';
-
-import 'semantic-ui-css/semantic.min.css';
-import '@polkadot/joy-roles/index.sass';
-
-export default {
-  title: 'Roles / Elements',
-  decorators: [withKnobs]
-};
-
-export const Balance = () => {
-  return (
-    <BalanceView balance={new u128(number('Balance', 10))} />
-  );
-};
-
-export const Memo = () => {
-  const actor = new Actor({ member_id: 1, account: '5HZ6GtaeyxagLynPryM7ZnmLzoWFePKuDrkb4AT8rT4pU1fp' });
-  const memo = new Text(text('Memo text', 'This is a memo'));
-
-  return (
-    <MemoView actor={actor} memo={memo} />
-  );
-};
-
-export const Handle = () => {
-  const profile = {
-    handle: new Text(text('Handle', 'benholdencrowther'))
-  };
-
-  return (
-    <HandleView profile={profile} />
-  );
-};
-
-export const Member = () => {
-  const actor = new Actor({ member_id: 1, account: '5HZ6GtaeyxagLynPryM7ZnmLzoWFePKuDrkb4AT8rT4pU1fp' });
-  const profile = {
-    handle: new Text(text('Handle', 'benholdencrowther'))
-  };
-
-  return (
-    <Table basic='very'>
-      <Table.Body>
-        <Table.Row>
-          <Table.Cell>
-            <MemberView
-              actor={actor}
-              balance={new u128(number('Balance', 10))}
-              profile={profile}
-            />
-          </Table.Cell>
-        </Table.Row>
-      </Table.Body>
-    </Table>
-  );
-};
-
-export const GroupMember = () => {
-  const actor = new Actor({ member_id: 1, account: '5HZ6GtaeyxagLynPryM7ZnmLzoWFePKuDrkb4AT8rT4pU1fp' });
-  const profile = {
-    handle: new Text(text('Handle', 'benholdencrowther'))
-  };
-
-  return (
-    <GroupMemberView
-      actor={actor}
-      profile={profile}
-      title={text('Title', 'Group lead')}
-      lead={boolean('Lead member', true)}
-      stake={new u128(number('Stake', 10))}
-      earned={new u128(number('Earned', 10))}
-    />
-  );
-};

+ 2 - 54
pioneer/packages/joy-roles/src/elements.tsx

@@ -1,20 +1,15 @@
 import React, { useEffect, useState } from 'react';
 import moment from 'moment';
-import { Header, Card, Icon, Image, Label, Statistic } from 'semantic-ui-react';
+import { Card, Icon, Image, Label, Statistic } from 'semantic-ui-react';
 import { Link } from 'react-router-dom';
 
 import { Balance } from '@polkadot/types/interfaces';
 import { formatBalance } from '@polkadot/util';
 import Identicon from '@polkadot/react-identicon';
-import { Actor } from '@joystream/types/roles';
 import { IProfile, MemberId } from '@joystream/types/members';
-import { Text, GenericAccountId } from '@polkadot/types';
+import { GenericAccountId } from '@polkadot/types';
 import { LeadRoleState } from '@joystream/types/content-working-group';
 
-type ActorProps = {
-  actor: Actor;
-}
-
 type BalanceProps = {
   balance?: Balance;
 }
@@ -27,23 +22,6 @@ export function BalanceView (props: BalanceProps) {
   );
 }
 
-type MemoProps = ActorProps & {
-  memo?: Text;
-}
-
-export function MemoView (props: MemoProps) {
-  if (typeof props.memo === 'undefined') {
-    return null;
-  }
-
-  return (
-    <div className="memo">
-      <span>Memo:</span> {props.memo.toString()}
-      <Link to={`/addressbook/memo/${props.actor.account.toString()}`}>{' view full memo'}</Link>
-    </div>
-  );
-}
-
 type ProfileProps = {
   profile: IProfile;
 }
@@ -58,36 +36,6 @@ export function HandleView (props: ProfileProps) {
   );
 }
 
-type MemberProps = ActorProps & BalanceProps & ProfileProps
-
-export function MemberView (props: MemberProps) {
-  let avatar = <Identicon value={props.actor.account.toString()} size={50} />;
-  if (typeof props.profile.avatar_uri !== 'undefined' && props.profile.avatar_uri.toString() !== '') {
-    avatar = <Image src={props.profile.avatar_uri.toString()} circular className='avatar' />;
-  }
-
-  return (
-    <Header as='h4' image>
-      {avatar}
-      <Header.Content>
-        <HandleView profile={props.profile} />
-        <BalanceView balance={props.balance} />
-      </Header.Content>
-    </Header>
-  );
-}
-
-type ActorDetailsProps = MemoProps & BalanceProps
-
-export function ActorDetailsView (props: ActorDetailsProps) {
-  return (
-    <div className="actor-summary" id={props.actor.account.toString()}>
-      {props.actor.account.toString()}
-      <MemoView actor={props.actor} memo={props.memo} />
-    </div>
-  );
-}
-
 export type GroupMember = {
   memberId: MemberId;
   roleAccount: GenericAccountId;

+ 3 - 3
pioneer/packages/joy-roles/src/transport.substrate.ts

@@ -29,7 +29,7 @@ import {
   Worker, WorkerId,
   WorkerRoleStakeProfile,
   Lead as LeadOf
-} from '@joystream/types/bureaucracy';
+} from '@joystream/types/working-group';
 
 import { Application, Opening, OpeningId } from '@joystream/types/hiring';
 import { Stake, StakeId } from '@joystream/types/stake';
@@ -97,7 +97,7 @@ type WGApiMapping = {
 
 const workingGroupsApiMapping: WGApiMapping = {
   [WorkingGroups.StorageProviders]: {
-    module: 'storageBureaucracy',
+    module: 'storageWorkingGroup',
     methods: {
       nextOpeningId: 'nextWorkerOpeningId',
       openingById: 'workerOpeningById',
@@ -291,7 +291,7 @@ export class Transport extends TransportBase implements ITransport {
   }
 
   protected async currentStorageLead (): Promise <GroupLeadWithMemberId | null> {
-    const optLead = (await this.cachedApi.query.storageBureaucracy.currentLead()) as Option<LeadOf>;
+    const optLead = (await this.cachedApi.query.storageWorkingGroup.currentLead()) as Option<LeadOf>;
 
     if (!optLead.isSome) {
       return null;

+ 3 - 3
types/src/content-working-group/index.ts

@@ -211,7 +211,7 @@ export class CuratorInduction extends JoyStruct<ICuratorInduction> {
     return this.getField<CuratorApplicationId>('curator_application_id')
   }
 
-  // Helper for bureaucracy compatibility
+  // Helper for working-group compatibility
   get worker_application_id(): CuratorApplicationId {
     return this.curator_application_id;
   }
@@ -294,7 +294,7 @@ export class CuratorApplication extends JoyStruct<ICuratorApplication> {
     return this.getField<CuratorOpeningId>('curator_opening_id')
   }
 
-  // Helper for bureaucracy compatibility
+  // Helper for working-group compatibility
   get worker_opening_id(): CuratorOpeningId {
     return this.curator_opening_id;
   }
@@ -476,7 +476,7 @@ export class Lead extends JoyStruct<ILead> {
     return this.getField<GenericAccountId>('role_account')
   }
 
-  // Helper for bureaucracy compatibility
+  // Helper for working-group compatibility
   get role_account_id(): GenericAccountId {
     return this.role_account;
   }

+ 2 - 2
types/src/index.ts

@@ -13,7 +13,7 @@ import { registerHiringTypes } from "./hiring";
 import { registerVersionedStoreTypes } from "./versioned-store";
 import { registerVersionedStorePermissionsTypes } from "./versioned-store/permissions";
 import { registerContentWorkingGroupTypes } from "./content-working-group";
-import { registerBureaucracyTypes } from "./bureaucracy";
+import { registerWorkingGroupTypes } from "./working-group";
 import { registerDiscoveryTypes } from "./discovery";
 import { registerMediaTypes } from "./media";
 import { registerProposalTypes } from "./proposals";
@@ -37,7 +37,7 @@ export function registerJoystreamTypes() {
   registerVersionedStoreTypes();
   registerVersionedStorePermissionsTypes();
   registerContentWorkingGroupTypes();
-  registerBureaucracyTypes();
+  registerWorkingGroupTypes();
   registerDiscoveryTypes();
   registerMediaTypes();
   registerProposalTypes();

+ 1 - 1
types/src/media.ts

@@ -2,7 +2,7 @@ import { Enum, Struct, Option, Vec as Vector, H256 } from '@polkadot/types';
 import { getTypeRegistry, u64, bool, Text } from '@polkadot/types';
 import { BlockAndTime } from './common';
 import { MemberId } from './members';
-import { StorageProviderId } from './bureaucracy'; // this should be in discovery really
+import { StorageProviderId } from './working-group'; // this should be in discovery really
 
 import { randomAsU8a } from '@polkadot/util-crypto';
 import { encodeAddress, decodeAddress } from '@polkadot/keyring';

+ 4 - 35
types/src/roles.ts

@@ -1,37 +1,9 @@
 import { Struct } from '@polkadot/types/codec';
-import { getTypeRegistry, u32, u128, GenericAccountId } from '@polkadot/types';
-import { BlockNumber, AccountId, Balance } from '@polkadot/types/interfaces';
-import { MemberId, Role } from './members';
-
-export class Actor extends Struct {
-  constructor (value?: any) {
-    super({
-      member_id: MemberId,
-      role: Role,
-      account: GenericAccountId,
-      joined_at: u32, // BlockNumber
-    }, value);
-  }
-
-  get member_id (): MemberId {
-    return this.get('member_id') as MemberId;
-  }
-
-  get role (): Role {
-    return this.get('role') as Role;
-  }
-
-  get account (): AccountId {
-    return this.get('account') as AccountId;
-  }
-  get joined_at (): BlockNumber {
-    return this.get('joined_at') as BlockNumber;
-  }
-}
-
-export type Request = [AccountId, MemberId, Role, BlockNumber];
-export type Requests = Array<Request>;
+import { getTypeRegistry, u32, u128 } from '@polkadot/types';
+import { BlockNumber, Balance } from '@polkadot/types/interfaces';
 
+// We only need this type for historic reasons to read old proposal state
+// that was related to the now defunct actors module
 export class RoleParameters extends Struct {
   constructor (value?: any) {
     super({
@@ -85,9 +57,6 @@ export function registerRolesTypes () {
     const typeRegistry = getTypeRegistry();
     typeRegistry.register({
       RoleParameters,
-      Request: '(AccountId, MemberId, Role, BlockNumber)',
-      Requests: 'Vec<Request>',
-      Actor
     });
   } catch (err) {
     console.error('Failed to register custom types of roles module', err);

+ 15 - 15
types/src/bureaucracy/index.ts → types/src/working-group/index.ts

@@ -13,7 +13,7 @@ export type ILead = {
 };
 
 // This type is also defined in /content-workig-group (and those are incosistent), but here
-// it is beeing registered as "LeadOf" (which is an alias used by the runtime bureaucracy module),
+// it is beeing registered as "LeadOf" (which is an alias used by the runtime working-group module),
 // so it shouldn't cause any conflicts)
 export class Lead extends JoyStruct<ILead> {
   constructor (value?: ILead) {
@@ -176,7 +176,7 @@ export class SlashingTerms extends Enum {
   }
 };
 
-export type IBureaucracyOpeningPolicyCommitment = {
+export type IWorkingGroupOpeningPolicyCommitment = {
   application_rationing_policy: Option<ApplicationRationingPolicy>,
   max_review_period_length: BlockNumber,
   application_staking_policy: Option<StakingPolicy>,
@@ -191,19 +191,19 @@ export type IBureaucracyOpeningPolicyCommitment = {
   exit_worker_role_stake_unstaking_period: Option<BlockNumber>,
 };
 
-// This type represents OpeningPolicyCommitment defined inside the runtime's bureaucracy module.
+// This type represents OpeningPolicyCommitment defined inside the runtime's working-grpup module.
 // The only difference between this and the one defined in /content-working-group is in the names of some fields.
 //
 // There is also a minor issue here:
-// Because api metadata still says that ie. the "commitment" argument of "forumBureaucracy.addWorkerOpening" extrinsic
-// is of type "OpeningPolicyCommitment" (not the "BureaucracyOpeningPolicyCommitment" defined here), the CWG's OpeningPolicyCommitment
+// Because api metadata still says that ie. the "commitment" argument of "storageWorkingGroup.addWorkerOpening" extrinsic
+// is of type "OpeningPolicyCommitment" (not the "WorkingGroupOpeningPolicyCommitment" defined here), the CWG's OpeningPolicyCommitment
 // type is used when sending this extrinsic (it has "terminate_curator_role_stake_unstaking_period" field insted
 // of "terminate_worker_role_stake_unstaking_period" etc.).
 // Since both those types are basically the same structs (only filed names are different) nothing seems to break, but it's
-// very fragile atm and any change to this type in bureaucracy module could result in "unsolvable" inconsistencies
-// (this won't be an issue after CWG gets refactored to use the bureaucracy module too)
-export class BureaucracyOpeningPolicyCommitment extends JoyStruct<IBureaucracyOpeningPolicyCommitment> {
-  constructor (value?: BureaucracyOpeningPolicyCommitment) {
+// very fragile atm and any change to this type in working-group module could result in "unsolvable" inconsistencies
+// (this won't be an issue after CWG gets refactored to use the working-grpup module too)
+export class WorkingGroupOpeningPolicyCommitment extends JoyStruct<IWorkingGroupOpeningPolicyCommitment> {
+  constructor (value?: WorkingGroupOpeningPolicyCommitment) {
     super({
       application_rationing_policy: Option.with(ApplicationRationingPolicy),
       max_review_period_length: "BlockNumber",
@@ -272,7 +272,7 @@ export class BureaucracyOpeningPolicyCommitment extends JoyStruct<IBureaucracyOp
 export type IWorkerOpening = {
   opening_id: OpeningId,
   worker_applications: BTreeSet<WorkerApplicationId>,
-  policy_commitment: BureaucracyOpeningPolicyCommitment,
+  policy_commitment: WorkingGroupOpeningPolicyCommitment,
 }
 
 export class WorkerOpening extends JoyStruct<IWorkerOpening> {
@@ -280,7 +280,7 @@ export class WorkerOpening extends JoyStruct<IWorkerOpening> {
     super({
       opening_id: OpeningId,
       worker_applications: BTreeSet.with(WorkerApplicationId),
-      policy_commitment: BureaucracyOpeningPolicyCommitment,
+      policy_commitment: WorkingGroupOpeningPolicyCommitment,
     }, value);
   }
 
@@ -292,12 +292,12 @@ export class WorkerOpening extends JoyStruct<IWorkerOpening> {
     return this.getField<BTreeSet<WorkerApplicationId>>('worker_applications');
   }
 
-  get policy_commitment(): BureaucracyOpeningPolicyCommitment {
-    return this.getField<BureaucracyOpeningPolicyCommitment>('policy_commitment');
+  get policy_commitment(): WorkingGroupOpeningPolicyCommitment {
+    return this.getField<WorkingGroupOpeningPolicyCommitment>('policy_commitment');
   }
 }
 
-export function registerBureaucracyTypes() {
+export function registerWorkingGroupTypes() {
   try {
     getTypeRegistry().register({
       // Note that it actually HAS TO be "LeadOf" in the runtime,
@@ -315,6 +315,6 @@ export function registerBureaucracyTypes() {
       StorageProviderId
     });
   } catch (err) {
-    console.error('Failed to register custom types of bureaucracy module', err);
+    console.error('Failed to register custom types of working-group module', err);
   }
 }