From 60bfe8d1439080cb365b2bd552146ebf58eafe5c Mon Sep 17 00:00:00 2001 From: First-Terraner Date: Sat, 9 Sep 2023 21:57:06 +0200 Subject: [PATCH 1/9] update error messages in the melting process #175 --- assets/translations/de.json | 4 ++- assets/translations/en.json | 4 ++- assets/translations/fr.json | 4 ++- src/model/index.ts | 8 +++++- src/screens/Payment/Processing.tsx | 37 +++++++++++++++++-------- src/screens/Payment/ProcessingError.tsx | 2 +- src/screens/Payment/Send/Inputfield.tsx | 6 ++-- src/screens/Payment/Success.tsx | 3 ++ src/wallet/index.ts | 9 +++--- 9 files changed, 55 insertions(+), 22 deletions(-) diff --git a/assets/translations/de.json b/assets/translations/de.json index b8fa1a13..90d4d1f4 100644 --- a/assets/translations/de.json +++ b/assets/translations/de.json @@ -230,7 +230,9 @@ "msg": "Es tut uns leid, dass dieses Problem bei Ihnen aufgetreten ist. Sie können uns helfen, die Software zu verbessern, indem Sie einen Screenshot machen und einen kurzen Fehlerbericht erstellen.", "reportBug": "Fehler melden", "requestMintErr": "Fehler beim Abrufen der Rechnung von der Mint.", - "stackNA": "Ursprung des Fehlers nicht verfügbar" + "stackNA": "Ursprung des Fehlers nicht verfügbar", + "generalMeltingErr": "Die Mint konnte keine geeignete Lightning-Zahlungsroute zu Ihrer Node finden.", + "invoiceFromLnurlError": "Es konnte keine Rechnung erstellt werden mit deiner LNURL." }, "history": { "checkSpent": "Überprüfen ob Token ausgegeben wurde", diff --git a/assets/translations/en.json b/assets/translations/en.json index de3cd3c3..147b77e5 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -230,7 +230,9 @@ "msg": "We are sorry that you encountered this problem. You can help us improve the software by taking a screenshot and creating a short bug report.", "reportBug": "Report the bug", "requestMintErr": "Error while requesting invoice from mint.", - "stackNA": "Error stack not available" + "stackNA": "Error stack not available", + "generalMeltingErr": "The mint was not able to find a proper Lightning payment route to your node.", + "invoiceFromLnurlError": "Could not create an invoice using your LNURL." }, "history": { "checkSpent": "Check if token has been spent", diff --git a/assets/translations/fr.json b/assets/translations/fr.json index b706eba9..8ccd2b64 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -227,7 +227,9 @@ "msg": "Nous sommes désolés que vous ayez rencontré ce problème. Vous pouvez nous aider à améliorer le logiciel en prenant une capture d'écran et en créant un court rapport de bug.", "reportBug": "Signaler le bug", "requestMintErr": "Erreur lors de la demande de la facture à partir de mint.", - "stackNA": "Pile d'erreur non disponible" + "stackNA": "Pile d'erreur non disponible", + "generalMeltingErr": "La mint n'a pas pu trouver un itinéraire de paiement Lightning approprié vers votre nœud.", + "invoiceFromLnurlError": "Impossible de créer une facture à l'aide de votre LNURL." }, "history": { "checkSpent": "Vérifier si le token a été dépensé", diff --git a/src/model/index.ts b/src/model/index.ts index d3eca0b1..05a94de1 100644 --- a/src/model/index.ts +++ b/src/model/index.ts @@ -82,9 +82,15 @@ export interface IProofSelection extends Proof { selected: boolean } +/** + * type: 1 | 2 | 3 + * 1 = send/receive Ecash + * 2 = LN invoice + * 3 = multimint swap + */ export interface IHistoryEntry { amount: number - type: 1 | 2 | 3 // 1 = send/receive Ecash | 2 = LN invoice | 3 = multimint swap + type: 1 | 2 | 3 timestamp: number value: string // Lightning invoice or encoded Cashu token mints: string[] // mints involved diff --git a/src/screens/Payment/Processing.tsx b/src/screens/Payment/Processing.tsx index a428e169..1535b4bc 100644 --- a/src/screens/Payment/Processing.tsx +++ b/src/screens/Payment/Processing.tsx @@ -15,7 +15,7 @@ import { cTo } from '@src/storage/store/utils' import { secureStore, store } from '@store' import { SECRET, STORE_KEYS } from '@store/consts' import { addLnPaymentToHistory } from '@store/HistoryStore' -import { addToHistory } from '@store/latestHistoryEntries' +import { addToHistory, updateLatestHistory } from '@store/latestHistoryEntries' import { globals } from '@styles' import { formatMintUrl, getInvoiceFromLnurl, isErr, isLnurl } from '@util' import { autoMintSwap, payLnInvoice, requestMint, requestToken, sendToken } from '@wallet' @@ -23,6 +23,11 @@ import { useEffect } from 'react' import { useTranslation } from 'react-i18next' import { StyleSheet, View } from 'react-native' +interface IErrorProps { + e?: unknown + customMsg?: 'requestMintErr' | 'generalMeltingErr' | 'invoiceFromLnurlError' +} + export default function ProcessingScreen({ navigation, route }: TProcessingPageProps) { const { t } = useTranslation([NS.mints]) const { color } = useThemeContext() @@ -40,9 +45,8 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP recipient } = route.params - const handleError = (e?: unknown) => { - // TODO check error screen msgs - const translatedErrMsg = t(isMelt ? 'requestMintErr' : 'requestMintErr', { ns: NS.error }) + const handleError = ({ e, customMsg }: IErrorProps) => { + const translatedErrMsg = t(customMsg || 'requestMintErr', { ns: NS.error }) navigation.navigate('processingError', { amount, mint, @@ -76,7 +80,7 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP if (mint.mintUrl === _testmintUrl) { const { success, invoice } = await requestToken(mint.mintUrl, amount, resp.hash) if (!success) { - handleError() + handleError({}) return } // add as history entry (receive ecash via lightning) @@ -98,7 +102,7 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP paymentRequest: decoded.paymentRequest }) } catch (e) { - handleError(e) + handleError({ e }) } } @@ -110,18 +114,19 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP try { invoice = await getInvoiceFromLnurl(recipient, +amount) if (!invoice?.length) { - handleError() + handleError({ customMsg: 'invoiceFromLnurlError' }) return } } catch (e) { - handleError(e) + handleError({ e }) return } } try { const res = await payLnInvoice(mint.mintUrl, invoice || recipient, estFee || 0, proofs || []) if (!res.result?.isPaid) { - handleError() + // here it could be a routing path finding issue + handleError({ customMsg: 'generalMeltingErr' }) return } // payment success, add as history entry @@ -131,13 +136,21 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP -amount, invoice || recipient ) + // update latest 3 history entries + await updateLatestHistory({ + amount: -amount, + type: 2, + value: invoice || recipient, + mints: [mint.mintUrl], + timestamp: Math.ceil(Date.now() / 1000) + }) navigation.navigate('success', { amount: amount - (estFee || 0), fee: res.realFee, isMelt: true }) } catch (e) { - handleError(e) + handleError({ e }) } } @@ -160,7 +173,7 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP isMelt: true }) } catch (e) { - handleError(e) + handleError({ e }) } } @@ -218,6 +231,7 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP ) } } + // start payment process useEffect(() => { if (isMelt) { @@ -235,6 +249,7 @@ export default function ProcessingScreen({ navigation, route }: TProcessingPageP void handleMintingProcess() // eslint-disable-next-line react-hooks/exhaustive-deps }, [isMelt, isSwap, isSendEcash]) + return ( diff --git a/src/screens/Payment/ProcessingError.tsx b/src/screens/Payment/ProcessingError.tsx index 9f79925b..a0da603a 100644 --- a/src/screens/Payment/ProcessingError.tsx +++ b/src/screens/Payment/ProcessingError.tsx @@ -15,7 +15,7 @@ export default function ProcessingErrorScreen({ navigation, route }: TProcessing - +