@depay/widgets 10.2.11 → 10.2.12

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
@@ -4801,14 +4801,24 @@ function _toConsumableArray(arr) {
4801
4801
 
4802
4802
  var findMaxRoute = (function (routes) {
4803
4803
  var sortedLowToHigh = _toConsumableArray(routes).sort(function (a, b) {
4804
+ if (a.fromBalance == '0' || a.fromAmount == '0') {
4805
+ return -1; // b
4806
+ }
4807
+
4808
+ if (b.fromBalance == '0' || b.fromAmount == '0') {
4809
+ return 1; // a
4810
+ }
4811
+
4804
4812
  var aAmountsAvailable = ethers.BigNumber.from(a.fromBalance).div(ethers.BigNumber.from(a.fromAmount));
4805
4813
  var bAmountsAvailable = ethers.BigNumber.from(b.fromBalance).div(ethers.BigNumber.from(b.fromAmount));
4806
4814
  if (aAmountsAvailable.lt(bAmountsAvailable)) {
4807
- return -1;
4815
+ return -1; // b
4808
4816
  }
4817
+
4809
4818
  if (bAmountsAvailable.lt(aAmountsAvailable)) {
4810
- return 1;
4819
+ return 1; // a
4811
4820
  }
4821
+
4812
4822
  return 0; // equal
4813
4823
  });
4814
4824
 
@@ -22393,8 +22403,8 @@ var PaymentProvider = (function (props) {
22393
22403
  recover = _useContext2.recover,
22394
22404
  before = _useContext2.before;
22395
22405
  var _useContext3 = useContext(PaymentRoutingContext),
22396
- selectedRoute = _useContext3.selectedRoute;
22397
- _useContext3.getPaymentRoutes;
22406
+ selectedRoute = _useContext3.selectedRoute,
22407
+ refreshPaymentRoutes = _useContext3.refreshPaymentRoutes;
22398
22408
  var _useContext4 = useContext(ClosableContext),
22399
22409
  open = _useContext4.open,
22400
22410
  close = _useContext4.close,
@@ -22527,13 +22537,15 @@ var PaymentProvider = (function (props) {
22527
22537
  }();
22528
22538
  var approve = function approve() {
22529
22539
  setClosable(false);
22540
+ setUpdatable(false);
22530
22541
  setPaymentState('approving');
22531
22542
  wallet.sendTransaction(Object.assign({}, payment.route.approvalTransaction, {
22532
22543
  succeeded: function succeeded() {
22533
- payment.route.approvalRequired = false;
22534
- setPayment(payment);
22544
+ setUpdatable(true);
22535
22545
  setClosable(true);
22536
- setPaymentState('initialized');
22546
+ refreshPaymentRoutes().then(function () {
22547
+ setPaymentState('initialized');
22548
+ });
22537
22549
  }
22538
22550
  })).then(function (sentTransaction) {
22539
22551
  setApprovalTransaction(sentTransaction);
@@ -22735,7 +22747,7 @@ var PaymentRoutingProvider = (function (props) {
22735
22747
  } else {
22736
22748
  roundAmounts(routes).then( /*#__PURE__*/function () {
22737
22749
  var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(roundedRoutes) {
22738
- var selectRoute, newSelectRoute;
22750
+ var selectRoute, updatedSelectedRoute;
22739
22751
  return regenerator.wrap(function _callee$(_context) {
22740
22752
  while (1) switch (_context.prev = _context.next) {
22741
22753
  case 0:
@@ -22743,13 +22755,19 @@ var PaymentRoutingProvider = (function (props) {
22743
22755
  selectRoute = roundedRoutes[0];
22744
22756
  setSelectedRoute(selectRoute);
22745
22757
  } else {
22746
- newSelectRoute = roundedRoutes[roundedRoutes.findIndex(function (route) {
22758
+ updatedSelectedRoute = roundedRoutes[roundedRoutes.findIndex(function (route) {
22747
22759
  return route.fromToken.address == selectedRoute.fromToken.address && route.blockchain == selectedRoute.blockchain;
22748
22760
  })];
22749
- if (newSelectRoute) {
22750
- if (selectedRoute.fromAmount != newSelectRoute.fromAmount) {
22751
- setUpdatedRouteWithNewPrice(newSelectRoute);
22761
+ if (updatedSelectedRoute) {
22762
+ if (selectedRoute.fromAmount != updatedSelectedRoute.fromAmount) {
22763
+ setUpdatedRouteWithNewPrice(updatedSelectedRoute);
22764
+ } else if (
22765
+ // other reasons but price to update selected route
22766
+ selectedRoute.approvalRequired != updatedSelectedRoute.approvalRequired) {
22767
+ setSelectedRoute(updatedSelectedRoute);
22752
22768
  }
22769
+ } else {
22770
+ setSelectedRoute(roundedRoutes[0]);
22753
22771
  }
22754
22772
  }
22755
22773
  setAllRoutes(roundedRoutes);
@@ -22777,23 +22795,41 @@ var PaymentRoutingProvider = (function (props) {
22777
22795
  return _ref.apply(this, arguments);
22778
22796
  };
22779
22797
  }();
22780
- var getPaymentRoutes = function getPaymentRoutes(_ref3) {
22781
- _ref3.allRoutes;
22782
- _ref3.selectedRoute;
22783
- var updatable = _ref3.updatable;
22784
- if (updatable == false || !props.accept || !account) {
22785
- return;
22786
- }
22787
- var slowRoutingTimeout = setTimeout(function () {
22788
- setSlowRouting(true);
22789
- }, 4000);
22790
- routePayments(Object.assign({}, props, {
22791
- account: account
22792
- })).then(function (routes) {
22793
- clearInterval(slowRoutingTimeout);
22794
- onRoutesUpdate(routes);
22795
- });
22796
- };
22798
+ var getPaymentRoutes = /*#__PURE__*/function () {
22799
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(_ref3) {
22800
+ var updatable, slowRoutingTimeout;
22801
+ return regenerator.wrap(function _callee3$(_context3) {
22802
+ while (1) switch (_context3.prev = _context3.next) {
22803
+ case 0:
22804
+ _ref3.allRoutes, _ref3.selectedRoute, updatable = _ref3.updatable;
22805
+ if (!(updatable == false || !props.accept || !account)) {
22806
+ _context3.next = 3;
22807
+ break;
22808
+ }
22809
+ return _context3.abrupt("return");
22810
+ case 3:
22811
+ slowRoutingTimeout = setTimeout(function () {
22812
+ setSlowRouting(true);
22813
+ }, 4000);
22814
+ _context3.next = 6;
22815
+ return routePayments(Object.assign({}, props, {
22816
+ account: account
22817
+ })).then(function (routes) {
22818
+ clearInterval(slowRoutingTimeout);
22819
+ onRoutesUpdate(routes);
22820
+ });
22821
+ case 6:
22822
+ return _context3.abrupt("return", _context3.sent);
22823
+ case 7:
22824
+ case "end":
22825
+ return _context3.stop();
22826
+ }
22827
+ }, _callee3);
22828
+ }));
22829
+ return function getPaymentRoutes(_x3) {
22830
+ return _ref4.apply(this, arguments);
22831
+ };
22832
+ }();
22797
22833
  var updateRouteAmount = function updateRouteAmount(route, amountBN) {
22798
22834
  route.fromAmount = amountBN.toString();
22799
22835
  route.transaction.params.amounts[0] = amountBN.toString();
@@ -22802,72 +22838,79 @@ var PaymentRoutingProvider = (function (props) {
22802
22838
  }
22803
22839
  };
22804
22840
  var roundAmount = /*#__PURE__*/function () {
22805
- var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(route, amountBN) {
22841
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(route, amountBN) {
22806
22842
  var readableAmount, roundedAmountBN;
22807
- return regenerator.wrap(function _callee3$(_context3) {
22808
- while (1) switch (_context3.prev = _context3.next) {
22843
+ return regenerator.wrap(function _callee4$(_context4) {
22844
+ while (1) switch (_context4.prev = _context4.next) {
22809
22845
  case 0:
22810
22846
  if (!route.directTransfer) {
22811
- _context3.next = 2;
22847
+ _context4.next = 2;
22812
22848
  break;
22813
22849
  }
22814
- return _context3.abrupt("return", route);
22850
+ return _context4.abrupt("return", route);
22815
22851
  case 2:
22816
- _context3.next = 4;
22852
+ _context4.next = 4;
22817
22853
  return route.fromToken.readable(amountBN || route.transaction.params.amounts[0]);
22818
22854
  case 4:
22819
- readableAmount = _context3.sent;
22820
- _context3.next = 7;
22855
+ readableAmount = _context4.sent;
22856
+ _context4.next = 7;
22821
22857
  return route.fromToken.BigNumber(round(readableAmount));
22822
22858
  case 7:
22823
- roundedAmountBN = _context3.sent;
22859
+ roundedAmountBN = _context4.sent;
22824
22860
  updateRouteAmount(route, roundedAmountBN);
22825
- return _context3.abrupt("return", route);
22861
+ return _context4.abrupt("return", route);
22826
22862
  case 10:
22827
22863
  case "end":
22828
- return _context3.stop();
22864
+ return _context4.stop();
22829
22865
  }
22830
- }, _callee3);
22866
+ }, _callee4);
22831
22867
  }));
22832
- return function roundAmount(_x3, _x4) {
22833
- return _ref4.apply(this, arguments);
22868
+ return function roundAmount(_x4, _x5) {
22869
+ return _ref5.apply(this, arguments);
22834
22870
  };
22835
22871
  }();
22836
22872
  var roundAmounts = /*#__PURE__*/function () {
22837
- var _ref5 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(routes) {
22838
- return regenerator.wrap(function _callee4$(_context4) {
22839
- while (1) switch (_context4.prev = _context4.next) {
22873
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(routes) {
22874
+ return regenerator.wrap(function _callee5$(_context5) {
22875
+ while (1) switch (_context5.prev = _context5.next) {
22840
22876
  case 0:
22841
- return _context4.abrupt("return", Promise.all(routes.map(function (route) {
22877
+ return _context5.abrupt("return", Promise.all(routes.map(function (route) {
22842
22878
  return roundAmount(route);
22843
22879
  })));
22844
22880
  case 1:
22845
22881
  case "end":
22846
- return _context4.stop();
22882
+ return _context5.stop();
22847
22883
  }
22848
- }, _callee4);
22884
+ }, _callee5);
22849
22885
  }));
22850
- return function roundAmounts(_x5) {
22851
- return _ref5.apply(this, arguments);
22886
+ return function roundAmounts(_x6) {
22887
+ return _ref6.apply(this, arguments);
22852
22888
  };
22853
22889
  }();
22854
22890
  var updateRouteWithNewPrice = /*#__PURE__*/function () {
22855
- var _ref6 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
22856
- return regenerator.wrap(function _callee5$(_context5) {
22857
- while (1) switch (_context5.prev = _context5.next) {
22891
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
22892
+ return regenerator.wrap(function _callee6$(_context6) {
22893
+ while (1) switch (_context6.prev = _context6.next) {
22858
22894
  case 0:
22859
22895
  setSelectedRoute(_objectSpread$2({}, updatedRouteWithNewPrice));
22860
22896
  setUpdatedRouteWithNewPrice(null);
22861
22897
  case 2:
22862
22898
  case "end":
22863
- return _context5.stop();
22899
+ return _context6.stop();
22864
22900
  }
22865
- }, _callee5);
22901
+ }, _callee6);
22866
22902
  }));
22867
22903
  return function updateRouteWithNewPrice() {
22868
- return _ref6.apply(this, arguments);
22904
+ return _ref7.apply(this, arguments);
22869
22905
  };
22870
22906
  }();
22907
+ var refreshPaymentRoutes = function refreshPaymentRoutes() {
22908
+ return getPaymentRoutes({
22909
+ allRoutes: allRoutes,
22910
+ selectedRoute: selectedRoute,
22911
+ updatable: updatable
22912
+ });
22913
+ };
22871
22914
  useEffect(function () {
22872
22915
  var timeout = setTimeout(function () {
22873
22916
  setReloadCount(reloadCount + 1);
@@ -22890,7 +22933,7 @@ var PaymentRoutingProvider = (function (props) {
22890
22933
  value: {
22891
22934
  selectedRoute: selectedRoute,
22892
22935
  setSelectedRoute: setSelectedRoute,
22893
- getPaymentRoutes: getPaymentRoutes,
22936
+ refreshPaymentRoutes: refreshPaymentRoutes,
22894
22937
  allRoutes: allRoutes,
22895
22938
  setAllRoutes: setAllRoutes,
22896
22939
  slowRouting: slowRouting,
@@ -23606,7 +23649,7 @@ var Footer = (function () {
23606
23649
  }
23607
23650
  };
23608
23651
  var approvalButton = function approvalButton() {
23609
- if (payment.route == undefined || !payment.route.approvalRequired || payment.route.directTransfer) {
23652
+ if (payment.route == undefined || !payment.route.approvalRequired || payment.route.directTransfer || updatedRouteWithNewPrice) {
23610
23653
  return null;
23611
23654
  } else if (paymentState == 'initialized') {
23612
23655
  return /*#__PURE__*/React.createElement("div", {