Skip to content

Commit

Permalink
Patch for bug in auto mint swap (#278)
Browse files Browse the repository at this point in the history
* fix checkFees and keyword "key" in success screen

* update nav UI on ios

* update var naming for estimated fee

* bump version to 0.2.1-beta
  • Loading branch information
KKA11010 committed Dec 11, 2023
1 parent 70a5f54 commit a89a519
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
"blind-signatures",
"lightning-network"
],
"version": "0.2.0",
"version": "0.2.1",
"license": "AGPL-3.0-only",
"bugs": {
"url": "https://github.com/cashubtc/eNuts/issues"
Expand Down
3 changes: 2 additions & 1 deletion src/components/nav/BottomNav.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BookIcon, SettingsIcon, WalletIcon } from '@comps/Icons'
import Txt from '@comps/Txt'
import { isIOS } from '@consts'
import type { TBottomNavProps, TRouteString } from '@model/nav'
import { useThemeContext } from '@src/context/Theme'
import { NS } from '@src/i18n'
Expand Down Expand Up @@ -51,7 +52,7 @@ export default function BottomNav({
<Animated.View
style={[
styles.bottomNav,
{ paddingBottom: vs(10) },
{ paddingBottom: isIOS ? vs(25) : vs(10) },
animatedBgStyles,
animatedPosStyles
]}>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Addressbook/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface ISearchStates {
hasResults: boolean
}

const marginBottom = vs(70)
const marginBottom = isIOS ? vs(45) : vs(70)
const marginBottomPayment = isIOS ? vs(20) : 0

// https://github.com/nostr-protocol/nips/blob/master/04.md#security-warning
Expand Down
6 changes: 3 additions & 3 deletions src/screens/Payment/Processing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP
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, estFee } = await fullAutoMintSwap(tokenInfo, targetMint.mintUrl)
const { payResult, requestTokenResult, estFeeResp } = await fullAutoMintSwap(tokenInfo, targetMint.mintUrl)
if (!payResult || !requestTokenResult) {
return handleError({ e: 'payResult or requestTokenResult is undefined' })
}
const amountSent = tokenInfo.value - estFee
const amountSent = tokenInfo.value - estFeeResp
// add as history entry (multimint swap)
await addToHistory({
amount: -amountSent,
Expand All @@ -203,7 +203,7 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP
navigation.navigate('success', {
amount: amountSent,
fee: payResult.realFee,
change: estFee - (payResult.realFee || 0),
change: estFeeResp - (payResult.realFee || 0),
isMelt: true
})
}
Expand Down
12 changes: 6 additions & 6 deletions src/screens/Payment/Success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ export default function SuccessPage({ navigation, route }: TSuccessPageProps) {
</View>
{isMelt && amount &&
<View style={styles.meltWrap}>
<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)} />}
<Details txt={t('paidOut', { ns: NS.wallet })} value={formatSatStr(amount)} />
<Details txt={t('fee')} value={formatSatStr(fee || 0)} />
<Details txt={t('totalInclFee')} value={formatSatStr(amount + (fee || 0))} />
{isNum(change) && <Details txt={t('change')} value={formatSatStr(change)} />}
</View>
}
</View>
Expand Down Expand Up @@ -141,10 +141,10 @@ export default function SuccessPage({ navigation, route }: TSuccessPageProps) {
)
}

function Details({ key, value }: { key: string, value: string }) {
function Details({ txt, value }: { txt: string, value: string }) {
return (
<View style={styles.meltOverview}>
<Txt txt={key} styles={[styles.meltTxt]} />
<Txt txt={txt} styles={[styles.meltTxt]} />
<Txt txt={value} styles={[styles.meltTxt]} />
</View>
)
Expand Down
9 changes: 5 additions & 4 deletions src/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export async function autoMintSwap(
fee: number,
proofs: Proof[] = []
): Promise<{ payResult: { result?: PayLnInvoiceResponse, fee?: number, realFee?: number, error?: unknown }; requestTokenResult: { success: boolean; invoice?: IInvoice | null } }> {
if (!isNum(fee) || fee <= 0) { fee = await checkFees(destMintUrl, (await requestMint(destMintUrl, amount)).pr) }
if (!isNum(fee) || fee <= 0) { fee = await checkFees(srcMintUrl, (await requestMint(destMintUrl, amount)).pr) }
l('[autoMintSwap]', { fee, amount, srcMintUrl, destMintUrl })
if (!amount || !isNum(amount) || isNaN(amount) || !isFinite(amount) || amount <= 0) {
throw new Error('Swap Error: not enough funds')
Expand All @@ -221,21 +221,22 @@ export async function autoMintSwap(
export async function fullAutoMintSwap(tokenInfo: ITokenInfo, destMintUrl: string) {
l('[fullAutoMintSwap] ', { tokenInfo, destMintUrl })
try {
const srcMintUrl = tokenInfo.mints[0]
const invoice = await requestMint(destMintUrl, tokenInfo.value)
const estFee = await checkFees(destMintUrl, invoice.pr)
const estFee = await checkFees(srcMintUrl, invoice.pr)
const proofs: Proof[] = []
for (const t of tokenInfo.decoded.token) {
proofs.push(...t.proofs)
}
const { payResult, requestTokenResult } = await autoMintSwap(
tokenInfo.mints[0],
srcMintUrl,
destMintUrl,
tokenInfo.value - estFee,
estFee,
proofs
)
l('[fullAutoMintSwap]', { payResult, requestTokenResult })
return { payResult, requestTokenResult, estFee }
return { payResult, requestTokenResult, estFeeResp: estFee }
} catch (e) {
return { payResult: undefined, requestTokenResult: undefined }
}
Expand Down

0 comments on commit a89a519

Please sign in to comment.