Skip to content

Commit

Permalink
fix(receive): #1606 round up fiat minimum amount
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr committed Apr 1, 2024
1 parent 660e5cc commit 686246a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/components/Money.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type MoneyProps = {
color?: keyof IColors;
enableHide?: boolean; // if true and settings.hideBalance === true it will replace number with dots
sign?: string;
shouldRoundUp?: boolean;
style?: StyleProp<ViewStyle>;
testID?: string;
size?:
Expand Down Expand Up @@ -59,9 +60,10 @@ const Money = (props: MoneyProps): ReactElement => {
const symbolColor = props.symbolColor;
const hide = (props.enableHide ?? false) && hideBalance;
const sign = props.sign;
const shouldRoundUp = props.shouldRoundUp ?? false;
const testID = props.testID;

const dv = useDisplayValues(sats);
const dv = useDisplayValues(sats, shouldRoundUp);

const [Text, lineHeight, iconHeight, iconWidth, iconMargin] = useMemo(() => {
switch (size) {
Expand Down
15 changes: 13 additions & 2 deletions src/hooks/displayValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
exchangeRatesSelector,
} from '../store/reselect/wallet';

export const useDisplayValues = (satoshis: number): IDisplayValues => {
export const useDisplayValues = (
satoshis: number,
shouldRoundUpFiat = false,
): IDisplayValues => {
const { fiatSymbol } = useCurrency();
const selectedCurrency = useAppSelector(selectedCurrencySelector);
const denomination = useAppSelector(denominationSelector);
Expand All @@ -27,8 +30,16 @@ export const useDisplayValues = (satoshis: number): IDisplayValues => {
currency: selectedCurrency,
currencySymbol: fiatSymbol,
locale: 'en-US', //TODO get from native module
shouldRoundUpFiat,
});
}, [satoshis, denomination, selectedCurrency, exchangeRate, fiatSymbol]);
}, [
satoshis,
denomination,
selectedCurrency,
exchangeRate,
fiatSymbol,
shouldRoundUpFiat,
]);
};

/**
Expand Down
7 changes: 6 additions & 1 deletion src/screens/Wallets/Receive/ReceiveAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ const ReceiveAmount = ({
<Caption13Up style={styles.minimumText} color="gray1">
{t('minimum')}
</Caption13Up>
<Money sats={MINIMUM_AMOUNT} size="text02m" symbol={true} />
<Money
sats={MINIMUM_AMOUNT}
size="text02m"
symbol={true}
shouldRoundUp={true}
/>
</View>
<View style={styles.actionButtons}>
<View style={styles.actionButtonContainer}>
Expand Down
10 changes: 10 additions & 0 deletions src/utils/displayValues/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
EUnit,
} from '../../store/types/wallet';
import { IExchangeRates, mostUsedExchangeTickers } from '../exchange-rate';
import { roundUpToTwoDecimals } from '../helpers';
import {
defaultFiatDisplayValues,
defaultBitcoinDisplayValues,
Expand Down Expand Up @@ -74,13 +75,15 @@ export const getFiatDisplayValues = ({
currency,
currencySymbol,
locale = 'en-US',
shouldRoundUp = false,
}: {
satoshis: number;
exchangeRate?: number;
exchangeRates?: IExchangeRates;
currency?: string;
currencySymbol?: string;
locale?: string;
shouldRoundUp?: boolean;
}): IFiatDisplayValues => {
const denomination = getSettingsStore().denomination;

Expand Down Expand Up @@ -125,6 +128,10 @@ export const getFiatDisplayValues = ({
.to(currency)
.value();

if (shouldRoundUp) {
fiatValue = roundUpToTwoDecimals(fiatValue);
}

return getFiatDisplayValuesForFiat({
value: fiatValue,
currency,
Expand Down Expand Up @@ -221,13 +228,15 @@ export const getDisplayValues = ({
currency,
currencySymbol,
locale = 'en-US',
shouldRoundUpFiat = false,
}: {
satoshis: number;
denomination?: EDenomination;
exchangeRate?: number;
currency?: string;
currencySymbol?: string;
locale?: string;
shouldRoundUpFiat?: boolean;
}): IDisplayValues => {
if (!denomination) {
denomination = getSettingsStore().denomination;
Expand All @@ -243,6 +252,7 @@ export const getDisplayValues = ({
currency,
currencySymbol,
locale,
shouldRoundUp: shouldRoundUpFiat,
});

return {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ export const getLastWordInString = (phrase: string): string => {
}
};

export const roundUpToTwoDecimals = (num: number): number => {
return Math.ceil(num * 100) / 100;
};

/**
* Determines if the two arrays passed as params match.
* @param arr1
Expand Down

0 comments on commit 686246a

Please sign in to comment.