From 1a63f6f17d5efafc0d0d048872e2767ba49fee79 Mon Sep 17 00:00:00 2001 From: minibits-cash Date: Tue, 4 Jun 2024 22:06:44 +0200 Subject: [PATCH] Fix keyboard not showing when entering amount, fix address recovery from seed in case server return error --- package.json | 2 +- src/screens/RemoteRecoveryScreen.tsx | 20 +++++++----- src/screens/SendScreen.tsx | 2 +- src/screens/TopupScreen.tsx | 7 +---- src/services/notificationService.ts | 47 +++++++++++++++++----------- 5 files changed, 44 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index e6ee08a7..b095ed38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minibits_wallet", - "version": "0.1.8-beta.20", + "version": "0.1.8-beta.21", "private": true, "scripts": { "android:clean": "cd android && ./gradlew clean", diff --git a/src/screens/RemoteRecoveryScreen.tsx b/src/screens/RemoteRecoveryScreen.tsx index cc8704d7..f8414195 100644 --- a/src/screens/RemoteRecoveryScreen.tsx +++ b/src/screens/RemoteRecoveryScreen.tsx @@ -522,16 +522,22 @@ export const RemoteRecoveryScreen: FC> = o setStatusMessage('Recovering wallet address...') setIsLoading(true) + + const seedHash = QuickCrypto.createHash('sha256') + .update(seed) + .digest('hex') + + // get nostr key from current on device profile + const {publicKey: newPublicKey} = await NostrClient.getOrCreateKeyPair() + // delete orphaned server profile then update server profile with seedHash with pubkey + update on device wallet name and address + await walletProfileStore.recover(seedHash as string, newPublicKey) + + // align walletId in userSettings with recovered profile + userSettingsStore.setWalletId(walletProfileStore.walletId) await KeyChain.saveMnemonic(mnemonic) await KeyChain.saveSeed(seed as Uint8Array) - const seedHash = await KeyChain.loadSeedHash() - - const {publicKey: newPublicKey} = await NostrClient.getOrCreateKeyPair() - // Updates pubkey and imports wallet profile - await walletProfileStore.recover(seedHash as string, newPublicKey) - // Align walletId in userSettings with recovered profile - userSettingsStore.setWalletId(walletProfileStore.walletId) + await delay(1000) setStatusMessage(`Recovery completed`) await delay(2000) diff --git a/src/screens/SendScreen.tsx b/src/screens/SendScreen.tsx index 3b0ff9ae..a1083a06 100644 --- a/src/screens/SendScreen.tsx +++ b/src/screens/SendScreen.tsx @@ -117,7 +117,7 @@ export const SendScreen: FC> = observer( ? amountInputRef.current.focus() : false } - const timer = setTimeout(() => focus(), 100) + const timer = setTimeout(() => focus(), 400) return () => { clearTimeout(timer) } diff --git a/src/screens/TopupScreen.tsx b/src/screens/TopupScreen.tsx index a926c70d..269c67cd 100644 --- a/src/screens/TopupScreen.tsx +++ b/src/screens/TopupScreen.tsx @@ -13,11 +13,7 @@ import { Share, Image, ImageStyle, - FlatList, - Keyboard, } from 'react-native' -import Clipboard from '@react-native-clipboard/clipboard' -import QRCode from 'react-native-qrcode-svg' import {spacing, useThemeColor, colors, typography} from '../theme' import {WalletStackScreenProps} from '../navigation' import { @@ -55,7 +51,6 @@ import useIsInternetReachable from '../utils/useIsInternetReachable' import { MintBalanceSelector } from './Mints/MintBalanceSelector' import { QRCodeBlock } from './Wallet/QRCode' import numbro from 'numbro' -import { MintListItem } from './Mints/MintListItem' import { TranItem } from './TranDetailScreen' if ( @@ -116,7 +111,7 @@ export const TopupScreen: FC> = observer( ? amountInputRef.current.focus() : false } - const timer = setTimeout(() => focus(), 100) + const timer = setTimeout(() => focus(), 400) return () => { clearTimeout(timer) diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index e5145d00..8dbb3f2d 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -4,14 +4,14 @@ import { log } from './logService'; import { MINIBIT_SERVER_NOSTR_PUBKEY, } from '@env' -import { FirebaseMessagingTypes } from '@react-native-firebase/messaging'; -import { MintUnit, formatCurrency, getCurrency } from './wallet/currency'; -import { NostrClient, NostrProfile } from './nostrService'; -import AppError, { Err } from '../utils/AppError'; -import { Platform } from 'react-native'; +import { FirebaseMessagingTypes } from '@react-native-firebase/messaging' +import { MintUnit, formatCurrency, getCurrency } from './wallet/currency' +import { NostrClient, NostrProfile } from './nostrService' +import AppError, { Err } from '../utils/AppError' +import { Platform } from 'react-native' -export type RemoteMessageReceiveToLnurl = { - type: 'RemoteMessageReceiveToLnurl', +export type NotifyReceiveToLnurlData = { + type: 'NotifyReceiveToLnurlData', data: { amount: number, unit: 'sat', @@ -32,21 +32,30 @@ const onReceiveRemoteNotification = async function(remoteMessage: FirebaseMessag } const serverPubkey = MINIBIT_SERVER_NOSTR_PUBKEY - const decrypted = await NostrClient.decryptNip04(serverPubkey, encrypted as string) - if (decrypted) { - const remoteData: RemoteMessageReceiveToLnurl = JSON.parse(decrypted) - const {amount, unit, comment, zapSenderProfile} = remoteData.data - - const currencyCode = getCurrency(unit as MintUnit).code - - await createLocalNotification( - `⚡${formatCurrency(amount, currencyCode)} ${currencyCode} incoming!`, - `${zapSenderProfile ? 'Zap' : 'Payment'} from ${zapSenderProfile?.nip05 || 'unknown payer'} is ready to be received.${comment ? ' Message from sender: ' + comment : ''}`, - zapSenderProfile?.picture - ) + if (!decrypted) { + throw new AppError(Err.VALIDATION_ERROR, 'Unknown remote message data received', {data: remoteMessage.data}) } + + const remoteData = JSON.parse(decrypted) + + // Remote notification building and showing per remoteData.type + if(remoteData.type === 'NotifyReceiveToLnurlData' || remoteData.type === 'RemoteMessageReceiveToLnurl') { + const {amount, unit, comment, zapSenderProfile} = remoteData.data + const currencyCode = getCurrency(unit as MintUnit).code + + await createLocalNotification( + `⚡${formatCurrency(amount, currencyCode)} ${currencyCode} incoming!`, + `${zapSenderProfile ? 'Zap' : 'Payment'} from ${zapSenderProfile?.nip05 || 'unknown payer'} is ready to be received.${comment ? ' Message from sender: ' + comment : ''}`, + zapSenderProfile?.picture + ) + + return + } + + throw new AppError(Err.VALIDATION_ERROR, 'Unknown remoteData.type', {remoteData}) + } catch (e: any) { log.error(e.name, e.message) }