-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4708 from Joystream/apps-metaprotocol
Apps release
- Loading branch information
Showing
62 changed files
with
1,447 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "Example app", | ||
"description": "Example app description", | ||
"category": "blockchain", | ||
"oneLiner": "best blokchain video platform", | ||
"platforms": [ | ||
"web", "mobile" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "Updated example app", | ||
"description": "Updated example app description", | ||
"category": "trading", | ||
"oneLiner": "best trading video platform", | ||
"platforms": [ | ||
"web" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { IAppMetadata } from '@joystream/metadata-protobuf' | ||
import MembershipsCommandBase from './MembershipsCommandBase' | ||
import { Bytes } from '@polkadot/types/primitive' | ||
import { u64 } from '@polkadot/types' | ||
import chalk from 'chalk' | ||
|
||
export default abstract class AppCommandBase extends MembershipsCommandBase { | ||
appMetadataForm = { | ||
description: 'App description?', | ||
authKey: 'App public auth key?', | ||
websiteUrl: 'Site URL where user can learn more about the app?', | ||
useUri: 'App URL?', | ||
platforms: 'Platforms supported by app? Format eg.: "web,mobile,native"', | ||
category: 'Category of the app? Format eg.: "messaging"', | ||
oneLiner: 'Tagline for the app?', | ||
termsOfService: 'Terms of service for the app?', | ||
bigIcon: 'Big icon URL?', | ||
mediumIcon: 'Medium icon URL?', | ||
smallIcon: 'Small icon URL?', | ||
} | ||
|
||
async promptAppMetadata(possibleFields?: Partial<IAppMetadata>): Promise<IAppMetadata> { | ||
this.log(chalk.green('App form initiated.')) | ||
this.log(chalk.yellow('To skip field just prompt empty input.')) | ||
this.log(`${chalk.yellow('To unset field prompt only: ')} ${chalk.magentaBright('"-"')}${chalk.yellow('.')}`) | ||
return Object.keys(this.appMetadataForm).reduce(async (prevPromise, key) => { | ||
const prev = await prevPromise | ||
const possibleValue = possibleFields?.[key as keyof IAppMetadata] | ||
if (possibleValue) { | ||
prev[key] = possibleValue | ||
return prev | ||
} | ||
const promptValue = await this.simplePrompt<string>({ message: this.appMetadataForm[key as keyof IAppMetadata] }) | ||
if (promptValue === '') { | ||
return prev | ||
} | ||
prev[key] = this.processValue(key, promptValue) | ||
return prev | ||
}, Promise.resolve({} as Record<string, string | string[]>)) | ||
} | ||
|
||
processValue(key: string, value: string): string | string[] { | ||
if (value === '-') { | ||
return key === 'platforms' ? [''] : '' | ||
} | ||
if (key === 'platforms') { | ||
return value.split(',').map((str: string) => str.trim()) | ||
} | ||
return value | ||
} | ||
|
||
async sendRemark(message: Bytes): Promise<u64> { | ||
const { | ||
id, | ||
membership: { controllerAccount }, | ||
} = await this.getRequiredMemberContext(true) | ||
const keypair = await this.getDecodedPair(controllerAccount) | ||
const result = await this.sendAndFollowNamedTx(keypair, 'members', 'memberRemark', [id, message]) | ||
|
||
const [memberId] = this.getEvent(result, 'members', 'MemberRemarked').data | ||
|
||
return memberId | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { flags } from '@oclif/command' | ||
import * as allMessages from '@joystream/metadata-protobuf' | ||
import allMessagesJson from '@joystream/metadata-protobuf/json' | ||
import { AnyMetadataClass } from '@joystream/metadata-protobuf/types' | ||
import DefaultCommandBase from './DefaultCommandBase' | ||
|
||
type MessageTypeName = keyof typeof allMessages & keyof typeof allMessagesJson & string | ||
|
||
/** | ||
* Abstract base class for commands that require a single protobuf message context. | ||
*/ | ||
export default abstract class ProtobufMessageCommandBase extends DefaultCommandBase { | ||
protected MessageClass!: AnyMetadataClass<unknown> | ||
protected messageJson!: Record<string, unknown> | ||
protected type!: keyof typeof allMessages | ||
|
||
static flags = { | ||
type: flags.enum<MessageTypeName>({ | ||
options: Object.keys(allMessages) as MessageTypeName[], | ||
required: false, | ||
description: 'Type of the message', | ||
}), | ||
} | ||
|
||
async init(): Promise<void> { | ||
await super.init() | ||
let { | ||
flags: { type }, | ||
} = this.parse(this.constructor as typeof ProtobufMessageCommandBase) | ||
|
||
if (!type) { | ||
type = await this.promptForMessageType() | ||
} | ||
|
||
this.type = type | ||
this.messageJson = allMessagesJson[type] | ||
this.MessageClass = allMessages[type] | ||
} | ||
|
||
async promptForMessageType(message = 'Choose a message type'): Promise<MessageTypeName> { | ||
return this.simplePrompt<MessageTypeName>({ | ||
type: 'list', | ||
choices: Object.keys(allMessages) | ||
.sort() | ||
.map((c) => ({ | ||
value: c, | ||
name: c, | ||
})), | ||
message, | ||
}) | ||
} | ||
} |
Oops, something went wrong.