From 4e6c6e9446ebe0d5bb38f435ace8dda72b6224ef Mon Sep 17 00:00:00 2001 From: minibits-cash Date: Fri, 13 Jun 2025 00:50:14 +0200 Subject: [PATCH] Finalize payment request details, improve offline mode UX --- src/i18n_messages/en.json | 3 +- src/screens/CashuPaymentRequestScreen.tsx | 77 +++--- src/screens/SendScreen.tsx | 57 +++-- src/screens/TokenReceiveScreen.tsx | 234 ++++++++---------- src/screens/TranDetailScreen.tsx | 61 ++++- .../Transactions/TransactionListItem.tsx | 8 + src/services/lightning/lightningUtils.ts | 8 +- .../wallet/cashuPaymentRequestTask.ts | 2 +- src/services/wallet/transferTask.ts | 5 +- 9 files changed, 260 insertions(+), 195 deletions(-) diff --git a/src/i18n_messages/en.json b/src/i18n_messages/en.json index 336ae46..70b9a15 100644 --- a/src/i18n_messages/en.json +++ b/src/i18n_messages/en.json @@ -487,11 +487,12 @@ }, "tranDetailScreen": { "amount": "Amount", + "paymentId": "Payment ID", "balanceAfter": "Balance after this transaction", "claim": "Claim", "createdAt": "Created at", "expiresAt": "Expires at", - "id": "ID", + "id": "Transaction ID", "invoice": "Lightning invoice to pay", "isOffline": "Redeem online", "lightningFee": "Lightning network fee", diff --git a/src/screens/CashuPaymentRequestScreen.tsx b/src/screens/CashuPaymentRequestScreen.tsx index 8df0f13..4792c17 100644 --- a/src/screens/CashuPaymentRequestScreen.tsx +++ b/src/screens/CashuPaymentRequestScreen.tsx @@ -8,7 +8,7 @@ import { useStores } from "../models" import { MintBalanceSelector } from "./Mints/MintBalanceSelector" import { CurrencyAmount } from "./Wallet/CurrencyAmount" import EventEmitter from '../utils/eventEmitter' -import { getCurrency, MintUnit, CurrencyCode } from "../services/wallet/currency" +import { getCurrency, MintUnit, CurrencyCode, convertToFromSats } from "../services/wallet/currency" import { round, toNumber } from "../utils/number" import { translate } from "../i18n" import AppError, { Err } from "../utils/AppError" @@ -25,7 +25,6 @@ import { Text, } from "../components" import useIsInternetReachable from "../utils/useIsInternetReachable" -import { PaymentRequest} from "@cashu/cashu-ts" import {HANDLE_RECEIVED_EVENT_TASK, log, TransactionTaskResult, WalletTask } from "../services" import { QRCodeBlock } from "./Wallet/QRCode" import { TranItem } from "./TranDetailScreen" @@ -33,6 +32,7 @@ import { Transaction, TransactionStatus } from "../models/Transaction" import { CASHU_PAYMENT_REQUEST_TASK } from "../services/wallet/cashuPaymentRequestTask" import { ResultModalInfo } from "./Wallet/ResultModalInfo" import { MintHeader } from "./Mints/MintHeader" +import { verticalScale } from "@gocodingnow/rn-size-matters" type Props = StaticScreenProps<{ unit: MintUnit, @@ -327,32 +327,30 @@ const headerBg = useThemeColor("header") const placeholderTextColor = useThemeColor("textDim") const amountInputColor = useThemeColor("amountInput") const inputText = useThemeColor("text") -const convertedAmountColor = useThemeColor("headerSubTitle") + const convertedAmountColor = useThemeColor('headerSubTitle') -const getConvertedAmount = () => { - if (!walletStore.exchangeRate) return undefined - const precision = getCurrency(unit).precision - return ( - round(toNumber(amountToRequest) * precision, 0) && - walletStore.exchangeRate && - walletStore.exchangeRate[getCurrency(unit).code] - ? round( - (toNumber(amountToRequest) * precision * walletStore.exchangeRate[userSettingsStore.exchangeCurrency]) / - walletStore.exchangeRate[getCurrency(unit).code], - 2, + const getConvertedAmount = function () { + if (!walletStore.exchangeRate) { + return undefined + } + + const precision = getCurrency(unit).precision + return convertToFromSats( + round(toNumber(amountToRequest) * precision, 0) || 0, + getCurrency(unit).code, + walletStore.exchangeRate ) - : undefined - ) -} + } + + const isConvertedAmountVisible = function () { + return ( + walletStore.exchangeRate && + (userSettingsStore.exchangeCurrency === getCurrency(unit).code || + unit === 'sat') && + getConvertedAmount() !== undefined + ) + } -const isConvertedAmountVisible = () => { - return ( - walletStore.exchangeRate && - (userSettingsStore.exchangeCurrency === getCurrency(unit).code || - unit === "sat") && - getConvertedAmount() !== undefined - ) -} return ( @@ -380,26 +378,15 @@ return ( selectTextOnFocus={true} returnKeyType={"done"} /> - {isConvertedAmountVisible() && ( - + {isConvertedAmountVisible() && ( + )} (null) // Initialize pubkeyInputRef // Offline send useEffect(() => { - if(isInternetReachable) return + //if(isInternetReachable) return log.trace('[Offline send]') // if offline we set all non-zero mint balances as available to allow ecash selection @@ -436,7 +436,7 @@ const pubkeyInputRef = useRef(null) // Initialize pubkeyInputRef setAvailableMintBalances(availableBalances) setMintBalanceToSendFrom(availableBalances[0]) setIsMintSelectorVisible(true) - }, [isInternetReachable]) + }, []) useEffect(() => { @@ -1427,6 +1427,7 @@ const SelectProofsBlock = observer(function (props: { const {proofsStore} = useStores() const hintColor = useThemeColor('textDim') + const statusColor = useThemeColor('header') const onCancel = function () { @@ -1436,13 +1437,48 @@ const SelectProofsBlock = observer(function (props: { return ( + + + + - + data={proofsStore.getByMint(props.mintBalanceToSendFrom.mintUrl, {isPending: false, unit: props.unit})} renderItem={({ item }) => { @@ -1464,21 +1500,6 @@ const SelectProofsBlock = observer(function (props: { /> - - -