@depay/widgets 7.11.0 → 7.13.1

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
  }
@@ -20323,7 +20368,6 @@ var ChangeAmountDialog = (function (props) {
20323
20368
  className: "Input FontSizeXXL TextAlignCenter",
20324
20369
  type: "number",
20325
20370
  name: "amount",
20326
- autoFocus: true,
20327
20371
  value: parseFloat(inputAmount),
20328
20372
  onChange: function onChange(event) {
20329
20373
  changeAmount(event.target.value);
@@ -20946,8 +20990,8 @@ var DonationOverviewDialog = (function (props) {
20946
20990
  });
20947
20991
 
20948
20992
  var PaymentErrorDialog = (function () {
20949
- var _useContext = useContext(NavigateStackContext),
20950
- navigate = _useContext.navigate;
20993
+ var _useContext = useContext(ClosableContext),
20994
+ close = _useContext.close;
20951
20995
 
20952
20996
  var _useContext2 = useContext(PaymentContext),
20953
20997
  transaction = _useContext2.transaction;
@@ -20956,7 +21000,7 @@ var PaymentErrorDialog = (function () {
20956
21000
  recover = _useContext3.recover;
20957
21001
 
20958
21002
  return /*#__PURE__*/React.createElement(Dialog$1, {
20959
- stacked: recover ? false : true,
21003
+ stacked: false,
20960
21004
  header: /*#__PURE__*/React.createElement("div", {
20961
21005
  className: "PaddingTopS PaddingLeftM PaddingRightM"
20962
21006
  }),
@@ -20987,7 +21031,7 @@ var PaymentErrorDialog = (function () {
20987
21031
  }, recover == undefined && /*#__PURE__*/React.createElement("button", {
20988
21032
  className: "ButtonPrimary",
20989
21033
  onClick: function onClick() {
20990
- return navigate('back');
21034
+ return close();
20991
21035
  }
20992
21036
  }, "Try again"))
20993
21037
  });
@@ -21133,6 +21177,9 @@ var PaymentTrackingProvider = (function (props) {
21133
21177
  var _useContext3 = useContext(ClosableContext),
21134
21178
  setClosable = _useContext3.setClosable;
21135
21179
 
21180
+ var _useContext4 = useContext(NavigateContext),
21181
+ navigate = _useContext4.navigate;
21182
+
21136
21183
  var openSocket = function openSocket(transaction) {
21137
21184
  var socket = new WebSocket('wss://integrate.depay.fi/cable');
21138
21185
 
@@ -21154,15 +21201,20 @@ var PaymentTrackingProvider = (function (props) {
21154
21201
  socket.onmessage = function (event) {
21155
21202
  var item = JSON.parse(event.data);
21156
21203
 
21157
- if (item.type === "ping") {
21204
+ if (item.type === "ping" || !item.message) {
21158
21205
  return;
21159
21206
  }
21160
21207
 
21161
- if (item.message && item.message.release) {
21162
- if (validated) {
21163
- validated(item.message.status == 'success');
21164
- }
21208
+ if (item.message.status == 'failed') {
21209
+ setClosable(true);
21210
+ navigate('PaymentError');
21211
+ }
21212
+
21213
+ if (validated) {
21214
+ validated(item.message.status == 'success');
21215
+ }
21165
21216
 
21217
+ if (item.message.release) {
21166
21218
  setRelease(true);
21167
21219
  setClosable(!item.message.forward_to);
21168
21220
  setForwardTo(item.message.forward_to);
@@ -21227,8 +21279,10 @@ var PaymentTrackingProvider = (function (props) {
21227
21279
  after_block: afterBlock,
21228
21280
  from_token: paymentRoute.fromToken.address,
21229
21281
  from_amount: paymentRoute.fromAmount.toString(),
21282
+ from_decimals: paymentRoute.fromDecimals,
21230
21283
  to_token: paymentRoute.toToken.address,
21231
21284
  to_amount: paymentRoute.toAmount.toString(),
21285
+ to_decimals: paymentRoute.toDecimals,
21232
21286
  fee_amount: paymentRoute === null || paymentRoute === void 0 ? void 0 : (_paymentRoute$feeAmou = paymentRoute.feeAmount) === null || _paymentRoute$feeAmou === void 0 ? void 0 : _paymentRoute$feeAmou.toString()
21233
21287
  }).then(function (response) {
21234
21288
  if (response.status != 200) {