From 17cb8a80e9e6285e19d8701a0c35fbcfc6ffe048 Mon Sep 17 00:00:00 2001 From: zaidmstrr Date: Fri, 26 Apr 2024 21:05:55 +0530 Subject: [PATCH] Improving Typescript Enhancement 2 --- components/AttestationButton.tsx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/components/AttestationButton.tsx b/components/AttestationButton.tsx index f8acd4b30..8a47e2f55 100644 --- a/components/AttestationButton.tsx +++ b/components/AttestationButton.tsx @@ -10,28 +10,28 @@ import NostrichNotLoaded from '../assets/images/SVG/Nostrich_not-loaded.svg'; import NostrichValid from '../assets/images/SVG/Nostrich_valid.svg'; import NostrichInvalid from '../assets/images/SVG/Nostrich_invalid.svg'; import NostrichNotFound from '../assets/images/SVG/Nostrich_not-found.svg'; - export default function AttestationButton(props: any) { const { navigation, hash, amount_msat } = props; const [attestationStatus, setAttestationStatus] = useState('neutral'); const [loading, setLoading] = useState(false); const [attestations, setAttestations] = useState([]); + type attestationStatus = 'neutral' | 'success' | 'warning' | 'error'; return ( { + onPress={ async () => { if (attestationStatus === 'neutral') { setLoading(true); - stores.lightningAddressStore - .lookupAttestations(hash, amount_msat) - .then(({ attestations, status }) => { - setAttestations(attestations); - setAttestationStatus(status || ''); - setLoading(false); - }) - .catch(() => { - setLoading(false); - }); + try { + const { attestations, status } = await stores.lightningAddressStore.lookupAttestations(hash, amount_msat); + setAttestations(attestations); + setAttestationStatus(status || '' || 'error'); + } catch (error){ + console.error('Error fetching attestations:', error); + setAttestationStatus('error' || ''); + } finally { + setLoading(false); + } } else { if (attestationStatus === 'success') { navigation.navigate('Attestation', {