Skip to content

Commit

Permalink
Merge branch 'master' into fix/graceful-missing-permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Dec 24, 2024
2 parents b1a19ec + 5a40ba2 commit f350d16
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 172 deletions.
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Alby Go",
"slug": "alby-mobile",
"version": "1.7.2",
"scheme": ["lightning", "bitcoin", "alby"],
"scheme": ["lightning", "bitcoin", "alby", "nostr+walletconnect"],
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "automatic",
Expand Down
2 changes: 1 addition & 1 deletion app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Slot, SplashScreen } from "expo-router";
import { StatusBar } from "expo-status-bar";
import { swrConfiguration } from "lib/swr";
import * as React from "react";
import { SafeAreaView } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import Toast from "react-native-toast-message";
import { SWRConfig } from "swr";
import { toastConfig } from "~/components/ToastConfig";
Expand Down
11 changes: 10 additions & 1 deletion components/DualCurrencyInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SATS_REGEX,
} from "~/lib/constants";
import { useAppStore } from "~/lib/state/appStore";
import { cn } from "~/lib/utils";
import { RefreshCw } from "./Icons";
import { Input } from "./ui/input";
import { Text } from "./ui/text";
Expand All @@ -17,13 +18,17 @@ type DualCurrencyInputProps = {
setAmount(amount: string): void;
autoFocus?: boolean;
readOnly?: boolean;
max?: number;
min?: number;
};

export function DualCurrencyInput({
amount,
setAmount,
autoFocus = false,
readOnly = false,
max,
min,
}: DualCurrencyInputProps) {
const getFiatAmount = useGetFiatAmount();
const getSatsAmount = useGetSatsAmount();
Expand Down Expand Up @@ -61,7 +66,11 @@ export function DualCurrencyInput({
return (
<View className="w-full flex flex-col items-center justify-center gap-5">
<Input
className="w-full border-transparent bg-transparent text-center mt-3"
className={cn(
"w-full border-transparent bg-transparent text-center mt-3",
((max && Number(amount) > max) || (min && Number(amount) < min)) &&
"text-destructive",
)}
placeholder="0"
keyboardType={inputMode === "sats" ? "number-pad" : "decimal-pad"}
value={inputMode === "sats" ? amount : fiatAmount}
Expand Down
20 changes: 19 additions & 1 deletion lib/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { router } from "expo-router";
import { BOLT11_REGEX } from "./constants";
import { lnurl as lnurlLib } from "./lnurl";

const SUPPORTED_SCHEMES = ["lightning:", "bitcoin:", "alby:"];
const SUPPORTED_SCHEMES = [
"lightning:",
"bitcoin:",
"alby:",
"nostr+walletconnect:",
];

// Register exp scheme for testing during development
// https://docs.expo.dev/guides/linking/#creating-urls
Expand All @@ -22,6 +27,19 @@ export const handleLink = async (url: string) => {

if (SUPPORTED_SCHEMES.indexOf(parsedUrl.protocol) > -1) {
let { username, hostname, protocol, pathname, search } = parsedUrl;
if (parsedUrl.protocol === "nostr+walletconnect:") {
if (router.canDismiss()) {
router.dismissAll();
}
console.info("Navigating to wallet setup");
router.push({
pathname: "/settings/wallets/setup",
params: {
nwcUrl: protocol + hostname + search,
},
});
return;
}

if (parsedUrl.protocol === "exp:") {
if (!parsedUrl.pathname) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"react-native-get-random-values": "^1.9.0",
"react-native-qrcode-svg": "^6.3.1",
"react-native-reanimated": "~3.16.1",
"react-native-safe-area-context": "4.12.0",
"react-native-safe-area-context": "5.0.0",
"react-native-screens": "~4.1.0",
"react-native-svg": "15.8.0",
"react-native-toast-message": "^2.2.0",
Expand Down
60 changes: 25 additions & 35 deletions pages/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ type Boostagram = {
name: string;
podcast: string;
url: string;
episode?: string;
itemID?: string;
ts?: string;
episode?: string | number;
itemID?: string | number;
ts?: string | number;
message?: string;
sender_id: string;
sender_id: string | number;
sender_name: string;
time: string;
action: string;
Expand Down Expand Up @@ -204,40 +204,30 @@ function TransactionDetailRow(props: {
}

function PodcastingInfo({ boost }: { boost: Boostagram }) {
const renderDetail = (title: string, content: any) => {
if (content === 0 || !!content) {
return <TransactionDetailRow title={title} content={String(content)} />;
}
return null;
};
return (
<>
{boost.message && (
<TransactionDetailRow title="Message" content={boost.message} />
)}
{boost.podcast && (
<TransactionDetailRow title="Podcast" content={boost.podcast} />
)}
{boost.episode && (
<TransactionDetailRow title="Episode" content={boost.episode} />
)}
{boost.action && (
<TransactionDetailRow title="Action" content={boost.action} />
)}
{boost.ts && (
<TransactionDetailRow title="Timestamp" content={boost.ts} />
)}
{boost.value_msat_total && (
<TransactionDetailRow
title="Total amount"
content={
Math.floor(boost.value_msat_total / 1000) +
(Math.floor(boost.value_msat_total / 1000) === 1 ? " sat" : " sats")
}
/>
)}
{boost.sender_name && (
<TransactionDetailRow title="Sender" content={boost.sender_name} />
)}
{boost.app_name && (
<TransactionDetailRow title="App" content={boost.app_name} />
{renderDetail("Message", boost.message)}
{renderDetail("Podcast", boost.podcast)}
{renderDetail("Episode", boost.episode)}
{renderDetail("Action", boost.action)}
{renderDetail("Timestamp", boost.ts)}
{renderDetail(
"Total amount",
boost.value_msat_total
? Math.floor(boost.value_msat_total / 1000) +
(Math.floor(boost.value_msat_total / 1000) === 1
? " sat"
: " sats")
: null,
)}
{renderDetail("Sender", boost.sender_name)}
{renderDetail("App", boost.app_name)}
</>
);
}

export default PodcastingInfo;
30 changes: 16 additions & 14 deletions pages/send/ConfirmPayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Invoice } from "@getalby/lightning-tools";

import { Link, router, useLocalSearchParams } from "expo-router";
import React from "react";
import { View } from "react-native";
import { Pressable, View } from "react-native";
import { TriangleAlert, ZapIcon } from "~/components/Icons";
import Loading from "~/components/Loading";
import { Receiver } from "~/components/Receiver";
Expand Down Expand Up @@ -119,19 +119,21 @@ export function ConfirmPayment() {
{transactions?.transactions.some(
(transaction) => transaction.state === "pending",
) && (
<Link href="/transactions" className="mb-6">
<Card className="w-full">
<CardContent className="flex flex-row items-center gap-4">
<TriangleAlert className="text-muted-foreground" />
<View className="flex flex-1 flex-col">
<CardTitle>One or more pending payments</CardTitle>
<CardDescription>
Please check your transaction list before paying to ensure
you do not make a payment twice.
</CardDescription>
</View>
</CardContent>
</Card>
<Link href="/transactions" className="mb-6" asChild>
<Pressable>
<Card className="w-full">
<CardContent className="flex flex-row items-center gap-4">
<TriangleAlert className="text-muted-foreground" />
<View className="flex flex-1 flex-col">
<CardTitle>One or more pending payments</CardTitle>
<CardDescription>
Please check your transaction list before paying to ensure
you do not make a payment twice.
</CardDescription>
</View>
</CardContent>
</Card>
</Pressable>
</Link>
)}
<Button
Expand Down
32 changes: 30 additions & 2 deletions pages/send/LNURLPay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Input } from "~/components/ui/input";
import { Text } from "~/components/ui/text";
import { errorToast } from "~/lib/errorToast";
import { LNURLPayServiceResponse, lnurl } from "~/lib/lnurl";
import { cn } from "~/lib/utils";

export function LNURLPay() {
const {
Expand All @@ -24,10 +25,17 @@ export function LNURLPay() {
};
const lnurlDetails: LNURLPayServiceResponse = JSON.parse(lnurlDetailsJSON);
const [isLoading, setLoading] = React.useState(false);
const [amount, setAmount] = React.useState(amountParam ?? 0);
const [amount, setAmount] = React.useState(amountParam ?? "");
const [comment, setComment] = React.useState("");
const [isAmountReadOnly, setAmountReadOnly] = React.useState(false);

const isAmountInvalid = React.useMemo(() => {
const min = Math.floor(lnurlDetails.minSendable / 1000);
const max = Math.floor(lnurlDetails.maxSendable / 1000);

return Number(amount) < min || Number(amount) > max;
}, [amount, lnurlDetails.minSendable, lnurlDetails.maxSendable]);

useEffect(() => {
// Handle fixed amount LNURLs
if (lnurlDetails.minSendable === lnurlDetails.maxSendable) {
Expand Down Expand Up @@ -76,7 +84,27 @@ export function LNURLPay() {
setAmount={setAmount}
readOnly={isAmountReadOnly}
autoFocus={!isAmountReadOnly && !amount}
min={Math.floor(lnurlDetails.minSendable / 1000)}
max={Math.floor(lnurlDetails.maxSendable / 1000)}
/>
<View className="w-full">
<Text
className={cn(
"text-muted-foreground text-center font-semibold2",
amount && isAmountInvalid ? "text-destructive" : "",
)}
>
Between{" "}
{new Intl.NumberFormat().format(
Math.floor(lnurlDetails.minSendable / 1000),
)}
{" and "}
{new Intl.NumberFormat().format(
Math.floor(lnurlDetails.maxSendable / 1000),
)}{" "}
sats
</Text>
</View>
<View className="w-full">
<Text className="text-muted-foreground text-center font-semibold2">
Comment
Expand All @@ -96,7 +124,7 @@ export function LNURLPay() {
size="lg"
className="flex flex-row gap-2"
onPress={requestInvoice}
disabled={isLoading}
disabled={isLoading || isAmountInvalid}
>
{isLoading && <Loading className="text-primary-foreground" />}
<Text>Next</Text>
Expand Down
Loading

0 comments on commit f350d16

Please sign in to comment.