Skip to content

Commit

Permalink
fix fee #242
Browse files Browse the repository at this point in the history
  • Loading branch information
BilligsterUser committed Oct 4, 2023
1 parent 6e9c822 commit f7001d1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
3 changes: 0 additions & 3 deletions src/screens/Payment/Processing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Payment/Send/Inputfield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/storage/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,11 @@ export async function getProofs(): Promise<Proof[]> {
export async function getProofsByIds(ids: string[]): Promise<Proof[]> {
const toGet = ids.map(id => `"${id}"`).join(',')
const proofs = await db.all<Proof>(`SELECT * FROM proofs WHERE id in (${toGet})`, [])
l('[getProofsByIds]', proofs)
return proofs
}
export async function getProofsByMintUrl(mintUrl: string): Promise<Proof[]> {
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<boolean | undefined> {
Expand Down
31 changes: 17 additions & 14 deletions src/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export async function checkFees(mintUrl: string, invoice: string): Promise<numbe
const { fee } = await CashuMint.checkFees(mintUrl, { pr: invoice })
return fee
}

export async function claimToken(encodedToken: string): Promise<boolean> {
encodedToken = isCashuToken(encodedToken) || ''
if (!encodedToken?.trim()) { return false }
Expand Down Expand Up @@ -119,7 +118,6 @@ export async function claimToken(encodedToken: string): Promise<boolean> {
if (!token?.token?.length) { return false }
return true
}

export async function requestMint(mintUrl: string, amount: number): Promise<RequestMintResponse> {
const wallet = await getWallet(mintUrl)
const result = await wallet.requestMint(amount)
Expand All @@ -128,7 +126,6 @@ export async function requestMint(mintUrl: string, amount: number): Promise<Requ
l('[requestMint]', { result, mintUrl, amount })
return result
}

export async function requestToken(mintUrl: string, amount: number, hash: string): Promise<{ success: boolean; invoice: IInvoice | null | undefined }> {
const invoice = await getInvoice(hash)
const wallet = await getWallet(mintUrl)
Expand Down Expand Up @@ -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 }
}
}
Expand Down

0 comments on commit f7001d1

Please sign in to comment.