Skip to content

Commit

Permalink
fix success screen data. Show change amount in success screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
KKA11010 committed Dec 6, 2023
1 parent b601f75 commit 95b62e0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/model/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export type RootStackParamList = {
isZap?: boolean
nostr?: INostrSendData
isScanned?: boolean
change?: number
}
mintmanagement: {
mint: IMintUrl
Expand Down
16 changes: 10 additions & 6 deletions src/screens/Payment/Processing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 })
Expand All @@ -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) {
Expand All @@ -183,23 +185,25 @@ 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 || '',
mints: [mint.mintUrl],
recipient: targetMint?.mintUrl || ''
})
navigation.navigate('success', {
amount: tokenInfo.value,
amount: amountSent,
fee: payResult.realFee,
change: estFee - (payResult.realFee || 0),
isMelt: true
})
}
Expand Down
40 changes: 26 additions & 14 deletions src/screens/Payment/Success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()
Expand Down Expand Up @@ -83,18 +94,10 @@ export default function SuccessPage({ navigation, route }: TSuccessPageProps) {
</View>
{isMelt && amount &&
<View style={styles.meltWrap}>
<View style={styles.meltOverview}>
<Txt txt={t('paidOut', { ns: NS.wallet })} styles={[styles.meltTxt]} />
<Txt txt={formatSatStr(amount)} styles={[styles.meltTxt]} />
</View>
<View style={styles.meltOverview}>
<Txt txt={t('fee')} styles={[styles.meltTxt]} />
<Txt txt={formatSatStr(fee || 0)} styles={[styles.meltTxt]} />
</View>
<View style={styles.meltOverview}>
<Txt txt={t('totalInclFee')} styles={[styles.meltTxt]} />
<Txt txt={formatSatStr(amount + (fee || 0))} styles={[styles.meltTxt]} />
</View>
<Details key={t('paidOut', { ns: NS.wallet })} value={formatSatStr(amount)} />
<Details key={t('fee')} value={formatSatStr(fee || 0)} />
<Details key={t('totalInclFee')} value={formatSatStr(amount + (fee || 0))} />
{isNum(change) && <Details key={t('change')} value={formatSatStr(change)} />}
</View>
}
</View>
Expand Down Expand Up @@ -138,6 +141,15 @@ export default function SuccessPage({ navigation, route }: TSuccessPageProps) {
)
}

function Details({ key, value }: { key: string, value: string }) {
return (
<View style={styles.meltOverview}>
<Txt txt={key} styles={[styles.meltTxt]} />
<Txt txt={value} styles={[styles.meltTxt]} />
</View>
)
}

const styles = ScaledSheet.create({
container: {
flex: 1,
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down

0 comments on commit 95b62e0

Please sign in to comment.