|
@@ -17,6 +17,7 @@ interface Props {
|
|
label?: React.ReactNode;
|
|
label?: React.ReactNode;
|
|
labelPost?: string;
|
|
labelPost?: string;
|
|
value?: Compact<any> | BN | string | null | 'all';
|
|
value?: Compact<any> | BN | string | null | 'all';
|
|
|
|
+ withCurrency?: boolean;
|
|
withSi?: boolean;
|
|
withSi?: boolean;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -24,21 +25,21 @@ interface Props {
|
|
const M_LENGTH = 6 + 1;
|
|
const M_LENGTH = 6 + 1;
|
|
const K_LENGTH = 3 + 1;
|
|
const K_LENGTH = 3 + 1;
|
|
|
|
|
|
-function format (value: Compact<any> | BN | string, currency: string, withSi?: boolean, _isShort?: boolean, labelPost?: string): React.ReactNode {
|
|
|
|
|
|
+function format (value: Compact<any> | BN | string, currency: string | null, withSi?: boolean, _isShort?: boolean, labelPost?: string): React.ReactNode {
|
|
const [prefix, postfix] = formatBalance(value, { forceUnit: '-', withSi: false }).split('.');
|
|
const [prefix, postfix] = formatBalance(value, { forceUnit: '-', withSi: false }).split('.');
|
|
const isShort = _isShort || (withSi && prefix.length >= K_LENGTH);
|
|
const isShort = _isShort || (withSi && prefix.length >= K_LENGTH);
|
|
|
|
|
|
if (prefix.length > M_LENGTH) {
|
|
if (prefix.length > M_LENGTH) {
|
|
// TODO Format with balance-postfix
|
|
// TODO Format with balance-postfix
|
|
- return `${formatBalance(value)}${labelPost || ''}`;
|
|
|
|
|
|
+ return `${formatBalance(value, { withUnit: !!currency })}${labelPost || ''}`;
|
|
}
|
|
}
|
|
|
|
|
|
- return <>{`${prefix}${isShort ? '' : '.'}`}{!isShort && (<><span className='ui--FormatBalance-postfix'>{`000${postfix || ''}`.slice(-3)}</span></>)} {`${currency}${labelPost || ''}`}</>;
|
|
|
|
|
|
+ return <>{`${prefix}${isShort ? '' : '.'}`}{!isShort && (<><span className='ui--FormatBalance-postfix'>{`000${postfix || ''}`.slice(-3)}</span></>)}{`${currency ? ` ${currency}` : ''}${labelPost || ''}`}</>;
|
|
}
|
|
}
|
|
|
|
|
|
-function FormatBalance ({ children, className = '', isShort, label, labelPost, value, withSi }: Props): React.ReactElement<Props> {
|
|
|
|
|
|
+function FormatBalance ({ children, className = '', isShort, label, labelPost, value, withCurrency = true, withSi }: Props): React.ReactElement<Props> {
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
- const [currency] = useState(formatBalance.getDefaults().unit);
|
|
|
|
|
|
+ const [currency] = useState(withCurrency ? formatBalance.getDefaults().unit : null);
|
|
|
|
|
|
// labelPost here looks messy, however we ensure we have one less text node
|
|
// labelPost here looks messy, however we ensure we have one less text node
|
|
return (
|
|
return (
|