making rate more user friendly (#388)
This commit is contained in:
+6
-1
@@ -10,6 +10,7 @@ import {
|
||||
} from '../../../../../constants/theme';
|
||||
import ThemeImage from '../../../../../functions/CustomElements/themeImage';
|
||||
import displayCorrectDenomination from '../../../../../functions/displayCorrectDenomination';
|
||||
import { formatBalanceAmount } from '../../../../../functions';
|
||||
|
||||
export default function ChoosePaymentMethod({
|
||||
theme,
|
||||
@@ -42,7 +43,11 @@ export default function ChoosePaymentMethod({
|
||||
fiatStats,
|
||||
})
|
||||
: displayCorrectDenomination({
|
||||
amount: Number(dollarBalanceToken).toFixed(2),
|
||||
amount: formatBalanceAmount(
|
||||
Number(dollarBalanceToken).toFixed(2),
|
||||
false,
|
||||
masterInfoObject,
|
||||
),
|
||||
masterInfoObject: {
|
||||
...masterInfoObject,
|
||||
userBalanceDenomination: 'fiat',
|
||||
|
||||
@@ -18,6 +18,7 @@ import { useNodeContext } from '../../../../../../context-store/nodeContext';
|
||||
import GetThemeColors from '../../../../../hooks/themeColors';
|
||||
import ThemeImage from '../../../../../functions/CustomElements/themeImage';
|
||||
import { useUserBalanceContext } from '../../../../../../context-store/userBalanceContext';
|
||||
import { formatBalanceAmount } from '../../../../../functions';
|
||||
|
||||
export default function SelectPaymentMethod({
|
||||
convertedSendAmount,
|
||||
@@ -127,7 +128,11 @@ export default function SelectPaymentMethod({
|
||||
<ThemeText
|
||||
styles={styles.amountText}
|
||||
content={`${displayCorrectDenomination({
|
||||
amount: Number(dollarBalanceToken).toFixed(2),
|
||||
amount: formatBalanceAmount(
|
||||
Number(dollarBalanceToken).toFixed(2),
|
||||
false,
|
||||
masterInfoObject,
|
||||
),
|
||||
masterInfoObject: {
|
||||
...masterInfoObject,
|
||||
userBalanceDenomination: 'fiat',
|
||||
|
||||
@@ -960,6 +960,15 @@ export function dollarsToSats(dollars, currentPriceAinB) {
|
||||
return (dollars * DOLLAR_DECIMALS) / currentPriceAinB;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert exchangeRate to fiat price
|
||||
*@param {string|number} currentPriceAinB - Price of Bitcoin in dollars
|
||||
* @returns {number} Amount in sats
|
||||
*/
|
||||
export function currentPriceAinBToPriceDollars(currentPriceAInB) {
|
||||
return (currentPriceAInB * 100000000) / 1000000;
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// ERROR HANDLING UTILITIES
|
||||
// ============================================
|
||||
|
||||
@@ -39,7 +39,8 @@ import { useGlobalContacts } from '../../../context-store/globalContacts';
|
||||
import { useImageCache } from '../../../context-store/imageCache';
|
||||
import { KeyboardAwareScrollView } from 'react-native-keyboard-controller';
|
||||
import CustomSettingsTopBar from '../../functions/CustomElements/settingsTopBar';
|
||||
import { dollarsToSats } from '../../functions/spark/flashnet';
|
||||
import { currentPriceAinBToPriceDollars } from '../../functions/spark/flashnet';
|
||||
import { formatBalanceAmount } from '../../functions';
|
||||
|
||||
export default function ExpandedTx(props) {
|
||||
const { decodedAddedContacts } = useGlobalContacts();
|
||||
@@ -413,23 +414,22 @@ export default function ExpandedTx(props) {
|
||||
{showConversionLine &&
|
||||
renderInfoRow(
|
||||
t('constants.rate'),
|
||||
`${displayCorrectDenomination({
|
||||
amount: 1,
|
||||
`${APPROXIMATE_SYMBOL} ${displayCorrectDenomination({
|
||||
amount: formatBalanceAmount(
|
||||
Number(
|
||||
currentPriceAinBToPriceDollars(
|
||||
transaction.details.currentPriceAInB,
|
||||
),
|
||||
).toFixed(2),
|
||||
false,
|
||||
masterInfoObject,
|
||||
),
|
||||
masterInfoObject: {
|
||||
...masterInfoObject,
|
||||
userBalanceDenomination: 'fiat',
|
||||
},
|
||||
forceCurrency: 'USD',
|
||||
convertAmount: false,
|
||||
})} ${APPROXIMATE_SYMBOL} ${displayCorrectDenomination({
|
||||
amount: Number(
|
||||
dollarsToSats(1, transaction.details.currentPriceAInB),
|
||||
).toFixed(0),
|
||||
masterInfoObject: {
|
||||
...masterInfoObject,
|
||||
userBalanceDenomination: 'sats',
|
||||
},
|
||||
forceCurrency: 'USD',
|
||||
})}`,
|
||||
true,
|
||||
)}
|
||||
|
||||
@@ -526,10 +526,14 @@ function QrCode(props) {
|
||||
},
|
||||
forceCurrency: 'USD',
|
||||
fiatStats: fiatStats,
|
||||
amount: (
|
||||
satsToDollars(initialSendAmount, poolInfoRef?.currentPriceAInB) *
|
||||
(1 - (poolInfoRef.lpFeeBps / 100 + 1) / 100)
|
||||
).toFixed(2),
|
||||
amount: formatBalanceAmount(
|
||||
(
|
||||
satsToDollars(initialSendAmount, poolInfoRef?.currentPriceAInB) *
|
||||
(1 - (poolInfoRef.lpFeeBps / 100 + 1) / 100)
|
||||
).toFixed(2),
|
||||
false,
|
||||
masterInfoObject,
|
||||
),
|
||||
convertAmount: false,
|
||||
},
|
||||
)}`;
|
||||
|
||||
@@ -1020,7 +1020,6 @@ export default function SwapsPage() {
|
||||
...masterInfoObject,
|
||||
userBalanceDenomination: 'sats',
|
||||
},
|
||||
forceCurrency: 'USD',
|
||||
convertAmount: false,
|
||||
})} ${APPROXIMATE_SYMBOL} ${displayCorrectDenomination({
|
||||
amount: Number(satsToDollars(1, poolInfo.currentPriceAInB)).toFixed(
|
||||
@@ -1049,7 +1048,6 @@ export default function SwapsPage() {
|
||||
...masterInfoObject,
|
||||
userBalanceDenomination: 'sats',
|
||||
},
|
||||
forceCurrency: 'USD',
|
||||
})}`;
|
||||
|
||||
const formattedBitcoinPrice = displayCorrectDenomination({
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
checkClawbackEligibility,
|
||||
requestManualClawback,
|
||||
dollarsToSats,
|
||||
currentPriceAinBToPriceDollars,
|
||||
} from '../app/functions/spark/flashnet';
|
||||
import { useAppStatus } from './appStatus';
|
||||
import { useSparkWallet } from './sparkContext';
|
||||
@@ -725,7 +726,7 @@ export function FlashnetProvider({ children }) {
|
||||
}, [sparkInformation.didConnectToFlashnet]);
|
||||
|
||||
const swapUSDPriceDollars = useMemo(() => {
|
||||
return (poolInfo?.currentPriceAInB * 100000000) / 1000000;
|
||||
return currentPriceAinBToPriceDollars(poolInfo?.currentPriceAInB);
|
||||
}, [poolInfo?.currentPriceAInB]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user