- Effective date: June 7, 2024 + Effective date: February 4, 2025
@@ -113,10 +113,9 @@ const TOS = (): ReactElement => (
- FUNDS TRANSFERRED USING CAVEMAN JUST-IN-TIME CHANNELS BY THIRD PARTIES - MAY NOT BE DELIVERED TO YOU BY THE THIRD PARTY. YOU ARE REFERRED TO - CLAUSE 9.3 OF THE TERMS AS TO SYNONYM’S LIABILITY FOR THIRD PARTY - SERVICES. + FUNDS TRANSFERRED USING JUST-IN-TIME CHANNELS BY THIRD PARTIES MAY NOT + BE DELIVERED TO YOU BY THE THIRD PARTY. YOU ARE REFERRED TO CLAUSE 9.3 + OF THE TERMS AS TO SYNONYM’S LIABILITY FOR THIRD PARTY SERVICES.
diff --git a/src/components/widgets/CalculatorWidget.tsx b/src/components/widgets/CalculatorWidget.tsx
index 79e445852..af29d2823 100644
--- a/src/components/widgets/CalculatorWidget.tsx
+++ b/src/components/widgets/CalculatorWidget.tsx
@@ -1,4 +1,4 @@
-import React, { ReactElement, useState } from 'react';
+import React, { ReactElement, useEffect, useState } from 'react';
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
import { useCurrency } from '../../hooks/displayValues';
@@ -9,6 +9,8 @@ import { fiatToBitcoinUnit } from '../../utils/conversion';
import { getDisplayValues } from '../../utils/displayValues';
import BaseWidget from './BaseWidget';
+const MAX_BITCOIN = 2_100_000_000_000_000; // Maximum bitcoin amount in sats
+
const CalculatorWidget = ({
isEditing = false,
style,
@@ -30,16 +32,58 @@ const CalculatorWidget = ({
return dv.fiatValue.toString();
});
+ // biome-ignore lint/correctness/useExhaustiveDependencies: update fiat amount when currency changes
+ useEffect(() => {
+ updateFiatAmount(bitcoinAmount);
+ }, [fiatTicker]);
+
const updateFiatAmount = (bitcoin: string) => {
- const amount = Number(bitcoin);
- const dv = getDisplayValues({ satoshis: amount, shouldRoundUpFiat: true });
+ // Remove leading zeros for positive numbers
+ const sanitizedBitcoin = bitcoin.replace(/^0+(?=\d)/, '');
+ const amount = Number(sanitizedBitcoin);
+ // Cap the amount at maximum bitcoin
+ const cappedAmount = Math.min(amount, MAX_BITCOIN);
+ const dv = getDisplayValues({
+ satoshis: cappedAmount,
+ shouldRoundUpFiat: true,
+ });
setFiatAmount(dv.fiatValue.toString());
+ // Update bitcoin amount if it was capped
+ if (cappedAmount !== amount) {
+ setBitcoinAmount(cappedAmount.toString());
+ }
};
const updateBitcoinAmount = (fiat: string) => {
- const amount = Number(fiat.replace(',', '.'));
+ // Remove leading zeros and handle decimal separator
+ const sanitizedFiat = fiat.replace(/^0+(?=\d)/, '');
+ // Only convert to number if it's not just a decimal point
+ const amount = sanitizedFiat === '.' ? 0 : Number(sanitizedFiat);
const sats = fiatToBitcoinUnit({ amount });
- setBitcoinAmount(sats.toString());
+ // Cap the amount at maximum bitcoin
+ const cappedSats = Math.min(sats, MAX_BITCOIN);
+ setBitcoinAmount(cappedSats.toString());
+ // Update fiat amount if bitcoin was capped
+ if (cappedSats !== sats) {
+ const dv = getDisplayValues({
+ satoshis: cappedSats,
+ shouldRoundUpFiat: true,
+ });
+ setFiatAmount(dv.fiatValue.toString());
+ }
+ };
+
+ const formatNumberWithSeparators = (value: string): string => {
+ const endsWithDecimal = value.endsWith('.');
+ const cleanNumber = value.replace(/[^\d.]/g, '');
+ const [integer, decimal] = cleanNumber.split('.');
+ const formattedInteger = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
+
+ if (decimal !== undefined) {
+ return `${formattedInteger}.${decimal}`;
+ }
+
+ return endsWithDecimal ? `${formattedInteger}.` : formattedInteger;
};
return (
@@ -56,13 +100,16 @@ const CalculatorWidget = ({