Skip to content
Closed
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
4 changes: 3 additions & 1 deletion app/features/receive/receive-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ export default function ReceiveInput() {
</button>

<LinkWithViewTransition
to={buildLinkWithSearchParams('/receive/scan')}
to={buildLinkWithSearchParams('/scan', {
selectedAccountId: receiveAccountId,
})}
transition="slideUp"
applyTo="newView"
>
Expand Down
62 changes: 0 additions & 62 deletions app/features/receive/receive-scanner.tsx

This file was deleted.

9 changes: 2 additions & 7 deletions app/features/send/resolve-destination.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { type DecodedBolt11, parseBolt11Invoice } from '~/lib/bolt11';
import { parseCashuPaymentRequest } from '~/lib/cashu';
import { isValidLightningAddress } from '~/lib/lnurl';
import type { Money } from '~/lib/money';
import { type Contact, isContact } from '../contacts/contact';
import { validateBolt11, validateLightningAddressFormat } from './validation';
Expand Down Expand Up @@ -33,10 +32,10 @@ type ResolveResult =
| { success: true; data: SendDestination }
| { success: false; error: string };

export async function resolveSendDestination(
export function resolveSendDestination(
input: string | Contact,
{ allowZeroAmountBolt11 = false }: { allowZeroAmountBolt11?: boolean } = {},
): Promise<ResolveResult> {
): ResolveResult {
if (isContact(input)) {
return {
success: true,
Expand All @@ -50,10 +49,6 @@ export async function resolveSendDestination(
}

if (validateLightningAddressFormat(input) === true) {
const isValid = await isValidLightningAddress(input);
if (!isValid) {
return { success: false, error: 'Invalid lightning address' };
}
return {
success: true,
data: {
Expand Down
6 changes: 4 additions & 2 deletions app/features/send/send-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function SendInput() {
};

const handleSelectDestination = async (destination: string | Contact) => {
const result = await selectDestination(destination);
const result = selectDestination(destination);
if (!result.success) {
toast({
title: 'Invalid destination',
Expand Down Expand Up @@ -241,7 +241,9 @@ export function SendInput() {
</button>

<LinkWithViewTransition
to={buildLinkWithSearchParams('/send/scan')}
to={buildLinkWithSearchParams('/scan', {
accountId: sendAccount.id,
})}
transition="slideUp"
applyTo="newView"
>
Expand Down
115 changes: 0 additions & 115 deletions app/features/send/send-scanner.tsx

This file was deleted.

17 changes: 8 additions & 9 deletions app/features/send/send-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,9 @@ type Actions = {
getSourceAccount: () => Account;
selectDestination: (
destination: string | Contact,
) => Promise<
) =>
| { success: true; data: DecodedDestination }
| { success: false; error: string }
>;
| { success: false; error: string };
clearDestination: () => void;
hasRequiredDestination: () => boolean;
proceedWithSend: (
Expand Down Expand Up @@ -256,9 +255,9 @@ export const createSendStore = ({
} as Partial<SendState>);
},

selectDestination: async (input) => {
selectDestination: (input) => {
const account = get().getSourceAccount();
const result = await resolveSendDestination(input, {
const result = resolveSendDestination(input, {
allowZeroAmountBolt11: account.type === 'spark',
});
if (!result.success) {
Expand All @@ -282,6 +281,9 @@ export const createSendStore = ({
: null;
const accountId = matched?.id ?? account.id;

const amount =
result.data.sendType === 'BOLT11_INVOICE' ? result.data.amount : null;

set({
accountId,
sendType,
Expand All @@ -294,10 +296,7 @@ export const createSendStore = ({
success: true,
data: {
type: result.data.sendType,
amount:
result.data.sendType === 'BOLT11_INVOICE'
? result.data.amount
: null,
amount,
},
};
},
Expand Down
10 changes: 0 additions & 10 deletions app/routes/_protected.receive.scan.tsx

This file was deleted.

10 changes: 6 additions & 4 deletions app/routes/_protected.scan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Button } from '~/components/ui/button';
import { classifyInput } from '~/features/scan';
import { validateBolt11 } from '~/features/send/validation';
import useIsPwa from '~/hooks/use-is-pwa';
import { useBuildLinkWithSearchParams } from '~/hooks/use-search-params-link';
import { useToast } from '~/hooks/use-toast';
import { readClipboard } from '~/lib/read-clipboard';
import { useNavigateWithViewTransition } from '~/lib/transitions';
Expand All @@ -20,6 +21,7 @@ export default function ScanPage() {
const navigate = useNavigateWithViewTransition();
const { toast } = useToast();
const isPwa = useIsPwa();
const buildLinkWithSearchParams = useBuildLinkWithSearchParams();

const handleInput = (raw: string) => {
const result = classifyInput(raw);
Expand All @@ -40,8 +42,8 @@ export default function ScanPage() {
// See https://github.com/remix-run/remix/discussions/10721
window.history.replaceState(null, '', hash);
navigate(
{ pathname: '/receive/cashu/token', hash },
{ transition: 'slideLeft', applyTo: 'newView' },
{ ...buildLinkWithSearchParams('/receive/cashu/token'), hash },
{ transition: 'slideDown', applyTo: 'oldView' },
);
return;
}
Expand All @@ -65,8 +67,8 @@ export default function ScanPage() {
// See https://github.com/remix-run/remix/discussions/10721
window.history.replaceState(null, '', hash);
navigate(
{ pathname: '/send', hash },
{ transition: 'slideLeft', applyTo: 'newView' },
{ ...buildLinkWithSearchParams('/send'), hash },
{ transition: 'slideDown', applyTo: 'oldView' },
);
};

Expand Down
10 changes: 0 additions & 10 deletions app/routes/_protected.send.scan.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions app/routes/_protected.send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { getQueryClient } from '~/features/shared/query-client';
import { toast } from '~/hooks/use-toast';
import type { Route } from './+types/_protected.send';

export async function clientLoader(): Promise<{
export function clientLoader(): {
initialDestination: SendDestination | null;
initialAccountId: string | null;
}> {
} {
const hash = window.location.hash.slice(1);
if (!hash) {
return { initialDestination: null, initialAccountId: null };
Expand All @@ -31,7 +31,7 @@ export async function clientLoader(): Promise<{
window.location.pathname + window.location.search,
);

const result = await resolveSendDestination(hash, {
const result = resolveSendDestination(hash, {
allowZeroAmountBolt11: true,
});

Expand Down
Loading