@depay/widgets 6.7.0 → 6.8.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/README.md CHANGED
@@ -204,6 +204,25 @@ BODY:
204
204
  }
205
205
  ```
206
206
 
207
+ Alternatively you can pass a method to track that performs the tracking request to your backend if you need to handle the request yourself (e.g. to add additional headers etc.):
208
+
209
+ ```javascript
210
+ DePayWidgets.Payment({
211
+
212
+ track: {
213
+ method: (payment)=>{
214
+ return fetch('/track/payments', {
215
+ method: 'POST',
216
+ body: JSON.stringify(payment),
217
+ headers: { "Content-Type": "application/json", "X-CSRF-TOKEN": document.querySelector('[name=csrf-token]').content }
218
+ })
219
+ }
220
+ }
221
+ })
222
+ ```
223
+
224
+ In case you pass a tracking method it needs to return a promise.
225
+
207
226
  Your endpoint needs to make sure to forward this to the [payment tracking api](https://depay.fi/documentation/api#payments).
208
227
 
209
228
  Also make sure to add `token`, `amount` and `confirmations` when forwarding the request to the payments api.
@@ -70167,10 +70167,10 @@ var TrackingProvider = (function (props) {
70167
70167
  var _useContext2 = react.useContext(ConfigurationContext),
70168
70168
  track = _useContext2.track;
70169
70169
 
70170
- var _useState = react.useState(track && !!track.endpoint),
70170
+ var _useState = react.useState(track && !!(track.endpoint || typeof track.method == 'function')),
70171
70171
  _useState2 = _slicedToArray(_useState, 2),
70172
- tracking = _useState2[0],
70173
- setTracking = _useState2[1];
70172
+ tracking = _useState2[0];
70173
+ _useState2[1];
70174
70174
 
70175
70175
  var _useState3 = react.useState(false),
70176
70176
  _useState4 = _slicedToArray(_useState3, 2),
@@ -70190,10 +70190,6 @@ var TrackingProvider = (function (props) {
70190
70190
  var _useContext3 = react.useContext(ClosableContext),
70191
70191
  setClosable = _useContext3.setClosable;
70192
70192
 
70193
- react.useEffect(function () {
70194
- setTracking(track && !!track.endpoint);
70195
- }, [track]);
70196
-
70197
70193
  var openSocket = function openSocket(transaction) {
70198
70194
  var socket = new WebSocket('wss://integrate.depay.fi/cable');
70199
70195
 
@@ -70258,17 +70254,27 @@ var TrackingProvider = (function (props) {
70258
70254
  }
70259
70255
  };
70260
70256
 
70257
+ var callTracking = function callTracking(payment) {
70258
+ if (track.endpoint) {
70259
+ return fetch(track.endpoint, {
70260
+ method: 'POST',
70261
+ body: JSON.stringify(payment)
70262
+ });
70263
+ } else if (track.method) {
70264
+ return track.method(payment);
70265
+ } else {
70266
+ throw 'No tracking defined!';
70267
+ }
70268
+ };
70269
+
70261
70270
  var startTracking = function startTracking(transaction, afterBlock, paymentRoute, attempt) {
70262
- fetch(track.endpoint, {
70263
- method: 'POST',
70264
- body: JSON.stringify({
70265
- blockchain: transaction.blockchain,
70266
- transaction: transaction.id.toLowerCase(),
70267
- sender: transaction.from.toLowerCase(),
70268
- nonce: transaction.nonce,
70269
- after_block: afterBlock,
70270
- to_token: paymentRoute.toToken.address
70271
- })
70271
+ callTracking({
70272
+ blockchain: transaction.blockchain,
70273
+ transaction: transaction.id.toLowerCase(),
70274
+ sender: transaction.from.toLowerCase(),
70275
+ nonce: transaction.nonce,
70276
+ after_block: afterBlock,
70277
+ to_token: paymentRoute.toToken.address
70272
70278
  }).then(function (response) {
70273
70279
  if (response.status == 200) {
70274
70280
  console.log('TRACKING INITIALIZED');
package/dist/esm/index.js CHANGED
@@ -3544,10 +3544,10 @@ var TrackingProvider = (function (props) {
3544
3544
  var _useContext2 = useContext(ConfigurationContext),
3545
3545
  track = _useContext2.track;
3546
3546
 
3547
- var _useState = useState(track && !!track.endpoint),
3547
+ var _useState = useState(track && !!(track.endpoint || typeof track.method == 'function')),
3548
3548
  _useState2 = _slicedToArray(_useState, 2),
3549
- tracking = _useState2[0],
3550
- setTracking = _useState2[1];
3549
+ tracking = _useState2[0];
3550
+ _useState2[1];
3551
3551
 
3552
3552
  var _useState3 = useState(false),
3553
3553
  _useState4 = _slicedToArray(_useState3, 2),
@@ -3567,10 +3567,6 @@ var TrackingProvider = (function (props) {
3567
3567
  var _useContext3 = useContext(ClosableContext),
3568
3568
  setClosable = _useContext3.setClosable;
3569
3569
 
3570
- useEffect(function () {
3571
- setTracking(track && !!track.endpoint);
3572
- }, [track]);
3573
-
3574
3570
  var openSocket = function openSocket(transaction) {
3575
3571
  var socket = new WebSocket('wss://integrate.depay.fi/cable');
3576
3572
 
@@ -3635,17 +3631,27 @@ var TrackingProvider = (function (props) {
3635
3631
  }
3636
3632
  };
3637
3633
 
3634
+ var callTracking = function callTracking(payment) {
3635
+ if (track.endpoint) {
3636
+ return fetch(track.endpoint, {
3637
+ method: 'POST',
3638
+ body: JSON.stringify(payment)
3639
+ });
3640
+ } else if (track.method) {
3641
+ return track.method(payment);
3642
+ } else {
3643
+ throw 'No tracking defined!';
3644
+ }
3645
+ };
3646
+
3638
3647
  var startTracking = function startTracking(transaction, afterBlock, paymentRoute, attempt) {
3639
- fetch(track.endpoint, {
3640
- method: 'POST',
3641
- body: JSON.stringify({
3642
- blockchain: transaction.blockchain,
3643
- transaction: transaction.id.toLowerCase(),
3644
- sender: transaction.from.toLowerCase(),
3645
- nonce: transaction.nonce,
3646
- after_block: afterBlock,
3647
- to_token: paymentRoute.toToken.address
3648
- })
3648
+ callTracking({
3649
+ blockchain: transaction.blockchain,
3650
+ transaction: transaction.id.toLowerCase(),
3651
+ sender: transaction.from.toLowerCase(),
3652
+ nonce: transaction.nonce,
3653
+ after_block: afterBlock,
3654
+ to_token: paymentRoute.toToken.address
3649
3655
  }).then(function (response) {
3650
3656
  if (response.status == 200) {
3651
3657
  console.log('TRACKING INITIALIZED');
@@ -70173,10 +70173,10 @@
70173
70173
  var _useContext2 = react.useContext(ConfigurationContext),
70174
70174
  track = _useContext2.track;
70175
70175
 
70176
- var _useState = react.useState(track && !!track.endpoint),
70176
+ var _useState = react.useState(track && !!(track.endpoint || typeof track.method == 'function')),
70177
70177
  _useState2 = _slicedToArray(_useState, 2),
70178
- tracking = _useState2[0],
70179
- setTracking = _useState2[1];
70178
+ tracking = _useState2[0];
70179
+ _useState2[1];
70180
70180
 
70181
70181
  var _useState3 = react.useState(false),
70182
70182
  _useState4 = _slicedToArray(_useState3, 2),
@@ -70196,10 +70196,6 @@
70196
70196
  var _useContext3 = react.useContext(ClosableContext),
70197
70197
  setClosable = _useContext3.setClosable;
70198
70198
 
70199
- react.useEffect(function () {
70200
- setTracking(track && !!track.endpoint);
70201
- }, [track]);
70202
-
70203
70199
  var openSocket = function openSocket(transaction) {
70204
70200
  var socket = new WebSocket('wss://integrate.depay.fi/cable');
70205
70201
 
@@ -70264,17 +70260,27 @@
70264
70260
  }
70265
70261
  };
70266
70262
 
70263
+ var callTracking = function callTracking(payment) {
70264
+ if (track.endpoint) {
70265
+ return fetch(track.endpoint, {
70266
+ method: 'POST',
70267
+ body: JSON.stringify(payment)
70268
+ });
70269
+ } else if (track.method) {
70270
+ return track.method(payment);
70271
+ } else {
70272
+ throw 'No tracking defined!';
70273
+ }
70274
+ };
70275
+
70267
70276
  var startTracking = function startTracking(transaction, afterBlock, paymentRoute, attempt) {
70268
- fetch(track.endpoint, {
70269
- method: 'POST',
70270
- body: JSON.stringify({
70271
- blockchain: transaction.blockchain,
70272
- transaction: transaction.id.toLowerCase(),
70273
- sender: transaction.from.toLowerCase(),
70274
- nonce: transaction.nonce,
70275
- after_block: afterBlock,
70276
- to_token: paymentRoute.toToken.address
70277
- })
70277
+ callTracking({
70278
+ blockchain: transaction.blockchain,
70279
+ transaction: transaction.id.toLowerCase(),
70280
+ sender: transaction.from.toLowerCase(),
70281
+ nonce: transaction.nonce,
70282
+ after_block: afterBlock,
70283
+ to_token: paymentRoute.toToken.address
70278
70284
  }).then(function (response) {
70279
70285
  if (response.status == 200) {
70280
70286
  console.log('TRACKING INITIALIZED');
package/dist/umd/index.js CHANGED
@@ -3539,10 +3539,10 @@
3539
3539
  var _useContext2 = React.useContext(ConfigurationContext),
3540
3540
  track = _useContext2.track;
3541
3541
 
3542
- var _useState = React.useState(track && !!track.endpoint),
3542
+ var _useState = React.useState(track && !!(track.endpoint || typeof track.method == 'function')),
3543
3543
  _useState2 = _slicedToArray(_useState, 2),
3544
- tracking = _useState2[0],
3545
- setTracking = _useState2[1];
3544
+ tracking = _useState2[0];
3545
+ _useState2[1];
3546
3546
 
3547
3547
  var _useState3 = React.useState(false),
3548
3548
  _useState4 = _slicedToArray(_useState3, 2),
@@ -3562,10 +3562,6 @@
3562
3562
  var _useContext3 = React.useContext(ClosableContext),
3563
3563
  setClosable = _useContext3.setClosable;
3564
3564
 
3565
- React.useEffect(function () {
3566
- setTracking(track && !!track.endpoint);
3567
- }, [track]);
3568
-
3569
3565
  var openSocket = function openSocket(transaction) {
3570
3566
  var socket = new WebSocket('wss://integrate.depay.fi/cable');
3571
3567
 
@@ -3630,17 +3626,27 @@
3630
3626
  }
3631
3627
  };
3632
3628
 
3629
+ var callTracking = function callTracking(payment) {
3630
+ if (track.endpoint) {
3631
+ return fetch(track.endpoint, {
3632
+ method: 'POST',
3633
+ body: JSON.stringify(payment)
3634
+ });
3635
+ } else if (track.method) {
3636
+ return track.method(payment);
3637
+ } else {
3638
+ throw 'No tracking defined!';
3639
+ }
3640
+ };
3641
+
3633
3642
  var startTracking = function startTracking(transaction, afterBlock, paymentRoute, attempt) {
3634
- fetch(track.endpoint, {
3635
- method: 'POST',
3636
- body: JSON.stringify({
3637
- blockchain: transaction.blockchain,
3638
- transaction: transaction.id.toLowerCase(),
3639
- sender: transaction.from.toLowerCase(),
3640
- nonce: transaction.nonce,
3641
- after_block: afterBlock,
3642
- to_token: paymentRoute.toToken.address
3643
- })
3643
+ callTracking({
3644
+ blockchain: transaction.blockchain,
3645
+ transaction: transaction.id.toLowerCase(),
3646
+ sender: transaction.from.toLowerCase(),
3647
+ nonce: transaction.nonce,
3648
+ after_block: afterBlock,
3649
+ to_token: paymentRoute.toToken.address
3644
3650
  }).then(function (response) {
3645
3651
  if (response.status == 200) {
3646
3652
  console.log('TRACKING INITIALIZED');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depay/widgets",
3
3
  "moduleName": "DePayWidgets",
4
- "version": "6.7.0",
4
+ "version": "6.8.0",
5
5
  "description": "Web3 Payments with any token. DePay simplifies and improves Web3 Payments with the power of DeFi. Accept any token with on-the-fly conversion.",
6
6
  "main": "./dist/umd/index.js",
7
7
  "module": "./dist/esm/index.js",