Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/money-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface MoneyInputDisplayProps<C extends Currency = Currency> {
/** Raw input value from user (e.g., "1", "1.", "1.0") */
inputValue: string;
currency: C;
unit: CurrencyUnit<C>;
unit?: CurrencyUnit<C>;
locale?: string;
}

Expand Down
15 changes: 15 additions & 0 deletions app/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Money } from '~/lib/money';

/**
* Configures the Money class default settings for the Agicash wallet app.
*/
export function configureMoney() {
Money.configure({
currencies: {
BTC: {
baseUnit: 'sat', // Override BTC base unit from 'btc' to 'sat'
},
// USD not specified - uses all defaults
},
});
}
5 changes: 4 additions & 1 deletion app/entry.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import * as Sentry from '@sentry/react-router';
import { StrictMode, startTransition } from 'react';
import { hydrateRoot } from 'react-dom/client';
import { HydratedRouter } from 'react-router/dom';
import { configureMoney } from './configuration';
import { getEnvironment, isServedLocally } from './environment';
import { Money } from './lib/money/money';
import { Money } from './lib/money';

// Register Chrome DevTools custom formatter for Money class (dev only)
if (process.env.NODE_ENV === 'development') {
Expand All @@ -31,6 +32,8 @@ configure({
clientId: openSecretClientId,
});

configureMoney();

const sentryDsn = import.meta.env.VITE_SENTRY_DSN ?? '';
if (!sentryDsn) {
throw new Error('VITE_SENTRY_DSN is not set');
Expand Down
4 changes: 3 additions & 1 deletion app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import './instrument.server';
import { PassThrough } from 'node:stream';

import { createReadableStreamFromReadable } from '@react-router/node';
import * as Sentry from '@sentry/react-router';
import {
Expand All @@ -15,9 +14,12 @@ import type {
unstable_RouterContextProvider,
} from 'react-router';
import { ServerRouter } from 'react-router';
import { configureMoney } from './configuration';

export const streamTimeout = 5_000;

configureMoney();

function handleRequest(
request: Request,
responseStatusCode: number,
Expand Down
13 changes: 2 additions & 11 deletions app/features/receive/receive-cashu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
LinkWithViewTransition,
useNavigateWithViewTransition,
} from '~/lib/transitions';
import { getDefaultUnit } from '../shared/currencies';
import { MoneyWithConvertedAmount } from '../shared/money-with-converted-amount';
import type { CashuReceiveQuote } from './cashu-receive-quote';
import {
Expand Down Expand Up @@ -78,22 +77,14 @@ const AmountBreakdownCard = ({
<div className="flex items-center justify-between">
<p className="text-muted-foreground">Receive</p>
<div>
<MoneyDisplay
size="sm"
money={amount}
unit={getDefaultUnit(amount.currency)}
/>
<MoneyDisplay size="sm" money={amount} />
</div>
</div>
<div />
<div className="flex items-center justify-between">
<p className="text-muted-foreground">Fee</p>
<div>
<MoneyDisplay
size="sm"
money={mintingFee}
unit={getDefaultUnit(amount.currency)}
/>
<MoneyDisplay size="sm" money={mintingFee} />
</div>
</div>
</CardContent>
Expand Down
12 changes: 2 additions & 10 deletions app/features/receive/receive-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
toAccountSelectorOption,
} from '~/features/accounts/account-selector';
import { accountOfflineToast } from '~/features/accounts/utils';
import { getDefaultUnit } from '~/features/shared/currencies';
import useAnimation from '~/hooks/use-animation';
import { useMoneyInput } from '~/hooks/use-money-input';
import { useToast } from '~/hooks/use-toast';
Expand Down Expand Up @@ -49,12 +48,7 @@ const ConvertedMoneySwitcher = ({
className="flex items-center gap-1"
onClick={onSwitchInputCurrency}
>
<MoneyDisplay
money={money}
unit={getDefaultUnit(money.currency)}
size="sm"
variant="muted"
/>
<MoneyDisplay money={money} size="sm" variant="muted" />
<ArrowUpDown className="mb-1 text-muted-foreground" />
</button>
);
Expand All @@ -69,7 +63,6 @@ export default function ReceiveInput() {
const receiveAccountId = useReceiveStore((s) => s.accountId);
const receiveAccount = useAccount(receiveAccountId);
const receiveAmount = useReceiveStore((s) => s.amount);
const receiveCurrencyUnit = getDefaultUnit(receiveAccount.currency);
const setReceiveAccount = useReceiveStore((s) => s.setAccount);
const setReceiveAmount = useReceiveStore((s) => s.setAmount);
const { data: accounts } = useAccounts();
Expand All @@ -83,7 +76,7 @@ export default function ReceiveInput() {
handleNumberInput,
switchInputCurrency,
} = useMoneyInput({
initialRawInputValue: receiveAmount?.toString(receiveCurrencyUnit) || '0',
initialRawInputValue: receiveAmount?.toString() || '0',
initialInputCurrency: receiveAccount.currency,
initialOtherCurrency: receiveAccount.currency === 'BTC' ? 'USD' : 'BTC',
});
Expand Down Expand Up @@ -161,7 +154,6 @@ export default function ReceiveInput() {
<MoneyInputDisplay
inputValue={rawInputValue}
currency={inputValue.currency}
unit={getDefaultUnit(inputValue.currency)}
/>
</div>

Expand Down
8 changes: 2 additions & 6 deletions app/features/send/cashu-send-quote-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { getCashuUnit, sumProofs } from '~/lib/cashu';
import { type Currency, Money } from '~/lib/money';
import type { CashuAccount } from '../accounts/account';
import { type CashuProof, toProof } from '../accounts/cashu-account';
import { getDefaultUnit } from '../shared/currencies';
import { DomainError } from '../shared/error';
import type { CashuSendQuote, DestinationDetails } from './cashu-send-quote';
import {
Expand Down Expand Up @@ -167,12 +166,10 @@ export class CashuSendQuoteService {
unit: cashuUnit,
});

const unit = getDefaultUnit(account.currency);

const sumOfSendProofs = sumProofs(proofs);
if (sumOfSendProofs < amountWithLightningFee) {
throw new DomainError(
`Insufficient balance. Estimated total including fee is ${amountToReceive.add(lightningFeeReserve).toLocaleString({ unit })}.`,
`Insufficient balance. Estimated total including fee is ${amountToReceive.add(lightningFeeReserve).toLocaleString()}.`,
);
}

Expand Down Expand Up @@ -264,11 +261,10 @@ export class CashuSendQuoteService {
unit: cashuUnit,
});
const estimatedTotalFee = lightningFeeReserve.add(cashuFee);
const unit = getDefaultUnit(account.currency);

if (proofsToSendSum < totalAmountToSend) {
throw new DomainError(
`Insufficient balance. Estimated total including fee is ${amountToReceive.add(estimatedTotalFee).toLocaleString({ unit })}.`,
`Insufficient balance. Estimated total including fee is ${amountToReceive.add(estimatedTotalFee).toLocaleString()}.`,
);
}

Expand Down
9 changes: 2 additions & 7 deletions app/features/send/cashu-send-swap-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
useCashuTokenSwapService,
} from '../receive/cashu-token-swap-service';
import { getTokenHash } from '../shared/cashu';
import { getDefaultUnit } from '../shared/currencies';
import { DomainError } from '../shared/error';
import type { CashuSendSwap } from './cashu-send-swap';
import {
Expand Down Expand Up @@ -367,10 +366,8 @@ export class CashuSendSwapService {
currency: currency,
unit: cashuUnit,
});
const unit = getDefaultUnit(currency);

throw new DomainError(
`Insufficient balance. Total amount including fees is ${totalAmount.toLocaleString({ unit })}.`,
`Insufficient balance. Total amount including fees is ${totalAmount.toLocaleString()}.`,
);
}

Expand All @@ -393,10 +390,8 @@ export class CashuSendSwapService {
currency: currency,
unit: cashuUnit,
});
const unit = getDefaultUnit(currency);

throw new DomainError(
`Insufficient balance. Total amount including fees is ${totalAmount.toLocaleString({ unit })}.`,
`Insufficient balance. Total amount including fees is ${totalAmount.toLocaleString()}.`,
);
}

Expand Down
31 changes: 4 additions & 27 deletions app/features/send/send-confirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useToast } from '~/hooks/use-toast';
import { decodeBolt11 } from '~/lib/bolt11';
import type { Money } from '~/lib/money';
import { useNavigateWithViewTransition } from '~/lib/transitions';
import { getDefaultUnit } from '../shared/currencies';
import { DomainError } from '../shared/error';
import type { DestinationDetails } from './cashu-send-quote';
import { useInitiateCashuSendQuote } from './cashu-send-quote-hooks';
Expand Down Expand Up @@ -214,22 +213,12 @@ export const PayBolt11Confirmation = ({
{[
{
label: 'Recipient gets',
value: (
<MoneyDisplay
size="sm"
money={bolt11Quote.amountToReceive}
unit={getDefaultUnit(bolt11Quote.amountToReceive.currency)}
/>
),
value: <MoneyDisplay size="sm" money={bolt11Quote.amountToReceive} />,
},
{
label: 'Estimated fee',
value: (
<MoneyDisplay
size="sm"
money={bolt11Quote.estimatedTotalFee}
unit={getDefaultUnit(bolt11Quote.estimatedTotalFee.currency)}
/>
<MoneyDisplay size="sm" money={bolt11Quote.estimatedTotalFee} />
),
},
{ label: 'From', value: account.name },
Expand Down Expand Up @@ -304,23 +293,11 @@ export const CreateCashuTokenConfirmation = ({
{[
{
label: 'Recipient gets',
value: (
<MoneyDisplay
size="sm"
money={quote.amountRequested}
unit={getDefaultUnit(quote.amountRequested.currency)}
/>
),
value: <MoneyDisplay size="sm" money={quote.amountRequested} />,
},
{
label: 'Estimated fee',
value: (
<MoneyDisplay
size="sm"
money={quote.totalFee}
unit={getDefaultUnit(quote.totalFee.currency)}
/>
),
value: <MoneyDisplay size="sm" money={quote.totalFee} />,
},
{ label: 'From', value: account.name },
{ label: 'Sending', value: 'ecash' },
Expand Down
17 changes: 3 additions & 14 deletions app/features/send/send-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
} from '~/lib/transitions';
import { AddContactDrawer, ContactsList } from '../contacts';
import type { Contact } from '../contacts/contact';
import { getDefaultUnit } from '../shared/currencies';
import { DomainError, getErrorMessage } from '../shared/error';
import { useSendStore } from './send-provider';

Expand All @@ -70,12 +69,7 @@ const ConvertedMoneySwitcher = ({
onSwitchInputCurrency();
}}
>
<MoneyDisplay
money={money}
unit={getDefaultUnit(money.currency)}
size="sm"
variant="muted"
/>
<MoneyDisplay money={money} size="sm" variant="muted" />
<ArrowUpDown className="mb-1 text-muted-foreground" />
</button>
);
Expand All @@ -99,9 +93,6 @@ export function SendInput() {
const continueSend = useSendStore((s) => s.proceedWithSend);
const status = useSendStore((s) => s.status);

const sendAmountCurrencyUnit = sendAmount
? getDefaultUnit(sendAmount.currency)
: undefined;
const initialInputCurrency = sendAmount?.currency ?? sendAccount.currency;

const {
Expand All @@ -114,7 +105,7 @@ export function SendInput() {
switchInputCurrency,
setInputValue,
} = useMoneyInput({
initialRawInputValue: sendAmount?.toString(sendAmountCurrencyUnit) || '0',
initialRawInputValue: sendAmount?.toString() || '0',
initialInputCurrency: initialInputCurrency,
initialOtherCurrency: initialInputCurrency === 'BTC' ? 'USD' : 'BTC',
});
Expand Down Expand Up @@ -180,11 +171,10 @@ export function SendInput() {
let latestConvertedValue = convertedValue;

if (amount) {
const defaultUnit = getDefaultUnit(amount.currency);
({
newInputValue: latestInputValue,
newConvertedValue: latestConvertedValue,
} = setInputValue(amount.toString(defaultUnit), amount.currency));
} = setInputValue(amount.toString(), amount.currency));
}

await handleContinue(latestInputValue, latestConvertedValue);
Expand Down Expand Up @@ -214,7 +204,6 @@ export function SendInput() {
<MoneyInputDisplay
inputValue={rawInputValue}
currency={inputValue.currency}
unit={getDefaultUnit(inputValue.currency)}
/>
</div>

Expand Down
12 changes: 0 additions & 12 deletions app/features/shared/currencies.ts

This file was deleted.

Loading