diff --git a/src/components/jars/Jar.module.css b/src/components/jars/Jar.module.css
index 126bf799..b24d8b0a 100644
--- a/src/components/jars/Jar.module.css
+++ b/src/components/jars/Jar.module.css
@@ -54,15 +54,12 @@
- 1.5ch for the dot and spaces
*/
min-width: 11.5ch;
-
+ min-height: 1rem;
font-size: 0.8rem;
}
.frozen.jarBalance {
- --bs-code-color: var(--bs-blue);
- color: var(--bs-blue);
- font-size: 0.75rem;
- min-height: 1rem;
+ font-size: 0.7rem;
}
.selectableJarContainer {
diff --git a/src/components/jars/Jar.tsx b/src/components/jars/Jar.tsx
index cdf487a2..4def150e 100644
--- a/src/components/jars/Jar.tsx
+++ b/src/components/jars/Jar.tsx
@@ -129,16 +129,14 @@ const Jar = ({ index, balance, frozenBalance, fillLevel, isOpen = false }: JarPr
- {frozenBalance && frozenBalance > 0 ? (
- <>
-
-
- >
- ) : null}
+ {frozenBalance > 0 && (
+
+ )}
diff --git a/src/utils.test.ts b/src/utils.test.ts
index a2ab28f5..c10b5098 100644
--- a/src/utils.test.ts
+++ b/src/utils.test.ts
@@ -1,4 +1,12 @@
-import { shortenStringMiddle, percentageToFactor, factorToPercentage, toSemVer, UNKNOWN_VERSION } from './utils'
+import {
+ shortenStringMiddle,
+ percentageToFactor,
+ factorToPercentage,
+ toSemVer,
+ UNKNOWN_VERSION,
+ formatSats,
+ formatBtc,
+} from './utils'
describe('shortenStringMiddle', () => {
it('should shorten string in the middle', () => {
@@ -113,3 +121,35 @@ describe('toSemVer', () => {
expect(toSemVer('21million')).toBe(UNKNOWN_VERSION)
})
})
+
+describe('formatSats', () => {
+ it('should format given value as amount in sats', () => {
+ expect(formatSats(-1_000)).toBe('-1,000')
+ expect(formatSats(-21)).toBe('-21')
+ expect(formatSats(-1)).toBe('-1')
+ expect(formatSats(0)).toBe('0')
+ expect(formatSats(1)).toBe('1')
+ expect(formatSats(999)).toBe('999')
+ expect(formatSats(1_000)).toBe('1,000')
+ expect(formatSats(2099999997690000)).toBe('2,099,999,997,690,000')
+ expect(formatSats(2100000000000000)).toBe('2,100,000,000,000,000')
+ })
+})
+
+describe('formatBtc', () => {
+ it('should format given value as amount in BTC', () => {
+ expect(formatBtc(-1_000)).toBe('-1,000.00000000')
+ expect(formatBtc(-21)).toBe('-21.00000000')
+ expect(formatBtc(-1)).toBe('-1.00000000')
+ expect(formatBtc(0)).toBe('0.00000000')
+ expect(formatBtc(1)).toBe('1.00000000')
+ expect(formatBtc(123.03224961)).toBe('123.03224961')
+ expect(formatBtc(123.456)).toBe('123.45600000')
+ expect(formatBtc(1_000)).toBe('1,000.00000000')
+ expect(formatBtc(20999999.9769)).toBe('20,999,999.97690000')
+ expect(formatBtc(20999999.9769)).toBe('20,999,999.97690000')
+ expect(formatBtc(21000000)).toBe('21,000,000.00000000')
+ expect(formatBtc(21000000.0)).toBe('21,000,000.00000000')
+ expect(formatBtc(21000000.0)).toBe('21,000,000.00000000')
+ })
+})
diff --git a/src/utils.ts b/src/utils.ts
index 5f53de08..48b2e015 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -3,11 +3,13 @@ import { OfferType, WalletFileName } from './libs/JmWalletApi'
const BTC_FORMATTER = new Intl.NumberFormat('en-US', {
minimumIntegerDigits: 1,
minimumFractionDigits: 8,
+ maximumFractionDigits: 8,
})
const SATS_FORMATTER = new Intl.NumberFormat('en-US', {
minimumIntegerDigits: 1,
minimumFractionDigits: 0,
+ maximumFractionDigits: 0,
})
export const BTC: Unit = 'BTC'
@@ -32,27 +34,11 @@ export const btcToSats = (value: string) => Math.round(parseFloat(value) * 10000
export const satsToBtc = (value: string) => parseInt(value, 10) / 100000000
-export const formatBtc = (value: number) => {
- const decimalPoint = '\u002E'
- const nbHalfSpace = '\u202F'
+export const formatBtc = (value: number) => BTC_FORMATTER.format(value)
- const numberString = BTC_FORMATTER.format(value)
+export const formatSats = (value: number) => SATS_FORMATTER.format(value)
- const [integerPart, fractionalPart] = numberString.split(decimalPoint)
-
- const formattedFractionalPart = fractionalPart
- .split('')
- .map((char, idx) => (idx === 2 || idx === 5 ? `${nbHalfSpace}${char}` : char))
- .join('')
-
- return integerPart + decimalPoint + formattedFractionalPart
-}
-
-export const formatSats = (value: number) => {
- return SATS_FORMATTER.format(value)
-}
-
-export const shortenStringMiddle = (value: string, chars = 8, separator = '…') => {
+export const shortenStringMiddle = (value: string, chars = 8, separator = '\u2026' /* \u2026 = … */) => {
const prefixLength = Math.max(Math.floor(chars / 2), 1)
if (value.length <= prefixLength * 2) {
return `${value}`
@@ -116,12 +102,17 @@ export const setIntervalDebounced = (
callback: () => Promise,
delay: Milliseconds,
onTimerIdChanged: (timerId: NodeJS.Timer) => void,
+ onError: (error: any, loop: () => void) => void = (_, loop) => loop(),
) => {
;(function loop() {
onTimerIdChanged(
setTimeout(async () => {
- await callback()
- loop()
+ try {
+ await callback()
+ loop()
+ } catch (e: any) {
+ onError(e, loop)
+ }
}, delay),
)
})()
|