Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const renderPriceField = ( { price, currency, ...props } ) => {
const { precision } = getCurrencyDefaults( currency.input.value );
// Tune the placeholder to the precision value: 0 -> '1', 1 -> '1.0', 2 -> '1.00'
const placeholder = precision > 0 ? padEnd( '1.', precision + 2, '0' ) : '1';
return (
);
};
}
const packageIds = Object.keys( selectedRates );
// Show the service name and cost when only one service/package exists
if ( 1 === packageIds.length ) {
const packageId = packageIds[ 0 ];
const selectedRate = selectedRates[ packageId ];
const packageRates = get( availableRates, [ packageId, 'rates' ], [] );
const rateInfo = find( packageRates, [ 'service_id', selectedRate ] );
if ( rateInfo ) {
return translate( '%(serviceName)s: %(rate)s', {
args: {
serviceName: rateInfo.title,
rate: formatCurrency( rateInfo.rate, 'USD' ),
},
} );
}
return '';
}
// Otherwise, just show the total
return translate( 'Total rate: %(total)s', {
args: {
total: formatCurrency( total, 'USD' ),
},
} );
};
getCurrencyList = SUPPORTED_CURRENCY_LIST.map( value => {
const { symbol } = getCurrencyDefaults( value );
// if symbol is equal to the code (e.g., 'CHF' === 'CHF'), don't duplicate it.
// trim the dot at the end, e.g., 'kr.' becomes 'kr'
const label = symbol === value ? value : `${ value } ${ trimEnd( symbol, '.' ) }`;
return { value, label };
} );
getCurrencyList = SUPPORTED_CURRENCY_LIST.map( value => {
const { symbol } = getCurrencyDefaults( value );
// if symbol is equal to the code (e.g., 'CHF' === 'CHF'), don't duplicate it.
// trim the dot at the end, e.g., 'kr.' becomes 'kr'
const label = symbol === value ? value : `${ value } ${ trimEnd( symbol, '.' ) }`;
return { value, label };
} );
getCurrencyList = SUPPORTED_CURRENCY_LIST.map( value => {
const { symbol } = getCurrencyDefaults( value );
// if symbol is equal to the code (e.g., 'CHF' === 'CHF'), don't duplicate it.
// trim the dot at the end, e.g., 'kr.' becomes 'kr'
const label = symbol === value ? value : `${ value } ${ trimEnd( symbol, '.' ) }`;
return { value, label };
} );
const VISUAL_CURRENCY_LIST = SUPPORTED_CURRENCY_LIST.map( code => {
const { symbol } = getCurrencyDefaults( code );
// if symbol is equal to the code (e.g., 'CHF' === 'CHF'), don't duplicate it.
// trim the dot at the end, e.g., 'kr.' becomes 'kr'
const label = symbol === code ? code : `${ code } ${ trimEnd( symbol, '.' ) }`;
return { code, label };
} );
formatPrice( price ) {
const priceObject = getCurrencyObject( price, this.props.currencyCode );
if ( price.toFixed( 5 ).split( '.' )[ 1 ] !== '00000' ) {
return `${ priceObject.symbol }${ priceObject.integer }${ priceObject.fraction }`;
}
return `${ priceObject.symbol }${ priceObject.integer }`;
}
renderPrice() {
if ( this.props.price === null ) {
return null;
}
const priceObject = getCurrencyObject( this.props.price, this.props.currencyCode );
let price = `${ priceObject.symbol }${ priceObject.integer }`;
if ( this.props.price.toFixed( 5 ).split( '.' )[ 1 ] !== '00000' ) {
price += priceObject.fraction;
}
return price;
}
}
formatPrice( price ) {
const priceObject = getCurrencyObject( price, this.props.currencyCode );
if ( price.toFixed( 5 ).split( '.' )[ 1 ] !== '00000' ) {
return `${ priceObject.symbol }${ priceObject.integer }${ priceObject.fraction }`;
}
return `${ priceObject.symbol }${ priceObject.integer }`;
}
renderPrice() {
if ( this.props.price === null ) {
return null;
}
const priceObject = getCurrencyObject( this.props.price, this.props.currencyCode );
let price = `${ priceObject.symbol }${ priceObject.integer }`;
if ( this.props.price.toFixed( 5 ).split( '.' )[ 1 ] !== '00000' ) {
price += priceObject.fraction;
}
return price;
}
}