From 95b62e01ad0e2f9c78b5baf309e5f5aa843a890b Mon Sep 17 00:00:00 2001 From: KKA11010 Date: Wed, 6 Dec 2023 15:00:29 +0100 Subject: [PATCH] fix success screen data. Show change amount in success screen. --- src/model/nav.ts | 1 + src/screens/Payment/Processing.tsx | 16 +++++++----- src/screens/Payment/Success.tsx | 40 +++++++++++++++++++----------- src/wallet/index.ts | 2 +- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/model/nav.ts b/src/model/nav.ts index efca4a35..16945820 100644 --- a/src/model/nav.ts +++ b/src/model/nav.ts @@ -164,6 +164,7 @@ export type RootStackParamList = { isZap?: boolean nostr?: INostrSendData isScanned?: boolean + change?: number } mintmanagement: { mint: IMintUrl diff --git a/src/screens/Payment/Processing.tsx b/src/screens/Payment/Processing.tsx index b83a848e..d9801f6e 100644 --- a/src/screens/Payment/Processing.tsx +++ b/src/screens/Payment/Processing.tsx @@ -14,7 +14,7 @@ import { addLnPaymentToHistory } from '@store/HistoryStore' import { addToHistory, updateLatestHistory } from '@store/latestHistoryEntries' import { getDefaultMint } from '@store/mintStore' import { globals } from '@styles' -import { decodeLnInvoice, getInvoiceFromLnurl, isErr, isLnurl, uniqByIContacts } from '@util' +import { decodeLnInvoice, getInvoiceFromLnurl, isErr, isLnurl, isNum, uniqByIContacts } from '@util' import { autoMintSwap, checkFees, fullAutoMintSwap, getHighestBalMint, payLnInvoice, requestMint, sendToken } from '@wallet' import { useEffect, useMemo } from 'react' import { useTranslation } from 'react-i18next' @@ -139,7 +139,8 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP amount, fee: res.realFee, isMelt: true, - isZap + isZap, + change: isNum(estFee) && isNum(res.realFee) ? estFee - res.realFee : undefined, }) } catch (e) { handleError({ e }) @@ -166,6 +167,7 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP navigation.navigate('success', { amount, fee: res.payResult.realFee, + change: isNum(estFee) && isNum(res.payResult.realFee) ? estFee - res.payResult.realFee : undefined, isMelt: true }) } catch (e) { @@ -183,14 +185,15 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP if (tokenInfo.mints.length !== 1) { return handleError({ e: 'Auto-mint-swap currently only supports a single source mint.' }) } - // TODO this process can take a while, we need to add it as pending transaction - const { payResult, requestTokenResult } = await fullAutoMintSwap(tokenInfo, targetMint.mintUrl) + // TODO this process can take a while, we need to add it as pending transaction? + const { payResult, requestTokenResult, estFee } = await fullAutoMintSwap(tokenInfo, targetMint.mintUrl) if (!payResult || !requestTokenResult) { return handleError({ e: 'payResult or requestTokenResult is undefined' }) } + const amountSent = tokenInfo.value - estFee // add as history entry (multimint swap) await addToHistory({ - amount: -tokenInfo.value - (payResult.realFee ?? 0), + amount: -amountSent, fee: payResult.realFee, type: 3, value: requestTokenResult.invoice?.pr || '', @@ -198,8 +201,9 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP recipient: targetMint?.mintUrl || '' }) navigation.navigate('success', { - amount: tokenInfo.value, + amount: amountSent, fee: payResult.realFee, + change: estFee - (payResult.realFee || 0), isMelt: true }) } diff --git a/src/screens/Payment/Success.tsx b/src/screens/Payment/Success.tsx index 5ace0b4b..d9637862 100644 --- a/src/screens/Payment/Success.tsx +++ b/src/screens/Payment/Success.tsx @@ -8,7 +8,7 @@ import ProfilePic from '@screens/Addressbook/ProfilePic' import { useThemeContext } from '@src/context/Theme' import { NS } from '@src/i18n' import { l } from '@src/logger' -import { formatSatStr, vib } from '@util' +import { formatSatStr, isNum, vib } from '@util' import LottieView from 'lottie-react-native' import { useEffect } from 'react' import { useTranslation } from 'react-i18next' @@ -17,7 +17,18 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context' import { s, ScaledSheet, vs } from 'react-native-size-matters' export default function SuccessPage({ navigation, route }: TSuccessPageProps) { - const { amount, memo, fee, mint, isClaim, isMelt, isZap, nostr, isScanned } = route.params + const { + amount, + memo, + fee, + change, + mint, + isClaim, + isMelt, + isZap, + nostr, + isScanned, + } = route.params const { t } = useTranslation([NS.common]) const { color } = useThemeContext() const insets = useSafeAreaInsets() @@ -83,18 +94,10 @@ export default function SuccessPage({ navigation, route }: TSuccessPageProps) { {isMelt && amount && - - - - - - - - - - - - +
+
+
+ {isNum(change) &&
} } @@ -138,6 +141,15 @@ export default function SuccessPage({ navigation, route }: TSuccessPageProps) { ) } +function Details({ key, value }: { key: string, value: string }) { + return ( + + + + + ) +} + const styles = ScaledSheet.create({ container: { flex: 1, diff --git a/src/wallet/index.ts b/src/wallet/index.ts index 71694397..5e68d979 100644 --- a/src/wallet/index.ts +++ b/src/wallet/index.ts @@ -235,7 +235,7 @@ export async function fullAutoMintSwap(tokenInfo: ITokenInfo, destMintUrl: strin proofs ) l('[fullAutoMintSwap]', { payResult, requestTokenResult }) - return { payResult, requestTokenResult } + return { payResult, requestTokenResult, estFee } } catch (e) { return { payResult: undefined, requestTokenResult: undefined } }