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 (
);
};
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 };
} );
export function getCurrencyFormatDecimal( number, currency = 'USD' ) {
const { precision } = getCurrencyDefaults( currency );
if ( 'number' !== typeof number ) {
number = parseFloat( number );
}
if ( isNaN( number ) ) {
return 0;
}
return Math.round( number * Math.pow( 10, precision ) ) / Math.pow( 10, precision );
}
{ translate( 'How can we help?' ) }
{ this.renderLiveChat() }
);
}
if ( surveyStep === steps.BUSINESS_AT_STEP ) {
return ;
}
if ( surveyStep === steps.UPGRADE_AT_STEP ) {
return ;
}
if ( surveyStep === steps.DOWNGRADE_STEP ) {
const { precision } = getCurrencyDefaults( purchase.currencyCode );
const planCost = parseFloat( this.props.downgradePlanPrice ).toFixed( precision );
return (
);
}
return (
<div>
{ translate( 'One more question before you go.' ) }
{ this.renderFreeformQuestion() }</div>
}
),
i18n.translate(
'The domain %(mappedDomain)s itself is not canceled. Only the connection between WordPress.com and ' +
'your domain is removed. %(mappedDomain)s is registered elsewhere and you can still use it with other sites.',
{
args: {
mappedDomain: includedDomainPurchase.meta,
},
}
)
);
showSupportLink = false;
} else if ( includedDomainPurchase && isDomainRegistration( includedDomainPurchase ) ) {
const { precision } = getCurrencyDefaults( purchase.currencyCode );
const planCostText =
purchase.currencySymbol +
parseFloat( purchase.refundAmount + includedDomainPurchase.costToUnbundle ).toFixed(
precision
);
if ( isRefundable( includedDomainPurchase ) ) {
text.push(
i18n.translate(
'Your plan included the custom domain %(domain)s. You can cancel your domain as well as the plan, but keep ' +
'in mind that when you cancel a domain you risk losing it forever, and visitors to your site may ' +
'experience difficulties accessing it.',
{
args: {
domain: includedDomainPurchase.meta,
},
}
validatePrice = () => {
const { currency, price } = this.props.attributes;
const { precision } = getCurrencyDefaults( currency );
if ( ! price || parseFloat( price ) === 0 ) {
this.setState( {
fieldPriceError: __(
'If you’re selling something, you need a price tag. Add yours here.',
'jetpack'
),
} );
return false;
}
if ( Number.isNaN( parseFloat( price ) ) ) {
this.setState( {
fieldPriceError: __( 'Invalid price', 'jetpack' ),
} );
return false;
renderCancellationEffect = () => {
const { purchase, translate, includedDomainPurchase, cancelBundledDomain } = this.props;
const overrides = {};
if (
cancelBundledDomain &&
includedDomainPurchase &&
isDomainRegistration( includedDomainPurchase )
) {
const { precision } = getCurrencyDefaults( purchase.currencyCode );
overrides.refundText =
purchase.currencySymbol +
parseFloat( purchase.refundAmount + includedDomainPurchase.amount ).toFixed( precision );
}
return (
<p>
{ cancellationEffectHeadline( purchase, translate ) }
{ cancellationEffectDetail( purchase, translate, overrides ) }
</p>
);
};