@depay/widgets 6.8.1 → 6.9.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
@@ -234,6 +234,24 @@ Payment tracking requests will be attempted up to 3 times by the widget and will
234
234
 
235
235
  A failed payment tracking will also call the [error callback](#error) with `{code: "TRACKING_FAILED"}`.
236
236
 
237
+ ##### Additional Polling
238
+
239
+ In order to ensure a 100% payment tracking coverage, you cant entirely rely on websockets initiated with `track`.
240
+
241
+ Hence, if you require better payment tracking coverage, you will also need to implement polling.
242
+
243
+ The `track.poll` configuration either takes an `enpoint` or a `method` (similiar to track itself).
244
+
245
+ It will use the endpoint or the method to request a payment status every 5 seconds.
246
+
247
+ You need to make sure to respond to this request with `404` in case the payment has not been finished yet (as reported from the tracking callback)
248
+ or `200` if the payment has been finished (as reported from the tracking callback).
249
+
250
+ In case you want to redirect the user to the next step in your system, the polling needs to respond with `{ forward_to: 'https://example.com/next_step_url' }`.
251
+
252
+ It is not enough to rely on setting `forward_to` initially with the tracking request (if you also implement polling),
253
+ as the entire reason polling exist is because websockets might fail to report the initially configured `forward_to` to your clients.
254
+
237
255
  #### connected
238
256
 
239
257
  `connected`
@@ -70167,25 +70167,43 @@ 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 || typeof track.method == 'function')),
70170
+ var _useState = react.useState(),
70171
70171
  _useState2 = _slicedToArray(_useState, 2),
70172
- tracking = _useState2[0];
70173
- _useState2[1];
70172
+ transaction = _useState2[0],
70173
+ setTransaction = _useState2[1];
70174
70174
 
70175
- var _useState3 = react.useState(false),
70175
+ var _useState3 = react.useState(),
70176
70176
  _useState4 = _slicedToArray(_useState3, 2),
70177
- release = _useState4[0],
70178
- setRelease = _useState4[1];
70177
+ afterBlock = _useState4[0],
70178
+ setAfterBlock = _useState4[1];
70179
70179
 
70180
- var _useState5 = react.useState(false),
70180
+ var _useState5 = react.useState(),
70181
70181
  _useState6 = _slicedToArray(_useState5, 2),
70182
- trackingFailed = _useState6[0],
70183
- setTrackingFailed = _useState6[1];
70182
+ paymentRoute = _useState6[0],
70183
+ setPaymentRoute = _useState6[1];
70184
70184
 
70185
- var _useState7 = react.useState(),
70186
- _useState8 = _slicedToArray(_useState7, 2),
70187
- forwardTo = _useState8[0],
70188
- setForwardTo = _useState8[1];
70185
+ var _useState7 = react.useState(track && !!(track.endpoint || typeof track.method == 'function')),
70186
+ _useState8 = _slicedToArray(_useState7, 1),
70187
+ tracking = _useState8[0];
70188
+
70189
+ var _useState9 = react.useState(track && track.poll && !!(track.poll.endpoint || typeof track.poll.method == 'function')),
70190
+ _useState10 = _slicedToArray(_useState9, 1),
70191
+ polling = _useState10[0];
70192
+
70193
+ var _useState11 = react.useState(false),
70194
+ _useState12 = _slicedToArray(_useState11, 2),
70195
+ release = _useState12[0],
70196
+ setRelease = _useState12[1];
70197
+
70198
+ var _useState13 = react.useState(false),
70199
+ _useState14 = _slicedToArray(_useState13, 2),
70200
+ trackingFailed = _useState14[0],
70201
+ setTrackingFailed = _useState14[1];
70202
+
70203
+ var _useState15 = react.useState(),
70204
+ _useState16 = _slicedToArray(_useState15, 2),
70205
+ forwardTo = _useState16[0],
70206
+ setForwardTo = _useState16[1];
70189
70207
 
70190
70208
  var _useContext3 = react.useContext(ClosableContext),
70191
70209
  setClosable = _useContext3.setClosable;
@@ -70287,7 +70305,59 @@ var TrackingProvider = (function (props) {
70287
70305
  });
70288
70306
  };
70289
70307
 
70308
+ var pollStatus = function pollStatus(polling, transaction, afterBlock, paymentRoute, pollingInterval) {
70309
+ if (!polling || transaction == undefined || afterBlock == undefined || paymentRoute == undefined) {
70310
+ return;
70311
+ }
70312
+
70313
+ var payment = {
70314
+ blockchain: transaction.blockchain,
70315
+ transaction: transaction.id.toLowerCase(),
70316
+ sender: transaction.from.toLowerCase(),
70317
+ nonce: transaction.nonce,
70318
+ after_block: afterBlock,
70319
+ to_token: paymentRoute.toToken.address
70320
+ };
70321
+
70322
+ var handleResponse = function handleResponse(response) {
70323
+ if (response.status == 200) {
70324
+ response.json().then(function (data) {
70325
+ if (data && data.forward_to) {
70326
+ setForwardTo(data.forward_to);
70327
+ }
70328
+ });
70329
+ clearInterval(pollingInterval);
70330
+ setRelease(true);
70331
+ }
70332
+ };
70333
+
70334
+ if (track.poll.endpoint) {
70335
+ fetch(track.poll.endpoint, {
70336
+ method: 'POST',
70337
+ body: JSON.stringify(payment)
70338
+ }).then(handleResponse);
70339
+ } else if (track.poll.method) {
70340
+ track.poll.method(payment).then(handleResponse);
70341
+ }
70342
+ };
70343
+
70344
+ react.useEffect(function () {
70345
+ if (!polling) {
70346
+ return;
70347
+ }
70348
+
70349
+ var pollingInterval = setInterval(function () {
70350
+ return pollStatus(polling, transaction, afterBlock, paymentRoute, pollingInterval);
70351
+ }, 5000);
70352
+ return function () {
70353
+ clearInterval(pollingInterval);
70354
+ };
70355
+ }, [polling, transaction, afterBlock, paymentRoute]);
70356
+
70290
70357
  var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
70358
+ setTransaction(transaction);
70359
+ setAfterBlock(afterBlock);
70360
+ setPaymentRoute(paymentRoute);
70291
70361
  openSocket(transaction);
70292
70362
  startTracking(transaction, afterBlock, paymentRoute);
70293
70363
  };
package/dist/esm/index.js CHANGED
@@ -3544,25 +3544,43 @@ var TrackingProvider = (function (props) {
3544
3544
  var _useContext2 = useContext(ConfigurationContext),
3545
3545
  track = _useContext2.track;
3546
3546
 
3547
- var _useState = useState(track && !!(track.endpoint || typeof track.method == 'function')),
3547
+ var _useState = useState(),
3548
3548
  _useState2 = _slicedToArray(_useState, 2),
3549
- tracking = _useState2[0];
3550
- _useState2[1];
3549
+ transaction = _useState2[0],
3550
+ setTransaction = _useState2[1];
3551
3551
 
3552
- var _useState3 = useState(false),
3552
+ var _useState3 = useState(),
3553
3553
  _useState4 = _slicedToArray(_useState3, 2),
3554
- release = _useState4[0],
3555
- setRelease = _useState4[1];
3554
+ afterBlock = _useState4[0],
3555
+ setAfterBlock = _useState4[1];
3556
3556
 
3557
- var _useState5 = useState(false),
3557
+ var _useState5 = useState(),
3558
3558
  _useState6 = _slicedToArray(_useState5, 2),
3559
- trackingFailed = _useState6[0],
3560
- setTrackingFailed = _useState6[1];
3559
+ paymentRoute = _useState6[0],
3560
+ setPaymentRoute = _useState6[1];
3561
3561
 
3562
- var _useState7 = useState(),
3563
- _useState8 = _slicedToArray(_useState7, 2),
3564
- forwardTo = _useState8[0],
3565
- setForwardTo = _useState8[1];
3562
+ var _useState7 = useState(track && !!(track.endpoint || typeof track.method == 'function')),
3563
+ _useState8 = _slicedToArray(_useState7, 1),
3564
+ tracking = _useState8[0];
3565
+
3566
+ var _useState9 = useState(track && track.poll && !!(track.poll.endpoint || typeof track.poll.method == 'function')),
3567
+ _useState10 = _slicedToArray(_useState9, 1),
3568
+ polling = _useState10[0];
3569
+
3570
+ var _useState11 = useState(false),
3571
+ _useState12 = _slicedToArray(_useState11, 2),
3572
+ release = _useState12[0],
3573
+ setRelease = _useState12[1];
3574
+
3575
+ var _useState13 = useState(false),
3576
+ _useState14 = _slicedToArray(_useState13, 2),
3577
+ trackingFailed = _useState14[0],
3578
+ setTrackingFailed = _useState14[1];
3579
+
3580
+ var _useState15 = useState(),
3581
+ _useState16 = _slicedToArray(_useState15, 2),
3582
+ forwardTo = _useState16[0],
3583
+ setForwardTo = _useState16[1];
3566
3584
 
3567
3585
  var _useContext3 = useContext(ClosableContext),
3568
3586
  setClosable = _useContext3.setClosable;
@@ -3664,7 +3682,59 @@ var TrackingProvider = (function (props) {
3664
3682
  });
3665
3683
  };
3666
3684
 
3685
+ var pollStatus = function pollStatus(polling, transaction, afterBlock, paymentRoute, pollingInterval) {
3686
+ if (!polling || transaction == undefined || afterBlock == undefined || paymentRoute == undefined) {
3687
+ return;
3688
+ }
3689
+
3690
+ var payment = {
3691
+ blockchain: transaction.blockchain,
3692
+ transaction: transaction.id.toLowerCase(),
3693
+ sender: transaction.from.toLowerCase(),
3694
+ nonce: transaction.nonce,
3695
+ after_block: afterBlock,
3696
+ to_token: paymentRoute.toToken.address
3697
+ };
3698
+
3699
+ var handleResponse = function handleResponse(response) {
3700
+ if (response.status == 200) {
3701
+ response.json().then(function (data) {
3702
+ if (data && data.forward_to) {
3703
+ setForwardTo(data.forward_to);
3704
+ }
3705
+ });
3706
+ clearInterval(pollingInterval);
3707
+ setRelease(true);
3708
+ }
3709
+ };
3710
+
3711
+ if (track.poll.endpoint) {
3712
+ fetch(track.poll.endpoint, {
3713
+ method: 'POST',
3714
+ body: JSON.stringify(payment)
3715
+ }).then(handleResponse);
3716
+ } else if (track.poll.method) {
3717
+ track.poll.method(payment).then(handleResponse);
3718
+ }
3719
+ };
3720
+
3721
+ useEffect(function () {
3722
+ if (!polling) {
3723
+ return;
3724
+ }
3725
+
3726
+ var pollingInterval = setInterval(function () {
3727
+ return pollStatus(polling, transaction, afterBlock, paymentRoute, pollingInterval);
3728
+ }, 5000);
3729
+ return function () {
3730
+ clearInterval(pollingInterval);
3731
+ };
3732
+ }, [polling, transaction, afterBlock, paymentRoute]);
3733
+
3667
3734
  var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
3735
+ setTransaction(transaction);
3736
+ setAfterBlock(afterBlock);
3737
+ setPaymentRoute(paymentRoute);
3668
3738
  openSocket(transaction);
3669
3739
  startTracking(transaction, afterBlock, paymentRoute);
3670
3740
  };
@@ -70173,25 +70173,43 @@
70173
70173
  var _useContext2 = react.useContext(ConfigurationContext),
70174
70174
  track = _useContext2.track;
70175
70175
 
70176
- var _useState = react.useState(track && !!(track.endpoint || typeof track.method == 'function')),
70176
+ var _useState = react.useState(),
70177
70177
  _useState2 = _slicedToArray(_useState, 2),
70178
- tracking = _useState2[0];
70179
- _useState2[1];
70178
+ transaction = _useState2[0],
70179
+ setTransaction = _useState2[1];
70180
70180
 
70181
- var _useState3 = react.useState(false),
70181
+ var _useState3 = react.useState(),
70182
70182
  _useState4 = _slicedToArray(_useState3, 2),
70183
- release = _useState4[0],
70184
- setRelease = _useState4[1];
70183
+ afterBlock = _useState4[0],
70184
+ setAfterBlock = _useState4[1];
70185
70185
 
70186
- var _useState5 = react.useState(false),
70186
+ var _useState5 = react.useState(),
70187
70187
  _useState6 = _slicedToArray(_useState5, 2),
70188
- trackingFailed = _useState6[0],
70189
- setTrackingFailed = _useState6[1];
70188
+ paymentRoute = _useState6[0],
70189
+ setPaymentRoute = _useState6[1];
70190
70190
 
70191
- var _useState7 = react.useState(),
70192
- _useState8 = _slicedToArray(_useState7, 2),
70193
- forwardTo = _useState8[0],
70194
- setForwardTo = _useState8[1];
70191
+ var _useState7 = react.useState(track && !!(track.endpoint || typeof track.method == 'function')),
70192
+ _useState8 = _slicedToArray(_useState7, 1),
70193
+ tracking = _useState8[0];
70194
+
70195
+ var _useState9 = react.useState(track && track.poll && !!(track.poll.endpoint || typeof track.poll.method == 'function')),
70196
+ _useState10 = _slicedToArray(_useState9, 1),
70197
+ polling = _useState10[0];
70198
+
70199
+ var _useState11 = react.useState(false),
70200
+ _useState12 = _slicedToArray(_useState11, 2),
70201
+ release = _useState12[0],
70202
+ setRelease = _useState12[1];
70203
+
70204
+ var _useState13 = react.useState(false),
70205
+ _useState14 = _slicedToArray(_useState13, 2),
70206
+ trackingFailed = _useState14[0],
70207
+ setTrackingFailed = _useState14[1];
70208
+
70209
+ var _useState15 = react.useState(),
70210
+ _useState16 = _slicedToArray(_useState15, 2),
70211
+ forwardTo = _useState16[0],
70212
+ setForwardTo = _useState16[1];
70195
70213
 
70196
70214
  var _useContext3 = react.useContext(ClosableContext),
70197
70215
  setClosable = _useContext3.setClosable;
@@ -70293,7 +70311,59 @@
70293
70311
  });
70294
70312
  };
70295
70313
 
70314
+ var pollStatus = function pollStatus(polling, transaction, afterBlock, paymentRoute, pollingInterval) {
70315
+ if (!polling || transaction == undefined || afterBlock == undefined || paymentRoute == undefined) {
70316
+ return;
70317
+ }
70318
+
70319
+ var payment = {
70320
+ blockchain: transaction.blockchain,
70321
+ transaction: transaction.id.toLowerCase(),
70322
+ sender: transaction.from.toLowerCase(),
70323
+ nonce: transaction.nonce,
70324
+ after_block: afterBlock,
70325
+ to_token: paymentRoute.toToken.address
70326
+ };
70327
+
70328
+ var handleResponse = function handleResponse(response) {
70329
+ if (response.status == 200) {
70330
+ response.json().then(function (data) {
70331
+ if (data && data.forward_to) {
70332
+ setForwardTo(data.forward_to);
70333
+ }
70334
+ });
70335
+ clearInterval(pollingInterval);
70336
+ setRelease(true);
70337
+ }
70338
+ };
70339
+
70340
+ if (track.poll.endpoint) {
70341
+ fetch(track.poll.endpoint, {
70342
+ method: 'POST',
70343
+ body: JSON.stringify(payment)
70344
+ }).then(handleResponse);
70345
+ } else if (track.poll.method) {
70346
+ track.poll.method(payment).then(handleResponse);
70347
+ }
70348
+ };
70349
+
70350
+ react.useEffect(function () {
70351
+ if (!polling) {
70352
+ return;
70353
+ }
70354
+
70355
+ var pollingInterval = setInterval(function () {
70356
+ return pollStatus(polling, transaction, afterBlock, paymentRoute, pollingInterval);
70357
+ }, 5000);
70358
+ return function () {
70359
+ clearInterval(pollingInterval);
70360
+ };
70361
+ }, [polling, transaction, afterBlock, paymentRoute]);
70362
+
70296
70363
  var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
70364
+ setTransaction(transaction);
70365
+ setAfterBlock(afterBlock);
70366
+ setPaymentRoute(paymentRoute);
70297
70367
  openSocket(transaction);
70298
70368
  startTracking(transaction, afterBlock, paymentRoute);
70299
70369
  };
package/dist/umd/index.js CHANGED
@@ -3539,25 +3539,43 @@
3539
3539
  var _useContext2 = React.useContext(ConfigurationContext),
3540
3540
  track = _useContext2.track;
3541
3541
 
3542
- var _useState = React.useState(track && !!(track.endpoint || typeof track.method == 'function')),
3542
+ var _useState = React.useState(),
3543
3543
  _useState2 = _slicedToArray(_useState, 2),
3544
- tracking = _useState2[0];
3545
- _useState2[1];
3544
+ transaction = _useState2[0],
3545
+ setTransaction = _useState2[1];
3546
3546
 
3547
- var _useState3 = React.useState(false),
3547
+ var _useState3 = React.useState(),
3548
3548
  _useState4 = _slicedToArray(_useState3, 2),
3549
- release = _useState4[0],
3550
- setRelease = _useState4[1];
3549
+ afterBlock = _useState4[0],
3550
+ setAfterBlock = _useState4[1];
3551
3551
 
3552
- var _useState5 = React.useState(false),
3552
+ var _useState5 = React.useState(),
3553
3553
  _useState6 = _slicedToArray(_useState5, 2),
3554
- trackingFailed = _useState6[0],
3555
- setTrackingFailed = _useState6[1];
3554
+ paymentRoute = _useState6[0],
3555
+ setPaymentRoute = _useState6[1];
3556
3556
 
3557
- var _useState7 = React.useState(),
3558
- _useState8 = _slicedToArray(_useState7, 2),
3559
- forwardTo = _useState8[0],
3560
- setForwardTo = _useState8[1];
3557
+ var _useState7 = React.useState(track && !!(track.endpoint || typeof track.method == 'function')),
3558
+ _useState8 = _slicedToArray(_useState7, 1),
3559
+ tracking = _useState8[0];
3560
+
3561
+ var _useState9 = React.useState(track && track.poll && !!(track.poll.endpoint || typeof track.poll.method == 'function')),
3562
+ _useState10 = _slicedToArray(_useState9, 1),
3563
+ polling = _useState10[0];
3564
+
3565
+ var _useState11 = React.useState(false),
3566
+ _useState12 = _slicedToArray(_useState11, 2),
3567
+ release = _useState12[0],
3568
+ setRelease = _useState12[1];
3569
+
3570
+ var _useState13 = React.useState(false),
3571
+ _useState14 = _slicedToArray(_useState13, 2),
3572
+ trackingFailed = _useState14[0],
3573
+ setTrackingFailed = _useState14[1];
3574
+
3575
+ var _useState15 = React.useState(),
3576
+ _useState16 = _slicedToArray(_useState15, 2),
3577
+ forwardTo = _useState16[0],
3578
+ setForwardTo = _useState16[1];
3561
3579
 
3562
3580
  var _useContext3 = React.useContext(ClosableContext),
3563
3581
  setClosable = _useContext3.setClosable;
@@ -3659,7 +3677,59 @@
3659
3677
  });
3660
3678
  };
3661
3679
 
3680
+ var pollStatus = function pollStatus(polling, transaction, afterBlock, paymentRoute, pollingInterval) {
3681
+ if (!polling || transaction == undefined || afterBlock == undefined || paymentRoute == undefined) {
3682
+ return;
3683
+ }
3684
+
3685
+ var payment = {
3686
+ blockchain: transaction.blockchain,
3687
+ transaction: transaction.id.toLowerCase(),
3688
+ sender: transaction.from.toLowerCase(),
3689
+ nonce: transaction.nonce,
3690
+ after_block: afterBlock,
3691
+ to_token: paymentRoute.toToken.address
3692
+ };
3693
+
3694
+ var handleResponse = function handleResponse(response) {
3695
+ if (response.status == 200) {
3696
+ response.json().then(function (data) {
3697
+ if (data && data.forward_to) {
3698
+ setForwardTo(data.forward_to);
3699
+ }
3700
+ });
3701
+ clearInterval(pollingInterval);
3702
+ setRelease(true);
3703
+ }
3704
+ };
3705
+
3706
+ if (track.poll.endpoint) {
3707
+ fetch(track.poll.endpoint, {
3708
+ method: 'POST',
3709
+ body: JSON.stringify(payment)
3710
+ }).then(handleResponse);
3711
+ } else if (track.poll.method) {
3712
+ track.poll.method(payment).then(handleResponse);
3713
+ }
3714
+ };
3715
+
3716
+ React.useEffect(function () {
3717
+ if (!polling) {
3718
+ return;
3719
+ }
3720
+
3721
+ var pollingInterval = setInterval(function () {
3722
+ return pollStatus(polling, transaction, afterBlock, paymentRoute, pollingInterval);
3723
+ }, 5000);
3724
+ return function () {
3725
+ clearInterval(pollingInterval);
3726
+ };
3727
+ }, [polling, transaction, afterBlock, paymentRoute]);
3728
+
3662
3729
  var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
3730
+ setTransaction(transaction);
3731
+ setAfterBlock(afterBlock);
3732
+ setPaymentRoute(paymentRoute);
3663
3733
  openSocket(transaction);
3664
3734
  startTracking(transaction, afterBlock, paymentRoute);
3665
3735
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depay/widgets",
3
3
  "moduleName": "DePayWidgets",
4
- "version": "6.8.1",
4
+ "version": "6.9.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",