From 71f4cca93a27055df8298621d7697a0714bbbabc Mon Sep 17 00:00:00 2001 From: karczuRF Date: Thu, 21 Nov 2024 10:48:24 +0100 Subject: [PATCH] fix front bugs --- locales/en/components.json | 5 +- locales/pl/components.json | 3 +- .../TransactionConfirmationModal.tsx | 46 ++++++------------- src/helpers/transaction.ts | 31 +++++++++++++ src/store/simulation/simulation.action.ts | 27 +++++++++-- 5 files changed, 72 insertions(+), 40 deletions(-) create mode 100644 src/helpers/transaction.ts diff --git a/locales/en/components.json b/locales/en/components.json index 15e4839..607901e 100644 --- a/locales/en/components.json +++ b/locales/en/components.json @@ -19,6 +19,7 @@ "open-logs-directory": "Logs", "simulation-status": "Simulation status", "simulation-error-msg": "Simulation error message", - "tx-simulation-status": "Simulated transaction error", - "tx-simulation-error-msg": "Simulated tx 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 b0d816d..0b80289 100644 --- a/locales/pl/components.json +++ b/locales/pl/components.json @@ -20,5 +20,6 @@ "simulation-status": "Status symulacji", "simulation-error-msg": "Błąd symulacji", "tx-simulation-status": "Status symulowanej transakcji", - "tx-simulation-error-msg": "Błąd 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 1958ee1..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,19 +77,24 @@ export const TransactionConfirmationModal: React.FC = () => { )} - {t("balance-updates", { ns: "components" })}: + {t("balance-updates", { ns: "components" })}:{" "} {Array.isArray(simulation?.balanceUpdates) && simulation.balanceUpdates.length > 0 ? ( simulation.balanceUpdates.map((update) => ) ) : ( - No balance updates available. // Optional: Provide feedback if there are no updates + {t("no-balance-update", { ns: "components" })} )} - {t("tx-simulation-status", { ns: "components" })}: {simulation?.transaction?.status ?? "-"} - - - {t("tx-simulation-error-msg", { ns: "components" })}: {simulation?.transaction?.errorMsg ?? "-"} + {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)} + + )}