transport.mock.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. import { Observable } from 'rxjs';
  2. import { Balance } from '@polkadot/types/interfaces';
  3. import { Subscribable } from '@polkadot/joy-utils/react/helpers';
  4. import MockTransportBase from '@polkadot/joy-utils/transport/mock/base';
  5. import { ITransport } from './transport';
  6. import { createType } from '@joystream/types';
  7. import { WorkingGroupMembership, GroupLeadStatus } from './tabs/WorkingGroup';
  8. import { WorkingGroupOpening } from './tabs/Opportunities';
  9. import { ActiveRole, OpeningApplication } from './tabs/MyRoles';
  10. import { ApplicationStakeRequirement, RoleStakeRequirement, StakeType } from './StakeRequirement';
  11. import { keyPairDetails } from './flows/apply';
  12. import { tomorrow, yesterday, newMockHumanReadableText } from './tabs/Opportunities.stories';
  13. import { OpeningState } from './classifiers';
  14. import * as faker from 'faker';
  15. import { mockProfile, mockStage } from './mocks';
  16. import { WorkingGroups, workerRoleNameByGroup } from './working_groups';
  17. export class Transport extends MockTransportBase implements ITransport {
  18. groupLeadStatus (group: WorkingGroups = WorkingGroups.ContentCurators): Promise<GroupLeadStatus> {
  19. return this.simulateApiResponse<GroupLeadStatus>({
  20. loaded: true
  21. });
  22. }
  23. async curationGroup (): Promise<WorkingGroupMembership> {
  24. return this.simulateApiResponse<WorkingGroupMembership>({
  25. leadStatus: await this.groupLeadStatus(),
  26. workerRolesAvailable: true,
  27. leadRolesAvailable: false,
  28. workers: [
  29. {
  30. memberId: createType('MemberId', 1),
  31. roleAccount: createType('AccountId', '5HZ6GtaeyxagLynPryM7ZnmLzoWFePKuDrkb4AT8rT4pU1fp'),
  32. profile: mockProfile(
  33. 'benholdencrowther',
  34. 'https://www.benholdencrowther.com/wp-content/uploads/2019/03/Hanging_Gardens_of_Babylon.jpg'
  35. ),
  36. title: 'Content curator',
  37. stake: createType('u128', 10101),
  38. workerId: 1,
  39. group: WorkingGroups.ContentCurators
  40. },
  41. {
  42. memberId: createType('MemberId', 2),
  43. roleAccount: createType('AccountId', '5DfJWGbBAH8hLAg8rcRYZW5BEZbE4BJeCQKoxUeqoyewLSew'),
  44. profile: mockProfile('bwhm0'),
  45. title: 'Content curator',
  46. stake: createType('u128', 10101),
  47. workerId: 2,
  48. group: WorkingGroups.ContentCurators
  49. },
  50. {
  51. memberId: createType('MemberId', 3),
  52. roleAccount: createType('AccountId', '5DQqNWRFPruFs9YKheVMqxUbqoXeMzAWfVfcJgzuia7NA3D3'),
  53. profile: mockProfile(
  54. 'yourheropaul',
  55. 'https://yhp.io/img/paul.svg'
  56. ),
  57. title: 'Content curator',
  58. stake: createType('u128', 10101),
  59. workerId: 3,
  60. group: WorkingGroups.ContentCurators
  61. },
  62. {
  63. memberId: createType('MemberId', 4),
  64. roleAccount: createType('AccountId', '5GSMNn8Sy8k64mGUWPDafjMZu9bQNX26GujbBQ1LeJpNbrfg'),
  65. profile: mockProfile(
  66. 'alex_joystream',
  67. 'https://avatars2.githubusercontent.com/u/153928?s=200&v=4'
  68. ),
  69. title: 'Content curator',
  70. stake: createType('u128', 10101),
  71. workerId: 4,
  72. group: WorkingGroups.ContentCurators
  73. },
  74. {
  75. memberId: createType('MemberId', 3),
  76. roleAccount: createType('AccountId', '5Gn9n7SDJ7VgHqHQWYzkSA4vX6DCmS5TFWdHxikTXp9b4L32'),
  77. profile: mockProfile(
  78. 'mokhtar',
  79. 'https://avatars2.githubusercontent.com/u/1621012?s=460&v=4'
  80. ),
  81. title: 'Content curator',
  82. stake: createType('u128', 10101),
  83. workerId: 5,
  84. group: WorkingGroups.ContentCurators
  85. }
  86. ]
  87. });
  88. }
  89. async storageGroup (): Promise<WorkingGroupMembership> {
  90. return this.simulateApiResponse<WorkingGroupMembership>({
  91. leadStatus: await this.groupLeadStatus(),
  92. workerRolesAvailable: true,
  93. leadRolesAvailable: true,
  94. workers: [
  95. {
  96. memberId: createType('MemberId', 1),
  97. roleAccount: createType('AccountId', '5HZ6GtaeyxagLynPryM7ZnmLzoWFePKuDrkb4AT8rT4pU1fp'),
  98. profile: mockProfile(
  99. 'benholdencrowther',
  100. 'https://www.benholdencrowther.com/wp-content/uploads/2019/03/Hanging_Gardens_of_Babylon.jpg'
  101. ),
  102. title: 'Storage provider',
  103. stake: createType('u128', 10101),
  104. workerId: 1,
  105. group: WorkingGroups.StorageProviders
  106. }
  107. ]
  108. });
  109. }
  110. currentOpportunities (): Promise<Array<WorkingGroupOpening>> {
  111. return this.simulateApiResponse<Array<WorkingGroupOpening>>(
  112. [
  113. {
  114. opening: createType('Opening', {
  115. created: 50000,
  116. stage: mockStage,
  117. max_review_period_length: 100,
  118. human_readable_text: newMockHumanReadableText({
  119. version: 1,
  120. headline: 'Help us curate awesome content',
  121. job: {
  122. title: 'Content curator',
  123. description: faker.lorem.paragraphs(4)
  124. },
  125. application: {
  126. sections: [
  127. {
  128. title: 'About you',
  129. questions: [
  130. {
  131. title: 'your name',
  132. type: 'text'
  133. }
  134. ]
  135. },
  136. {
  137. title: 'About you',
  138. questions: [
  139. {
  140. title: 'your name',
  141. type: 'text area'
  142. }
  143. ]
  144. }
  145. ]
  146. },
  147. reward: '10 JOY per block',
  148. process: {
  149. details: [
  150. 'Some custom detail'
  151. ]
  152. }
  153. })
  154. }),
  155. meta: {
  156. id: '1',
  157. group: WorkingGroups.ContentCurators
  158. },
  159. stage: {
  160. state: OpeningState.AcceptingApplications,
  161. starting_block: 2956498,
  162. starting_block_hash: 'somehash',
  163. starting_time: yesterday(),
  164. review_end_block: 3956498,
  165. review_end_time: tomorrow()
  166. },
  167. applications: {
  168. numberOfApplications: 0,
  169. maxNumberOfApplications: 0,
  170. requiredApplicationStake: new ApplicationStakeRequirement(
  171. createType('u128', 500)
  172. ),
  173. requiredRoleStake: new RoleStakeRequirement(
  174. createType('u128', 0)
  175. ),
  176. defactoMinimumStake: createType('u128', 0)
  177. },
  178. defactoMinimumStake: createType('u128', 0)
  179. }
  180. ]
  181. );
  182. }
  183. // eslint-disable-next-line @typescript-eslint/require-await
  184. async groupOpening (group: WorkingGroups, id: number): Promise<WorkingGroupOpening> {
  185. return this.simulateApiResponse<WorkingGroupOpening>(
  186. {
  187. opening: createType('Opening', {
  188. created: 50000,
  189. stage: mockStage,
  190. max_review_period_length: 100,
  191. human_readable_text: newMockHumanReadableText({
  192. version: 1,
  193. headline: 'Help us curate awesome content',
  194. job: {
  195. title: 'Content curator',
  196. description: faker.lorem.paragraphs(4)
  197. },
  198. application: {
  199. sections: [
  200. {
  201. title: 'About you',
  202. questions: [
  203. {
  204. title: 'Your name',
  205. type: 'text'
  206. },
  207. {
  208. title: 'Your e-mail address',
  209. type: 'text'
  210. }
  211. ]
  212. },
  213. {
  214. title: 'Your experience',
  215. questions: [
  216. {
  217. title: 'Why would you be good for this role?',
  218. type: 'text area'
  219. }
  220. ]
  221. }
  222. ]
  223. },
  224. reward: '10 JOY per block',
  225. process: {
  226. details: [
  227. 'Some custom detail'
  228. ]
  229. }
  230. })
  231. }),
  232. meta: {
  233. id: '1',
  234. group: WorkingGroups.ContentCurators
  235. },
  236. stage: {
  237. state: OpeningState.AcceptingApplications,
  238. starting_block: 2956498,
  239. starting_block_hash: 'somehash',
  240. starting_time: yesterday(),
  241. review_end_block: 3956498,
  242. review_end_time: tomorrow()
  243. },
  244. applications: {
  245. numberOfApplications: 0,
  246. maxNumberOfApplications: 0,
  247. requiredApplicationStake: new ApplicationStakeRequirement(
  248. createType('u128', 501),
  249. StakeType.AtLeast
  250. ),
  251. requiredRoleStake: new RoleStakeRequirement(
  252. createType('u128', 502)
  253. ),
  254. defactoMinimumStake: createType('u128', 0)
  255. },
  256. defactoMinimumStake: createType('u128', 0)
  257. }
  258. );
  259. }
  260. openingApplicationRanks (group: WorkingGroups, openingId: number): Promise<Balance[]> {
  261. const slots: Balance[] = [];
  262. for (let i = 0; i < 20; i++) {
  263. slots.push(createType('u128', (i * 100) + 10 + i + 1));
  264. }
  265. return this.simulateApiResponse<Balance[]>(slots);
  266. }
  267. expectedBlockTime (): number {
  268. return 6;
  269. }
  270. blockHash (height: number): Promise<string> {
  271. return this.promise<string>('somehash');
  272. }
  273. blockTimestamp (height: number): Promise<Date> {
  274. return this.promise<Date>(new Date());
  275. }
  276. accounts (): Subscribable<keyPairDetails[]> {
  277. return new Observable<keyPairDetails[]>((observer) => {
  278. observer.next(
  279. [
  280. {
  281. shortName: 'KP1',
  282. accountId: createType('AccountId', '5HZ6GtaeyxagLynPryM7ZnmLzoWFePKuDrkb4AT8rT4pU1fp'),
  283. balance: createType('u128', 23342)
  284. },
  285. {
  286. shortName: 'KP2',
  287. accountId: createType('AccountId', '5DQqNWRFPruFs9YKheVMqxUbqoXeMzAWfVfcJgzuia7NA3D3'),
  288. balance: createType('u128', 993342)
  289. },
  290. {
  291. shortName: 'KP3',
  292. accountId: createType('AccountId', '5DBaczGTDhcHgwsZzNE5qW15GrQxxdyros4pYkcKrSUovFQ9'),
  293. balance: createType('u128', 242)
  294. }
  295. ]
  296. );
  297. });
  298. }
  299. // eslint-disable-next-line @typescript-eslint/require-await
  300. async openingApplicationsByAddress (address: string): Promise<OpeningApplication[]> {
  301. return [{
  302. id: 1,
  303. meta: {
  304. id: '1',
  305. group: WorkingGroups.ContentCurators
  306. },
  307. stage: {
  308. state: OpeningState.AcceptingApplications,
  309. starting_block: 2956498,
  310. starting_block_hash: 'somehash',
  311. starting_time: yesterday()
  312. },
  313. opening: createType('Opening', {
  314. created: 50000,
  315. stage: mockStage,
  316. max_review_period_length: 100,
  317. human_readable_text: newMockHumanReadableText({
  318. version: 1,
  319. headline: 'Help us curate awesome content',
  320. job: {
  321. title: 'Content curator',
  322. description: faker.lorem.paragraphs(4)
  323. },
  324. application: {
  325. sections: [
  326. {
  327. title: 'About you',
  328. questions: [
  329. {
  330. title: 'Your name',
  331. type: 'text'
  332. },
  333. {
  334. title: 'Your e-mail address',
  335. type: 'text'
  336. }
  337. ]
  338. },
  339. {
  340. title: 'Your experience',
  341. questions: [
  342. {
  343. title: 'Why would you be good for this role?',
  344. type: 'text area'
  345. }
  346. ]
  347. }
  348. ]
  349. },
  350. reward: '10 JOY per block',
  351. process: {
  352. details: [
  353. 'Some custom detail'
  354. ]
  355. }
  356. })
  357. }),
  358. applicationStake: createType('u128', 5),
  359. roleStake: createType('u128', 15),
  360. rank: 21,
  361. capacity: 20
  362. }];
  363. }
  364. // eslint-disable-next-line @typescript-eslint/require-await
  365. async myRoles (address: string): Promise<ActiveRole[]> {
  366. return [
  367. {
  368. workerId: createType('CuratorId', 1),
  369. name: workerRoleNameByGroup[WorkingGroups.ContentCurators],
  370. group: WorkingGroups.ContentCurators,
  371. url: 'some URL',
  372. reward: createType('u128', 321),
  373. stake: createType('u128', 12343200)
  374. }
  375. ];
  376. }
  377. // eslint-disable-next-line @typescript-eslint/require-await
  378. async applyToOpening (
  379. group: WorkingGroups,
  380. id: number,
  381. roleAccountName: string,
  382. sourceAccount: string,
  383. appStake: Balance,
  384. roleStake: Balance,
  385. applicationText: string): Promise<number> {
  386. return 0;
  387. }
  388. leaveRole (group: WorkingGroups, sourceAccount: string, id: number, rationale: string) {
  389. /* do nothing */
  390. }
  391. withdrawApplication (group: WorkingGroups, sourceAccount: string, id: number) {
  392. /* do nothing */
  393. }
  394. }