Add new component WalletEmbed to handle tx requests via iframe messaging #18

Merged
nabarun merged 16 commits from deep-stack/laconic-wallet-web:ag-iframe into main 2024-11-12 09:46:17 +00:00
Showing only changes of commit 198ccd98c3 - Show all commits

View File

@ -200,7 +200,7 @@ export const WalletEmbed = () => {
useEffect(() => {
window.addEventListener('message', handleTxRequested);
return () => window.removeEventListener('message', handleTxRequested);
}, [networksData, handleTxRequested]);
}, [handleTxRequested]);
const acceptRequestHandler = async () => {
try {
@ -242,7 +242,7 @@ export const WalletEmbed = () => {
const event = txEventRef.current;
if (event?.source) {
sendMessage(event.source as Window, 'TRANSACTION_SUCCESS', txResult.transactionHash, event.origin);
sendMessage(event.source as Window, 'TRANSACTION_RESPONSE', txResult.transactionHash, event.origin);
} else {
console.error('No event source available to send message');
}
@ -255,9 +255,15 @@ export const WalletEmbed = () => {
};
const rejectRequestHandler = () => {
const event = txEventRef.current;
setIsTxRequested(false);
setTransactionDetails(null);
sendMessage(window, 'TRANSACTION_REJECTED', null, '*');
if (event?.source) {
sendMessage(event.source as Window, 'TRANSACTION_RESPONSE', null, event.origin);
} else {
console.error('No event source available to send message');
}
};
return (