diff --git a/package.json b/package.json index 106399cf..4bc94022 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minibits_wallet", - "version": "0.1.10-beta.11", + "version": "0.1.10-beta.12", "private": true, "scripts": { "android:clean": "cd android && ./gradlew clean", diff --git a/src/navigation/TabsNavigator.tsx b/src/navigation/TabsNavigator.tsx index 4c986824..e9a87043 100644 --- a/src/navigation/TabsNavigator.tsx +++ b/src/navigation/TabsNavigator.tsx @@ -152,9 +152,13 @@ export type WalletStackParamList = { unit: MintUnit, encodedInvoice?: string, paymentRequest?: PaymentRequest, - lnurlParams?: LNURLPayParams & {address?: string}, + lnurlParams?: LNURLPayParams & {address?: string}, + fixedAmount?: number, + comment?: string paymentOption?: SendOption, - mintUrl?: string, + mintUrl?: string, + isDonation?: boolean, + donationForName?: string } Topup: { unit: MintUnit, diff --git a/src/screens/Contacts/OwnName.tsx b/src/screens/Contacts/OwnName.tsx index fac8c108..e3e4ef4b 100644 --- a/src/screens/Contacts/OwnName.tsx +++ b/src/screens/Contacts/OwnName.tsx @@ -1,6 +1,6 @@ import {observer} from 'mobx-react-lite' import React, {FC, useCallback, useEffect, useLayoutEffect, useRef, useState} from 'react' -import {Text as RNText, TextStyle, View, ViewStyle, InteractionManager, TextInput, ScrollView } from 'react-native' +import {Text as RNText, TextStyle, View, ViewStyle, TextInput } from 'react-native' import {colors, spacing, typography, useThemeColor} from '../../theme' import {BottomModal, Button, Card, ErrorModal, Icon, InfoModal, ListItem, Loading, Screen, Text} from '../../components' import {useStores} from '../../models' @@ -17,16 +17,17 @@ import { CurrencyAmount } from '../Wallet/CurrencyAmount' import { CurrencyCode } from '../../services/wallet/currency' import { QRCodeBlock } from '../Wallet/QRCode' import { MintBalance } from '../../models/Mint' -import { MintListItem } from '../Mints/MintListItem' import Clipboard from '@react-native-clipboard/clipboard' -import { round, roundUp } from '../../utils/number' +import { roundUp } from '../../utils/number' +import { LnurlClient } from '../../services/lnurlService' const DEFAULT_DONATION_AMOUNT = 500 +const DONATION_LNURL_ADDRESS = 'minibits@minibits.cash' export const OwnName = observer(function (props: {navigation: any, pubkey: string}) { // const navigation = useNavigation() const ownNameInputRef = useRef(null) - const {proofsStore, walletProfileStore, userSettingsStore, mintsStore} = useStores() + const {proofsStore, walletProfileStore} = useStores() const {pubkey, navigation} = props const [ownName, setOwnName] = useState('') @@ -34,8 +35,7 @@ export const OwnName = observer(function (props: {navigation: any, pubkey: strin const [selectedBalance, setSelectedBalance] = useState(undefined) const [donationAmount, setDonationAmount] = useState(DEFAULT_DONATION_AMOUNT) const [donationInvoice, setDonationInvoice] = useState<{payment_hash: string, payment_request: string} | undefined>(undefined) - const [isLoading, setIsLoading] = useState(false) - const [isQRcodeVisible, setIsQRCodeVisible] = useState(false) + const [isLoading, setIsLoading] = useState(false) const [isChecked, setIsChecked] = useState(false) // const [isNameInputEnabled, setIsNameInputEnabled] = useState(true) const [isInvoicePaid, setIsInvoicePaid] = useState(false) @@ -80,7 +80,7 @@ export const OwnName = observer(function (props: {navigation: any, pubkey: strin checkDonationPaid, { interval: 2 * 1000, // every 2s to make it responsive. - maxPolls: 120, + maxPolls: 60, maxErrors: 10 }) .then(() => log.trace('[checkDonationPaid]', 'Polling completed')) @@ -126,8 +126,7 @@ export const OwnName = observer(function (props: {navigation: any, pubkey: strin setInfo('') setIsLoading(false) setDonationInvoice(undefined) - setDonationAmount(DEFAULT_DONATION_AMOUNT) - setIsQRCodeVisible(false) + setDonationAmount(DEFAULT_DONATION_AMOUNT) setIsInvoicePaid(false) } @@ -179,20 +178,35 @@ export const OwnName = observer(function (props: {navigation: any, pubkey: strin const onCreateDonation = async function () { try { setIsLoading(true) - const memo = `Donation for ${ownName+MINIBITS_NIP05_DOMAIN}` - const invoice = await MinibitsClient.createDonation( - donationAmount, - memo, - pubkey - ) - if(invoice) { - setDonationInvoice(invoice) - const feeReserve = roundUp(donationAmount / 100, 0) + const comment = `Donation for ${ownName+MINIBITS_NIP05_DOMAIN}` + const feeReserve = roundUp(donationAmount / 100, 0) - if(!selectedBalance || donationAmount >= selectedBalance.balances['sat']! + feeReserve) { - setIsQRCodeVisible(true) - } + if(selectedBalance && selectedBalance.balances['sat']! + feeReserve >= donationAmount) { + + const addressParamsResult = await LnurlClient.getLnurlAddressParams(DONATION_LNURL_ADDRESS) // throws + + return navigation.navigate('WalletNavigator', { + screen: 'Transfer', + params: { + lnurlParams: addressParamsResult.lnurlParams, + paymentOption: SendOption.LNURL_PAY, + fixedAmount: donationAmount, + unit: 'sat', + comment, + mintUrl: selectedBalance.mintUrl, + isDonation: true, + donationForName: ownName + }, + }) + } else { + const invoice = await MinibitsClient.createDonation( + donationAmount, + comment, + pubkey + ) + + setDonationInvoice(invoice) } setIsLoading(false) @@ -211,22 +225,6 @@ export const OwnName = observer(function (props: {navigation: any, pubkey: strin } } - - const onPayDonation = async function () { - try { - return navigation.navigate('WalletNavigator', { - screen: 'Transfer', - params: { - encodedInvoice: donationInvoice?.payment_request, - unit: userSettingsStore.preferredUnit || 'sat', - paymentOption: SendOption.DONATION - }, - }) - } catch (e: any) { - handleError(e) - } - } - // poll handler const checkDonationPaid = async function (): Promise { try { @@ -331,70 +329,13 @@ export const OwnName = observer(function (props: {navigation: any, pubkey: strin text={translate("contactsScreen.ownName.payToGetOwnName", { name: ownName+MINIBITS_NIP05_DOMAIN })} style={[$supportText, {color: hint}]} /> - {isQRcodeVisible && ( - - )} - {(!!selectedBalance && selectedBalance.balances['sat']! > donationAmount) ? ( - <> - - } - topSeparator={true} - bottomSeparator={true} - leftIcon='faBolt' - onPress={onCopyInvoice} - /> - - - -