Skip to content

Commit

Permalink
Fix/simple stuff (#488)
Browse files Browse the repository at this point in the history
* fix create account few times

* fix scan + receive with link + ui

* improve cashu ui and fix
  • Loading branch information
MSghais authored Feb 14, 2025
1 parent bb9211b commit 439b66a
Show file tree
Hide file tree
Showing 19 changed files with 401 additions and 177 deletions.
6 changes: 4 additions & 2 deletions apps/mobile/src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ export const Input: React.FC<InputProps> = (props) => {
} = props;

const {theme} = useTheme();
const styles = useStyles(stylesheet, !!error, !!left, !!right, !!paddingRight);
const styles = useStyles(stylesheet, !!error, !!left, !!right, !!paddingRight, inputProps);

return (
<View style={[styles.container, containerStyleProp]}>
<View style={[styles.content, styleProp]}>
{left}

<TextInput
style={[styles.input, inputStyleProp]}
style={[
styles.input,
inputStyleProp]}
placeholderTextColor={theme.colors.inputPlaceholder}
underlineColorAndroid="transparent"
{...inputProps}
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/components/Input/styles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Spacing, ThemedStyleSheet, Typography} from '../../styles';

export default ThemedStyleSheet(
(theme, error: boolean, left: boolean, right: boolean, paddingRight = true) => ({
(theme, error: boolean, left: boolean, right: boolean, paddingRight = true, inputProps: TextInputProps) => ({
container: {
width: '100%',
},
Expand All @@ -14,7 +14,7 @@ export default ThemedStyleSheet(
backgroundColor: theme.colors.inputBackground,
borderColor: theme.colors.inputBorder,
height: 56,

...inputProps,
...(error && {
backgroundColor: theme.colors.errorLight,
borderColor: theme.colors.errorDark,
Expand Down
13 changes: 12 additions & 1 deletion apps/mobile/src/components/QR/ScanCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {usePayment} from '../../hooks/usePayment';
import {Button} from '../Button';
import {Input} from '../Input';
import stylesheet from './styles';
import { useNavigation } from '@react-navigation/native';
import { MainStackNavigationProps, MainStackParams } from '../../types';

interface ScanCashuQRCodeProps {
onClose: () => void;
Expand All @@ -38,6 +40,7 @@ export const ScanQRCode: React.FC<ScanCashuQRCodeProps> = ({onClose, onSuccess})
const {theme} = useTheme();
const styles = useStyles(stylesheet);

const navigation = useNavigation<MainStackNavigationProps>();
// Web-specific refs and state
const videoRef = useRef<VideoElementRef | null>(null);
const canvasRef = useRef<HTMLCanvasElement | null>(null);
Expand Down Expand Up @@ -312,7 +315,15 @@ export const ScanQRCode: React.FC<ScanCashuQRCodeProps> = ({onClose, onSuccess})
) : null}
{renderCamera()}
{Platform.OS === 'web' && !webPermissionGranted ? (
<Text style={styles.waitingText}>Waiting for permissions...</Text>
<View
style={styles.waitingContainer}
>
<Button onPress={() => {
// navigation.goBack();
handleScannerClose()
}}>Cancel</Button>
<Text style={styles.waitingText}>Waiting for permissions...</Text>
</View>
) : null}
{Platform.OS !== 'web' || webPermissionGranted ? (
<TouchableOpacity onPress={handleScannerClose}>
Expand Down
10 changes: 10 additions & 0 deletions apps/mobile/src/components/QR/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,14 @@ export default ThemedStyleSheet((theme) => ({
bottom: 10,
zIndex: 10000,
},
waitingContainer:{
backgroundColor: theme.colors.surface,
padding: 20,
borderRadius: 10,
width: '100%',
height: '100%',
alignItems: 'center',
justifyContent: 'space-between',
flexDirection: 'column',
}
}));
48 changes: 34 additions & 14 deletions apps/mobile/src/hooks/account/useInternalAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ export const useInternalAccount = () => {
const [isFirstLoadDone, setIsFirstLoadDone] = useState(false);
const {setIsSeedCashuStorage} = useCashuStore();

const handlePasskey = async (publicKey?: string) => {
try {
const passkeyToGenerate = DEFAULT_PASSKEY_VALUES;
passkeyToGenerate.publicKey = publicKey;
showToast({title: 'Passkey in process', type: 'info'});

const result = await PasskeyManager.generatePasskeyAndSave(passkeyToGenerate);
if (!result) {
showToast({title: 'Passkey issue.', type: 'error'});
// return router.push("/onboarding")
return undefined;
} else {
showToast({title: 'Passkey generated', type: 'success'});

return result;
}
} catch (error) {

}
};
const handleGeneratePasskey = async (publicKey?: string) => {
try {
const isWalletSetup = await PasskeyManager.getIsWalletSetup();
Expand All @@ -40,20 +60,14 @@ export const useInternalAccount = () => {
// if (isWalletSetup) return;

if (isWalletSetup && isWalletSetup == 'true') {
// const result = await PasskeyManager.getDecryptedPrivateKey()
// if (!result) {
// showToast({ title: "Authentication issue.", type: "error" })

// // return router.push("/onboarding")

// } else {
// const { secretKey, mnemonic, publicKey, strkPrivateKey } = result
// console.log("result", result)
// showToast({ title: "Authentication succeed.", type: "success" })
const passkeyToGenerate = DEFAULT_PASSKEY_VALUES;
passkeyToGenerate.publicKey = publicKey;
// showToast({title: 'Passkey in process', type: 'info'});

// setIsConnected(true)
// }
return undefined;
const result = await handlePasskey(publicKey)

return result;
} else if (!isWalletSetup) {
const passkeyToGenerate = DEFAULT_PASSKEY_VALUES;
passkeyToGenerate.publicKey = publicKey;
Expand Down Expand Up @@ -128,9 +142,14 @@ export const useInternalAccount = () => {
try {
console.log('handleGenerateNostrWallet');

if (passkey) {
if (passkey && passkey != null) {
console.log('passkey exist', passkey);
const res = await NostrKeyManager.getOrCreateKeyPair(passkey);
console.log('res', res);
if(!res) {
showToast({title: 'Nostr wallet generation failed.', type: 'error'});
return undefined;
}
const {secretKey, mnemonic, publicKey} = res;
showToast({title: 'Nostr wallet generated successfully.', type: 'success'});
resultNostr.secretKey = secretKey;
Expand All @@ -144,7 +163,8 @@ export const useInternalAccount = () => {
console.log('resultNostrValue', resultNostrValue);
setIsConnected(true);
return resultNostr;
} else if (!passkey) {
} else if (!passkey || passkey == null) {
console.log('passkey not exist');
const result = await PasskeyManager.generatePasskeyAndSave(DEFAULT_PASSKEY_VALUES);
if (!result) {
showToast({title: 'Passkey issue.', type: 'error'});
Expand Down
15 changes: 12 additions & 3 deletions apps/mobile/src/hooks/usePayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
useCreateTokenEvent,
useDeleteTokenEvents,
} from 'afk_nostr_sdk';
import {EventMarker} from 'afk_nostr_sdk/src/hooks/cashu/useCreateSpendingEvent';
import {useState} from 'react';

import {useCashuContext} from '../providers/CashuProvider';
import {useToast} from './modals';
import {useGetTokensByProofs} from './useGetTokensByProof';
import {useProofsStorage, useTransactionsStorage, useWalletIdStorage} from './useStorageState';
import { EventMarker } from '../../../../packages/afk_nostr_sdk/src/hooks/cashu/useCreateSpendingEvent';

export const usePayment = () => {
const {showToast} = useToast();
Expand All @@ -35,10 +35,14 @@ export const usePayment = () => {

const handlePayInvoice = async (pInvoice: string) => {
if (!wallet) {
console.log('no wallet');
return undefined;
} else if (proofs) {
try {
console.log('proofs', proofs);

const response = await meltTokens(pInvoice, proofs);
console.log('response', response);
if (response) {
const {meltQuote, meltResponse, proofsToKeep, remainingProofs, selectedProofs} = response;
setProofsFilter(selectedProofs);
Expand Down Expand Up @@ -85,9 +89,11 @@ export const usePayment = () => {
return undefined;
}
} catch (error) {
console.log('error', error);
return undefined;
}
} else {
console.log('no proofs');
// no proofs = no balance
return undefined;
}
Expand Down Expand Up @@ -187,13 +193,15 @@ export const usePayment = () => {

const handleReceiveEcash = async (ecashToken?: string) => {
try {
console.log('handleReceiveEcash', ecashToken);
if (!ecashToken) {
return undefined;
}
const decodedToken = getDecodedToken(ecashToken);

console.log('decodedToken', decodedToken);
console.log('wallet', wallet);
const receiveEcashProofs = await wallet?.receive(decodedToken);

console.log('receiveEcashProofs', receiveEcashProofs);
if (receiveEcashProofs?.length > 0) {
const proofsAmount = receiveEcashProofs.reduce((acc, item) => acc + item.amount, 0);
if (privateKey && publicKey) {
Expand Down Expand Up @@ -228,6 +236,7 @@ export const usePayment = () => {
}
return undefined;
} catch (e) {
console.log('handleReceiveEcash error', e);
return undefined;
}
};
Expand Down
Loading

0 comments on commit 439b66a

Please sign in to comment.