mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-08 17:10:07 +00:00
[API Node] User management (#3567)
Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Chenlei Hu <hcl@comfy.org>
This commit is contained in:
@@ -416,6 +416,49 @@ export function compareVersions(
|
||||
return 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a currency amount to Metronome's integer representation.
|
||||
* For USD, converts to cents (multiplied by 100).
|
||||
* For all other currencies (including custom pricing units), returns the amount as is.
|
||||
* This is specific to Metronome's API requirements.
|
||||
*
|
||||
* @param amount - The amount in currency to convert
|
||||
* @param currency - The currency to convert
|
||||
* @returns The amount in Metronome's integer format (cents for USD, base units for others)
|
||||
* @example
|
||||
* toMetronomeCurrency(1.23, 'usd') // returns 123 (cents)
|
||||
* toMetronomeCurrency(1000, 'jpy') // returns 1000 (yen)
|
||||
*/
|
||||
export function toMetronomeCurrency(amount: number, currency: string): number {
|
||||
if (currency === 'usd') {
|
||||
return Math.round(amount * 100)
|
||||
}
|
||||
return amount
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts Metronome's integer amount back to a formatted currency string.
|
||||
* For USD, converts from cents to dollars.
|
||||
* For all other currencies (including custom pricing units), returns the amount as is.
|
||||
* This is specific to Metronome's API requirements.
|
||||
*
|
||||
* @param amount - The amount in Metronome's integer format (cents for USD, base units for others)
|
||||
* @param currency - The currency to convert
|
||||
* @returns The formatted amount in currency with 2 decimal places for USD
|
||||
* @example
|
||||
* formatMetronomeCurrency(123, 'usd') // returns "1.23" (cents to USD)
|
||||
* formatMetronomeCurrency(1000, 'jpy') // returns "1000" (yen)
|
||||
*/
|
||||
export function formatMetronomeCurrency(
|
||||
amount: number,
|
||||
currency: string
|
||||
): string {
|
||||
if (currency === 'usd') {
|
||||
return (amount / 100).toFixed(2)
|
||||
}
|
||||
return amount.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a USD amount to microdollars (1/1,000,000 of a dollar).
|
||||
* This conversion is commonly used in financial systems to avoid floating-point precision issues
|
||||
|
||||
Reference in New Issue
Block a user