Display transaction error in wallet embed component

This commit is contained in:
Adw8 2024-11-11 10:21:34 +05:30
parent 198ccd98c3
commit cd640e77f8

View File

@ -1,6 +1,7 @@
import React, { useEffect, useState, useCallback, useRef } from 'react'; import React, { useEffect, useState, useCallback, useRef } from 'react';
import { ScrollView, View } from 'react-native'; import { ScrollView, View } from 'react-native';
import { import {
ActivityIndicator,
Button, Button,
Text, Text,
TextInput, TextInput,
@ -193,7 +194,10 @@ export const WalletEmbed = () => {
setIsTxRequested(true); setIsTxRequested(true);
} catch (error) { } catch (error) {
console.error('Error processing transaction request:', error); if (!(error instanceof Error)) {
throw error;
}
setTxError(error.message);
} }
}, [networksData]); }, [networksData]);
@ -247,8 +251,10 @@ export const WalletEmbed = () => {
console.error('No event source available to send message'); console.error('No event source available to send message');
} }
} catch (error) { } catch (error) {
console.error('Transaction error:', error); if (!(error instanceof Error)) {
setTxError('Transaction failed'); throw error;
}
setTxError(error.message);
} finally { } finally {
setIsTxLoading(false); setIsTxLoading(false);
} }
@ -314,7 +320,7 @@ export const WalletEmbed = () => {
mode="contained" mode="contained"
onPress={acceptRequestHandler} onPress={acceptRequestHandler}
loading={isTxLoading} loading={isTxLoading}
disabled={!transactionDetails.balance || !fees} disabled={!transactionDetails.balance || !fees || isTxLoading}
> >
{isTxLoading ? 'Processing' : 'Yes'} {isTxLoading ? 'Processing' : 'Yes'}
</Button> </Button>
@ -328,11 +334,21 @@ export const WalletEmbed = () => {
</Button> </Button>
</View> </View>
</> </>
) : null} ) : (
<View style={styles.spinnerContainer}>
<Text style={styles.LoadingText}>Loading...</Text>
<ActivityIndicator size="large" color="#0000ff" />
</View>
)}
<TxErrorDialog <TxErrorDialog
error={txError!} error={txError!}
visible={!!txError} visible={!!txError}
hideDialog={() => setTxError(null)} hideDialog={() => {
setTxError(null)
if (window.parent) {
window.parent.postMessage('closeIframe', '*');
}
}}
/> />
</> </>
); );