Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reorder and use wallet name from lud16 #143

Merged
merged 21 commits into from
Oct 25, 2024
Merged
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 animations/Paid.tsx → animations/Tick.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import LottieView from "lottie-react-native";

export function Paid() {
export function Tick() {
return (
<LottieView
autoPlay
Expand Down
9 changes: 4 additions & 5 deletions app/(app)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { useRouteInfo } from 'expo-router/build/hooks';
export default function AppLayout() {
const { hasSession } = useSession();
const isOnboarded = useAppStore(store => store.isOnboarded);
const nwcClient = useAppStore(store => store.nwcClient);
const selectedWalletId = useAppStore((store) => store.selectedWalletId);
const wallets = useAppStore(store => store.wallets);
const route = useRouteInfo();
useHandleLinking();

Expand All @@ -22,10 +21,10 @@ export default function AppLayout() {
return <Redirect href="/unlock" />;
}

const connectionPage = `/settings/wallets/${selectedWalletId}/wallet-connection`;
const connectionPage = "/settings/wallets/setup";
// Check the current pathname to prevent redirect loops
if (!nwcClient && route.pathname !== connectionPage) {
console.log("No NWC client available, redirecting to wallet setup");
if (!wallets.length && route.pathname !== connectionPage) {
console.log("No wallets available, redirecting to setup");
return <Redirect href={connectionPage} />;
}

Expand Down
5 changes: 0 additions & 5 deletions app/(app)/settings/wallets/[id]/wallet-connection.js

This file was deleted.

5 changes: 0 additions & 5 deletions app/(app)/settings/wallets/new.js

This file was deleted.

5 changes: 5 additions & 0 deletions app/(app)/settings/wallets/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SetupWallet } from "../../../../pages/settings/wallets/SetupWallet";

export default function Page() {
return <SetupWallet />;
}
2 changes: 1 addition & 1 deletion components/Icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
CircleCheck,
TriangleAlert,
LogOut,
ArchiveRestore
ArchiveRestore,
} from "lucide-react-native";
import { cssInterop } from "nativewind";

Expand Down
9 changes: 9 additions & 0 deletions components/ToastConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export const toastConfig: ToastConfig = {
{text2 && <Text className="text-background text-center">{text2}</Text>}
</View>
),
info: ({ text1, text2, hide }) => (
<View className="bg-yellow-500 rounded-full px-6 py-3 mx-6">
<View className="flex flex-row gap-2 justify-center items-center">
<XCircle className="text-background" width={16} height={16} />
<Text className="text-background font-semibold2">{text1}</Text>
</View>
{text2 && <Text className="text-background text-center">{text2}</Text>}
</View>
),
error: ({ text1, text2, hide }) => (
<View className="bg-destructive rounded-xl px-6 py-3 mx-6">
<View className="flex flex-row gap-2 justify-center items-center">
Expand Down
29 changes: 5 additions & 24 deletions lib/state/appStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ interface AppState {
setUnlocked: (unlocked: boolean) => void;
setOnboarded: (isOnboarded: boolean) => void;
setNWCClient: (nwcClient: NWCClient | undefined) => void;
setNostrWalletConnectUrl(nostrWalletConnectUrl: string): void;
removeNostrWalletConnectUrl(): void;
updateCurrentWallet(wallet: Partial<Wallet>): void;
removeCurrentWallet(): void;
setFiatCurrency(fiatCurrency: string): void;
Expand Down Expand Up @@ -67,9 +65,6 @@ function loadWallets(): Wallet[] {
}
wallets.push(JSON.parse(walletJSON));
}
if (!wallets.length) {
wallets.push({});
}
return wallets;
}

Expand Down Expand Up @@ -111,13 +106,13 @@ export const useAppStore = create<AppState>()((set, get) => {
if (wallets.length <= 1) {
// set to initial wallet status
secureStorage.removeItem(hasOnboardedKey);
secureStorage.removeItem(getWalletKey(0));
secureStorage.setItem(selectedWalletIdKey, "0");
secureStorage.setItem(getWalletKey(0), JSON.stringify({}));
set({
nwcClient: undefined,
selectedWalletId: 0,
wallets: [{}],
isOnboarded: false,
wallets: [],
selectedWalletId: 0,
nwcClient: undefined,
});
return;
}
Expand Down Expand Up @@ -171,18 +166,6 @@ export const useAppStore = create<AppState>()((set, get) => {
set({ isOnboarded });
},
setNWCClient: (nwcClient) => set({ nwcClient }),
removeNostrWalletConnectUrl: () => {
updateCurrentWallet({
nostrWalletConnectUrl: undefined,
});

set({ nwcClient: undefined });
},
setNostrWalletConnectUrl: (nostrWalletConnectUrl) => {
updateCurrentWallet({
nostrWalletConnectUrl,
});
},
reneaaron marked this conversation as resolved.
Show resolved Hide resolved
setSecurityEnabled: (isEnabled) => {
secureStorage.setItem(isSecurityEnabledKey, isEnabled.toString());
set({
Expand All @@ -208,7 +191,6 @@ export const useAppStore = create<AppState>()((set, get) => {
set({
wallets: [...currentWallets, wallet],
selectedWalletId: newWalletId,
nwcClient: undefined,
});
},
addAddressBookEntry: (addressBookEntry: AddressBookEntry) => {
Expand Down Expand Up @@ -256,13 +238,12 @@ export const useAppStore = create<AppState>()((set, get) => {

// set to initial wallet status
secureStorage.setItem(selectedWalletIdKey, "0");
secureStorage.setItem(getWalletKey(0), JSON.stringify({}));

set({
nwcClient: undefined,
fiatCurrency: undefined,
selectedWalletId: 0,
wallets: [{}],
wallets: [],
addressBookEntries: [],
isSecurityEnabled: false,
isOnboarded: false,
Expand Down
3 changes: 0 additions & 3 deletions pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { View, Pressable, StyleSheet, TouchableOpacity } from "react-native";
import React, { useState } from "react";
import { useBalance } from "hooks/useBalance";
import { useAppStore } from "lib/state/appStore";
import {
Link, useFocusEffect
} from "expo-router";
Expand Down Expand Up @@ -29,8 +28,6 @@ enum BalanceState {
}

export function Home() {
const selectedWalletId = useAppStore((store) => store.selectedWalletId);
const nwcClient = useAppStore((store) => store.nwcClient);
const { data: balance, mutate: reloadBalance } = useBalance();
const getFiatAmount = useGetFiatAmount();
const [balanceState, setBalanceState] = useState<BalanceState>(
Expand Down
4 changes: 2 additions & 2 deletions pages/receive/ReceiveSuccess.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Invoice } from "@getalby/lightning-tools";
import { router, useLocalSearchParams } from "expo-router";
import { ScrollView, View } from "react-native";
import { Paid } from "~/animations/Paid";
import { Tick } from "~/animations/Tick";
import Screen from "~/components/Screen";
import { Button } from "~/components/ui/button";
import { Text } from "~/components/ui/text";
Expand All @@ -21,7 +21,7 @@ export function ReceiveSuccess() {
/>
<ScrollView contentContainerClassName="flex justify-center items-center gap-8 p-6">
<View className="flex-1 w-full">
<Paid />
<Tick />
</View>
<Text className="text-3xl font-bold2 text-muted-foreground">
Received
Expand Down
4 changes: 2 additions & 2 deletions pages/send/PaymentSuccess.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { router, useLocalSearchParams } from "expo-router";
import { ScrollView, View } from "react-native";
import { Paid } from "~/animations/Paid";
import { Tick } from "~/animations/Tick";
import { Button } from "~/components/ui/button";
import { Text } from "~/components/ui/text";
import Screen from "~/components/Screen";
Expand Down Expand Up @@ -28,7 +28,7 @@ export function PaymentSuccess() {
/>
<ScrollView contentContainerClassName="flex justify-center items-center gap-8 p-6">
<View className="flex-1 w-full">
<Paid />
<Tick />
</View>
<View className="flex flex-col items-center gap-2">
<View className="flex flex-row items-end justify-center">
Expand Down
2 changes: 1 addition & 1 deletion pages/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function Settings() {
<TouchableOpacity className="flex flex-row items-center gap-4">
<Wallet2 className="text-foreground" />
<Text className="font-medium2 text-xl text-foreground">Wallets</Text>
<Text className="text-muted-foreground text-xl">
<Text className="text-muted-foreground text-xl flex-shrink" numberOfLines={1} ellipsizeMode="tail">
({wallet.name || DEFAULT_WALLET_NAME})
</Text>
</TouchableOpacity>
Expand Down
18 changes: 11 additions & 7 deletions pages/settings/Wallets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export function Wallets() {
active ? "border-primary" : "border-transparent",
)}
>
<View className="flex flex-row gap-4 items-center">
<View className="flex flex-row gap-4 items-center flex-shrink">
reneaaron marked this conversation as resolved.
Show resolved Hide resolved
<Wallet2 className="text-foreground" />
<Text className={cn("text-xl", active && "font-semibold2")}>
<Text className={cn("text-xl pr-16", active && "font-semibold2")} numberOfLines={1} ellipsizeMode="tail">
{item.item.name || DEFAULT_WALLET_NAME}
</Text>
</View>
Expand All @@ -69,11 +69,15 @@ export function Wallets() {
/>
</View>
<View className="p-6">
<Link href="/settings/wallets/new" asChild>
<Button size="lg">
<Text>Connect a Wallet</Text>
</Button>
</Link>
<Button
size="lg"
onPress={() => {
router.dismissAll();
router.push("/settings/wallets/setup");
}}
>
<Text>Connect a Wallet</Text>
</Button>
</View>
</View>
</>
Expand Down
53 changes: 0 additions & 53 deletions pages/settings/wallets/NewWallet.tsx

This file was deleted.

Loading
Loading