@depay/widgets 10.2.11 → 10.2.13

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", {
@@ -24940,6 +24983,8 @@ var Login = function Login(options) {
24940
24983
  }());
24941
24984
  };
24942
24985
 
24986
+ var SUPPORTED_CURRENCIES = ["all", "xcd", "eur", "bbd", "btn", "bnd", "xaf", "cup", "usd", "fkp", "gip", "huf", "irr", "jmd", "aud", "lak", "lyd", "mkd", "xof", "nzd", "omr", "pgk", "rwf", "wst", "rsd", "sek", "tzs", "amd", "bsd", "bam", "cve", "cny", "crc", "czk", "ern", "gel", "htg", "inr", "jod", "krw", "lbp", "mwk", "mru", "mzn", "ang", "pen", "qar", "std", "sll", "sos", "sdg", "syp", "aoa", "awg", "bhd", "bzd", "bwp", "bif", "kyd", "cop", "dkk", "gtq", "hnl", "idr", "ils", "kzt", "kwd", "lsl", "myr", "mur", "mnt", "mmk", "ngn", "pab", "php", "ron", "sar", "sgd", "zar", "srd", "twd", "top", "vef", "dzd", "ars", "azn", "bob", "bgn", "cad", "clp", "cdf", "dop", "fjd", "gmd", "gyd", "isk", "iqd", "jpy", "kpw", "chf", "mga", "mdl", "mad", "npr", "nio", "pkr", "pyg", "shp", "scr", "sbd", "lkr", "thb", "try", "aed", "vuv", "yer", "afn", "bdt", "brl", "khr", "kmf", "hrk", "djf", "egp", "etb", "xpf", "ghs", "gnf", "hkd", "xdr", "kes", "kgs", "lrd", "mop", "mvr", "mxn", "nad", "nok", "pln", "rub", "szl", "tjs", "ttd", "ugx", "uyu", "vnd", "tnd", "uah", "uzs", "tmt", "gbp", "zmw", "byn", "bmd", "ggp", "clf", "cuc", "imp", "jep", "svc", "xag", "zwl"];
24987
+
24943
24988
  var PaymentAmountRoutingContext = /*#__PURE__*/React.createContext();
24944
24989
 
24945
24990
  var PaymentAmountRoutingProvider = (function (props) {
@@ -25015,7 +25060,8 @@ var PaymentOverviewDialog = (function (props) {
25015
25060
  var _useContext = useContext(ConfigurationContext),
25016
25061
  currencyCode = _useContext.currencyCode,
25017
25062
  recover = _useContext.recover,
25018
- amountConfiguration = _useContext.amount;
25063
+ amountConfiguration = _useContext.amount,
25064
+ currency = _useContext.currency;
25019
25065
  var _useContext2 = useContext(PaymentContext),
25020
25066
  payment = _useContext2.payment,
25021
25067
  paymentState = _useContext2.paymentState;
@@ -25129,7 +25175,7 @@ var PaymentOverviewDialog = (function (props) {
25129
25175
  className: "TokenSymbolCell"
25130
25176
  }, payment.symbol), /*#__PURE__*/React.createElement("span", null, "\xA0"), /*#__PURE__*/React.createElement("span", {
25131
25177
  className: "TokenAmountCell"
25132
- }, format(payment.amount))), displayedPaymentValue != "".concat(payment.symbol, " ").concat(format(payment.amount)) && !(amountsMissing && !fixedCurrency) && /*#__PURE__*/React.createElement("div", {
25178
+ }, format(payment.amount))), displayedPaymentValue != "".concat(payment.symbol, " ").concat(format(payment.amount)) && !(amountsMissing && !fixedCurrency) && currency !== false && /*#__PURE__*/React.createElement("div", {
25133
25179
  className: "TokenAmountRow small grey"
25134
25180
  }, /*#__PURE__*/React.createElement("span", {
25135
25181
  className: "TokenAmountCell"
@@ -25294,13 +25340,16 @@ var Payment = /*#__PURE__*/function () {
25294
25340
  case 0:
25295
25341
  accept = _ref3.accept, amount = _ref3.amount, sent = _ref3.sent, succeeded = _ref3.succeeded, validated = _ref3.validated, failed = _ref3.failed, error = _ref3.error, critical = _ref3.critical, style = _ref3.style, whitelist = _ref3.whitelist, blacklist = _ref3.blacklist, providers = _ref3.providers, currency = _ref3.currency, connected = _ref3.connected, closed = _ref3.closed, track = _ref3.track, fee = _ref3.fee, recover = _ref3.recover, closable = _ref3.closable, integration = _ref3.integration, link = _ref3.link, container = _ref3.container, before = _ref3.before, wallet = _ref3.wallet, document = _ref3.document;
25296
25342
  requireReactVersion();
25297
- _context2.prev = 2;
25298
- _context2.next = 5;
25343
+ if (currency && !SUPPORTED_CURRENCIES.includes(currency.toLowerCase())) {
25344
+ currency = false;
25345
+ }
25346
+ _context2.prev = 3;
25347
+ _context2.next = 6;
25299
25348
  return preflight$1({
25300
25349
  accept: accept,
25301
25350
  recover: recover
25302
25351
  });
25303
- case 5:
25352
+ case 6:
25304
25353
  if (typeof window._depayUnmountLoading == 'function') {
25305
25354
  window._depayUnmountLoading();
25306
25355
  }
@@ -25367,18 +25416,18 @@ var Payment = /*#__PURE__*/function () {
25367
25416
  return _context2.abrupt("return", {
25368
25417
  unmount: unmount
25369
25418
  });
25370
- case 10:
25371
- _context2.prev = 10;
25372
- _context2.t0 = _context2["catch"](2);
25419
+ case 11:
25420
+ _context2.prev = 11;
25421
+ _context2.t0 = _context2["catch"](3);
25373
25422
  console.log('critical error', _context2.t0);
25374
25423
  if (critical != undefined) {
25375
25424
  critical(_context2.t0);
25376
25425
  }
25377
- case 14:
25426
+ case 15:
25378
25427
  case "end":
25379
25428
  return _context2.stop();
25380
25429
  }
25381
- }, _callee2, null, [[2, 10]]);
25430
+ }, _callee2, null, [[3, 11]]);
25382
25431
  }));
25383
25432
  return function Payment(_x2) {
25384
25433
  return _ref4.apply(this, arguments);