@depay/widgets 7.12.0 → 7.13.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/esm/index.js CHANGED
@@ -19232,8 +19232,8 @@ var PaymentProvider = (function (props) {
19232
19232
  before = _useContext2.before;
19233
19233
 
19234
19234
  var _useContext3 = useContext(PaymentRoutingContext),
19235
- selectedRoute = _useContext3.selectedRoute,
19236
- getPaymentRoutes = _useContext3.getPaymentRoutes;
19235
+ selectedRoute = _useContext3.selectedRoute;
19236
+ _useContext3.getPaymentRoutes;
19237
19237
 
19238
19238
  var _useContext4 = useContext(ClosableContext),
19239
19239
  open = _useContext4.open,
@@ -19298,10 +19298,7 @@ var PaymentProvider = (function (props) {
19298
19298
  failed(transaction, error);
19299
19299
  }
19300
19300
 
19301
- setPaymentState('initialized');
19302
19301
  setClosable(true);
19303
- setUpdatable(true);
19304
- getPaymentRoutes({});
19305
19302
  navigate('PaymentError');
19306
19303
  };
19307
19304
 
@@ -19601,7 +19598,8 @@ var PaymentRoutingProvider = (function (props) {
19601
19598
 
19602
19599
  var calculateAmountInWithSlippage = /*#__PURE__*/function () {
19603
19600
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(route) {
19604
- var currentBlock, blocks, i, exchangeRoute, lastAmountsIn, difference1, difference2, slippage, newAmountBN, readableAmount, roundedAmountBN;
19601
+ var currentBlock, blocks, i, exchangeRoute, lastAmountsIn, difference1, difference2, slippage, newAmountBN, readableAmount, roundedAmountBN, _difference, _difference2, _slippage, highestAmountBN, _newAmountBN, _readableAmount, _roundedAmountBN;
19602
+
19605
19603
  return regenerator.wrap(function _callee2$(_context2) {
19606
19604
  while (1) {
19607
19605
  switch (_context2.prev = _context2.next) {
@@ -19682,10 +19680,11 @@ var PaymentRoutingProvider = (function (props) {
19682
19680
 
19683
19681
  case 15:
19684
19682
  if (!(lastAmountsIn[0].gt(lastAmountsIn[1]) && lastAmountsIn[1].gt(lastAmountsIn[2]))) {
19685
- _context2.next = 29;
19683
+ _context2.next = 31;
19686
19684
  break;
19687
19685
  }
19688
19686
 
19687
+ // directional slippage
19689
19688
  difference1 = lastAmountsIn[0].sub(lastAmountsIn[1]);
19690
19689
  difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]);
19691
19690
 
@@ -19717,7 +19716,53 @@ var PaymentRoutingProvider = (function (props) {
19717
19716
  case 28:
19718
19717
  return _context2.abrupt("return", newAmountBN);
19719
19718
 
19720
- case 29:
19719
+ case 31:
19720
+ if (lastAmountsIn[0].eq(lastAmountsIn[1]) && lastAmountsIn[1].eq(lastAmountsIn[2])) {
19721
+ _context2.next = 46;
19722
+ break;
19723
+ }
19724
+
19725
+ // base slippage
19726
+ _difference = lastAmountsIn[0].sub(lastAmountsIn[1]).abs();
19727
+ _difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]).abs();
19728
+
19729
+ if (_difference.lt(_difference2)) {
19730
+ _slippage = _difference;
19731
+ } else {
19732
+ _slippage = _difference2;
19733
+ }
19734
+
19735
+ if (lastAmountsIn[0].gt(lastAmountsIn[1]) && lastAmountsIn[0].gt(lastAmountsIn[2])) {
19736
+ highestAmountBN = lastAmountsIn[0];
19737
+ } else if (lastAmountsIn[1].gt(lastAmountsIn[2]) && lastAmountsIn[1].gt(lastAmountsIn[0])) {
19738
+ highestAmountBN = lastAmountsIn[1];
19739
+ } else {
19740
+ highestAmountBN = lastAmountsIn[2];
19741
+ }
19742
+
19743
+ _newAmountBN = highestAmountBN.add(_slippage);
19744
+ _context2.next = 39;
19745
+ return route.fromToken.readable(_newAmountBN);
19746
+
19747
+ case 39:
19748
+ _readableAmount = _context2.sent;
19749
+ _context2.next = 42;
19750
+ return route.fromToken.BigNumber(round(_readableAmount));
19751
+
19752
+ case 42:
19753
+ _roundedAmountBN = _context2.sent;
19754
+
19755
+ if (!(route.fromAmount == _roundedAmountBN.toString())) {
19756
+ _context2.next = 45;
19757
+ break;
19758
+ }
19759
+
19760
+ return _context2.abrupt("return");
19761
+
19762
+ case 45:
19763
+ return _context2.abrupt("return", _newAmountBN);
19764
+
19765
+ case 46:
19721
19766
  case "end":
19722
19767
  return _context2.stop();
19723
19768
  }
@@ -20946,8 +20991,8 @@ var DonationOverviewDialog = (function (props) {
20946
20991
  });
20947
20992
 
20948
20993
  var PaymentErrorDialog = (function () {
20949
- var _useContext = useContext(NavigateStackContext),
20950
- navigate = _useContext.navigate;
20994
+ var _useContext = useContext(ClosableContext),
20995
+ close = _useContext.close;
20951
20996
 
20952
20997
  var _useContext2 = useContext(PaymentContext),
20953
20998
  transaction = _useContext2.transaction;
@@ -20956,7 +21001,7 @@ var PaymentErrorDialog = (function () {
20956
21001
  recover = _useContext3.recover;
20957
21002
 
20958
21003
  return /*#__PURE__*/React.createElement(Dialog$1, {
20959
- stacked: recover ? false : true,
21004
+ stacked: false,
20960
21005
  header: /*#__PURE__*/React.createElement("div", {
20961
21006
  className: "PaddingTopS PaddingLeftM PaddingRightM"
20962
21007
  }),
@@ -20987,7 +21032,7 @@ var PaymentErrorDialog = (function () {
20987
21032
  }, recover == undefined && /*#__PURE__*/React.createElement("button", {
20988
21033
  className: "ButtonPrimary",
20989
21034
  onClick: function onClick() {
20990
- return navigate('back');
21035
+ return close();
20991
21036
  }
20992
21037
  }, "Try again"))
20993
21038
  });
@@ -21133,6 +21178,9 @@ var PaymentTrackingProvider = (function (props) {
21133
21178
  var _useContext3 = useContext(ClosableContext),
21134
21179
  setClosable = _useContext3.setClosable;
21135
21180
 
21181
+ var _useContext4 = useContext(NavigateContext),
21182
+ navigate = _useContext4.navigate;
21183
+
21136
21184
  var openSocket = function openSocket(transaction) {
21137
21185
  var socket = new WebSocket('wss://integrate.depay.fi/cable');
21138
21186
 
@@ -21154,15 +21202,20 @@ var PaymentTrackingProvider = (function (props) {
21154
21202
  socket.onmessage = function (event) {
21155
21203
  var item = JSON.parse(event.data);
21156
21204
 
21157
- if (item.type === "ping") {
21205
+ if (item.type === "ping" || !item.message) {
21158
21206
  return;
21159
21207
  }
21160
21208
 
21161
- if (item.message && item.message.release) {
21162
- if (validated) {
21163
- validated(item.message.status == 'success');
21164
- }
21209
+ if (item.message.status == 'failed') {
21210
+ setClosable(true);
21211
+ navigate('PaymentError');
21212
+ }
21213
+
21214
+ if (validated) {
21215
+ validated(item.message.status == 'success');
21216
+ }
21165
21217
 
21218
+ if (item.message.release) {
21166
21219
  setRelease(true);
21167
21220
  setClosable(!item.message.forward_to);
21168
21221
  setForwardTo(item.message.forward_to);