@openzeppelin/ui-renderer 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -761,6 +761,44 @@ function extractRuntimeSecrets(data, fields) {
761
761
  };
762
762
  }
763
763
 
764
+ //#endregion
765
+ //#region src/utils/transactionSuccessCallback.ts
766
+ /**
767
+ * Normalizes adapter `txHash` for the success callback (non-empty trimmed string or omitted).
768
+ * Expects the `txHash` string from `signAndBroadcast`, not arbitrary values (avoids coercing objects).
769
+ */
770
+ function normalizeTransactionSuccessHash(finalTxHash) {
771
+ if (finalTxHash == null) return;
772
+ const trimmed = finalTxHash.trim();
773
+ return trimmed !== "" ? trimmed : void 0;
774
+ }
775
+ /**
776
+ * Builds the {@link TransactionSuccessPayload} passed to `onTransactionSuccess`.
777
+ */
778
+ function buildTransactionSuccessPayload(options) {
779
+ const hash = normalizeTransactionSuccessHash(options.finalTxHash);
780
+ return {
781
+ network_id: options.networkId,
782
+ ecosystem: options.ecosystem,
783
+ execution_method: options.executionMethod,
784
+ ...hash !== void 0 ? { transaction_hash: hash } : {}
785
+ };
786
+ }
787
+ /**
788
+ * Invokes `onTransactionSuccess` with error containment: synchronous throws and async
789
+ * rejections are logged and never rethrown, so host callbacks cannot break transaction flow.
790
+ */
791
+ function invokeOnTransactionSuccess(callback, payload, log) {
792
+ try {
793
+ const maybePromise = callback?.(payload);
794
+ Promise.resolve(maybePromise).catch((error) => {
795
+ log.error("TransactionForm", "onTransactionSuccess callback rejected with an error", error);
796
+ });
797
+ } catch (error) {
798
+ log.error("TransactionForm", "onTransactionSuccess callback threw an error", error);
799
+ }
800
+ }
801
+
764
802
  //#endregion
765
803
  //#region src/components/fieldRegistry.ts
766
804
  /**
@@ -1208,7 +1246,7 @@ const PENDING_STATES = [
1208
1246
  *
1209
1247
  * @returns The rendered form component
1210
1248
  */
1211
- function TransactionForm({ schema, contractSchema, adapter, isWalletConnected = false, executionConfig }) {
1249
+ function TransactionForm({ schema, contractSchema, adapter, isWalletConnected = false, executionConfig, onTransactionSuccess }) {
1212
1250
  const [formError, setFormError] = (0, react.useState)(null);
1213
1251
  const [executionConfigError, setExecutionConfigError] = (0, react.useState)(null);
1214
1252
  const [runtimeApiKey, setRuntimeApiKey] = (0, react.useState)("");
@@ -1295,9 +1333,19 @@ function TransactionForm({ schema, contractSchema, adapter, isWalletConnected =
1295
1333
  setTxResult(result);
1296
1334
  _openzeppelin_ui_utils.logger.info("TransactionForm", "Execution result received:", result);
1297
1335
  }
1336
+ const reportTransactionSuccess = () => {
1337
+ const executionMethod = executionConfig?.method ?? "eoa";
1338
+ invokeOnTransactionSuccess(onTransactionSuccess, buildTransactionSuccessPayload({
1339
+ networkId: adapter.networkConfig.id,
1340
+ ecosystem: adapter.networkConfig.ecosystem,
1341
+ executionMethod,
1342
+ finalTxHash
1343
+ }), _openzeppelin_ui_utils.logger);
1344
+ };
1298
1345
  if (canExecuteLocally) {
1299
1346
  setTxStatus("success");
1300
1347
  setTxError(null);
1348
+ reportTransactionSuccess();
1301
1349
  return;
1302
1350
  }
1303
1351
  if (adapter.waitForTransactionConfirmation) {
@@ -1308,6 +1356,7 @@ function TransactionForm({ schema, contractSchema, adapter, isWalletConnected =
1308
1356
  _openzeppelin_ui_utils.logger.info("TransactionForm", `Transaction confirmed: ${finalTxHash}`, confirmationResult.receipt);
1309
1357
  setTxStatus("success");
1310
1358
  setTxError(null);
1359
+ reportTransactionSuccess();
1311
1360
  } else {
1312
1361
  _openzeppelin_ui_utils.logger.error("TransactionForm", `Transaction failed confirmation: ${finalTxHash}`, confirmationResult.error);
1313
1362
  setTxError(confirmationResult.error?.message ?? "Transaction failed during confirmation.");
@@ -1317,6 +1366,7 @@ function TransactionForm({ schema, contractSchema, adapter, isWalletConnected =
1317
1366
  _openzeppelin_ui_utils.logger.warn("TransactionForm", "Adapter does not support waitForTransactionConfirmation. Marking as success after submission.");
1318
1367
  setTxStatus("success");
1319
1368
  setTxError(null);
1369
+ reportTransactionSuccess();
1320
1370
  }
1321
1371
  } catch (error) {
1322
1372
  _openzeppelin_ui_utils.logger.error("TransactionForm", "Transaction error during submission process:", error);
@@ -2818,6 +2868,7 @@ exports.NetworkSettingsDialog = NetworkSettingsDialog;
2818
2868
  exports.TransactionExecuteButton = TransactionExecuteButton;
2819
2869
  exports.TransactionForm = TransactionForm;
2820
2870
  exports.WalletConnectionWithSettings = WalletConnectionWithSettings;
2871
+ exports.buildTransactionSuccessPayload = buildTransactionSuccessPayload;
2821
2872
  exports.createAddressTransform = createAddressTransform;
2822
2873
  exports.createArrayObjectTransform = createArrayObjectTransform;
2823
2874
  exports.createArrayTransform = createArrayTransform;
@@ -2831,6 +2882,8 @@ exports.createTextTransform = createTextTransform;
2831
2882
  exports.createTransformForFieldType = createTransformForFieldType;
2832
2883
  exports.generateDefaultValue = generateDefaultValue;
2833
2884
  exports.getDefaultValueByFieldType = getDefaultValueByFieldType;
2885
+ exports.invokeOnTransactionSuccess = invokeOnTransactionSuccess;
2886
+ exports.normalizeTransactionSuccessHash = normalizeTransactionSuccessHash;
2834
2887
  exports.rendererConfig = rendererConfig;
2835
2888
  exports.useAliasEditState = useAliasEditState;
2836
2889
  exports.validateField = validateField;