This commit is contained in:
minibits-cash
2025-12-10 16:46:24 +01:00
parent 7605b27a0b
commit 52c1d7d07e
6 changed files with 97 additions and 11 deletions
+1 -1
View File
@@ -1 +1 @@
019aee8e-ae33-77d0-a617-530181bcc686
019b0359-9f11-775c-a6eb-a2562f2f15ad
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "minibits_wallet",
"version": "0.3.4-beta.3",
"version": "0.3.4-beta.4",
"private": true,
"scripts": {
"android:clean": "cd android && ./gradlew clean",
+2
View File
@@ -34,6 +34,7 @@ import RNExitApp from 'react-native-exit-app'
import { TransactionStatus } from '../models/Transaction'
import { maxTransactionsInHistory } from '../models/TransactionsStore'
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
// refresh // refresh
type Props = StaticScreenProps<undefined>
@@ -295,6 +296,7 @@ export const DeveloperScreen = observer(function DeveloperScreen({ route }: Prop
tx="developerScreen_info"
subText={`Environment: ${APP_ENV}
JS Bundle version: ${JS_BUNDLE_VERSION}
${Platform.OS === 'android' ? 'Android version code:' + ANDROID_VERSION_CODE : ''}
Commit: ${COMMIT}
DB version: ${dbVersion}
State size: ${walletStateSize.toLocaleString()} bytes
+90 -6
View File
@@ -5,9 +5,10 @@ import {
TextStyle,
Alert,
ColorValue,
Platform,
} from 'react-native'
import { PaymentRequest as CashuPaymentRequest, MeltQuoteResponse, PaymentRequestTransport, PaymentRequestTransportType, decodePaymentRequest, getDecodedToken } from '@cashu/cashu-ts'
import NfcManager, { NfcTech, Ndef, NfcEvents } from 'react-native-nfc-manager'
import NfcManager, { NfcTech, Ndef, NfcEvents, TagEvent } from 'react-native-nfc-manager'
import { colors, spacing, typography, useThemeColor } from '../theme'
import EventEmitter from '../utils/eventEmitter'
import { log } from '../services/logService'
@@ -182,6 +183,7 @@ export const NfcPayScreen = observer(function NfcPayScreen({ route }: Props) {
return () => {
NfcManager.cancelTechnologyRequest().catch(() => {})
NfcManager.setEventListener(NfcEvents.DiscoverTag, null)
NfcManager.setEventListener(NfcEvents.SessionClosed, null)
}
}, [])
@@ -524,17 +526,97 @@ export const NfcPayScreen = observer(function NfcPayScreen({ route }: Props) {
}, [handleTransferTaskResult])
const readNdefOnce = function () {
const cleanUp = () => {
NfcManager.setEventListener(NfcEvents.DiscoverTag, null);
NfcManager.setEventListener(NfcEvents.SessionClosed, null);
};
return new Promise<TagEvent | null>((resolve) => {
let tagFound: TagEvent | null = null;
NfcManager.setEventListener(NfcEvents.DiscoverTag, (tag: TagEvent) => {
tagFound = tag;
resolve(tagFound);
NfcManager.unregisterTagEvent().catch(() => 0);
});
NfcManager.setEventListener(NfcEvents.SessionClosed, (e: any) => {
if (e) {
log.error(Err.NFC_ERROR, 'NFC Session closed with error', e.message);
}
cleanUp()
if (!tagFound) {
resolve(null)
}
});
NfcManager.registerTagEvent();
});
}
const readTag = async function() {
try {
await NfcManager.requestTechnology([NfcTech.Ndef]);
const tag = await NfcManager.getTag();
return tag
} catch (e: any) {
// for tag reading, we don't actually need to show any error
log.error(Err.NFC_ERROR, 'Failed to read NFC tag', e.message);
} finally {
NfcManager.cancelTechnologyRequest();
}
}
const startNfcSession = async () => {
try {
log.debug('Starting NFC session for payment request reading...', {caller: 'startNfcSession'})
await NfcManager.requestTechnology(NfcTech.Ndef, {
const tag = await readNdefOnce()
// const tag = await readTag()
if (!tag) {
return
}
log.warn('Tag found', {tag});
/*await NfcManager.requestTechnology(NfcTech.Ndef, {
alertMessage: 'Hold phone near the device...',
//invalidateAfterFirstRead: false,
invalidateAfterFirstRead: false,
})
const tag = await NfcManager.getTag();
log.warn('Tag found', {tag});
if(!tag || !tag.ndefMessage || tag.ndefMessage.length === 0) {
setInfo('No NDEF message found on the NFC tag')
return
}
const bytes = new Uint8Array(
tag.ndefMessage[0].payload
);
let payload: string
const decoded = Ndef.text.decodePayload(bytes);
log.warn('NFC tag decoded', { decoded })*/
// setNfcInfo('Reading payment request...')
// Listen for tag discovery
NfcManager.setEventListener(NfcEvents.DiscoverTag, async (tag: any) => {
/*NfcManager.setEventListener(NfcEvents.DiscoverTag, async (tag: any) => {
if (isProcessing) return
setIsProcessing(true)
setNfcInfo('Reading payment request...')
@@ -568,10 +650,12 @@ export const NfcPayScreen = observer(function NfcPayScreen({ route }: Props) {
} finally {
setIsProcessing(false)
}
})
})*/
} catch (e: any) {
log.error(Err.NFC_ERROR, e.message)
handleError(e)
} finally {
NfcManager.cancelTechnologyRequest().catch(() => {})
}
}
@@ -974,7 +1058,7 @@ export const NfcPayScreen = observer(function NfcPayScreen({ route }: Props) {
)
})
// Styles remain unchanged
const $screen: ViewStyle = { flex: 1 }
const $contentContainer: ViewStyle = { flex: 1, marginTop: -spacing.extraLarge * 2, padding: spacing.extraSmall }
const $headerContainer: TextStyle = { alignItems: 'center', paddingBottom: spacing.medium, height: spacing.screenHeight * 0.15 }
+1 -1
View File
@@ -825,7 +825,7 @@ export const WalletScreen = observer(function WalletScreen({ route }: Props) {
<ListItem
leftIcon='faNfcSymbol'
text="Pay with NFC"
subText="Tap to pay using NFC-enabled wallets or POS"
subText="Tap NFC-enabled wallet or POS to pay"
onPress={() => gotoNfcPay()}
/>
</>
+2 -2
View File
@@ -417,7 +417,7 @@ const fetchApi = async (url: string, options: MinibitsRequestOptions, timeout =
}
// legacy headers
const getHeaders = () => {
/*const getHeaders = () => {
return {
'Content-Type': 'application/json',
'Accept': 'application/json',
@@ -425,7 +425,7 @@ const getHeaders = () => {
'Authorization': `Bearer ${MINIBITS_SERVER_API_KEY}`,
'User-Agent': `Minibits/${JS_BUNDLE_VERSION}`
}
}
}*/
const getPublicHeaders = () => {
return {