diff --git a/ironfish-cli/src/commands/wallet/assets.ts b/ironfish-cli/src/commands/wallet/assets.ts index 288721d983..0a14037d5f 100644 --- a/ironfish-cli/src/commands/wallet/assets.ts +++ b/ironfish-cli/src/commands/wallet/assets.ts @@ -12,7 +12,7 @@ import { BufferUtils } from '@ironfish/sdk' import { CliUx } from '@oclif/core' import { IronfishCommand } from '../../command' import { RemoteFlags } from '../../flags' -import { renderAssetNameFromHex } from '../../utils' +import { renderAssetWithVerificationStatus } from '../../utils' import { TableCols } from '../../utils/table' const MAX_ASSET_METADATA_COLUMN_WIDTH = ASSET_METADATA_LENGTH + 1 @@ -64,12 +64,13 @@ export class AssetsCommand extends IronfishCommand { header: 'Name', width: assetNameWidth, get: (row) => - renderAssetNameFromHex(row.name, { - verification: row.verification, - outputType: flags.output, - verbose: !!flags.verbose, - logWarn: this.warn.bind(this), - }), + renderAssetWithVerificationStatus( + BufferUtils.toHuman(Buffer.from(row.name, 'hex')), + { + verification: row.verification, + outputType: flags.output, + }, + ), }), id: { header: 'ID', diff --git a/ironfish-cli/src/commands/wallet/balance.ts b/ironfish-cli/src/commands/wallet/balance.ts index 25e689d402..5c4eef8aa8 100644 --- a/ironfish-cli/src/commands/wallet/balance.ts +++ b/ironfish-cli/src/commands/wallet/balance.ts @@ -5,7 +5,7 @@ import { CurrencyUtils, GetBalanceResponse, isNativeIdentifier } from '@ironfish import { Flags } from '@oclif/core' import { IronfishCommand } from '../../command' import { RemoteFlags } from '../../flags' -import { renderAssetName } from '../../utils' +import { renderAssetWithVerificationStatus } from '../../utils' export class BalanceCommand extends IronfishCommand { static description = @@ -63,11 +63,10 @@ export class BalanceCommand extends IronfishCommand { ).content const assetId = response.content.assetId - const assetName = renderAssetName(isNativeIdentifier(assetId) ? '$IRON' : assetId, { - verification: asset.verification, - verbose: !!flags.verbose, - logWarn: this.warn.bind(this), - }) + const assetName = renderAssetWithVerificationStatus( + isNativeIdentifier(assetId) ? '$IRON' : assetId, + asset, + ) if (flags.explain) { this.explainBalance(response.content, assetName) diff --git a/ironfish-cli/src/commands/wallet/balances.ts b/ironfish-cli/src/commands/wallet/balances.ts index bee764eef8..feadcfc26e 100644 --- a/ironfish-cli/src/commands/wallet/balances.ts +++ b/ironfish-cli/src/commands/wallet/balances.ts @@ -1,11 +1,11 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import { CurrencyUtils, GetBalancesResponse, RpcAsset } from '@ironfish/sdk' +import { BufferUtils, CurrencyUtils, GetBalancesResponse, RpcAsset } from '@ironfish/sdk' import { CliUx, Flags } from '@oclif/core' import { IronfishCommand } from '../../command' import { RemoteFlags } from '../../flags' -import { compareAssets, renderAssetNameFromHex } from '../../utils' +import { compareAssets, renderAssetWithVerificationStatus } from '../../utils' type AssetBalancePairs = { asset: RpcAsset; balance: GetBalancesResponse['balances'][number] } @@ -63,12 +63,13 @@ export class BalancesCommand extends IronfishCommand { assetName: { header: 'Asset Name', get: ({ asset }) => - renderAssetNameFromHex(asset.name, { - verification: asset.verification, - outputType: flags.output, - verbose: !!flags.verbose, - logWarn: this.warn.bind(this), - }), + renderAssetWithVerificationStatus( + BufferUtils.toHuman(Buffer.from(asset.name, 'hex')), + { + verification: asset.verification, + outputType: flags.output, + }, + ), }, 'asset.id': { header: 'Asset Id', diff --git a/ironfish-cli/src/utils/asset.ts b/ironfish-cli/src/utils/asset.ts index 8cc6f62f05..a201007dd5 100644 --- a/ironfish-cli/src/utils/asset.ts +++ b/ironfish-cli/src/utils/asset.ts @@ -17,11 +17,12 @@ import inquirer from 'inquirer' type RenderAssetNameOptions = { verification?: RpcAssetVerification outputType?: string - verbose?: boolean - logWarn?: (msg: string) => void } -export function renderAssetName(name: string, options?: RenderAssetNameOptions): string { +export function renderAssetWithVerificationStatus( + name: string, + options?: RenderAssetNameOptions, +): string { if (options?.outputType) { // User requested some machine-readable output (like CSV, JSON, or YAML). // Do not alter the name in any way. @@ -34,23 +35,12 @@ export function renderAssetName(name: string, options?: RenderAssetNameOptions): case 'verified': return chalk.green(name + '✓') case 'unknown': - if (options?.verbose && options?.logWarn) { - options.logWarn(`Could not check whether ${name} is a verified asset`) - } - return name + return chalk.green(name + '?') default: return name } } -export function renderAssetNameFromHex( - hexName: string, - options?: RenderAssetNameOptions, -): string { - const name = BufferUtils.toHuman(Buffer.from(hexName, 'hex')) - return renderAssetName(name, options) -} - export function compareAssets( leftName: string, leftVerification: RpcAssetVerification,