@depay/widgets 6.6.0 → 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 +40 -2
- package/dist/esm/index.bundle.js +120 -43
- package/dist/esm/index.js +120 -43
- package/dist/umd/index.bundle.js +120 -43
- package/dist/umd/index.js +120 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -199,10 +199,30 @@ BODY:
|
|
|
199
199
|
"transaction": "0x4311a9820195c2a5af99c45c72c88848ed403a4020863c913feed81d15855ae4",
|
|
200
200
|
"sender": "0x769794c94e9f113e357023dab73e81dbd6db201c",
|
|
201
201
|
"nonce": 103,
|
|
202
|
-
"after_block": 13230369
|
|
202
|
+
"after_block": 13230369,
|
|
203
|
+
"to_token": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
|
|
203
204
|
}
|
|
204
205
|
```
|
|
205
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
|
+
|
|
206
226
|
Your endpoint needs to make sure to forward this to the [payment tracking api](https://depay.fi/documentation/api#payments).
|
|
207
227
|
|
|
208
228
|
Also make sure to add `token`, `amount` and `confirmations` when forwarding the request to the payments api.
|
|
@@ -212,7 +232,25 @@ Make sure you read the [Payment Tracking API](https://depay.fi/documentation/api
|
|
|
212
232
|
|
|
213
233
|
Payment tracking requests will be attempted up to 3 times by the widget and will display "Payment tracking failed!" to the user if the widget was not able to start payment tracking via the given endpoint after 3 attempts.
|
|
214
234
|
|
|
215
|
-
A failed payment tracking will also call the [error callback](#
|
|
235
|
+
A failed payment tracking will also call the [error callback](#error) with `{code: "TRACKING_FAILED"}`.
|
|
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.
|
|
216
254
|
|
|
217
255
|
#### connected
|
|
218
256
|
|
package/dist/esm/index.bundle.js
CHANGED
|
@@ -62415,7 +62415,7 @@ var PaymentProvider = (function (props) {
|
|
|
62415
62415
|
wallet = _useContext7.wallet;
|
|
62416
62416
|
|
|
62417
62417
|
var _useContext8 = react.useContext(TrackingContext),
|
|
62418
|
-
|
|
62418
|
+
release = _useContext8.release,
|
|
62419
62419
|
tracking = _useContext8.tracking,
|
|
62420
62420
|
initializeTracking = _useContext8.initializeTracking;
|
|
62421
62421
|
|
|
@@ -62487,7 +62487,7 @@ var PaymentProvider = (function (props) {
|
|
|
62487
62487
|
}
|
|
62488
62488
|
})).then(function (sentTransaction) {
|
|
62489
62489
|
if (tracking) {
|
|
62490
|
-
initializeTracking(sentTransaction, currentBlock);
|
|
62490
|
+
initializeTracking(sentTransaction, currentBlock, payment.route);
|
|
62491
62491
|
}
|
|
62492
62492
|
|
|
62493
62493
|
setTransaction(sentTransaction);
|
|
@@ -62535,10 +62535,10 @@ var PaymentProvider = (function (props) {
|
|
|
62535
62535
|
};
|
|
62536
62536
|
|
|
62537
62537
|
react.useEffect(function () {
|
|
62538
|
-
if (
|
|
62538
|
+
if (release) {
|
|
62539
62539
|
setPaymentState('confirmed');
|
|
62540
62540
|
}
|
|
62541
|
-
}, [
|
|
62541
|
+
}, [release]);
|
|
62542
62542
|
react.useEffect(function () {
|
|
62543
62543
|
if (selectedRoute) {
|
|
62544
62544
|
var fromToken = selectedRoute.fromToken;
|
|
@@ -69761,7 +69761,7 @@ var Footer = (function () {
|
|
|
69761
69761
|
|
|
69762
69762
|
var _useContext3 = react.useContext(TrackingContext),
|
|
69763
69763
|
tracking = _useContext3.tracking,
|
|
69764
|
-
|
|
69764
|
+
release = _useContext3.release,
|
|
69765
69765
|
forwardTo = _useContext3.forwardTo,
|
|
69766
69766
|
trackingFailed = _useContext3.trackingFailed;
|
|
69767
69767
|
|
|
@@ -69787,7 +69787,7 @@ var Footer = (function () {
|
|
|
69787
69787
|
return null;
|
|
69788
69788
|
}
|
|
69789
69789
|
|
|
69790
|
-
if (
|
|
69790
|
+
if (release) {
|
|
69791
69791
|
return /*#__PURE__*/react.createElement("div", null, /*#__PURE__*/react.createElement("div", {
|
|
69792
69792
|
className: "Card transparent small disabled"
|
|
69793
69793
|
}, /*#__PURE__*/react.createElement("div", {
|
|
@@ -69933,7 +69933,7 @@ var Footer = (function () {
|
|
|
69933
69933
|
}, /*#__PURE__*/react.createElement(LoadingText, null, "Paying"));
|
|
69934
69934
|
} else if (paymentState == 'confirmed') {
|
|
69935
69935
|
if (tracking == true) {
|
|
69936
|
-
if (
|
|
69936
|
+
if (release) {
|
|
69937
69937
|
if (forwardTo) {
|
|
69938
69938
|
return /*#__PURE__*/react.createElement("a", {
|
|
69939
69939
|
className: "ButtonPrimary",
|
|
@@ -70167,33 +70167,47 @@ var TrackingProvider = (function (props) {
|
|
|
70167
70167
|
var _useContext2 = react.useContext(ConfigurationContext),
|
|
70168
70168
|
track = _useContext2.track;
|
|
70169
70169
|
|
|
70170
|
-
var _useState = react.useState(
|
|
70170
|
+
var _useState = react.useState(),
|
|
70171
70171
|
_useState2 = _slicedToArray(_useState, 2),
|
|
70172
|
-
|
|
70173
|
-
|
|
70172
|
+
transaction = _useState2[0],
|
|
70173
|
+
setTransaction = _useState2[1];
|
|
70174
70174
|
|
|
70175
|
-
var _useState3 = react.useState(
|
|
70175
|
+
var _useState3 = react.useState(),
|
|
70176
70176
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
70177
|
-
|
|
70178
|
-
|
|
70177
|
+
afterBlock = _useState4[0],
|
|
70178
|
+
setAfterBlock = _useState4[1];
|
|
70179
70179
|
|
|
70180
|
-
var _useState5 = react.useState(
|
|
70180
|
+
var _useState5 = react.useState(),
|
|
70181
70181
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
70182
|
-
|
|
70183
|
-
|
|
70182
|
+
paymentRoute = _useState6[0],
|
|
70183
|
+
setPaymentRoute = _useState6[1];
|
|
70184
70184
|
|
|
70185
|
-
var _useState7 = react.useState(),
|
|
70186
|
-
_useState8 = _slicedToArray(_useState7,
|
|
70187
|
-
|
|
70188
|
-
|
|
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;
|
|
70192
70210
|
|
|
70193
|
-
react.useEffect(function () {
|
|
70194
|
-
setTracking(track && !!track.endpoint);
|
|
70195
|
-
}, [track]);
|
|
70196
|
-
|
|
70197
70211
|
var openSocket = function openSocket(transaction) {
|
|
70198
70212
|
var socket = new WebSocket('wss://integrate.depay.fi/cable');
|
|
70199
70213
|
|
|
@@ -70219,10 +70233,10 @@ var TrackingProvider = (function (props) {
|
|
|
70219
70233
|
return;
|
|
70220
70234
|
}
|
|
70221
70235
|
|
|
70222
|
-
if (item.message && item.message.
|
|
70236
|
+
if (item.message && item.message.release) {
|
|
70223
70237
|
setClosable(!item.message.forward_to);
|
|
70224
70238
|
setForwardTo(item.message.forward_to);
|
|
70225
|
-
|
|
70239
|
+
setRelease(item.message.release);
|
|
70226
70240
|
socket.close();
|
|
70227
70241
|
|
|
70228
70242
|
if (!!item.message.forward_to) {
|
|
@@ -70238,13 +70252,13 @@ var TrackingProvider = (function (props) {
|
|
|
70238
70252
|
};
|
|
70239
70253
|
};
|
|
70240
70254
|
|
|
70241
|
-
var retryStartTracking = function retryStartTracking(transaction, afterBlock, attempt) {
|
|
70255
|
+
var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
70242
70256
|
attempt = parseInt(attempt || 1, 10);
|
|
70243
70257
|
console.log('RETRY TRACKING ATTEMPT ', attempt);
|
|
70244
70258
|
|
|
70245
70259
|
if (attempt < 3) {
|
|
70246
70260
|
setTimeout(function () {
|
|
70247
|
-
startTracking(transaction, afterBlock, attempt + 1);
|
|
70261
|
+
startTracking(transaction, afterBlock, paymentRoute, attempt + 1);
|
|
70248
70262
|
}, 3000);
|
|
70249
70263
|
} else {
|
|
70250
70264
|
console.log('TRACKING FAILED AFTER 3 ATTEMPTS!');
|
|
@@ -70258,38 +70272,101 @@ var TrackingProvider = (function (props) {
|
|
|
70258
70272
|
}
|
|
70259
70273
|
};
|
|
70260
70274
|
|
|
70261
|
-
var
|
|
70262
|
-
|
|
70263
|
-
|
|
70264
|
-
|
|
70265
|
-
|
|
70266
|
-
|
|
70267
|
-
|
|
70268
|
-
|
|
70269
|
-
|
|
70270
|
-
|
|
70275
|
+
var callTracking = function callTracking(payment) {
|
|
70276
|
+
if (track.endpoint) {
|
|
70277
|
+
return fetch(track.endpoint, {
|
|
70278
|
+
method: 'POST',
|
|
70279
|
+
body: JSON.stringify(payment)
|
|
70280
|
+
});
|
|
70281
|
+
} else if (track.method) {
|
|
70282
|
+
return track.method(payment);
|
|
70283
|
+
} else {
|
|
70284
|
+
throw 'No tracking defined!';
|
|
70285
|
+
}
|
|
70286
|
+
};
|
|
70287
|
+
|
|
70288
|
+
var startTracking = function startTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
70289
|
+
callTracking({
|
|
70290
|
+
blockchain: transaction.blockchain,
|
|
70291
|
+
transaction: transaction.id.toLowerCase(),
|
|
70292
|
+
sender: transaction.from.toLowerCase(),
|
|
70293
|
+
nonce: transaction.nonce,
|
|
70294
|
+
after_block: afterBlock,
|
|
70295
|
+
to_token: paymentRoute.toToken.address
|
|
70271
70296
|
}).then(function (response) {
|
|
70272
70297
|
if (response.status == 200) {
|
|
70273
70298
|
console.log('TRACKING INITIALIZED');
|
|
70274
70299
|
} else {
|
|
70275
|
-
retryStartTracking(transaction, afterBlock, attempt);
|
|
70300
|
+
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
70276
70301
|
}
|
|
70277
70302
|
})["catch"](function (error) {
|
|
70278
70303
|
console.log('TRACKING FAILED', error);
|
|
70279
|
-
retryStartTracking(transaction, afterBlock, attempt);
|
|
70304
|
+
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
70280
70305
|
});
|
|
70281
70306
|
};
|
|
70282
70307
|
|
|
70283
|
-
var
|
|
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
|
+
|
|
70357
|
+
var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
|
|
70358
|
+
setTransaction(transaction);
|
|
70359
|
+
setAfterBlock(afterBlock);
|
|
70360
|
+
setPaymentRoute(paymentRoute);
|
|
70284
70361
|
openSocket(transaction);
|
|
70285
|
-
startTracking(transaction, afterBlock);
|
|
70362
|
+
startTracking(transaction, afterBlock, paymentRoute);
|
|
70286
70363
|
};
|
|
70287
70364
|
|
|
70288
70365
|
return /*#__PURE__*/react.createElement(TrackingContext.Provider, {
|
|
70289
70366
|
value: {
|
|
70290
70367
|
tracking: tracking,
|
|
70291
70368
|
initializeTracking: initializeTracking,
|
|
70292
|
-
|
|
70369
|
+
release: release,
|
|
70293
70370
|
forwardTo: forwardTo,
|
|
70294
70371
|
trackingFailed: trackingFailed
|
|
70295
70372
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -2262,7 +2262,7 @@ var PaymentProvider = (function (props) {
|
|
|
2262
2262
|
wallet = _useContext7.wallet;
|
|
2263
2263
|
|
|
2264
2264
|
var _useContext8 = useContext(TrackingContext),
|
|
2265
|
-
|
|
2265
|
+
release = _useContext8.release,
|
|
2266
2266
|
tracking = _useContext8.tracking,
|
|
2267
2267
|
initializeTracking = _useContext8.initializeTracking;
|
|
2268
2268
|
|
|
@@ -2334,7 +2334,7 @@ var PaymentProvider = (function (props) {
|
|
|
2334
2334
|
}
|
|
2335
2335
|
})).then(function (sentTransaction) {
|
|
2336
2336
|
if (tracking) {
|
|
2337
|
-
initializeTracking(sentTransaction, currentBlock);
|
|
2337
|
+
initializeTracking(sentTransaction, currentBlock, payment.route);
|
|
2338
2338
|
}
|
|
2339
2339
|
|
|
2340
2340
|
setTransaction(sentTransaction);
|
|
@@ -2382,10 +2382,10 @@ var PaymentProvider = (function (props) {
|
|
|
2382
2382
|
};
|
|
2383
2383
|
|
|
2384
2384
|
useEffect(function () {
|
|
2385
|
-
if (
|
|
2385
|
+
if (release) {
|
|
2386
2386
|
setPaymentState('confirmed');
|
|
2387
2387
|
}
|
|
2388
|
-
}, [
|
|
2388
|
+
}, [release]);
|
|
2389
2389
|
useEffect(function () {
|
|
2390
2390
|
if (selectedRoute) {
|
|
2391
2391
|
var fromToken = selectedRoute.fromToken;
|
|
@@ -3138,7 +3138,7 @@ var Footer = (function () {
|
|
|
3138
3138
|
|
|
3139
3139
|
var _useContext3 = useContext(TrackingContext),
|
|
3140
3140
|
tracking = _useContext3.tracking,
|
|
3141
|
-
|
|
3141
|
+
release = _useContext3.release,
|
|
3142
3142
|
forwardTo = _useContext3.forwardTo,
|
|
3143
3143
|
trackingFailed = _useContext3.trackingFailed;
|
|
3144
3144
|
|
|
@@ -3164,7 +3164,7 @@ var Footer = (function () {
|
|
|
3164
3164
|
return null;
|
|
3165
3165
|
}
|
|
3166
3166
|
|
|
3167
|
-
if (
|
|
3167
|
+
if (release) {
|
|
3168
3168
|
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
3169
3169
|
className: "Card transparent small disabled"
|
|
3170
3170
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -3310,7 +3310,7 @@ var Footer = (function () {
|
|
|
3310
3310
|
}, /*#__PURE__*/React.createElement(LoadingText, null, "Paying"));
|
|
3311
3311
|
} else if (paymentState == 'confirmed') {
|
|
3312
3312
|
if (tracking == true) {
|
|
3313
|
-
if (
|
|
3313
|
+
if (release) {
|
|
3314
3314
|
if (forwardTo) {
|
|
3315
3315
|
return /*#__PURE__*/React.createElement("a", {
|
|
3316
3316
|
className: "ButtonPrimary",
|
|
@@ -3544,33 +3544,47 @@ var TrackingProvider = (function (props) {
|
|
|
3544
3544
|
var _useContext2 = useContext(ConfigurationContext),
|
|
3545
3545
|
track = _useContext2.track;
|
|
3546
3546
|
|
|
3547
|
-
var _useState = useState(
|
|
3547
|
+
var _useState = useState(),
|
|
3548
3548
|
_useState2 = _slicedToArray(_useState, 2),
|
|
3549
|
-
|
|
3550
|
-
|
|
3549
|
+
transaction = _useState2[0],
|
|
3550
|
+
setTransaction = _useState2[1];
|
|
3551
3551
|
|
|
3552
|
-
var _useState3 = useState(
|
|
3552
|
+
var _useState3 = useState(),
|
|
3553
3553
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
3554
|
-
|
|
3555
|
-
|
|
3554
|
+
afterBlock = _useState4[0],
|
|
3555
|
+
setAfterBlock = _useState4[1];
|
|
3556
3556
|
|
|
3557
|
-
var _useState5 = useState(
|
|
3557
|
+
var _useState5 = useState(),
|
|
3558
3558
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
3559
|
-
|
|
3560
|
-
|
|
3559
|
+
paymentRoute = _useState6[0],
|
|
3560
|
+
setPaymentRoute = _useState6[1];
|
|
3561
3561
|
|
|
3562
|
-
var _useState7 = useState(),
|
|
3563
|
-
_useState8 = _slicedToArray(_useState7,
|
|
3564
|
-
|
|
3565
|
-
|
|
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;
|
|
3569
3587
|
|
|
3570
|
-
useEffect(function () {
|
|
3571
|
-
setTracking(track && !!track.endpoint);
|
|
3572
|
-
}, [track]);
|
|
3573
|
-
|
|
3574
3588
|
var openSocket = function openSocket(transaction) {
|
|
3575
3589
|
var socket = new WebSocket('wss://integrate.depay.fi/cable');
|
|
3576
3590
|
|
|
@@ -3596,10 +3610,10 @@ var TrackingProvider = (function (props) {
|
|
|
3596
3610
|
return;
|
|
3597
3611
|
}
|
|
3598
3612
|
|
|
3599
|
-
if (item.message && item.message.
|
|
3613
|
+
if (item.message && item.message.release) {
|
|
3600
3614
|
setClosable(!item.message.forward_to);
|
|
3601
3615
|
setForwardTo(item.message.forward_to);
|
|
3602
|
-
|
|
3616
|
+
setRelease(item.message.release);
|
|
3603
3617
|
socket.close();
|
|
3604
3618
|
|
|
3605
3619
|
if (!!item.message.forward_to) {
|
|
@@ -3615,13 +3629,13 @@ var TrackingProvider = (function (props) {
|
|
|
3615
3629
|
};
|
|
3616
3630
|
};
|
|
3617
3631
|
|
|
3618
|
-
var retryStartTracking = function retryStartTracking(transaction, afterBlock, attempt) {
|
|
3632
|
+
var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
3619
3633
|
attempt = parseInt(attempt || 1, 10);
|
|
3620
3634
|
console.log('RETRY TRACKING ATTEMPT ', attempt);
|
|
3621
3635
|
|
|
3622
3636
|
if (attempt < 3) {
|
|
3623
3637
|
setTimeout(function () {
|
|
3624
|
-
startTracking(transaction, afterBlock, attempt + 1);
|
|
3638
|
+
startTracking(transaction, afterBlock, paymentRoute, attempt + 1);
|
|
3625
3639
|
}, 3000);
|
|
3626
3640
|
} else {
|
|
3627
3641
|
console.log('TRACKING FAILED AFTER 3 ATTEMPTS!');
|
|
@@ -3635,38 +3649,101 @@ var TrackingProvider = (function (props) {
|
|
|
3635
3649
|
}
|
|
3636
3650
|
};
|
|
3637
3651
|
|
|
3638
|
-
var
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3652
|
+
var callTracking = function callTracking(payment) {
|
|
3653
|
+
if (track.endpoint) {
|
|
3654
|
+
return fetch(track.endpoint, {
|
|
3655
|
+
method: 'POST',
|
|
3656
|
+
body: JSON.stringify(payment)
|
|
3657
|
+
});
|
|
3658
|
+
} else if (track.method) {
|
|
3659
|
+
return track.method(payment);
|
|
3660
|
+
} else {
|
|
3661
|
+
throw 'No tracking defined!';
|
|
3662
|
+
}
|
|
3663
|
+
};
|
|
3664
|
+
|
|
3665
|
+
var startTracking = function startTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
3666
|
+
callTracking({
|
|
3667
|
+
blockchain: transaction.blockchain,
|
|
3668
|
+
transaction: transaction.id.toLowerCase(),
|
|
3669
|
+
sender: transaction.from.toLowerCase(),
|
|
3670
|
+
nonce: transaction.nonce,
|
|
3671
|
+
after_block: afterBlock,
|
|
3672
|
+
to_token: paymentRoute.toToken.address
|
|
3648
3673
|
}).then(function (response) {
|
|
3649
3674
|
if (response.status == 200) {
|
|
3650
3675
|
console.log('TRACKING INITIALIZED');
|
|
3651
3676
|
} else {
|
|
3652
|
-
retryStartTracking(transaction, afterBlock, attempt);
|
|
3677
|
+
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
3653
3678
|
}
|
|
3654
3679
|
})["catch"](function (error) {
|
|
3655
3680
|
console.log('TRACKING FAILED', error);
|
|
3656
|
-
retryStartTracking(transaction, afterBlock, attempt);
|
|
3681
|
+
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
3657
3682
|
});
|
|
3658
3683
|
};
|
|
3659
3684
|
|
|
3660
|
-
var
|
|
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
|
+
|
|
3734
|
+
var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
|
|
3735
|
+
setTransaction(transaction);
|
|
3736
|
+
setAfterBlock(afterBlock);
|
|
3737
|
+
setPaymentRoute(paymentRoute);
|
|
3661
3738
|
openSocket(transaction);
|
|
3662
|
-
startTracking(transaction, afterBlock);
|
|
3739
|
+
startTracking(transaction, afterBlock, paymentRoute);
|
|
3663
3740
|
};
|
|
3664
3741
|
|
|
3665
3742
|
return /*#__PURE__*/React.createElement(TrackingContext.Provider, {
|
|
3666
3743
|
value: {
|
|
3667
3744
|
tracking: tracking,
|
|
3668
3745
|
initializeTracking: initializeTracking,
|
|
3669
|
-
|
|
3746
|
+
release: release,
|
|
3670
3747
|
forwardTo: forwardTo,
|
|
3671
3748
|
trackingFailed: trackingFailed
|
|
3672
3749
|
}
|
package/dist/umd/index.bundle.js
CHANGED
|
@@ -62421,7 +62421,7 @@
|
|
|
62421
62421
|
wallet = _useContext7.wallet;
|
|
62422
62422
|
|
|
62423
62423
|
var _useContext8 = react.useContext(TrackingContext),
|
|
62424
|
-
|
|
62424
|
+
release = _useContext8.release,
|
|
62425
62425
|
tracking = _useContext8.tracking,
|
|
62426
62426
|
initializeTracking = _useContext8.initializeTracking;
|
|
62427
62427
|
|
|
@@ -62493,7 +62493,7 @@
|
|
|
62493
62493
|
}
|
|
62494
62494
|
})).then(function (sentTransaction) {
|
|
62495
62495
|
if (tracking) {
|
|
62496
|
-
initializeTracking(sentTransaction, currentBlock);
|
|
62496
|
+
initializeTracking(sentTransaction, currentBlock, payment.route);
|
|
62497
62497
|
}
|
|
62498
62498
|
|
|
62499
62499
|
setTransaction(sentTransaction);
|
|
@@ -62541,10 +62541,10 @@
|
|
|
62541
62541
|
};
|
|
62542
62542
|
|
|
62543
62543
|
react.useEffect(function () {
|
|
62544
|
-
if (
|
|
62544
|
+
if (release) {
|
|
62545
62545
|
setPaymentState('confirmed');
|
|
62546
62546
|
}
|
|
62547
|
-
}, [
|
|
62547
|
+
}, [release]);
|
|
62548
62548
|
react.useEffect(function () {
|
|
62549
62549
|
if (selectedRoute) {
|
|
62550
62550
|
var fromToken = selectedRoute.fromToken;
|
|
@@ -69767,7 +69767,7 @@
|
|
|
69767
69767
|
|
|
69768
69768
|
var _useContext3 = react.useContext(TrackingContext),
|
|
69769
69769
|
tracking = _useContext3.tracking,
|
|
69770
|
-
|
|
69770
|
+
release = _useContext3.release,
|
|
69771
69771
|
forwardTo = _useContext3.forwardTo,
|
|
69772
69772
|
trackingFailed = _useContext3.trackingFailed;
|
|
69773
69773
|
|
|
@@ -69793,7 +69793,7 @@
|
|
|
69793
69793
|
return null;
|
|
69794
69794
|
}
|
|
69795
69795
|
|
|
69796
|
-
if (
|
|
69796
|
+
if (release) {
|
|
69797
69797
|
return /*#__PURE__*/react.createElement("div", null, /*#__PURE__*/react.createElement("div", {
|
|
69798
69798
|
className: "Card transparent small disabled"
|
|
69799
69799
|
}, /*#__PURE__*/react.createElement("div", {
|
|
@@ -69939,7 +69939,7 @@
|
|
|
69939
69939
|
}, /*#__PURE__*/react.createElement(LoadingText, null, "Paying"));
|
|
69940
69940
|
} else if (paymentState == 'confirmed') {
|
|
69941
69941
|
if (tracking == true) {
|
|
69942
|
-
if (
|
|
69942
|
+
if (release) {
|
|
69943
69943
|
if (forwardTo) {
|
|
69944
69944
|
return /*#__PURE__*/react.createElement("a", {
|
|
69945
69945
|
className: "ButtonPrimary",
|
|
@@ -70173,33 +70173,47 @@
|
|
|
70173
70173
|
var _useContext2 = react.useContext(ConfigurationContext),
|
|
70174
70174
|
track = _useContext2.track;
|
|
70175
70175
|
|
|
70176
|
-
var _useState = react.useState(
|
|
70176
|
+
var _useState = react.useState(),
|
|
70177
70177
|
_useState2 = _slicedToArray(_useState, 2),
|
|
70178
|
-
|
|
70179
|
-
|
|
70178
|
+
transaction = _useState2[0],
|
|
70179
|
+
setTransaction = _useState2[1];
|
|
70180
70180
|
|
|
70181
|
-
var _useState3 = react.useState(
|
|
70181
|
+
var _useState3 = react.useState(),
|
|
70182
70182
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
70183
|
-
|
|
70184
|
-
|
|
70183
|
+
afterBlock = _useState4[0],
|
|
70184
|
+
setAfterBlock = _useState4[1];
|
|
70185
70185
|
|
|
70186
|
-
var _useState5 = react.useState(
|
|
70186
|
+
var _useState5 = react.useState(),
|
|
70187
70187
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
70188
|
-
|
|
70189
|
-
|
|
70188
|
+
paymentRoute = _useState6[0],
|
|
70189
|
+
setPaymentRoute = _useState6[1];
|
|
70190
70190
|
|
|
70191
|
-
var _useState7 = react.useState(),
|
|
70192
|
-
_useState8 = _slicedToArray(_useState7,
|
|
70193
|
-
|
|
70194
|
-
|
|
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;
|
|
70198
70216
|
|
|
70199
|
-
react.useEffect(function () {
|
|
70200
|
-
setTracking(track && !!track.endpoint);
|
|
70201
|
-
}, [track]);
|
|
70202
|
-
|
|
70203
70217
|
var openSocket = function openSocket(transaction) {
|
|
70204
70218
|
var socket = new WebSocket('wss://integrate.depay.fi/cable');
|
|
70205
70219
|
|
|
@@ -70225,10 +70239,10 @@
|
|
|
70225
70239
|
return;
|
|
70226
70240
|
}
|
|
70227
70241
|
|
|
70228
|
-
if (item.message && item.message.
|
|
70242
|
+
if (item.message && item.message.release) {
|
|
70229
70243
|
setClosable(!item.message.forward_to);
|
|
70230
70244
|
setForwardTo(item.message.forward_to);
|
|
70231
|
-
|
|
70245
|
+
setRelease(item.message.release);
|
|
70232
70246
|
socket.close();
|
|
70233
70247
|
|
|
70234
70248
|
if (!!item.message.forward_to) {
|
|
@@ -70244,13 +70258,13 @@
|
|
|
70244
70258
|
};
|
|
70245
70259
|
};
|
|
70246
70260
|
|
|
70247
|
-
var retryStartTracking = function retryStartTracking(transaction, afterBlock, attempt) {
|
|
70261
|
+
var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
70248
70262
|
attempt = parseInt(attempt || 1, 10);
|
|
70249
70263
|
console.log('RETRY TRACKING ATTEMPT ', attempt);
|
|
70250
70264
|
|
|
70251
70265
|
if (attempt < 3) {
|
|
70252
70266
|
setTimeout(function () {
|
|
70253
|
-
startTracking(transaction, afterBlock, attempt + 1);
|
|
70267
|
+
startTracking(transaction, afterBlock, paymentRoute, attempt + 1);
|
|
70254
70268
|
}, 3000);
|
|
70255
70269
|
} else {
|
|
70256
70270
|
console.log('TRACKING FAILED AFTER 3 ATTEMPTS!');
|
|
@@ -70264,38 +70278,101 @@
|
|
|
70264
70278
|
}
|
|
70265
70279
|
};
|
|
70266
70280
|
|
|
70267
|
-
var
|
|
70268
|
-
|
|
70269
|
-
|
|
70270
|
-
|
|
70271
|
-
|
|
70272
|
-
|
|
70273
|
-
|
|
70274
|
-
|
|
70275
|
-
|
|
70276
|
-
|
|
70281
|
+
var callTracking = function callTracking(payment) {
|
|
70282
|
+
if (track.endpoint) {
|
|
70283
|
+
return fetch(track.endpoint, {
|
|
70284
|
+
method: 'POST',
|
|
70285
|
+
body: JSON.stringify(payment)
|
|
70286
|
+
});
|
|
70287
|
+
} else if (track.method) {
|
|
70288
|
+
return track.method(payment);
|
|
70289
|
+
} else {
|
|
70290
|
+
throw 'No tracking defined!';
|
|
70291
|
+
}
|
|
70292
|
+
};
|
|
70293
|
+
|
|
70294
|
+
var startTracking = function startTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
70295
|
+
callTracking({
|
|
70296
|
+
blockchain: transaction.blockchain,
|
|
70297
|
+
transaction: transaction.id.toLowerCase(),
|
|
70298
|
+
sender: transaction.from.toLowerCase(),
|
|
70299
|
+
nonce: transaction.nonce,
|
|
70300
|
+
after_block: afterBlock,
|
|
70301
|
+
to_token: paymentRoute.toToken.address
|
|
70277
70302
|
}).then(function (response) {
|
|
70278
70303
|
if (response.status == 200) {
|
|
70279
70304
|
console.log('TRACKING INITIALIZED');
|
|
70280
70305
|
} else {
|
|
70281
|
-
retryStartTracking(transaction, afterBlock, attempt);
|
|
70306
|
+
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
70282
70307
|
}
|
|
70283
70308
|
})["catch"](function (error) {
|
|
70284
70309
|
console.log('TRACKING FAILED', error);
|
|
70285
|
-
retryStartTracking(transaction, afterBlock, attempt);
|
|
70310
|
+
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
70286
70311
|
});
|
|
70287
70312
|
};
|
|
70288
70313
|
|
|
70289
|
-
var
|
|
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
|
+
|
|
70363
|
+
var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
|
|
70364
|
+
setTransaction(transaction);
|
|
70365
|
+
setAfterBlock(afterBlock);
|
|
70366
|
+
setPaymentRoute(paymentRoute);
|
|
70290
70367
|
openSocket(transaction);
|
|
70291
|
-
startTracking(transaction, afterBlock);
|
|
70368
|
+
startTracking(transaction, afterBlock, paymentRoute);
|
|
70292
70369
|
};
|
|
70293
70370
|
|
|
70294
70371
|
return /*#__PURE__*/react.createElement(TrackingContext.Provider, {
|
|
70295
70372
|
value: {
|
|
70296
70373
|
tracking: tracking,
|
|
70297
70374
|
initializeTracking: initializeTracking,
|
|
70298
|
-
|
|
70375
|
+
release: release,
|
|
70299
70376
|
forwardTo: forwardTo,
|
|
70300
70377
|
trackingFailed: trackingFailed
|
|
70301
70378
|
}
|
package/dist/umd/index.js
CHANGED
|
@@ -2257,7 +2257,7 @@
|
|
|
2257
2257
|
wallet = _useContext7.wallet;
|
|
2258
2258
|
|
|
2259
2259
|
var _useContext8 = React.useContext(TrackingContext),
|
|
2260
|
-
|
|
2260
|
+
release = _useContext8.release,
|
|
2261
2261
|
tracking = _useContext8.tracking,
|
|
2262
2262
|
initializeTracking = _useContext8.initializeTracking;
|
|
2263
2263
|
|
|
@@ -2329,7 +2329,7 @@
|
|
|
2329
2329
|
}
|
|
2330
2330
|
})).then(function (sentTransaction) {
|
|
2331
2331
|
if (tracking) {
|
|
2332
|
-
initializeTracking(sentTransaction, currentBlock);
|
|
2332
|
+
initializeTracking(sentTransaction, currentBlock, payment.route);
|
|
2333
2333
|
}
|
|
2334
2334
|
|
|
2335
2335
|
setTransaction(sentTransaction);
|
|
@@ -2377,10 +2377,10 @@
|
|
|
2377
2377
|
};
|
|
2378
2378
|
|
|
2379
2379
|
React.useEffect(function () {
|
|
2380
|
-
if (
|
|
2380
|
+
if (release) {
|
|
2381
2381
|
setPaymentState('confirmed');
|
|
2382
2382
|
}
|
|
2383
|
-
}, [
|
|
2383
|
+
}, [release]);
|
|
2384
2384
|
React.useEffect(function () {
|
|
2385
2385
|
if (selectedRoute) {
|
|
2386
2386
|
var fromToken = selectedRoute.fromToken;
|
|
@@ -3133,7 +3133,7 @@
|
|
|
3133
3133
|
|
|
3134
3134
|
var _useContext3 = React.useContext(TrackingContext),
|
|
3135
3135
|
tracking = _useContext3.tracking,
|
|
3136
|
-
|
|
3136
|
+
release = _useContext3.release,
|
|
3137
3137
|
forwardTo = _useContext3.forwardTo,
|
|
3138
3138
|
trackingFailed = _useContext3.trackingFailed;
|
|
3139
3139
|
|
|
@@ -3159,7 +3159,7 @@
|
|
|
3159
3159
|
return null;
|
|
3160
3160
|
}
|
|
3161
3161
|
|
|
3162
|
-
if (
|
|
3162
|
+
if (release) {
|
|
3163
3163
|
return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3164
3164
|
className: "Card transparent small disabled"
|
|
3165
3165
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
@@ -3305,7 +3305,7 @@
|
|
|
3305
3305
|
}, /*#__PURE__*/React__default["default"].createElement(LoadingText, null, "Paying"));
|
|
3306
3306
|
} else if (paymentState == 'confirmed') {
|
|
3307
3307
|
if (tracking == true) {
|
|
3308
|
-
if (
|
|
3308
|
+
if (release) {
|
|
3309
3309
|
if (forwardTo) {
|
|
3310
3310
|
return /*#__PURE__*/React__default["default"].createElement("a", {
|
|
3311
3311
|
className: "ButtonPrimary",
|
|
@@ -3539,33 +3539,47 @@
|
|
|
3539
3539
|
var _useContext2 = React.useContext(ConfigurationContext),
|
|
3540
3540
|
track = _useContext2.track;
|
|
3541
3541
|
|
|
3542
|
-
var _useState = React.useState(
|
|
3542
|
+
var _useState = React.useState(),
|
|
3543
3543
|
_useState2 = _slicedToArray(_useState, 2),
|
|
3544
|
-
|
|
3545
|
-
|
|
3544
|
+
transaction = _useState2[0],
|
|
3545
|
+
setTransaction = _useState2[1];
|
|
3546
3546
|
|
|
3547
|
-
var _useState3 = React.useState(
|
|
3547
|
+
var _useState3 = React.useState(),
|
|
3548
3548
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
3549
|
-
|
|
3550
|
-
|
|
3549
|
+
afterBlock = _useState4[0],
|
|
3550
|
+
setAfterBlock = _useState4[1];
|
|
3551
3551
|
|
|
3552
|
-
var _useState5 = React.useState(
|
|
3552
|
+
var _useState5 = React.useState(),
|
|
3553
3553
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
3554
|
-
|
|
3555
|
-
|
|
3554
|
+
paymentRoute = _useState6[0],
|
|
3555
|
+
setPaymentRoute = _useState6[1];
|
|
3556
3556
|
|
|
3557
|
-
var _useState7 = React.useState(),
|
|
3558
|
-
_useState8 = _slicedToArray(_useState7,
|
|
3559
|
-
|
|
3560
|
-
|
|
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;
|
|
3564
3582
|
|
|
3565
|
-
React.useEffect(function () {
|
|
3566
|
-
setTracking(track && !!track.endpoint);
|
|
3567
|
-
}, [track]);
|
|
3568
|
-
|
|
3569
3583
|
var openSocket = function openSocket(transaction) {
|
|
3570
3584
|
var socket = new WebSocket('wss://integrate.depay.fi/cable');
|
|
3571
3585
|
|
|
@@ -3591,10 +3605,10 @@
|
|
|
3591
3605
|
return;
|
|
3592
3606
|
}
|
|
3593
3607
|
|
|
3594
|
-
if (item.message && item.message.
|
|
3608
|
+
if (item.message && item.message.release) {
|
|
3595
3609
|
setClosable(!item.message.forward_to);
|
|
3596
3610
|
setForwardTo(item.message.forward_to);
|
|
3597
|
-
|
|
3611
|
+
setRelease(item.message.release);
|
|
3598
3612
|
socket.close();
|
|
3599
3613
|
|
|
3600
3614
|
if (!!item.message.forward_to) {
|
|
@@ -3610,13 +3624,13 @@
|
|
|
3610
3624
|
};
|
|
3611
3625
|
};
|
|
3612
3626
|
|
|
3613
|
-
var retryStartTracking = function retryStartTracking(transaction, afterBlock, attempt) {
|
|
3627
|
+
var retryStartTracking = function retryStartTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
3614
3628
|
attempt = parseInt(attempt || 1, 10);
|
|
3615
3629
|
console.log('RETRY TRACKING ATTEMPT ', attempt);
|
|
3616
3630
|
|
|
3617
3631
|
if (attempt < 3) {
|
|
3618
3632
|
setTimeout(function () {
|
|
3619
|
-
startTracking(transaction, afterBlock, attempt + 1);
|
|
3633
|
+
startTracking(transaction, afterBlock, paymentRoute, attempt + 1);
|
|
3620
3634
|
}, 3000);
|
|
3621
3635
|
} else {
|
|
3622
3636
|
console.log('TRACKING FAILED AFTER 3 ATTEMPTS!');
|
|
@@ -3630,38 +3644,101 @@
|
|
|
3630
3644
|
}
|
|
3631
3645
|
};
|
|
3632
3646
|
|
|
3633
|
-
var
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3647
|
+
var callTracking = function callTracking(payment) {
|
|
3648
|
+
if (track.endpoint) {
|
|
3649
|
+
return fetch(track.endpoint, {
|
|
3650
|
+
method: 'POST',
|
|
3651
|
+
body: JSON.stringify(payment)
|
|
3652
|
+
});
|
|
3653
|
+
} else if (track.method) {
|
|
3654
|
+
return track.method(payment);
|
|
3655
|
+
} else {
|
|
3656
|
+
throw 'No tracking defined!';
|
|
3657
|
+
}
|
|
3658
|
+
};
|
|
3659
|
+
|
|
3660
|
+
var startTracking = function startTracking(transaction, afterBlock, paymentRoute, attempt) {
|
|
3661
|
+
callTracking({
|
|
3662
|
+
blockchain: transaction.blockchain,
|
|
3663
|
+
transaction: transaction.id.toLowerCase(),
|
|
3664
|
+
sender: transaction.from.toLowerCase(),
|
|
3665
|
+
nonce: transaction.nonce,
|
|
3666
|
+
after_block: afterBlock,
|
|
3667
|
+
to_token: paymentRoute.toToken.address
|
|
3643
3668
|
}).then(function (response) {
|
|
3644
3669
|
if (response.status == 200) {
|
|
3645
3670
|
console.log('TRACKING INITIALIZED');
|
|
3646
3671
|
} else {
|
|
3647
|
-
retryStartTracking(transaction, afterBlock, attempt);
|
|
3672
|
+
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
3648
3673
|
}
|
|
3649
3674
|
})["catch"](function (error) {
|
|
3650
3675
|
console.log('TRACKING FAILED', error);
|
|
3651
|
-
retryStartTracking(transaction, afterBlock, attempt);
|
|
3676
|
+
retryStartTracking(transaction, afterBlock, paymentRoute, attempt);
|
|
3652
3677
|
});
|
|
3653
3678
|
};
|
|
3654
3679
|
|
|
3655
|
-
var
|
|
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
|
+
|
|
3729
|
+
var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
|
|
3730
|
+
setTransaction(transaction);
|
|
3731
|
+
setAfterBlock(afterBlock);
|
|
3732
|
+
setPaymentRoute(paymentRoute);
|
|
3656
3733
|
openSocket(transaction);
|
|
3657
|
-
startTracking(transaction, afterBlock);
|
|
3734
|
+
startTracking(transaction, afterBlock, paymentRoute);
|
|
3658
3735
|
};
|
|
3659
3736
|
|
|
3660
3737
|
return /*#__PURE__*/React__default["default"].createElement(TrackingContext.Provider, {
|
|
3661
3738
|
value: {
|
|
3662
3739
|
tracking: tracking,
|
|
3663
3740
|
initializeTracking: initializeTracking,
|
|
3664
|
-
|
|
3741
|
+
release: release,
|
|
3665
3742
|
forwardTo: forwardTo,
|
|
3666
3743
|
trackingFailed: trackingFailed
|
|
3667
3744
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@depay/widgets",
|
|
3
3
|
"moduleName": "DePayWidgets",
|
|
4
|
-
"version": "6.
|
|
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",
|