Browse Source

Review fixes - https://github.com/Joystream/joystream/pull/1516#issuecomment-709446079

Leszek Wiesner 4 years ago
parent
commit
e5c1888c2e

+ 1 - 1
cli/src/Api.ts

@@ -550,6 +550,6 @@ export default class Api {
     )
 
     const bestNumber = await this.bestNumber()
-    return !!accounInfoEntries.filter(([, info]) => info.expires_at.toNumber() > bestNumber)
+    return !!accounInfoEntries.filter(([, info]) => info.expires_at.toNumber() > bestNumber).length
   }
 }

+ 15 - 3
cli/src/base/AccountsCommandBase.ts

@@ -216,11 +216,23 @@ export default abstract class AccountsCommandBase extends ApiCommandBase {
   }
 
   async requestAccountDecoding(account: NamedKeyringPair): Promise<void> {
-    const password: string = await this.promptForPassword()
+    // First - try decoding using empty string
     try {
-      account.decodePkcs8(password)
+      account.decodePkcs8('')
+      return
     } catch (e) {
-      this.error('Invalid password!', { exit: ExitCodes.InvalidInput })
+      // Continue...
+    }
+
+    let isPassValid = false
+    while (!isPassValid) {
+      try {
+        const password = await this.promptForPassword()
+        account.decodePkcs8(password)
+        isPassValid = true
+      } catch (e) {
+        this.warn('Invalid password... Try again.')
+      }
     }
   }
 

+ 4 - 1
cli/src/base/ContentDirectoryCommandBase.ts

@@ -9,6 +9,7 @@ import { Worker } from '@joystream/types/working-group'
 import { CLIError } from '@oclif/errors'
 import { Codec } from '@polkadot/types/types'
 import _ from 'lodash'
+import chalk from 'chalk'
 
 /**
  * Abstract base class for commands related to content directory
@@ -264,7 +265,9 @@ export default abstract class ContentDirectoryCommandBase extends AccountsComman
     const parsedEntities = (await Promise.all(
       entityEntries.map(([id, entity]) => ({
         'ID': id.toString(),
-        ..._.mapValues(this.parseEntityPropertyValues(entity, entityClass, includedProps), (v) => v.value.toString()),
+        ..._.mapValues(this.parseEntityPropertyValues(entity, entityClass, includedProps), (v) =>
+          v.value.toJSON() === false && v.type !== 'Single<Bool>' ? chalk.grey('[not set]') : v.value.toString()
+        ),
       }))
     )) as Record<string, string>[]
 

+ 8 - 1
cli/src/commands/content-directory/entity.ts

@@ -32,6 +32,13 @@ export default class EntityCommand extends ContentDirectoryCommandBase {
       'Total references': entity.reference_counter.total.toNumber(),
     })
     displayHeader('Property values')
-    displayCollapsedRow(_.mapValues(propertyValues, (v) => `${v.value.toString()} ${chalk.green(`${v.type}`)}`))
+    displayCollapsedRow(
+      _.mapValues(
+        propertyValues,
+        (v) =>
+          (v.value.toJSON() === false && v.type !== 'Single<Bool>' ? chalk.grey('[not set]') : v.value.toString()) +
+          ` ${chalk.green(`${v.type}`)}`
+      )
+    )
   }
 }

+ 4 - 3
cli/src/helpers/JsonSchemaPrompt.ts

@@ -34,7 +34,8 @@ export class JsonSchemaPrompter<JsonResult> {
     this.customPropmpts = customPrompts
     this.schema = schema
     this.schemaPath = schemaPath
-    this.ajv = new Ajv()
+    // allErrors prevents .validate from setting only one error when in fact there are multiple
+    this.ajv = new Ajv({ allErrors: true })
     this.filledObject = defaults || {}
   }
 
@@ -116,11 +117,11 @@ export class JsonSchemaPrompter<JsonResult> {
 
     // Normalizers
     if (schema.type === 'integer') {
-      normalizer = (v) => parseInt(v)
+      normalizer = (v) => (parseInt(v).toString() === v ? parseInt(v) : v)
     }
 
     if (schema.type === 'number') {
-      normalizer = (v) => Number(v)
+      normalizer = (v) => (Number(v).toString() === v ? Number(v) : v)
     }
 
     const promptOptions = { ...basicPromptOptions, ...additionalPromptOptions, ...customPrompt }