Skip to content

Commit

Permalink
Use the new render function definition
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-if committed Apr 8, 2024
1 parent 589bb8b commit a5fad39
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 34 deletions.
8 changes: 4 additions & 4 deletions ironfish-cli/src/commands/wallet/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}
12 changes: 8 additions & 4 deletions ironfish-cli/src/commands/wallet/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}

Expand All @@ -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',
Expand Down
9 changes: 7 additions & 2 deletions ironfish-cli/src/commands/wallet/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down Expand Up @@ -254,7 +259,7 @@ export class Burn extends IronfishCommand {
fee: bigint,
account: string,
): Promise<boolean> {
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}`,
Expand Down
20 changes: 12 additions & 8 deletions ironfish-cli/src/commands/wallet/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')}`)
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion ironfish-cli/src/commands/wallet/notes/combine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 7 additions & 1 deletion ironfish-cli/src/commands/wallet/notes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
7 changes: 6 additions & 1 deletion ironfish-cli/src/commands/wallet/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')}`)
Expand Down
3 changes: 2 additions & 1 deletion ironfish-cli/src/commands/wallet/transaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 3 additions & 4 deletions ironfish-cli/src/commands/wallet/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
})
Expand Down
3 changes: 2 additions & 1 deletion ironfish-cli/src/utils/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`

Expand Down
6 changes: 4 additions & 2 deletions ironfish-cli/src/utils/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`
}
Expand Down Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions ironfish-cli/src/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')}`)
Expand Down Expand Up @@ -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}`)
Expand Down Expand Up @@ -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}`)
Expand All @@ -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}`)
Expand Down Expand Up @@ -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 = `\
Expand Down

0 comments on commit a5fad39

Please sign in to comment.