From c99d491a381c99bc3acdbe786dc5cc82226f3beb Mon Sep 17 00:00:00 2001 From: Mat Date: Mon, 8 Apr 2024 12:01:32 -0700 Subject: [PATCH] Use the new render function definition --- ironfish-cli/src/commands/wallet/balance.ts | 8 +++---- ironfish-cli/src/commands/wallet/balances.ts | 12 ++++++---- ironfish-cli/src/commands/wallet/burn.ts | 9 ++++++-- ironfish-cli/src/commands/wallet/mint.ts | 20 ++++++++++------- .../src/commands/wallet/notes/combine.ts | 3 ++- .../src/commands/wallet/notes/index.ts | 8 ++++++- ironfish-cli/src/commands/wallet/send.ts | 7 +++++- .../src/commands/wallet/transaction/index.ts | 3 ++- .../src/commands/wallet/transactions.ts | 7 +++--- ironfish-cli/src/utils/asset.ts | 3 ++- ironfish-cli/src/utils/currency.ts | 6 +++-- ironfish-cli/src/utils/transaction.ts | 22 ++++++++++++++----- 12 files changed, 74 insertions(+), 34 deletions(-) diff --git a/ironfish-cli/src/commands/wallet/balance.ts b/ironfish-cli/src/commands/wallet/balance.ts index be89bd8f4a..d5df1817eb 100644 --- a/ironfish-cli/src/commands/wallet/balance.ts +++ b/ironfish-cli/src/commands/wallet/balance.ts @@ -67,8 +67,8 @@ export class BalanceCommand extends IronfishCommand { let nameToRender if (isNativeIdentifier(assetId)) { nameToRender = '$IRON' - } else if (asset.symbol) { - nameToRender = asset.symbol + } else if (asset.verification.symbol) { + nameToRender = asset.verification.symbol } else { nameToRender = assetId } @@ -155,8 +155,8 @@ function renderValue(amount: string | bigint, asset: RpcAsset, assetName: string const renderNameManually = asset.verification.status === 'verified' if (renderNameManually) { - return `${assetName} ${CurrencyUtils.render(amount, false, asset)}` + return `${assetName} ${CurrencyUtils.render(amount, false, asset.id, asset.verification)}` } else { - return CurrencyUtils.render(amount, true, asset) + return CurrencyUtils.render(amount, true, asset.id, asset.verification) } } diff --git a/ironfish-cli/src/commands/wallet/balances.ts b/ironfish-cli/src/commands/wallet/balances.ts index b815ce1c9d..6e1edcb8e2 100644 --- a/ironfish-cli/src/commands/wallet/balances.ts +++ b/ironfish-cli/src/commands/wallet/balances.ts @@ -76,7 +76,8 @@ export class BalancesCommand extends IronfishCommand { }, available: { header: 'Available Balance', - get: ({ asset, balance }) => CurrencyUtils.render(balance.available, false, asset), + get: ({ asset, balance }) => + CurrencyUtils.render(balance.available, false, asset.id, asset.verification), }, } @@ -85,15 +86,18 @@ export class BalancesCommand extends IronfishCommand { ...columns, confirmed: { header: 'Confirmed Balance', - get: ({ asset, balance }) => CurrencyUtils.render(balance.confirmed, false, asset), + get: ({ asset, balance }) => + CurrencyUtils.render(balance.confirmed, false, asset.id, asset.verification), }, unconfirmed: { header: 'Unconfirmed Balance', - get: ({ asset, balance }) => CurrencyUtils.render(balance.unconfirmed, false, asset), + get: ({ asset, balance }) => + CurrencyUtils.render(balance.unconfirmed, false, asset.id, asset.verification), }, pending: { header: 'Pending Balance', - get: ({ asset, balance }) => CurrencyUtils.render(balance.pending, false, asset), + get: ({ asset, balance }) => + CurrencyUtils.render(balance.pending, false, asset.id, asset.verification), }, blockHash: { header: 'Head Hash', diff --git a/ironfish-cli/src/commands/wallet/burn.ts b/ironfish-cli/src/commands/wallet/burn.ts index 47287b8c99..55db221697 100644 --- a/ironfish-cli/src/commands/wallet/burn.ts +++ b/ironfish-cli/src/commands/wallet/burn.ts @@ -219,7 +219,12 @@ export class Burn extends IronfishCommand { } const assetName = BufferUtils.toHuman(Buffer.from(assetData.name, 'hex')) - const renderedAmount = CurrencyUtils.render(amount, false, assetData) + const renderedAmount = CurrencyUtils.render( + amount, + false, + assetData.id, + assetData.verification, + ) this.log(`Burned asset ${assetName} from ${account}`) this.log(`Asset Identifier: ${assetId}`) @@ -254,7 +259,7 @@ export class Burn extends IronfishCommand { fee: bigint, account: string, ): Promise { - const renderedAmount = CurrencyUtils.render(amount, true, asset) + const renderedAmount = CurrencyUtils.render(amount, true, asset.id, asset.verification) const renderedFee = CurrencyUtils.render(fee, true) this.log( `You are about to burn: ${renderedAmount} plus a transaction fee of ${renderedFee} with the account ${account}`, diff --git a/ironfish-cli/src/commands/wallet/mint.ts b/ironfish-cli/src/commands/wallet/mint.ts index 94e1df7190..9a1524d2ba 100644 --- a/ironfish-cli/src/commands/wallet/mint.ts +++ b/ironfish-cli/src/commands/wallet/mint.ts @@ -289,10 +289,12 @@ export class Mint extends IronfishCommand { this.warn(`Transaction '${transaction.hash().toString('hex')}' failed to broadcast`) } - const renderedValue = CurrencyUtils.render(minted.value, true, { - id: minted.asset.id().toString('hex'), - ...assetData, - }) + const renderedValue = CurrencyUtils.render( + minted.value, + true, + minted.asset.id().toString('hex'), + assetData?.verification, + ) const renderedFee = CurrencyUtils.render(transaction.fee(), true) this.log(`Minted asset ${BufferUtils.toHuman(minted.asset.name())} from ${account}`) this.log(`Asset Identifier: ${minted.asset.id().toString('hex')}`) @@ -334,10 +336,12 @@ export class Mint extends IronfishCommand { const nameString = name ? `\nName: ${name}` : '' const metadataString = metadata ? `\nMetadata: ${metadata}` : '' - const renderedAmount = CurrencyUtils.render(amount, !!assetId, { - id: assetId, - ...assetData, - }) + const renderedAmount = CurrencyUtils.render( + amount, + !!assetId, + assetId, + assetData?.verification, + ) const renderedFee = CurrencyUtils.render(fee, true) this.log( diff --git a/ironfish-cli/src/commands/wallet/notes/combine.ts b/ironfish-cli/src/commands/wallet/notes/combine.ts index 12653b5b3e..226d712863 100644 --- a/ironfish-cli/src/commands/wallet/notes/combine.ts +++ b/ironfish-cli/src/commands/wallet/notes/combine.ts @@ -416,7 +416,8 @@ export class CombineNotesCommand extends IronfishCommand { }, value: { header: 'Value', - get: (note) => CurrencyUtils.render(note.value, true, assetData), + get: (note) => + CurrencyUtils.render(note.value, true, assetData.id, assetData.verification), }, owner: { header: 'Owner', diff --git a/ironfish-cli/src/commands/wallet/notes/index.ts b/ironfish-cli/src/commands/wallet/notes/index.ts index bd289b84e6..e8ec7f3275 100644 --- a/ironfish-cli/src/commands/wallet/notes/index.ts +++ b/ironfish-cli/src/commands/wallet/notes/index.ts @@ -71,7 +71,13 @@ export class NotesCommand extends IronfishCommand { ...TableCols.asset({ extended: flags.extended }), value: { header: 'Amount', - get: (row) => CurrencyUtils.render(row.value, false, assetLookup.get(row.assetId)), + get: (row) => + CurrencyUtils.render( + row.value, + false, + row.assetId, + assetLookup.get(row.assetId)?.verification, + ), minWidth: 16, }, noteHash: { diff --git a/ironfish-cli/src/commands/wallet/send.ts b/ironfish-cli/src/commands/wallet/send.ts index 5457dd4989..7647ad43af 100644 --- a/ironfish-cli/src/commands/wallet/send.ts +++ b/ironfish-cli/src/commands/wallet/send.ts @@ -276,7 +276,12 @@ export class Send extends IronfishCommand { this.warn(`Transaction '${transaction.hash().toString('hex')}' failed to broadcast`) } - const renderedAmount = CurrencyUtils.render(amount, true, assetData) + const renderedAmount = CurrencyUtils.render( + amount, + true, + assetData.id, + assetData.verification, + ) const renderedFee = CurrencyUtils.render(transaction.fee(), true) this.log(`Sent ${renderedAmount} to ${to} from ${from}`) this.log(`Hash: ${transaction.hash().toString('hex')}`) diff --git a/ironfish-cli/src/commands/wallet/transaction/index.ts b/ironfish-cli/src/commands/wallet/transaction/index.ts index 64bc1b3b17..465230aeaf 100644 --- a/ironfish-cli/src/commands/wallet/transaction/index.ts +++ b/ironfish-cli/src/commands/wallet/transaction/index.ts @@ -94,7 +94,8 @@ export class TransactionCommand extends IronfishCommand { CliUx.ux.table(noteAssetPairs, { amount: { header: 'Amount', - get: ({ asset, note }) => CurrencyUtils.render(note.value, false, asset), + get: ({ asset, note }) => + CurrencyUtils.render(note.value, false, asset.id, asset.verification), }, assetName: { header: 'Asset Name', diff --git a/ironfish-cli/src/commands/wallet/transactions.ts b/ironfish-cli/src/commands/wallet/transactions.ts index 9607fdc24a..243e7074a7 100644 --- a/ironfish-cli/src/commands/wallet/transactions.ts +++ b/ironfish-cli/src/commands/wallet/transactions.ts @@ -198,8 +198,8 @@ export class TransactionsCommand extends IronfishCommand { const amount = BigInt(note.value) const assetId = note.assetId const assetName = assetLookup[note.assetId].name - const assetDecimals = assetLookup[note.assetId].decimals - const assetSymbol = assetLookup[note.assetId].symbol + const assetDecimals = assetLookup[note.assetId].verification.decimals + const assetSymbol = assetLookup[note.assetId].verification.symbol const sender = note.sender const recipient = note.owner const memo = note.memo @@ -296,8 +296,7 @@ export class TransactionsCommand extends IronfishCommand { header: 'Amount', get: (row) => { Assert.isNotUndefined(row.amount) - return CurrencyUtils.render(row.amount, false, { - id: row.assetId, + return CurrencyUtils.render(row.amount, false, row.assetId, { decimals: row.assetDecimals, symbol: row.assetSymbol, }) diff --git a/ironfish-cli/src/utils/asset.ts b/ironfish-cli/src/utils/asset.ts index 398ce7a1c6..7be9e29257 100644 --- a/ironfish-cli/src/utils/asset.ts +++ b/ironfish-cli/src/utils/asset.ts @@ -137,7 +137,8 @@ export async function selectAsset( const renderedAvailable = CurrencyUtils.render( balance.available, false, - assetLookup[balance.assetId], + balance.assetId, + assetLookup[balance.assetId].verification, ) const name = `${balance.assetId} (${assetName}) (${renderedAvailable})` diff --git a/ironfish-cli/src/utils/currency.ts b/ironfish-cli/src/utils/currency.ts index a3359e7802..6c7d4d030e 100644 --- a/ironfish-cli/src/utils/currency.ts +++ b/ironfish-cli/src/utils/currency.ts @@ -47,7 +47,8 @@ export async function promptCurrency(options: { const renderedAvailable = CurrencyUtils.render( balance.content.available, false, - options.balance.asset, + options.balance.asset?.id, + options.balance.asset?.verification, ) text += ` (balance ${renderedAvailable})` } @@ -75,7 +76,8 @@ export async function promptCurrency(options: { const renderedMinimum = CurrencyUtils.render( options.minimum, false, - options.balance?.asset, + options.balance?.asset?.id, + options.balance?.asset?.verification, ) options.logger.error(`Error: Minimum is ${renderedMinimum}`) continue diff --git a/ironfish-cli/src/utils/transaction.ts b/ironfish-cli/src/utils/transaction.ts index af41fec15c..973aa56846 100644 --- a/ironfish-cli/src/utils/transaction.ts +++ b/ironfish-cli/src/utils/transaction.ts @@ -120,7 +120,8 @@ export async function renderUnsignedTransactionDetails( const renderedAmount = CurrencyUtils.render( mint.value, false, - assetLookup[mint.asset.id().toString('hex')], + mint.asset.id().toString('hex'), + assetLookup[mint.asset.id().toString('hex')].verification, ) logger.log(`Asset ID: ${mint.asset.id().toString('hex')}`) logger.log(`Name: ${mint.asset.name().toString('utf8')}`) @@ -152,7 +153,8 @@ export async function renderUnsignedTransactionDetails( const renderedAmount = CurrencyUtils.render( burn.value, false, - assetLookup[burn.assetId.toString('hex')], + burn.assetId.toString('hex'), + assetLookup[burn.assetId.toString('hex')].verification, ) logger.log(`Asset ID: ${burn.assetId.toString('hex')}`) logger.log(`Amount: ${renderedAmount}`) @@ -182,7 +184,12 @@ export async function renderUnsignedTransactionDetails( } logger.log('') - const renderedAmount = CurrencyUtils.render(note.value, true, assetLookup[note.assetId]) + const renderedAmount = CurrencyUtils.render( + note.value, + true, + note.assetId, + assetLookup[note.assetId].verification, + ) logger.log(`Amount: ${renderedAmount}`) logger.log(`Memo: ${note.memo}`) logger.log(`Recipient: ${note.owner}`) @@ -201,7 +208,12 @@ export async function renderUnsignedTransactionDetails( } logger.log('') - const renderedAmount = CurrencyUtils.render(note.value, true, assetLookup[note.assetId]) + const renderedAmount = CurrencyUtils.render( + note.value, + true, + note.assetId, + assetLookup[note.assetId].verification, + ) logger.log(`Amount: ${renderedAmount}`) logger.log(`Memo: ${note.memo}`) logger.log(`Recipient: ${note.owner}`) @@ -231,7 +243,7 @@ export function displayTransactionSummary( ): void { logger = logger ?? createRootLogger() - const amountString = CurrencyUtils.render(amount, true, asset) + const amountString = CurrencyUtils.render(amount, true, asset.id, asset.verification) const feeString = CurrencyUtils.render(transaction.fee, true) const summary = `\