Skip to content

Commit

Permalink
fix status
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey committed Jul 12, 2024
1 parent 8c23399 commit 0958bc0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib/massa-react/hooks/useWriteSmartContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export function useWriteSmartContract(
const [isSuccess, setIsSuccess] = useState(false);
const [isError, setIsError] = useState(false);
const [opId, setOpId] = useState<string | undefined>(undefined);
const success = OperationStatus.SpeculativeSuccess || OperationStatus.Success;

function resetState() {
setIsPending(false);
Expand Down Expand Up @@ -117,6 +116,7 @@ export function useWriteSmartContract(
try {
const publicClient = await clientFromNetwork();

// TODO - get minimal fee from the network used by the wallet. For now, we are using the massa default node.
fee = await getMinimalFee(publicClient, fee);

let maxGas = await gasEstimation(
Expand Down Expand Up @@ -148,7 +148,11 @@ export function useWriteSmartContract(
const op = new Operation(publicClient, operationId);
const finalStatus = await op.waitSpeculativeExecution();

if (!success) {
if (
![OperationStatus.SpeculativeSuccess, OperationStatus.Success].includes(
finalStatus,
)
) {
const errorMessage = `Operation failed with status: ${finalStatus}`;
logSmartContractEvents(publicClient, operationId);
throw new Error(errorMessage);
Expand All @@ -161,7 +165,7 @@ export function useWriteSmartContract(
setIsError(true);
showToast(
'error',
messages.timeout || Intl.t('steps.failed-timeout'),
messages.error || Intl.t('steps.failed-timeout'),
opId,
);
} finally {
Expand Down

0 comments on commit 0958bc0

Please sign in to comment.