Skip to content

Commit

Permalink
add receipt retrieval for transaction (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
KannuSingh authored Nov 6, 2024
1 parent 8bd5d1a commit 52dc546
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import RequestModal from './RequestModal'
import ModalStore from '@/store/ModalStore'
import { styledToast } from '@/utils/HelperUtil'
import { approveEIP155Request } from '@/utils/EIP155RequestHandlerUtil'
import { convertTokenBalance, decodeErc20Transaction, getAssetByContractAddress } from '@/utils/MultibridgeUtil'
import {
convertTokenBalance,
decodeErc20Transaction,
getAssetByContractAddress
} from '@/utils/MultibridgeUtil'
import { getWallet } from '@/utils/EIP155WalletUtil'
import { walletkit } from '@/utils/WalletConnectUtil'
import { EIP155_CHAINS, TEIP155Chain } from '@/data/EIP155Data'
Expand Down Expand Up @@ -65,30 +69,30 @@ export default function MultibridgeRequestModal({
for (const transaction of bridgingTransactions) {
console.log('Bridging transaction', transaction)
const chainId = transaction.chainId
const chainProvider = new providers.JsonRpcProvider(EIP155_CHAINS[chainId as TEIP155Chain].rpc)
const chainProvider = new providers.JsonRpcProvider(
EIP155_CHAINS[chainId as TEIP155Chain].rpc
)
const chainConnectedWallet = await wallet.connect(chainProvider)
const walletAddress = wallet.getAddress()

const hash = await chainConnectedWallet.sendTransaction({
const txResponse = await chainConnectedWallet.sendTransaction({
from: walletAddress,
to: transaction.to,
value: transaction.value,
data: transaction.data,
nonce:transaction.nonce,
nonce: transaction.nonce,
gasPrice: transaction.gasPrice,
gasLimit: transaction.gas
})
const receipt = typeof hash === 'string' ? hash : hash?.hash
console.log(`Transaction broadcasted on chain ${chainId} , ${{ receipt }}`)
const txHash = typeof txResponse === 'string' ? txResponse : txResponse?.hash
const txReceipt = await txResponse.wait()
const txStatus = txReceipt.status
console.log(
`Transaction broadcasted on chain ${chainId} , ${{ txHash }}, status: ${txStatus}`
)
}

try {
await pollOrchestrationStatus(orchestrationId)
} catch (e) {
console.error(e)
onReject()
}
}, [ bridgingTransactions, orchestrationId, onReject, params])
await pollOrchestrationStatus(orchestrationId)
}, [bridgingTransactions, orchestrationId, onReject, params])

async function pollOrchestrationStatus(
orchestrationId: string,
Expand Down Expand Up @@ -172,7 +176,11 @@ export default function MultibridgeRequestModal({
<Row>
<Col>
<Text h5>Transaction details</Text>
<Text color="" data-testid="request-details-chain" css={{ paddingTop: '$6', paddingBottom: '$6' }}>
<Text
color=""
data-testid="request-details-chain"
css={{ paddingTop: '$6', paddingBottom: '$6' }}
>
Sending {amount} {asset} to:
</Text>
<Text color="$gray400" data-testid="request-details-chain" size="sm">
Expand All @@ -186,13 +194,17 @@ export default function MultibridgeRequestModal({
<Text h5>Chain details</Text>
<Text color="">Target chain:</Text>
<Row align="center" css={{ marginTop: '$6' }}>
<Col><Avatar src={targetChain.logo} /></Col>
<Col>
<Avatar src={targetChain.logo} />
</Col>
<Col>{targetChain.name}</Col>
</Row>

<Text color="">Sourcing funds from:</Text>
<Row align="center" css={{ marginTop: '$6' }}>
<Col><Avatar src={sourceChain.logo} /></Col>
<Col>
<Avatar src={sourceChain.logo} />
</Col>
<Col>{sourceChain.name}</Col>
</Row>
</Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export type SendPreparedCallsParams = {

export type SendPreparedCallsReturnValue = string

export type GetCallsStatusParams = string;
export type GetCallsStatusParams = string
export type GetCallsStatusReturnValue = {
status: 'PENDING' | 'CONFIRMED'
receipts?: {
Expand Down
15 changes: 11 additions & 4 deletions advanced/wallets/react-wallet-v2/src/pages/api/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ async function handleGetCallsStatus(
const pimlicoChainName = PIMLICO_NETWORK_NAMES[chain.name]
const apiKey = process.env.NEXT_PUBLIC_PIMLICO_KEY
const localBundlerUrl = process.env.NEXT_PUBLIC_LOCAL_BUNDLER_URL
const bundlerUrl = localBundlerUrl || `https://api.pimlico.io/v1/${pimlicoChainName}/rpc?apikey=${apiKey}`
const bundlerUrl =
localBundlerUrl || `https://api.pimlico.io/v1/${pimlicoChainName}/rpc?apikey=${apiKey}`
const bundlerClient = createPimlicoBundlerClient({
entryPoint: ENTRYPOINT_ADDRESS_V07,
transport: http(bundlerUrl)
Expand Down Expand Up @@ -117,13 +118,17 @@ async function handleGetCallsStatus(
: undefined
}
return receipt

}

export default async function handler(
req: NextApiRequest,
res: NextApiResponse<
JsonRpcResponse<PrepareCallsReturnValue[] | SendPreparedCallsReturnValue[] | GetCallsStatusReturnValue[] | ErrorResponse>
JsonRpcResponse<
| PrepareCallsReturnValue[]
| SendPreparedCallsReturnValue[]
| GetCallsStatusReturnValue[]
| ErrorResponse
>
>
) {
if (req.method === 'OPTIONS') {
Expand All @@ -138,7 +143,9 @@ export default async function handler(

const jsonRpcRequest: JsonRpcRequest = req.body
const { id, method, params } = jsonRpcRequest
if (!['wallet_prepareCalls', 'wallet_sendPreparedCalls', 'wallet_getCallsStatus'].includes(method)) {
if (
!['wallet_prepareCalls', 'wallet_sendPreparedCalls', 'wallet_getCallsStatus'].includes(method)
) {
return res
.status(200)
.json(createErrorResponse(id, ERROR_CODES.METHOD_NOT_FOUND, `${method} method not found`))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ export async function approveEIP155Request(requestEvent: RequestEventArgs) {
const provider = new providers.JsonRpcProvider(EIP155_CHAINS[chainId as TEIP155Chain].rpc)
const sendTransaction = request.params[0]
const connectedWallet = await wallet.connect(provider)
const hash = await connectedWallet.sendTransaction(sendTransaction)
const receipt = typeof hash === 'string' ? hash : hash?.hash // TODO improve interface
return formatJsonRpcResult(id, receipt)
const txResponse = await connectedWallet.sendTransaction(sendTransaction)
const txHash = typeof txResponse === 'string' ? txResponse : txResponse?.hash
const txReceipt = await txResponse.wait()
console.log(
`Transaction broadcasted on chain ${chainId} , ${{ txHash }}, status: ${txReceipt.status}`
)
return formatJsonRpcResult(id, txHash)
} catch (error: any) {
console.error(error)
alert(error.message)
return formatJsonRpcError(id, error.message)
}

Expand Down

0 comments on commit 52dc546

Please sign in to comment.