Set event for tx success
This commit is contained in:
parent
f82ff49d77
commit
08711b50d6
@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useState, useCallback } from 'react';
|
||||
import React, { useEffect, useState, useCallback, useRef } from 'react';
|
||||
|
||||
import { ScrollView, View } from 'react-native';
|
||||
import {
|
||||
@ -32,6 +32,7 @@ export const WalletEmbed = () => {
|
||||
const [gasLimit, setGasLimit] = useState('');
|
||||
const [isTxLoading, setIsTxLoading] = useState(false);
|
||||
const [txError, setTxError] = useState<string | null>(null);
|
||||
const txEventRef = useRef<MessageEvent | null>(null);
|
||||
|
||||
const { networksData } = useNetworks();
|
||||
|
||||
@ -117,6 +118,8 @@ export const WalletEmbed = () => {
|
||||
const handleTxRequested = async (event: MessageEvent) => {
|
||||
if (event.data.type !== 'REQUEST_TX') return;
|
||||
|
||||
txEventRef.current = event;
|
||||
|
||||
const { chainId, fromAddress, toAddress, amount } = event.data;
|
||||
const network = networksData.find(
|
||||
net => net.chainId === chainId
|
||||
@ -200,7 +203,7 @@ export const WalletEmbed = () => {
|
||||
useEffect(() => {
|
||||
window.addEventListener('message', handleTxRequested);
|
||||
return () => window.removeEventListener('message', handleTxRequested);
|
||||
}, [networksData]);
|
||||
}, [networksData, handleTxRequested]);
|
||||
|
||||
const acceptRequestHandler = async () => {
|
||||
try {
|
||||
@ -240,7 +243,12 @@ export const WalletEmbed = () => {
|
||||
fee
|
||||
);
|
||||
|
||||
sendMessage(window, 'TRANSACTION_SUCCESS', txResult.transactionHash, '*');
|
||||
const event = txEventRef.current;
|
||||
if (event?.source) {
|
||||
sendMessage(event.source as Window, 'TRANSACTION_SUCCESS', txResult.transactionHash, '*');
|
||||
} else {
|
||||
console.error('No event source available to send message');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Transaction error:', error);
|
||||
setTxError('Transaction failed');
|
||||
|
Loading…
Reference in New Issue
Block a user