Skip to content

Commit

Permalink
feat: shows undefined fees inclusion/total with a dash.
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitdevos committed May 10, 2024
1 parent 44c5a44 commit 41b342a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/common/AmountFormat.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LgntFormatter, Lgnt, Numbers } from "@logion/node-api";

export default function AmountFormat(props: { amount?: Lgnt | undefined, decimals?: number, unit?: Numbers.UnitPrefix }) {
export default function AmountFormat(props: { amount?: Lgnt | undefined, decimals?: number, unit?: Numbers.UnitPrefix, undefinedText?: string }) {

if(props.amount) {
const unit = props.unit ? props.unit : toUnit(props.amount);
Expand All @@ -9,7 +9,7 @@ export default function AmountFormat(props: { amount?: Lgnt | undefined, decimal
<span>{ formatter.format(props.amount) }</span>
);
} else {
return <span></span>
return <span>{ props.undefinedText }</span>
}
}

Expand Down
34 changes: 17 additions & 17 deletions src/loc/fees/EstimatedFees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export default function EstimatedFees(props: Props) {
return props.otherFeesPaidBy !== undefined || props.inclusionFeePaidBy !== undefined;
}, [ props.otherFeesPaidBy, props.inclusionFeePaidBy ]);

if(!props.fees) {
return null;
}
const fees = props.fees;

const className = customClassName("EstimatedFees", props.centered === true ? "centered-table" : undefined);
return (
Expand All @@ -34,84 +32,85 @@ export default function EstimatedFees(props: Props) {
<td>Blockchain record</td>
<td>
<AmountFormat
amount={ props.fees.inclusionFee }
amount={ fees?.inclusionFee }
unit={ Numbers.NONE }
decimals={4}
undefinedText="-"
/>
</td>
{ showPaidBy && <td>{ props.inclusionFeePaidBy || "" }</td> }
</tr>
{ props.fees.storageFee !== undefined &&
{ fees?.storageFee !== undefined &&
<tr>
<td>File storage</td>
<td>
<AmountFormat
amount={ props.fees.storageFee }
amount={ fees.storageFee }
unit={ Numbers.NONE }
decimals={4}
/>
</td>
{ showPaidBy && <td>{ props.otherFeesPaidBy || "" }</td> }
</tr>
}
{ props.fees.legalFee !== undefined &&
{ fees?.legalFee !== undefined &&
<tr>
<td>Legal fee</td>
<td>
<AmountFormat
amount={ props.fees.legalFee }
amount={ fees.legalFee }
unit={ Numbers.NONE }
decimals={4}
/>
</td>
{ showPaidBy && <td>{ props.otherFeesPaidBy || "" }</td> }
</tr>
}
{ props.fees.certificateFee !== undefined &&
{ fees?.certificateFee !== undefined &&
<tr>
<td>Certificate fee</td>
<td>
<AmountFormat
amount={ props.fees.certificateFee }
amount={ fees.certificateFee }
unit={ Numbers.NONE }
decimals={4}
/>
</td>
{ showPaidBy && <td>{ props.otherFeesPaidBy || "" }</td> }
</tr>
}
{ props.fees.valueFee !== undefined &&
{ fees?.valueFee !== undefined &&
<tr>
<td>Value fee</td>
<td>
<AmountFormat
amount={ props.fees.valueFee }
amount={ fees.valueFee }
unit={ Numbers.NONE }
decimals={4}
/>
</td>
{ showPaidBy && <td>{ props.otherFeesPaidBy || "" }</td> }
</tr>
}
{ props.fees.collectionItemFee !== undefined &&
{ fees?.collectionItemFee !== undefined &&
<tr>
<td>Collection item fee</td>
<td>
<AmountFormat
amount={ props.fees.collectionItemFee }
amount={ fees.collectionItemFee }
unit={ Numbers.NONE }
decimals={4}
/>
</td>
{ showPaidBy && <td>{ props.otherFeesPaidBy || "" }</td> }
</tr>
}
{ props.fees.tokensRecordFee !== undefined &&
{ fees?.tokensRecordFee !== undefined &&
<tr>
<td>Tokens record fee</td>
<td>
<AmountFormat
amount={ props.fees.tokensRecordFee }
amount={ fees.tokensRecordFee }
unit={ Numbers.NONE }
decimals={4}
/>
Expand All @@ -123,9 +122,10 @@ export default function EstimatedFees(props: Props) {
<td>Total</td>
<td>
<AmountFormat
amount={ props.fees.totalFee }
amount={ fees?.totalFee }
unit={ Numbers.NONE }
decimals={4}
undefinedText="-"
/>
</td>
{ showPaidBy && <td></td> }
Expand Down
10 changes: 10 additions & 0 deletions src/loc/fees/__snapshots__/EstimatedFees.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exports[`EstimatedFees renders fees with certificate 1`] = `
}
}
decimals={4}
undefinedText="-"
unit={
Object {
"symbol": "",
Expand Down Expand Up @@ -63,6 +64,7 @@ exports[`EstimatedFees renders fees with certificate 1`] = `
}
}
decimals={4}
undefinedText="-"
unit={
Object {
"symbol": "",
Expand Down Expand Up @@ -98,6 +100,7 @@ exports[`EstimatedFees renders fees with legal 1`] = `
}
}
decimals={4}
undefinedText="-"
unit={
Object {
"symbol": "",
Expand Down Expand Up @@ -140,6 +143,7 @@ exports[`EstimatedFees renders fees with legal 1`] = `
}
}
decimals={4}
undefinedText="-"
unit={
Object {
"symbol": "",
Expand Down Expand Up @@ -175,6 +179,7 @@ exports[`EstimatedFees renders fees with storage 1`] = `
}
}
decimals={4}
undefinedText="-"
unit={
Object {
"symbol": "",
Expand Down Expand Up @@ -217,6 +222,7 @@ exports[`EstimatedFees renders fees with storage 1`] = `
}
}
decimals={4}
undefinedText="-"
unit={
Object {
"symbol": "",
Expand Down Expand Up @@ -252,6 +258,7 @@ exports[`EstimatedFees renders fees with storage and paid by 1`] = `
}
}
decimals={4}
undefinedText="-"
unit={
Object {
"symbol": "",
Expand Down Expand Up @@ -300,6 +307,7 @@ exports[`EstimatedFees renders fees with storage and paid by 1`] = `
}
}
decimals={4}
undefinedText="-"
unit={
Object {
"symbol": "",
Expand Down Expand Up @@ -336,6 +344,7 @@ exports[`EstimatedFees renders fees without storage 1`] = `
}
}
decimals={4}
undefinedText="-"
unit={
Object {
"symbol": "",
Expand All @@ -357,6 +366,7 @@ exports[`EstimatedFees renders fees without storage 1`] = `
}
}
decimals={4}
undefinedText="-"
unit={
Object {
"symbol": "",
Expand Down

0 comments on commit 41b342a

Please sign in to comment.