feat(gui): Display markup on "waiting for bitcoin deposit page" (#209)

* feat(gui): Display markup on "waiting for bitcoin deposit page"
* feat: Enable fetching of fiat rates by default
This commit is contained in:
binarybaron 2024-11-26 14:18:20 +01:00 committed by GitHub
parent bdb406a299
commit e336051c1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 49 additions and 21 deletions

View file

@ -6,7 +6,7 @@ import {
MoneroBitcoinExchangeRate, MoneroBitcoinExchangeRate,
SatsAmount, SatsAmount,
} from "renderer/components/other/Units"; } from "renderer/components/other/Units";
import { satsToBtc, secondsToDays } from "utils/conversionUtils"; import { getMarkup, satsToBtc, secondsToDays } from "utils/conversionUtils";
import { isMakerOutdated } from 'utils/multiAddrUtils'; import { isMakerOutdated } from 'utils/multiAddrUtils';
import WarningIcon from '@material-ui/icons/Warning'; import WarningIcon from '@material-ui/icons/Warning';
import { useAppSelector } from "store/hooks"; import { useAppSelector } from "store/hooks";
@ -43,12 +43,12 @@ const useStyles = makeStyles((theme) => ({
*/ */
function MakerMarkupChip({ maker }: { maker: ExtendedMakerStatus }) { function MakerMarkupChip({ maker }: { maker: ExtendedMakerStatus }) {
const marketExchangeRate = useAppSelector(s => s.rates?.xmrBtcRate); const marketExchangeRate = useAppSelector(s => s.rates?.xmrBtcRate);
if (marketExchangeRate === null) if (marketExchangeRate == null)
return null; return null;
const makerExchangeRate = satsToBtc(maker.price); const makerExchangeRate = satsToBtc(maker.price);
/** The markup of the exchange rate compared to the market rate in percent */ /** The markup of the exchange rate compared to the market rate in percent */
const markup = (makerExchangeRate - marketExchangeRate) / marketExchangeRate * 100; const markup = getMarkup(makerExchangeRate, marketExchangeRate);
return ( return (
<Tooltip title="The markup this maker charges compared to centralized markets. A lower markup means that you get more Monero for your Bitcoin."> <Tooltip title="The markup this maker charges compared to centralized markets. A lower markup means that you get more Monero for your Bitcoin.">

View file

@ -58,7 +58,7 @@ export default function WaitingForBtcDepositPage({
<li> <li>
All Bitcoin sent to this this address will converted into All Bitcoin sent to this this address will converted into
Monero at an exchance rate of{" "} Monero at an exchance rate of{" "}
<MoneroSatsExchangeRate rate={quote.price} /> <MoneroSatsExchangeRate rate={quote.price} displayMarkup={true} />
</li> </li>
<li> <li>
The network fee of{" "} The network fee of{" "}

View file

@ -1,6 +1,6 @@
import { Tooltip } from "@material-ui/core"; import { Tooltip } from "@material-ui/core";
import { useAppSelector } from "store/hooks"; import { useAppSelector } from "store/hooks";
import { piconerosToXmr, satsToBtc } from "utils/conversionUtils"; import { getMarkup, piconerosToXmr, satsToBtc } from "utils/conversionUtils";
type Amount = number | null | undefined; type Amount = number | null | undefined;
@ -9,11 +9,13 @@ export function AmountWithUnit({
unit, unit,
fixedPrecision, fixedPrecision,
exchangeRate, exchangeRate,
parenthesisText = null,
}: { }: {
amount: Amount; amount: Amount;
unit: string; unit: string;
fixedPrecision: number; fixedPrecision: number;
exchangeRate?: Amount; exchangeRate?: Amount;
parenthesisText?: string;
}) { }) {
const fetchFiatPrices = useAppSelector((state) => state.settings.fetchFiatPrices); const fetchFiatPrices = useAppSelector((state) => state.settings.fetchFiatPrices);
const fiatCurrency = useAppSelector((state) => state.settings.fiatCurrency); const fiatCurrency = useAppSelector((state) => state.settings.fiatCurrency);
@ -29,6 +31,7 @@ export function AmountWithUnit({
? Number.parseFloat(amount.toFixed(fixedPrecision)) ? Number.parseFloat(amount.toFixed(fixedPrecision))
: "?"}{" "} : "?"}{" "}
{unit} {unit}
{parenthesisText != null ? ` (${parenthesisText})` : null}
</span> </span>
</Tooltip> </Tooltip>
); );
@ -64,25 +67,44 @@ export function MoneroAmount({ amount }: { amount: Amount }) {
); );
} }
export function MoneroBitcoinExchangeRate( export function MoneroBitcoinExchangeRate({
state: { rate: Amount } | { satsAmount: number; piconeroAmount: number }, rate,
) { displayMarkup = false,
if ("rate" in state) { }: {
rate: Amount;
displayMarkup?: boolean;
}) {
const marketRate = useAppSelector((state) => state.rates?.xmrBtcRate);
const markup = (displayMarkup && marketRate != null) ? `${getMarkup(rate, marketRate).toFixed(2)}% markup` : null;
return ( return (
<AmountWithUnit amount={state.rate} unit="BTC/XMR" fixedPrecision={8} /> <AmountWithUnit
amount={rate}
unit="BTC/XMR"
fixedPrecision={8}
parenthesisText={markup}
/>
); );
} }
const rate = export function MoneroBitcoinExchangeRateFromAmounts({
satsToBtc(state.satsAmount) / piconerosToXmr(state.piconeroAmount); satsAmount,
piconeroAmount,
displayMarkup = false,
}: {
satsAmount: number;
piconeroAmount: number;
displayMarkup?: boolean;
}) {
const rate = satsToBtc(satsAmount) / piconerosToXmr(piconeroAmount);
return <AmountWithUnit amount={rate} unit="BTC/XMR" fixedPrecision={8} />; return <MoneroBitcoinExchangeRate rate={rate} displayMarkup={displayMarkup} />;
} }
export function MoneroSatsExchangeRate({ rate }: { rate: Amount }) { export function MoneroSatsExchangeRate({ rate, displayMarkup = false }: { rate: Amount, displayMarkup?: boolean }) {
const btc = satsToBtc(rate); const btc = satsToBtc(rate);
return <AmountWithUnit amount={btc} unit="BTC/XMR" fixedPrecision={6} />; return <MoneroBitcoinExchangeRate rate={btc} displayMarkup={displayMarkup} />;
} }
export function SatsAmount({ amount }: { amount: Amount }) { export function SatsAmount({ amount }: { amount: Amount }) {

View file

@ -14,6 +14,7 @@ import ActionableMonospaceTextBox from "renderer/components/other/ActionableMono
import MonospaceTextBox from "renderer/components/other/MonospaceTextBox"; import MonospaceTextBox from "renderer/components/other/MonospaceTextBox";
import { import {
MoneroBitcoinExchangeRate, MoneroBitcoinExchangeRate,
MoneroBitcoinExchangeRateFromAmounts,
PiconeroAmount, PiconeroAmount,
SatsAmount, SatsAmount,
} from "renderer/components/other/Units"; } from "renderer/components/other/Units";
@ -78,7 +79,7 @@ export default function HistoryRowExpanded({
<TableRow> <TableRow>
<TableCell>Exchange Rate</TableCell> <TableCell>Exchange Rate</TableCell>
<TableCell> <TableCell>
<MoneroBitcoinExchangeRate <MoneroBitcoinExchangeRateFromAmounts
satsAmount={swap.btc_amount} satsAmount={swap.btc_amount}
piconeroAmount={swap.xmr_amount} piconeroAmount={swap.xmr_amount}
/> />

View file

@ -96,7 +96,7 @@ const initialState: SettingsState = {
} }
}, },
theme: Theme.Darker, theme: Theme.Darker,
fetchFiatPrices: false, fetchFiatPrices: true,
fiatCurrency: FiatCurrency.Usd, fiatCurrency: FiatCurrency.Usd,
}; };

View file

@ -70,3 +70,8 @@ export function rendezvousSellerToMakerStatus(
export function bytesToMb(bytes: number): number { export function bytesToMb(bytes: number): number {
return bytes / (1024 * 1024); return bytes / (1024 * 1024);
} }
/// Get the markup of a maker's exchange rate compared to the market rate in percent
export function getMarkup(makerPrice: number, marketPrice: number): number {
return (makerPrice - marketPrice) / marketPrice * 100;
}