import React, { useState, useEffect } from 'react'; import AsyncStorage from '@react-native-async-storage/async-storage'; import { Image, Linking, ScrollView, StyleSheet, View } from 'react-native'; import { BlueButtonLink, BlueCard, BlueLoading, BlueSpacing20, BlueSpacing40, BlueText } from '../../BlueComponents'; import Lnurl from '../../class/lnurl'; import Button from '../../components/Button'; import SafeArea from '../../components/SafeArea'; import loc from '../../loc'; import { SuccessView } from '../send/success'; import { popToTop } from '../../NavigationService'; import { useRoute, RouteProp } from '@react-navigation/native'; import { DetailViewStackParamList } from '../../navigation/DetailViewStackParamList'; import { useExtendedNavigation } from '../../hooks/useExtendedNavigation.ts'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; type LnurlPaySuccessRouteProp = RouteProp; type LnurlPaySuccessNavigationProp = NativeStackNavigationProp; const LnurlPaySuccess: React.FC = () => { const route = useRoute(); const { navigate } = useExtendedNavigation(); const { paymentHash, fromWalletID, justPaid } = route.params; console.log({ paymentHash, fromWalletID, justPaid }); const [isLoading, setIsLoading] = useState(true); const [LN, setLN] = useState(null); const [preamble, setPreamble] = useState(''); const [message, setMessage] = useState(''); const [url, setUrl] = useState(''); useEffect(() => { const loadSuccessfulPayment = async () => { const lnurl = new Lnurl(false, AsyncStorage); await lnurl.loadSuccessfulPayment(paymentHash); const successAction = lnurl.getSuccessAction(); if (!successAction) { setIsLoading(false); setLN(lnurl); return; } switch (successAction.tag) { case 'aes': { const preimage = lnurl.getPreimage(); if (!preimage) { break; } setMessage(Lnurl.decipherAES(successAction.ciphertext, preimage, successAction.iv)); setPreamble(successAction.description); break; } case 'url': setUrl(successAction.url); setPreamble(successAction.description); break; case 'message': setMessage(successAction.message); break; } setIsLoading(false); setLN(lnurl); }; loadSuccessfulPayment(); }, [paymentHash]); if (isLoading || !LN) { return ; } const domain = LN.getDomain(); const repeatable = !LN.getDisposable(); const lnurl = LN.getLnurl(); const description = LN.getDescription(); const image = LN.getImage(); return ( {justPaid && } {domain} {description} {image && } {(preamble || url || message) && ( {preamble} {url ? ( { Linking.openURL(url); }} /> ) : ( {message} )} )} {repeatable ? (