From 745a80cd817355f0c1dd4220e357c3cfbfb927c2 Mon Sep 17 00:00:00 2001 From: zoeyTM Date: Sun, 20 Oct 2024 23:49:05 -0400 Subject: [PATCH] add contractName and pending tx status --- packages/core/src/list-transactions.ts | 50 +++++++++++++++----- packages/core/src/types/list-transactions.ts | 1 + 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/packages/core/src/list-transactions.ts b/packages/core/src/list-transactions.ts index 3ceafe8ee..a2e3fe903 100644 --- a/packages/core/src/list-transactions.ts +++ b/packages/core/src/list-transactions.ts @@ -64,14 +64,20 @@ export async function listTransactions( "Expected network interaction to be an onchain interaction" ); - for (const transaction of networkInteraction.transactions) { + for (const [ + index, + transaction, + ] of networkInteraction.transactions.entries()) { switch (exState.type) { case ExecutionSateType.DEPLOYMENT_EXECUTION_STATE: { transactions.push({ type: exState.type, from: exState.from, txHash: transaction.hash, - status: getTransactionStatus(transaction), + status: getTransactionStatus( + transaction, + index === networkInteraction.transactions.length - 1 + ), name: exState.contractName, address: transaction.receipt?.status === TransactionReceiptStatus.SUCCESS @@ -86,12 +92,19 @@ export async function listTransactions( break; } case ExecutionSateType.CALL_EXECUTION_STATE: { + const artifact = await deploymentLoader.loadArtifact( + exState.artifactId + ); + transactions.push({ type: exState.type, from: exState.from, txHash: transaction.hash, - status: getTransactionStatus(transaction), - name: exState.functionName, + status: getTransactionStatus( + transaction, + index === networkInteraction.transactions.length - 1 + ), + name: `${artifact.contractName}#${exState.functionName}`, to: networkInteraction.to, params: exState.args, value: networkInteraction.value, @@ -104,7 +117,10 @@ export async function listTransactions( type: exState.type, from: exState.from, txHash: transaction.hash, - status: getTransactionStatus(transaction), + status: getTransactionStatus( + transaction, + index === networkInteraction.transactions.length - 1 + ), to: networkInteraction.to, value: networkInteraction.value, }); @@ -132,13 +148,21 @@ function doesSendTransactions( ); } -function getTransactionStatus(transaction: Transaction): TransactionStatus { - const status = - transaction.receipt === undefined - ? TransactionStatus.DROPPED - : transaction.receipt.status === TransactionReceiptStatus.SUCCESS - ? TransactionStatus.SUCCESS - : TransactionStatus.FAILURE; +function getTransactionStatus( + transaction: Transaction, + isFinalTransaction: boolean +): TransactionStatus { + if (transaction.receipt === undefined) { + if (isFinalTransaction) { + return TransactionStatus.PENDING; + } + + return TransactionStatus.DROPPED; + } + + if (transaction.receipt.status === TransactionReceiptStatus.SUCCESS) { + return TransactionStatus.SUCCESS; + } - return status; + return TransactionStatus.FAILURE; } diff --git a/packages/core/src/types/list-transactions.ts b/packages/core/src/types/list-transactions.ts index 567ae5236..81aafa37a 100644 --- a/packages/core/src/types/list-transactions.ts +++ b/packages/core/src/types/list-transactions.ts @@ -9,6 +9,7 @@ export enum TransactionStatus { SUCCESS = "SUCCESS", FAILURE = "FAILURE", DROPPED = "DROPPED", + PENDING = "PENDING", } /**