Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 pages/Unlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export function Unlock() {
if (biometricAuth.success) {
signIn();
router.replace("/");
} else {
throw new Error("Failed to unlock");
}
} catch (e) {
errorToast(e, "Failed to unlock");
errorToast(e);
} finally {
setIsUnlocking(false);
}
Expand Down
104 changes: 59 additions & 45 deletions pages/settings/wallets/EditWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as LocalAuthentication from "expo-local-authentication";
import { Link, router, useLocalSearchParams } from "expo-router";
import React, { useState } from "react";
import {
Expand All @@ -22,6 +23,7 @@ import Loading from "~/components/Loading";
import Screen from "~/components/Screen";
import { Text } from "~/components/ui/text";
import { IS_EXPO_GO, REQUIRED_CAPABILITIES } from "~/lib/constants";
import { errorToast } from "~/lib/errorToast";
import { deregisterWalletNotifications } from "~/lib/notifications";
import { useAppStore } from "~/lib/state/appStore";
import { cn, copyToClipboard } from "~/lib/utils";
Expand Down Expand Up @@ -50,6 +52,62 @@ export function EditWallet() {
}
};

const onExportWallet = () => {
RNAlert.alert(
"Export Wallet",
"Your Wallet Connection Secret will be copied to the clipboard which you can add to another app. For per-app permission management, try out Alby Hub or add your Wallet Connection Secret to an Alby Account.",
[
{
text: "Cancel",
style: "cancel",
},
{
text: "Confirm",
onPress: async () => {
const isSuperuser = useAppStore
.getState()
.wallets[walletId].nwcCapabilities?.includes("create_connection");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

if (isSuperuser) {
Toast.show({
type: "error",
text1: "Wallet cannot be exported",
text2:
"This wallet supports authorizing new connections and cannot be exported. Please create a new connection from Alby Hub instead",
});
return;
}

try {
if (useAppStore.getState().isSecurityEnabled) {
const biometricAuth =
await LocalAuthentication.authenticateAsync({
promptMessage: "Authenticate to export wallet",
});
if (!biometricAuth.success) {
throw new Error("Failed to authenticate");
}
}
} catch (e) {
errorToast(e);
return;
}

const nwcUrl =
useAppStore.getState().wallets[walletId].nostrWalletConnectUrl;
if (!nwcUrl) {
return;
}
await copyToClipboard(
nwcUrl,
"Connection Secret copied to clipboard",
);
},
},
],
);
};

return (
<View className="flex-1">
<Screen title="Edit Wallet" />
Expand Down Expand Up @@ -160,51 +218,7 @@ export function EditWallet() {
</TouchableOpacity>
<TouchableOpacity
className="flex flex-row items-center gap-4 px-6 py-4"
onPress={() => {
RNAlert.alert(
"Export Wallet",
"Your Wallet Connection Secret will be copied to the clipboard which you can add to another app. For per-app permission management, try out Alby Hub or add your Wallet Connection Secret to an Alby Account.",

[
{
text: "Cancel",
style: "cancel",
},
{
text: "Confirm",
onPress: async () => {
const isSuperuser = useAppStore
.getState()
.wallets[
walletId
].nwcCapabilities?.includes("create_connection");

if (isSuperuser) {
Toast.show({
type: "error",
text1: "Wallet cannot be exported",
text2:
"This wallet supports authorizing new connections and cannot be exported. Please create a new connection from Alby Hub instead",
});
return;
}

const nwcUrl =
useAppStore.getState().wallets[
useAppStore.getState().selectedWalletId
].nostrWalletConnectUrl;
if (!nwcUrl) {
return;
}
await copyToClipboard(
nwcUrl,
"Connection Secret copied to clipboard",
);
},
},
],
);
}}
onPress={onExportWallet}
>
<ShareIcon
className="text-muted-foreground"
Expand Down
Loading