diff --git a/locales/en/components.json b/locales/en/components.json index cb5fd8c..607901e 100644 --- a/locales/en/components.json +++ b/locales/en/components.json @@ -18,5 +18,8 @@ "create-account": "New account", "open-logs-directory": "Logs", "simulation-status": "Simulation status", - "simulation-error-msg": "Simulation error" + "simulation-error-msg": "Simulation error message", + "tx-simulation-status": "Simulated transaction status", + "tx-simulation-error-msg": "Simulated tx error message", + "no-balance-update": "No balance updates available." } diff --git a/locales/pl/components.json b/locales/pl/components.json index e9c7946..0b80289 100644 --- a/locales/pl/components.json +++ b/locales/pl/components.json @@ -18,5 +18,8 @@ "create-account": "Dodaj nowe konto", "open-logs-directory": "Logi", "simulation-status": "Status symulacji", - "simulation-error-msg": "Błąd symulacji" + "simulation-error-msg": "Błąd symulacji", + "tx-simulation-status": "Status symulowanej transakcji", + "tx-simulation-error-msg": "Błąd symulowanej transakcji", + "no-balance-update": "Aktualizacja balansów niedostępna" } diff --git a/src/components/TransactionConfirmationModal.tsx b/src/components/TransactionConfirmationModal.tsx index 145b6ca..9ae8a9a 100644 --- a/src/components/TransactionConfirmationModal.tsx +++ b/src/components/TransactionConfirmationModal.tsx @@ -10,9 +10,9 @@ import { simulationActions } from "../store/simulation/simulation.slice" import { BalanceUpdateView } from "./BalanceUpdate" import { useTranslation } from "react-i18next" import { ErrorSource } from "../store/error/error.types" -import { CallFunction, CallMethod } from "@tari-project/tarijs/dist/builders/types/Instruction" import { resolveBackendErrorMessage } from "./ErrorSnackBar" import { metadataSelector } from "../store/metadata/metadata.selector" +import { getFunctionOrMethod, getTransactionStatusName } from "../helpers/transaction" const selectSimulationById = (state: RootState, id?: number) => (id ? simulationsSelectors.selectById(state, id) : null) @@ -50,31 +50,6 @@ export const TransactionConfirmationModal: React.FC = () => { ) } - interface InstructionWithArgs { - instructionName: string - args: any[] - } - // Function to get function or method fields - function getFunctionOrMethod(instructions: object[]): InstructionWithArgs[] { - let functionNames: InstructionWithArgs[] = [] - instructions.forEach((instruction) => { - // Check if the instruction is an object and not a string - if (typeof instruction === "object" && instruction !== null) { - if ("CallFunction" in instruction) { - const callFunction = instruction as CallFunction - functionNames.push({ - instructionName: callFunction.CallFunction.function, - args: callFunction.CallFunction.args, - }) - } else if ("CallMethod" in instruction) { - const callMethod = instruction as CallMethod - functionNames.push({ instructionName: callMethod.CallMethod.method, args: callMethod.CallMethod.args }) - } - } - }) - return functionNames - } - return ( {t("transaction-confirmation", { ns: "components" })}: @@ -88,7 +63,7 @@ export const TransactionConfirmationModal: React.FC = () => { {getFunctionOrMethod(arg.instructions) .flatMap((i) => i.instructionName + " with args: " + i.args) .map((instruction, index) => ( -
{instruction}
// Using
or to wrap each instruction +
{instruction}
))} ))} @@ -102,11 +77,24 @@ export const TransactionConfirmationModal: React.FC = () => { )} - {t("balance-updates", { ns: "components" })}: - {simulation?.balanceUpdates?.map((update) => ( - - ))} + {t("balance-updates", { ns: "components" })}:{" "} + {Array.isArray(simulation?.balanceUpdates) && simulation.balanceUpdates.length > 0 ? ( + simulation.balanceUpdates.map((update) => ) + ) : ( + {t("no-balance-update", { ns: "components" })} + )} + + + {t("tx-simulation-status", { ns: "components" })}: {getTransactionStatusName(simulation?.transaction?.status)} + {simulation?.transaction.errorMsg && ( + + {t("tx-simulation-error-msg", { ns: "components" })}:{" "} + {typeof simulation?.transaction?.errorMsg === "string" + ? simulation.transaction.errorMsg + : JSON.stringify(simulation?.transaction?.errorMsg)} + + )}