From cd3bc306ba21ec9fc32a171f7209470fbfaa501d Mon Sep 17 00:00:00 2001 From: Jason Brown <86845131+jasonabrown@users.noreply.github.com> Date: Fri, 26 Apr 2024 10:28:01 -0700 Subject: [PATCH 1/3] Add loadEventCallback The snippet allows for a callback on certain methods. Since the React SDK handles _ps("load") under the hood we need allow users to specify an error handling callback for this method. --- src/PSClickWrap.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PSClickWrap.js b/src/PSClickWrap.js index aededbe..6dc02b6 100644 --- a/src/PSClickWrap.js +++ b/src/PSClickWrap.js @@ -220,6 +220,7 @@ class PSClickWrap extends React.Component { signerIdSelector, snapshotLocation, allowDisagreed, + loadEventCallback, } = this.props; const options = { ...(allowDisagreed !== undefined && { allow_disagreed: allowDisagreed }), @@ -255,6 +256,7 @@ class PSClickWrap extends React.Component { if (!isDynamic) group.render(); this.registerEventListeners(key); } + loadEventCallback && loadEventCallback(err, group); }; if (customData) { @@ -334,6 +336,7 @@ PSClickWrap.propTypes = { (props) => props.hasOwnProperty('onInvalid'), PSClickWrap.MUST_SET_ALLOW_DISAGREED, ), + loadEventCallback: PropTypes.func, debug: PropTypes.bool, onAll: PropTypes.func, onSent: PropTypes.func, From edb32e704328919f67b7289530fd0453ce354eab Mon Sep 17 00:00:00 2001 From: Jason Brown <86845131+jasonabrown@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:16:17 -0700 Subject: [PATCH 2/3] Updated naming convention to onLoadCallback this name leaves room for a JS SDK supported onLoad event in the future --- src/PSClickWrap.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PSClickWrap.js b/src/PSClickWrap.js index 6dc02b6..832122e 100644 --- a/src/PSClickWrap.js +++ b/src/PSClickWrap.js @@ -220,7 +220,7 @@ class PSClickWrap extends React.Component { signerIdSelector, snapshotLocation, allowDisagreed, - loadEventCallback, + onLoadCallback, } = this.props; const options = { ...(allowDisagreed !== undefined && { allow_disagreed: allowDisagreed }), @@ -256,7 +256,7 @@ class PSClickWrap extends React.Component { if (!isDynamic) group.render(); this.registerEventListeners(key); } - loadEventCallback && loadEventCallback(err, group); + onLoadCallback && onLoadCallback(err, group); }; if (customData) { @@ -336,7 +336,7 @@ PSClickWrap.propTypes = { (props) => props.hasOwnProperty('onInvalid'), PSClickWrap.MUST_SET_ALLOW_DISAGREED, ), - loadEventCallback: PropTypes.func, + onLoadCallback: PropTypes.func, debug: PropTypes.bool, onAll: PropTypes.func, onSent: PropTypes.func, From 55216c118052eab2551c889bb4fd31016e67a8a7 Mon Sep 17 00:00:00 2001 From: Jason Brown <86845131+jasonabrown@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:41:08 -0700 Subject: [PATCH 3/3] Update README.md --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 32847b2..2992177 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ For accounts at `app.demo.pactsafe.com`, set the `psScriptUrl` prop as `//vault. | `snapshotLocation` | Ironclad Clickwrap Snapshot Location Key, this is found within the Snapshot Location configuration | string | No | undefined | | `testMode` | Enable this to register any contract acceptances as test data that can be cleared within the Ironclad Clickwrap UI | bool | No | false | | `allowDisagreed` | Enable this to allow invalid events to be triggered when a signer unchecks a checkbox. | bool | Required to be true if `onInvalid` is passed | Value specified in Ironclad Clickwrap Group's UI | +| `onLoadCallback` | See [onLoadCallback](#onLoadCallback) below | function | No | undefined | | `onAll` | See [onAll](#onAll) below | function | No | undefined | | `onSent` | See [onSent](#onSent) below | function | No | undefined | | `onRetrieved` | See [onRetrieved](#onRetrieved) below | function | No | undefined | @@ -182,11 +183,24 @@ If you do not want to use event callback props, the `_ps` is loaded into the win The list below describes the props names and corresponding Ironclad Clickwrap events: +## onLoadCallback + +_ps event: n/a + +A callback that can be added specifically for the load event which is not included in the default set of events below. The first argument is an object containing an error if detected and null otherwise. The remaining arguments will match the arguments were passed to the original event's callback function. + +### Callback Arguments + +| Name | Type | Description | +|:----------------:|:------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------:| +| err | Object | An object containing the error if detected; null otherwise. | +|[arguments] | Array | The arguments passed to the original load event. | + ## onAll _ps event: `all` -A special event that is triggered when any other event is triggered. The name of the original event is always the first argument passed to the callback function. The rest of the arguments will match whatever arguments were passed to the original event's callback function. +A special event that is triggered when any event below is triggered (note that this does not include the onLoadCallback event). The name of the original event is always the first argument passed to the callback function. The rest of the arguments will match whatever arguments were passed to the original event's callback function. ### Callback Arguments