From 5b9ec5cbc812036d50a3442a92085c56a7ae21f3 Mon Sep 17 00:00:00 2001 From: ruisantiago Date: Tue, 11 Mar 2025 14:46:43 +0000 Subject: [PATCH 1/2] feat: Add callback URLs for transaction redirection Added walletCallbackUrl to executeWithAccount and callbackUrl to executeWithWallet functions. These parameters ensure that users are redirected back to the original URL after signing a transaction, improving the user experience by maintaining context and continuity. --- src/hooks/useTransaction.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/hooks/useTransaction.ts b/src/hooks/useTransaction.ts index e4aabf0..71a364f 100644 --- a/src/hooks/useTransaction.ts +++ b/src/hooks/useTransaction.ts @@ -4,10 +4,7 @@ import { Wallet, } from "@near-wallet-selector/core"; import { Account } from "near-api-js"; -import { - EthTransactionParams, - SignRequestData -} from "near-safe"; +import { EthTransactionParams, SignRequestData } from "near-safe"; import { EVMWalletAdapter } from "../types"; export interface SuccessInfo { @@ -81,6 +78,7 @@ export const executeWithAccount = async ( args: txn.actions[0].params.args, attachedDeposit: BigInt(txn.actions[0].params.deposit), gas: BigInt(txn.actions[0].params.gas), + walletCallbackUrl: window.location.href, }); } catch (error) { console.error( @@ -107,6 +105,7 @@ export const executeWithWallet = async ( } return wallet.signAndSendTransactions({ transactions: transactions, + callbackUrl: window.location.href, }); }; From 4a36119ef8bafa2a6a8918e73cc2ca6ab58093f0 Mon Sep 17 00:00:00 2001 From: Markeljan Date: Tue, 11 Mar 2025 16:40:31 -0400 Subject: [PATCH 2/2] Track bitte wallet transaction hash from url (#119) --- .../chat/transactions/ReviewTransaction.tsx | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/components/chat/transactions/ReviewTransaction.tsx b/src/components/chat/transactions/ReviewTransaction.tsx index b52c9b1..df8fe6a 100644 --- a/src/components/chat/transactions/ReviewTransaction.tsx +++ b/src/components/chat/transactions/ReviewTransaction.tsx @@ -1,7 +1,7 @@ import { Transaction } from "@near-wallet-selector/core"; import BN from "bn.js"; import { SafeEncodedSignRequest } from "near-safe"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useAccountBalance } from "../../../hooks/useAccountBalance"; import { SuccessInfo, useTransaction } from "../../../hooks/useTransaction"; import { useTxnFees } from "../../../hooks/useTxnFees"; @@ -70,6 +70,37 @@ export const ReviewTransaction = ({ const { width } = useWindowSize(); const isMobile = !!width && width < 640; + useEffect(() => { + if (!result) { + const searchParams = new URLSearchParams(window.location.search); + const txHash = searchParams.get("transactionHashes"); + + if (txHash) { + // Create a success info object from the transaction hash + const successInfo = { + near: { + receipts: [ + { + transaction: { + hash: txHash, + }, + }, + ], + }, + }; + setResult(successInfo); + + // Clear the URL parameters + searchParams.delete("transactionHashes"); + searchParams.delete("account_id"); + const newUrl = `${window.location.pathname}${ + searchParams.toString() ? "?" + searchParams.toString() : "" + }`; + window.history.replaceState({}, "", newUrl); + } + } + }, [result]); + if (!transactions || transactions.length === 0) { return (