submitTx, a helper that sends a signed transaction to Stellar RPC and waits for the result. Other guides reuse it.
Send statuses
sendTransaction returns right away with one of four statuses. Only ERROR is a final rejection.
For more about these statuses and the errors behind them, see Debugging errors.
Wait for the result
getTransaction returns NOT_FOUND until the transaction is in a ledger. NOT_FOUND does not mean that the transaction failed. The transaction can go into a ledger at any time until its time bound (maxTime) passes.
Poll until getTransaction returns SUCCESS or FAILED. If it still returns NOT_FOUND after a ledger closes later than maxTime, the transaction can never go into a ledger. Only then is it safe to build and send a new transaction.
The submitTx helper
latestLedgerCloseTime as a string, so the helper converts it with Number() before it compares it with maxTime.