diff --git a/src/screens/Payment/Processing.tsx b/src/screens/Payment/Processing.tsx index 0d0bac46..6949ffca 100644 --- a/src/screens/Payment/Processing.tsx +++ b/src/screens/Payment/Processing.tsx @@ -106,9 +106,6 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP } try { const target = invoice || recipient || '' - l({ target }) - l({ estFee }) - l({ proofs }) const res = await payLnInvoice(mint.mintUrl, target, estFee || 0, proofs || []) if (!res?.result?.isPaid) { // here it could be a routing path finding issue diff --git a/src/screens/Payment/Send/Inputfield.tsx b/src/screens/Payment/Send/Inputfield.tsx index 51388dde..077db93d 100644 --- a/src/screens/Payment/Send/Inputfield.tsx +++ b/src/screens/Payment/Send/Inputfield.tsx @@ -10,6 +10,7 @@ import TopNav from '@nav/TopNav' import { usePromptContext } from '@src/context/Prompt' import { useThemeContext } from '@src/context/Theme' import { NS } from '@src/i18n' +import { l } from '@src/logger' import { globals } from '@styles' import { decodeLnInvoice, getStrFromClipboard, isErr, isLnurl, openUrl } from '@util' import { checkFees } from '@wallet' @@ -18,7 +19,6 @@ import { useTranslation } from 'react-i18next' import { KeyboardAvoidingView, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native' import { MeltOverview } from '../SelectAmount' -import { l } from '@src/logger' export default function InputfieldScreen({ navigation, route }: TMeltInputfieldPageProps) { const { mint, balance } = route.params diff --git a/src/storage/db/index.ts b/src/storage/db/index.ts index d2440d89..7d552817 100644 --- a/src/storage/db/index.ts +++ b/src/storage/db/index.ts @@ -185,13 +185,11 @@ export async function getProofs(): Promise { export async function getProofsByIds(ids: string[]): Promise { const toGet = ids.map(id => `"${id}"`).join(',') const proofs = await db.all(`SELECT * FROM proofs WHERE id in (${toGet})`, []) - l('[getProofsByIds]', proofs) return proofs } export async function getProofsByMintUrl(mintUrl: string): Promise { const mintsIds = (await getMintIdsByUrl(mintUrl)).map(x => x.id) const proofs = await getProofsByIds(mintsIds) - l('[getProofsByMintUrl]', proofs) return proofs } export async function deleteProofs(proofs: Proof[]): Promise { diff --git a/src/wallet/index.ts b/src/wallet/index.ts index 1fde4b17..748f8658 100644 --- a/src/wallet/index.ts +++ b/src/wallet/index.ts @@ -90,7 +90,6 @@ export async function checkFees(mintUrl: string, invoice: string): Promise { encodedToken = isCashuToken(encodedToken) || '' if (!encodedToken?.trim()) { return false } @@ -119,7 +118,6 @@ export async function claimToken(encodedToken: string): Promise { if (!token?.token?.length) { return false } return true } - export async function requestMint(mintUrl: string, amount: number): Promise { const wallet = await getWallet(mintUrl) const result = await wallet.requestMint(amount) @@ -128,7 +126,6 @@ export async function requestMint(mintUrl: string, amount: number): Promise { const invoice = await getInvoice(hash) const wallet = await getWallet(mintUrl) @@ -163,21 +160,27 @@ export async function payLnInvoice(mintUrl: string, invoice: string, fee: number const { proofsToUse } = await getProofsToUse(mintUrl, amountToPay) proofs = proofsToUse } - const { send, returnChange, newKeys } = await wallet.send(amountToPay, proofs) - if (newKeys) { _setKeys(mintUrl, newKeys) } - if (returnChange?.length) { await addToken({ token: [{ mint: mintUrl, proofs: returnChange }] }) } - if (send?.length) { await deleteProofs(proofs) } + if (sumProofsValue(proofs) > amountToPay) { + l('[payLnInvoce] use send ', { amountToPay, amount, fee, proofs: sumProofsValue(proofs) }) + const { send, returnChange, newKeys } = await wallet.send(amountToPay, proofs) + if (newKeys) { _setKeys(mintUrl, newKeys) } + if (returnChange?.length) { await addToken({ token: [{ mint: mintUrl, proofs: returnChange }] }) } + if (send?.length) { await deleteProofs(proofs) } + proofs = send + } try { - const result = await wallet.payLnInvoice(invoice, send, fee) + l({ fee, sum: sumProofsValue(proofs) }) + const result = await wallet.payLnInvoice(invoice, proofs, fee) if (result?.newKeys) { _setKeys(mintUrl, result.newKeys) } if (result?.change?.length) { await addToken({ token: [{ mint: mintUrl, proofs: result.change }] }) } - if (result.isPaid) { await deleteProofs(send) } - l({ fee, change: result.change, sum: sumProofsValue(result.change) }) - l({ sumProofsValue: sumProofsValue(result.change) }) - l({ resultChange: result.change }) - return { result, fee, realFee: fee - sumProofsValue(returnChange.concat(result.change)) } + if (result.isPaid) { await deleteProofs(proofs) } + if (fee - sumProofsValue((result.change)) < 0) { + l('######################################## ERROR ####################################') + l({ result, fee, realFee: fee - sumProofsValue((result.change)), amountToPay, amount, proofs: sumProofsValue(proofs) }) + } + return { result, fee, realFee: fee - sumProofsValue(result.change) } } catch (error) { - await addToken({ token: [{ mint: mintUrl, proofs: send }] }) + await addToken({ token: [{ mint: mintUrl, proofs }] }) return { result: undefined, error } } }