@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/umd/index.js CHANGED
@@ -19227,8 +19227,8 @@
19227
19227
  before = _useContext2.before;
19228
19228
 
19229
19229
  var _useContext3 = React.useContext(PaymentRoutingContext),
19230
- selectedRoute = _useContext3.selectedRoute,
19231
- getPaymentRoutes = _useContext3.getPaymentRoutes;
19230
+ selectedRoute = _useContext3.selectedRoute;
19231
+ _useContext3.getPaymentRoutes;
19232
19232
 
19233
19233
  var _useContext4 = React.useContext(ClosableContext),
19234
19234
  open = _useContext4.open,
@@ -19293,10 +19293,7 @@
19293
19293
  failed(transaction, error);
19294
19294
  }
19295
19295
 
19296
- setPaymentState('initialized');
19297
19296
  setClosable(true);
19298
- setUpdatable(true);
19299
- getPaymentRoutes({});
19300
19297
  navigate('PaymentError');
19301
19298
  };
19302
19299
 
@@ -19596,7 +19593,8 @@
19596
19593
 
19597
19594
  var calculateAmountInWithSlippage = /*#__PURE__*/function () {
19598
19595
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(route) {
19599
- var currentBlock, blocks, i, exchangeRoute, lastAmountsIn, difference1, difference2, slippage, newAmountBN, readableAmount, roundedAmountBN;
19596
+ var currentBlock, blocks, i, exchangeRoute, lastAmountsIn, difference1, difference2, slippage, newAmountBN, readableAmount, roundedAmountBN, _difference, _difference2, _slippage, highestAmountBN, _newAmountBN, _readableAmount, _roundedAmountBN;
19597
+
19600
19598
  return regenerator.wrap(function _callee2$(_context2) {
19601
19599
  while (1) {
19602
19600
  switch (_context2.prev = _context2.next) {
@@ -19677,10 +19675,11 @@
19677
19675
 
19678
19676
  case 15:
19679
19677
  if (!(lastAmountsIn[0].gt(lastAmountsIn[1]) && lastAmountsIn[1].gt(lastAmountsIn[2]))) {
19680
- _context2.next = 29;
19678
+ _context2.next = 31;
19681
19679
  break;
19682
19680
  }
19683
19681
 
19682
+ // directional slippage
19684
19683
  difference1 = lastAmountsIn[0].sub(lastAmountsIn[1]);
19685
19684
  difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]);
19686
19685
 
@@ -19712,7 +19711,53 @@
19712
19711
  case 28:
19713
19712
  return _context2.abrupt("return", newAmountBN);
19714
19713
 
19715
- case 29:
19714
+ case 31:
19715
+ if (lastAmountsIn[0].eq(lastAmountsIn[1]) && lastAmountsIn[1].eq(lastAmountsIn[2])) {
19716
+ _context2.next = 46;
19717
+ break;
19718
+ }
19719
+
19720
+ // base slippage
19721
+ _difference = lastAmountsIn[0].sub(lastAmountsIn[1]).abs();
19722
+ _difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]).abs();
19723
+
19724
+ if (_difference.lt(_difference2)) {
19725
+ _slippage = _difference;
19726
+ } else {
19727
+ _slippage = _difference2;
19728
+ }
19729
+
19730
+ if (lastAmountsIn[0].gt(lastAmountsIn[1]) && lastAmountsIn[0].gt(lastAmountsIn[2])) {
19731
+ highestAmountBN = lastAmountsIn[0];
19732
+ } else if (lastAmountsIn[1].gt(lastAmountsIn[2]) && lastAmountsIn[1].gt(lastAmountsIn[0])) {
19733
+ highestAmountBN = lastAmountsIn[1];
19734
+ } else {
19735
+ highestAmountBN = lastAmountsIn[2];
19736
+ }
19737
+
19738
+ _newAmountBN = highestAmountBN.add(_slippage);
19739
+ _context2.next = 39;
19740
+ return route.fromToken.readable(_newAmountBN);
19741
+
19742
+ case 39:
19743
+ _readableAmount = _context2.sent;
19744
+ _context2.next = 42;
19745
+ return route.fromToken.BigNumber(round(_readableAmount));
19746
+
19747
+ case 42:
19748
+ _roundedAmountBN = _context2.sent;
19749
+
19750
+ if (!(route.fromAmount == _roundedAmountBN.toString())) {
19751
+ _context2.next = 45;
19752
+ break;
19753
+ }
19754
+
19755
+ return _context2.abrupt("return");
19756
+
19757
+ case 45:
19758
+ return _context2.abrupt("return", _newAmountBN);
19759
+
19760
+ case 46:
19716
19761
  case "end":
19717
19762
  return _context2.stop();
19718
19763
  }
@@ -20318,7 +20363,6 @@
20318
20363
  className: "Input FontSizeXXL TextAlignCenter",
20319
20364
  type: "number",
20320
20365
  name: "amount",
20321
- autoFocus: true,
20322
20366
  value: parseFloat(inputAmount),
20323
20367
  onChange: function onChange(event) {
20324
20368
  changeAmount(event.target.value);
@@ -20941,8 +20985,8 @@
20941
20985
  });
20942
20986
 
20943
20987
  var PaymentErrorDialog = (function () {
20944
- var _useContext = React.useContext(reactDialogStack.NavigateStackContext),
20945
- navigate = _useContext.navigate;
20988
+ var _useContext = React.useContext(ClosableContext),
20989
+ close = _useContext.close;
20946
20990
 
20947
20991
  var _useContext2 = React.useContext(PaymentContext),
20948
20992
  transaction = _useContext2.transaction;
@@ -20951,7 +20995,7 @@
20951
20995
  recover = _useContext3.recover;
20952
20996
 
20953
20997
  return /*#__PURE__*/React__default["default"].createElement(Dialog$1, {
20954
- stacked: recover ? false : true,
20998
+ stacked: false,
20955
20999
  header: /*#__PURE__*/React__default["default"].createElement("div", {
20956
21000
  className: "PaddingTopS PaddingLeftM PaddingRightM"
20957
21001
  }),
@@ -20982,7 +21026,7 @@
20982
21026
  }, recover == undefined && /*#__PURE__*/React__default["default"].createElement("button", {
20983
21027
  className: "ButtonPrimary",
20984
21028
  onClick: function onClick() {
20985
- return navigate('back');
21029
+ return close();
20986
21030
  }
20987
21031
  }, "Try again"))
20988
21032
  });
@@ -21128,6 +21172,9 @@
21128
21172
  var _useContext3 = React.useContext(ClosableContext),
21129
21173
  setClosable = _useContext3.setClosable;
21130
21174
 
21175
+ var _useContext4 = React.useContext(NavigateContext),
21176
+ navigate = _useContext4.navigate;
21177
+
21131
21178
  var openSocket = function openSocket(transaction) {
21132
21179
  var socket = new WebSocket('wss://integrate.depay.fi/cable');
21133
21180
 
@@ -21149,15 +21196,20 @@
21149
21196
  socket.onmessage = function (event) {
21150
21197
  var item = JSON.parse(event.data);
21151
21198
 
21152
- if (item.type === "ping") {
21199
+ if (item.type === "ping" || !item.message) {
21153
21200
  return;
21154
21201
  }
21155
21202
 
21156
- if (item.message && item.message.release) {
21157
- if (validated) {
21158
- validated(item.message.status == 'success');
21159
- }
21203
+ if (item.message.status == 'failed') {
21204
+ setClosable(true);
21205
+ navigate('PaymentError');
21206
+ }
21207
+
21208
+ if (validated) {
21209
+ validated(item.message.status == 'success');
21210
+ }
21160
21211
 
21212
+ if (item.message.release) {
21161
21213
  setRelease(true);
21162
21214
  setClosable(!item.message.forward_to);
21163
21215
  setForwardTo(item.message.forward_to);
@@ -21222,8 +21274,10 @@
21222
21274
  after_block: afterBlock,
21223
21275
  from_token: paymentRoute.fromToken.address,
21224
21276
  from_amount: paymentRoute.fromAmount.toString(),
21277
+ from_decimals: paymentRoute.fromDecimals,
21225
21278
  to_token: paymentRoute.toToken.address,
21226
21279
  to_amount: paymentRoute.toAmount.toString(),
21280
+ to_decimals: paymentRoute.toDecimals,
21227
21281
  fee_amount: paymentRoute === null || paymentRoute === void 0 ? void 0 : (_paymentRoute$feeAmou = paymentRoute.feeAmount) === null || _paymentRoute$feeAmou === void 0 ? void 0 : _paymentRoute$feeAmou.toString()
21228
21282
  }).then(function (response) {
21229
21283
  if (response.status != 200) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depay/widgets",
3
3
  "moduleName": "DePayWidgets",
4
- "version": "7.11.0",
4
+ "version": "7.13.1",
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",