Skip to content

Commit

Permalink
[uma-bridge] Confirm quote (#13359)
Browse files Browse the repository at this point in the history
<img width="732" alt="Screenshot 2024-11-14 at 5 33 55 PM"
src="https://github.com/user-attachments/assets/23b890a4-71de-4f97-b02b-824695282bd0">
GitOrigin-RevId: b6ed44d00fb0a282409969ee72e43ebc5a6c997c
  • Loading branch information
coreymartin authored and Lightspark Eng committed Nov 15, 2024
1 parent ae008d8 commit 57b972d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/utils/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ function asNumber(value: string | number | null | undefined) {
return value || 0;
}

function getCurrencyAmount(currencyAmountArg: CurrencyAmountArg) {
export function getCurrencyAmount(currencyAmountArg: CurrencyAmountArg) {
let value = 0;
let unit = undefined;

Expand Down Expand Up @@ -536,6 +536,8 @@ export const abbrCurrencyUnit = (unit: CurrencyUnitType) => {
return "MSAT";
case CurrencyUnit.USD:
return "USD";
case CurrencyUnit.MXN:
return "MXN";
}
return "Unsupported CurrencyUnit";
};
Expand Down
31 changes: 19 additions & 12 deletions packages/ui/src/components/CurrencyAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
import {
CurrencyUnit,
formatCurrencyStr,
getCurrencyAmount,
isCurrencyMap,
mapCurrencyAmount,
} from "@lightsparkdev/core";
Expand All @@ -31,7 +32,7 @@ type CurrencyAmountProps = {

export function CurrencyAmount({
amount,
displayUnit = CurrencyUnit.SATOSHI,
displayUnit: displayUnitProp,
shortNumber = false,
showUnits = false,
includeEstimatedIndicator = false,
Expand All @@ -41,32 +42,38 @@ export function CurrencyAmount({
typography,
unitsPerBtc,
}: CurrencyAmountProps) {
const unit = displayUnit;

const amountMap = isCurrencyMap(amount)
? amount
: mapCurrencyAmount(amount, unitsPerBtc);
let displayUnit: CurrencyUnitType;
let amountMap: CurrencyMap;
if (isCurrencyMap(amount)) {
displayUnit = displayUnitProp || CurrencyUnit.SATOSHI;
amountMap = amount;
} else {
const resolvedCurrencyAmount = getCurrencyAmount(amount);
/* default to the currency amount unit if defined and displayUnit is not provided: */
displayUnit = displayUnitProp || resolvedCurrencyAmount.unit;
amountMap = mapCurrencyAmount(amount, unitsPerBtc);
}

const value = amountMap[unit];
const defaultFormattedNumber = amountMap.formatted[unit];
const value = amountMap[displayUnit];
const defaultFormattedNumber = amountMap.formatted[displayUnit];

/* There are just a few ways that CurrencyAmounts need to be formatted
throughout the UI. In general the default should always be used: */
let formattedNumber = defaultFormattedNumber;
if (shortNumber) {
formattedNumber = formatCurrencyStr(
{ value: Number(value), unit },
{ value: Number(value), unit: displayUnit },
{ precision: 1, compact: true },
);
} else if (fullPrecision) {
formattedNumber = formatCurrencyStr(
{ value: Number(value), unit },
{ value: Number(value), unit: displayUnit },
{ precision: "full" },
);
}

if (showUnits) {
formattedNumber += ` ${shorttext(unit, value)}`;
formattedNumber += ` ${shorttext(displayUnit, value)}`;
}

let content: string | ReactNode = formattedNumber;
Expand All @@ -81,7 +88,7 @@ export function CurrencyAmount({
return (
<StyledCurrencyAmount ml={ml} id={id}>
{includeEstimatedIndicator && "Est. "}
<CurrencyIcon unit={unit} />
<CurrencyIcon unit={displayUnit} />
{content}
</StyledCurrencyAmount>
);
Expand Down
22 changes: 17 additions & 5 deletions packages/ui/src/components/Flex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@ import { type ElementType, type ReactNode } from "react";

type FlexProps = {
center?: boolean | undefined;
justify?: "center" | "flex-start" | "flex-end" | "space-between" | undefined;
align?: "center" | "flex-start" | "flex-end" | "space-between" | undefined;
justify?:
| "stretch"
| "center"
| "flex-start"
| "flex-end"
| "space-between"
| undefined;
align?:
| "stretch"
| "center"
| "flex-start"
| "flex-end"
| "space-between"
| undefined;
children?: ReactNode;
as?: ElementType | undefined;
column?: boolean | undefined;
Expand Down Expand Up @@ -38,8 +50,8 @@ export function Flex({
mr,
ml,
}: FlexProps) {
const justify = justifyProp ? justifyProp : center ? "center" : "flex-start";
const align = alignProp ? alignProp : center ? "center" : "flex-start";
const justify = justifyProp ? justifyProp : center ? "center" : "stretch";
const align = alignProp ? alignProp : center ? "center" : "stretch";

return (
<StyledFlex
Expand Down Expand Up @@ -74,7 +86,7 @@ type StyledFlexProps = {
gap: number | undefined;
};

const StyledFlex = styled.div<StyledFlexProps>`
export const StyledFlex = styled.div<StyledFlexProps>`
display: flex;
text-overflow: ellipsis;
Expand Down

0 comments on commit 57b972d

Please sign in to comment.