Skip to content

Commit

Permalink
Add donation modal (#152)
Browse files Browse the repository at this point in the history
* fix error in ecash history overview screen

* Fixes #151

* format int of proof value

* format int of balance in sending screen

* make test-mint DEV-only

* provide optional default enuts mint

* add default enuts mint disclaimer

* fix spellin

* add separator

* enhance the risk section

* add donation modal

* update translation

* update color

* fix CI

* check case of testmint added by user

* remove the build workflow on release-tag
  • Loading branch information
KKA11010 authored Sep 2, 2023
1 parent 1cb308d commit 0f413af
Show file tree
Hide file tree
Showing 18 changed files with 308 additions and 169 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/eas.yml

This file was deleted.

17 changes: 12 additions & 5 deletions assets/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"accept": "Annehmen",
"addMemo": "Fügen Sie ein Memo mit max. 21 Zeichen hinzu.",
"addMint": "Erste Mint hinzufügen",
"addEnutsMint": "eNuts mint verwenden",
"amount": "Betrag",
"back": "Zurück",
"backToDashboard": "Zurück zu Wallet",
Expand Down Expand Up @@ -156,7 +157,7 @@
"scanTokenOrLn": "Cashu Token oder LN Rechnung scannen",
"scanLn": "Lightning Rechnung scannen",
"scan": "Scannen",
"enutsBeta": "eNuts ist beta Software.",
"enutsBeta": "eNuts ist beta Software",
"seconds": "Sekunden",
"selectAmount": "Betrag auswählen",
"selected": "Ausgewählt",
Expand All @@ -165,7 +166,7 @@
"sendEcash": "Ecash senden",
"share": "Teilen",
"smthWrong": "Etwas is schief gelaufen",
"startHint": "Sie sollten eine Mint hinzufügen und via Lightning aufladen um Ecash senden zu können.",
"startHint": "Sie können entweder die bereits vorhandene eNuts-Mint verwenden oder Ihre eigene.",
"submitPaymentReq": "Zahlungsanfrage absenden",
"to": "bis",
"today": "Heute",
Expand All @@ -178,6 +179,7 @@
"unknownType": "Unbekannter Code-Typ",
"version": "Version",
"willDoLater": "Mache ich später",
"addOwn": "Mint URL hinzufügen",
"yes": "Ja",
"invalidPubKey": "Invalider öffentlicher Schlüssel!",
"whatsNostr": "Was ist NOSTR?",
Expand Down Expand Up @@ -209,7 +211,10 @@
"seeFullHistory": "Gesamter Transaktionsverlauf",
"hideLatestTxs": "Aktuellste Transaktionen verbergen",
"hiddenTxs": "Transaktionen verborgen",
"next": "Weiter"
"next": "Weiter",
"donateLn": "Spenden über Lightning",
"supportDev": "Zap die Entwicklung",
"supportHint": "Jeder Beitrag, ganz gleich in welcher Höhe, hat eine bedeutende Auswirkung. (Die eNuts Bestätigungsseite befindet sich in der Entwicklung)"
},
"error": {
"addAllMintIdsErr": "Fehler beim Abrufen der Schlüsselsatz-IDs von Mint",
Expand Down Expand Up @@ -283,7 +288,7 @@
"copyShareTokenHint": "Kopieren Sie den Ecash-Token und teilen Sie ihn über eine Messenger App.",
"sendNostr": "Senden via NOSTR",
"sendNostrHint": "Senden Sie Ecash ohne Umwege an eins Ihrer Kontakte in NOSTR.",
"meltToken": "Tokens auszahlen",
"meltToken": "Satoshi zurückfordern",
"mintConnectionFail": "Verbindung zu Mint fehlgeschlagen",
"mintInfo": "Mint Info",
"mintNewTokens": "Neues Ecash Anfordern",
Expand Down Expand Up @@ -322,7 +327,7 @@
"history": "Transaktionsverlauf",
"language": "Sprache",
"mintBackup": "Guthabensicherung",
"mintSettings": "Mint Einstellungen",
"mintSettings": "Mint Management",
"security": "Sicherheit",
"settings": "Einstellungen",
"privacy": "Privatsphäre",
Expand All @@ -339,6 +344,8 @@
"enutsDisclaimer": "eNuts ist unvollendete Beta-Software.",
"lossContent": "Cashu-Token sind Inhabertoken, was bedeutet, dass es derzeit keine Möglichkeit zur Wiederherstellung gibt, wenn Sie den Zugriff darauf verlieren. eNuts speichert Ihre Token auf Ihrem Gerät. Stellen Sie vor dem Löschen der App sicher, dass Sie Ihre Token gesichert haben.",
"lossOfTokens": "Verlust von Geldern.",
"enutsMint": "Die standardmäßige eNuts-Mint",
"mintDisclaimer": "Die Verwendung der standardmäßigen eNuts-Mint erfolgt vollständig auf eigenes Risiko. Wir empfehlen dringend, Vorsicht walten zu lassen und sie nur für experimentelle oder Bildungszwecke zu nutzen. Es gibt keine Garantien hinsichtlich ihrer Funktionalität, Sicherheit oder Verfügbarkeit, und sie kann ohne Vorankündigung verschwinden. Einlagen, die in diese Mint getätigt werden, sollten als Spenden betrachtet werden und können möglicherweise nicht zurückgegeben werden, sondern eventuell für die Weiterentwicklung verwendet werden. Seien Sie sich der mit Beta-Software verbundenen Risiken bewusst, und es liegt in Ihrer Verantwortung, Ihre Vermögenswerte beim Gebrauch dieser Mint zu schützen.",
"paidOut": "Ausbezahlt",
"pasteToken": "Ecash aus Zwischenablage",
"payInvoice": "Rechnung bezahlen",
Expand Down
17 changes: 12 additions & 5 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"accept": "Accept",
"addMemo": "Add a memo with max. 21 chars.",
"addMint": "Add a mint",
"addEnutsMint": "Use the eNuts mint",
"amount": "Amount",
"back": "Back",
"backToDashboard": "Back to dashboard",
Expand Down Expand Up @@ -156,7 +157,7 @@
"scanTokenOrLn": "Scan Cashu token or Lightning invoice",
"scanLn": "Scan Lightning invoice",
"scan": "Scan",
"enutsBeta": "eNuts is beta software.",
"enutsBeta": "eNuts is beta software →",
"seconds": "seconds",
"selectAmount": "Select amount",
"selected": "Selected",
Expand All @@ -165,7 +166,7 @@
"sendEcash": "Send Ecash",
"share": "Share",
"smthWrong": "Something went wrong",
"startHint": "You should add a mint and top it up via Lightning to be able to send Ecash.",
"startHint": "You can either use the pre-existing eNuts mint or introduce another custom mint.",
"submitPaymentReq": "Submit Payment Request",
"to": "to",
"today": "Today",
Expand All @@ -178,6 +179,7 @@
"unknownType": "Unknown data",
"version": "Version",
"willDoLater": "Will do later",
"addOwn": "Add mint URL",
"yes": "Yes",
"invalidPubKey": "Invalid public key!",
"whatsNostr": "What is NOSTR?",
Expand Down Expand Up @@ -209,7 +211,10 @@
"seeFullHistory": "See full transaction history",
"hideLatestTxs": "Hide your latest transactions",
"hiddenTxs": "Latest transactions hidden",
"next": "Next"
"next": "Next",
"donateLn": "Donate via Lightning",
"supportDev": "Zap the devs",
"supportHint": "Every contribution, no matter the size, makes a significant impact. (eNuts confirmation screen is under development)"
},
"error": {
"addAllMintIdsErr": "Error while getting keyset ids from mint",
Expand Down Expand Up @@ -283,7 +288,7 @@
"copyShareTokenHint": "Copy the generated token and share it via any messenger app.",
"sendNostr": "Send via NOSTR",
"sendNostrHint": "Send Ecash directly to one of your NOSTR contacts.",
"meltToken": "Melt token",
"meltToken": "Cash out",
"mintConnectionFail": "Connection to mint failed",
"mintInfo": "Mint info",
"mintNewTokens": "Mint New Token",
Expand Down Expand Up @@ -322,7 +327,7 @@
"history": "Transaction history",
"language": "Language",
"mintBackup": "Backup funds",
"mintSettings": "Mint settings",
"mintSettings": "Mint management",
"security": "Security",
"settings": "Settings",
"privacy": "Privacy",
Expand All @@ -339,6 +344,8 @@
"enutsDisclaimer": "eNuts is unfinished beta software.",
"lossContent": "Cashu tokens are bearer tokens, implying that if you lose access to them, there is no recovery option implemented yet. eNuts stores your tokens in your device. Before deleting the app, ensure you back up your tokens.",
"lossOfTokens": "Loss of funds.",
"enutsMint": "The default eNuts mint",
"mintDisclaimer": "The usage of the default eNuts mint is entirely at your own risk. We strongly encourage you to exercise caution and only use it for experimental or educational purposes. There are no guarantees regarding its functionality, security, or availability, and it may vanish without notice. Deposits made to this mint should be considered as donations and may not be returned, potentially used for further development. Be aware of the risks associated with beta software, and it's your responsibility to safeguard your assets while using this mint.",
"paidOut": "Paid out",
"pasteToken": "Paste & redeem Ecash",
"payInvoice": "Pay invoice",
Expand Down
15 changes: 11 additions & 4 deletions assets/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"accept": "Accepter",
"addMemo": "Ajouter une note avec un maximum de 21 caractères.",
"addMint": "Ajouter une mint",
"addEnutsMint": "Utiliser eNuts mint",
"amount": "Montant",
"back": "Retour",
"backToDashboard": "Retour au tableau de bord",
Expand Down Expand Up @@ -156,7 +157,7 @@
"scanTokenOrLn": "Scanner le Cashu token ou facture Lightning",
"scanLn": "Scanner la facture Lightning",
"scan": "Scanner",
"enutsBeta": "enuts est une version bêta.",
"enutsBeta": "enuts est une version bêta",
"seconds": "secondes",
"selectAmount": "Sélectionner le montant",
"selected": "Sélectionné",
Expand All @@ -165,7 +166,7 @@
"sendEcash": "Envoyer Ecash",
"share": "Partager",
"smthWrong": "Quelque chose s'est mal passé",
"startHint": "Vous devriez ajouter un mint et le recharger via Lightning pour pouvoir envoyer de l'Ecash.",
"startHint": "Vous pouvez soit utiliser la mint de eNuts préexistante, soit une autre out votre propre mint.",
"submitPaymentReq": "Demande de paiement",
"to": "à",
"today": "Aujourd'hui",
Expand All @@ -178,6 +179,7 @@
"unknownType": "Données inconnues",
"version": "Version",
"willDoLater": "Je ferai plus tard",
"addOwn": "Ajouter mint URL",
"yes": "Oui",
"invalidPubKey": "Clé publique invalide!",
"whatsNostr": "C'est quoi NOSTR?",
Expand Down Expand Up @@ -206,7 +208,10 @@
"enutsPub": "eNuts clé public: ",
"seeFullHistory": "Gesamter Transaktionsverlauf",
"hiddenTxs": "Dernières transactions masquées",
"next": "Suivant"
"next": "Suivant",
"donateLn": "Faire un don via Lightning",
"supportDev": "Zap le développement",
"supportHint": "Chaque contribution, quelle que soit sa taille, a un impact significatif. (L'écran de confirmation eNuts est en cours de développement)"
},
"error": {
"addAllMintIdsErr": "Erreur lors de l'obtention de l'ensemble de clés de la mint",
Expand Down Expand Up @@ -280,7 +285,7 @@
"copyShareTokenHint": "Copiez le Ecash token généré et partagez-le via n'importe quelle application de messagerie.",
"sendNostr": "Envoyer via NOSTR",
"sendNostrHint": "Envoyez Ecash directement à l'un de vos contacts NOSTR.",
"meltToken": "Échanger des token",
"meltToken": "Retirer vos Satoshi",
"mintConnectionFail": "Échec de la connexion à la mint",
"mintInfo": "Informations sur la mint",
"mintNewTokens": "Créer de nouveaux token",
Expand Down Expand Up @@ -340,6 +345,8 @@
"enutsDisclaimer": "eNuts est un logiciel beta inachevé.",
"lossContent": "Les token Cashu sont des token au porteur, ce qui signifie qu'en cas de perte d'accès, il n'y a pas d'option de récupération. eNuts stocke vos token sur votre appareil. Avant de supprimer l'application, assurez-vous de sauvegarder vos token.",
"lossOfTokens": "Perte de fonds.",
"enutsMint": "Die standardmäßige eNuts-Mint",
"mintDisclaimer": "L'utilisation de la mint eNuts par défaut se fait entièrement à vos propres risques. Nous vous encourageons vivement à faire preuve de prudence et à ne l'utiliser que à des fins expérimentales ou éducatives. Aucune garantie n'est donnée quant à sa fonctionnalité, sa sécurité ou sa disponibilité, et elle peut disparaître sans préavis. Les dépôts effectués dans cette mint doivent être considérés comme des dons et ne pourront éventuellement pas être restitués, mais pourraient être utilisés pour le développement ultérieur. Soyez conscient des risques associés aux logiciels en version bêta, et il est de votre responsabilité de protéger vos actifs lors de l'utilisation de cette mint.",
"paidOut": "Payé",
"pasteToken": "Coller et échanger Ecash",
"payInvoice": "Payer une facture",
Expand Down
4 changes: 2 additions & 2 deletions src/components/InitialModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export default function InitialModal({ visible, onConfirm, onCancel }: IInitialM
<Text style={globals(color, highlight).modalTxt}>
{t('startHint')}
</Text>
<Button txt={t('addMint')} onPress={onConfirm} />
<Button txt={t('addEnutsMint')} onPress={onConfirm} />
<TxtButton
txt={t('willDoLater')}
txt={t('addOwn')}
onPress={onCancel}
style={[{ paddingTop: 25, paddingBottom: 10, }]}
/>
Expand Down
118 changes: 118 additions & 0 deletions src/components/modal/Zap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import Button, { TxtButton } from '@comps/Button'
import useLoading from '@comps/hooks/Loading'
import RadioBtn from '@comps/RadioBtn'
import Separator from '@comps/Separator'
import Txt from '@comps/Txt'
import { DONATION_ADDR } from '@consts/mints'
import { usePromptContext } from '@src/context/Prompt'
import { useThemeContext } from '@src/context/Theme'
import { NS } from '@src/i18n'
import { globals } from '@styles'
import { formatInt, getInvoiceFromLnurl, isErr, openUrl } from '@util'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'

import MyModal from '.'

interface IQuestionModalProps {
visible: boolean
close: () => void
}

interface IZap { amount: number, emoji: string, selected: boolean }

export function ZapModal({ visible, close }: IQuestionModalProps) {
const { t } = useTranslation([NS.common])
const { color } = useThemeContext()
const { openPromptAutoClose } = usePromptContext()
const { loading, startLoading, stopLoading } = useLoading()
const [zaps, setZaps] = useState([
{ amount: 210, emoji: '❤️', selected: true },
{ amount: 2100, emoji: '🙏', selected: false },
{ amount: 21000, emoji: '🌟', selected: false },
{ amount: 210000, emoji: '🚀', selected: false },
{ amount: 420000, emoji: '💎', selected: false },
{ amount: 840000, emoji: '😱', selected: false },
])

const handleSelect = (zap: IZap) => {
setZaps(zaps.map(z => ({ ...z, selected: z.amount === zap.amount })))
}

const handleDonation = async () => {
startLoading()
try {
const zap = zaps.find(z => z.selected)
if (!zap) {
openPromptAutoClose({ msg: 'Zap error' })
return
}
// TODO store invoice and check if it has been payed
const invoice = await getInvoiceFromLnurl(DONATION_ADDR, zap.amount)
stopLoading()
close()
await openUrl(`lightning:${invoice}`)?.catch(e =>
openPromptAutoClose({ msg: isErr(e) ? e.message : t('deepLinkErr') }))
} catch (e) {
openPromptAutoClose({ msg: isErr(e) ? e.message : t('deepLinkErr') })
}
}

return (
<MyModal type='bottom' animation='slide' visible={visible} close={close} >
<Text style={globals(color).modalHeader}>
{t('supportDev')}
</Text>
<Text style={globals(color).modalTxt}>
{t('supportHint')}
</Text>
<View style={{ width: '100%', marginBottom: 20 }}>
{zaps.map(z => <Selection key={z.amount} zap={z} onPress={handleSelect} />)}
</View>
<Button
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
txt={`${t('donateLn')} 🎁`}
onPress={() => void handleDonation()}
loading={loading}
/>
<TxtButton txt={t('cancel')} onPress={close} />
</MyModal>
)
}

interface ISelectionProps {
zap: IZap
onPress: (zap: IZap) => void
}

function Selection({ zap, onPress }: ISelectionProps) {
return (
<>
<TouchableOpacity style={styles.zapRow} onPress={() => onPress(zap)} >
<View style={styles.amountWrap}>
<Text>{zap.emoji}</Text>
<Txt
txt={`${formatInt(zap.amount, 'compact')} Satoshi`}
styles={[{ marginLeft: 10 }]}
/>
</View>
<RadioBtn selected={zap.selected} />
</TouchableOpacity>
{zap.amount < 840000 && <Separator />}
</>
)
}

const styles = StyleSheet.create({
zapRow: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingVertical: 15
},
amountWrap: {
flexDirection: 'row',
alignItems: 'center'
}
})
Loading

0 comments on commit 0f413af

Please sign in to comment.