@depay/widgets 6.23.0 → 6.25.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
@@ -1694,7 +1694,7 @@ var CardStyle = (function (style) {
1694
1694
  });
1695
1695
 
1696
1696
  var DialogStyle = (function (style) {
1697
- return "\n\n .ReactDialogBackground {\n backdrop-filter: blur(5px);\n background: rgba(0,0,0,0.7);\n }\n\n .Dialog {\n margin: 0 auto;\n position: relative;\n width: 420px;\n box-shadow: 0 0 20px rgba(0,0,0,0.1);\n border-radius: 0.8rem;\n background: rgb(248,248,248);\n }\n\n @media (max-width: 450px) {\n\n .Dialog {\n border-radius: 0;\n width: 100%;\n }\n\n\n .DialogHeader {\n border-top-left-radius: 0 !important;\n border-top-right-radius: 0 !important;\n }\n }\n\n @media (orientation: portrait) and (max-width: 800px) {\n\n .ReactDialogAnimation {\n width: 100%;\n }\n\n .ReactDialog {\n height: 100%;\n min-height: 100%;\n }\n\n .ReactDialogStack {\n align-items: flex-end;\n }\n\n .Dialog {\n align-content: stretch;\n border-radius: 0.8rem;\n border-top-radius: 0.8rem;\n display: flex;\n flex-direction: column;\n }\n\n .DialogBody {\n flex: 1;\n align-items: flex-end;\n }\n\n .DialogFooter {\n padding-bottom: 20px;\n }\n\n .ReactDialogAnimation {\n margin-bottom: -100px !important;\n top: inherit !important;\n position: relative;\n transition: opacity 0.4s ease, margin-bottom 0.4s ease;\n }\n\n .ReactDialog.ReactDialogOpen .ReactDialogAnimation {\n margin-bottom: 0px !important;\n }\n\n .DialogFooter {\n border-bottom-left-radius: 0 !important;\n border-bottom-right-radius: 0 !important;\n }\n\n .ReactShadowDOMInsideContainer > .ReactDialog {\n align-items: flex-end;\n }\n }\n\n .DialogBody {\n background: rgb(248,248,248);\n overflow-x: hidden;\n overflow-y: auto;\n }\n\n .DialogBody.ScrollHeight {\n height: 30vh !important;\n max-height: 30vh !important;\n }\n\n .DialogHeader {\n background: rgb(248,248,248);\n border-top-left-radius: 0.8rem;\n border-top-right-radius: 0.8rem;\n min-height: 3.4rem;\n position: relative;\n width: 100%;\n }\n\n .DialogHeaderActionRight {\n position: absolute;\n top: 0;\n right: 0;\n height: 3rem;\n }\n\n .DialogHeaderActionLeft {\n position: absolute;\n top: 0;\n left: 0;\n height: 3rem;\n }\n\n .DialogFooter {\n background: rgb(248,248,248);\n border-bottom-left-radius: 0.8rem;\n border-bottom-right-radius: 0.8rem;\n line-height: 1.5rem;\n min-height: 2rem;\n position: relative;\n text-align: center;\n }\n\n ";
1697
+ return "\n\n .ReactDialogBackground {\n backdrop-filter: blur(5px);\n background: rgba(0,0,0,0.7);\n }\n\n .Dialog {\n margin: 0 auto;\n position: relative;\n width: 420px;\n box-shadow: 0 0 20px rgba(0,0,0,0.1);\n border-radius: 0.8rem;\n background: rgb(248,248,248);\n }\n\n @media (max-width: 450px) {\n\n .Dialog {\n border-radius: 0;\n width: 100%;\n }\n }\n\n @media (orientation: portrait) and (max-width: 800px) {\n\n .ReactDialogAnimation {\n width: 100%;\n }\n\n .ReactDialog {\n height: 100%;\n min-height: 100%;\n }\n\n .ReactDialogStack {\n align-items: flex-end;\n }\n\n .Dialog {\n align-content: stretch;\n border-radius: 0.8rem;\n border-top-radius: 0.8rem;\n display: flex;\n flex-direction: column;\n }\n\n .DialogBody {\n flex: 1;\n align-items: flex-end;\n }\n\n .DialogFooter {\n padding-bottom: 20px;\n }\n\n .ReactDialogAnimation {\n margin-bottom: -100px !important;\n top: inherit !important;\n position: relative;\n transition: opacity 0.4s ease, margin-bottom 0.4s ease;\n }\n\n .ReactDialog.ReactDialogOpen .ReactDialogAnimation {\n margin-bottom: 0px !important;\n }\n\n .DialogFooter {\n border-bottom-left-radius: 0 !important;\n border-bottom-right-radius: 0 !important;\n }\n\n .ReactShadowDOMInsideContainer > .ReactDialog {\n align-items: flex-end;\n }\n }\n\n .DialogBody {\n background: rgb(248,248,248);\n overflow-x: hidden;\n overflow-y: auto;\n }\n\n .DialogBody.ScrollHeight {\n height: 30vh !important;\n max-height: 30vh !important;\n }\n\n .DialogHeader {\n background: rgb(248,248,248);\n border-top-left-radius: 0.8rem;\n border-top-right-radius: 0.8rem;\n min-height: 3.4rem;\n position: relative;\n width: 100%;\n }\n\n .DialogHeaderActionRight {\n position: absolute;\n top: 0;\n right: 0;\n height: 3rem;\n }\n\n .DialogHeaderActionLeft {\n position: absolute;\n top: 0;\n left: 0;\n height: 3rem;\n }\n\n .DialogFooter {\n background: rgb(248,248,248);\n border-bottom-left-radius: 0.8rem;\n border-bottom-right-radius: 0.8rem;\n line-height: 1.5rem;\n min-height: 2rem;\n position: relative;\n text-align: center;\n }\n\n ";
1698
1698
  });
1699
1699
 
1700
1700
  var FontStyle = (function (style) {
@@ -2598,6 +2598,41 @@ function _defineProperty(obj, key, value) {
2598
2598
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2599
2599
 
2600
2600
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2601
+
2602
+ var prepareAcceptedPayments = function prepareAcceptedPayments(accept) {
2603
+ var toAddress = _typeof(accept.receiver) == 'object' ? accept.receiver.address : accept.receiver;
2604
+ var toContract = _typeof(accept.receiver) == 'object' ? accept.receiver : undefined;
2605
+ return _objectSpread(_objectSpread({}, accept), {}, {
2606
+ toAddress: toAddress,
2607
+ toContract: toContract
2608
+ });
2609
+ };
2610
+
2611
+ var mergeFromAccounts = function mergeFromAccounts(accept, account) {
2612
+ var from = {};
2613
+ accept.forEach(function (accept) {
2614
+ from[accept.blockchain] = account;
2615
+ });
2616
+ return from;
2617
+ };
2618
+
2619
+ var routePayments = (function (_ref) {
2620
+ var accept = _ref.accept,
2621
+ account = _ref.account,
2622
+ whitelist = _ref.whitelist,
2623
+ blacklist = _ref.blacklist,
2624
+ event = _ref.event,
2625
+ fee = _ref.fee;
2626
+ return route$1({
2627
+ accept: accept.map(prepareAcceptedPayments),
2628
+ from: mergeFromAccounts(accept, account),
2629
+ whitelist: whitelist,
2630
+ blacklist: blacklist,
2631
+ event: event,
2632
+ fee: fee
2633
+ });
2634
+ });
2635
+
2601
2636
  var PaymentRoutingProvider = (function (props) {
2602
2637
  var _useState = useState(),
2603
2638
  _useState2 = _slicedToArray(_useState, 2),
@@ -2609,10 +2644,15 @@ var PaymentRoutingProvider = (function (props) {
2609
2644
  selectedRoute = _useState4[0],
2610
2645
  setSelectedRoute = _useState4[1];
2611
2646
 
2612
- var _useState5 = useState(0),
2647
+ var _useState5 = useState(false),
2613
2648
  _useState6 = _slicedToArray(_useState5, 2),
2614
- reloadCount = _useState6[0],
2615
- setReloadCount = _useState6[1];
2649
+ slowRouting = _useState6[0],
2650
+ setSlowRouting = _useState6[1];
2651
+
2652
+ var _useState7 = useState(0),
2653
+ _useState8 = _slicedToArray(_useState7, 2),
2654
+ reloadCount = _useState8[0],
2655
+ setReloadCount = _useState8[1];
2616
2656
 
2617
2657
  var _useContext = useContext(WalletContext),
2618
2658
  account = _useContext.account;
@@ -2623,49 +2663,54 @@ var PaymentRoutingProvider = (function (props) {
2623
2663
  var _useContext3 = useContext(ConfigurationContext),
2624
2664
  recover = _useContext3.recover;
2625
2665
 
2626
- var prepareAcceptedPayments = function prepareAcceptedPayments(accept) {
2627
- var toAddress = _typeof(accept.receiver) == 'object' ? accept.receiver.address : accept.receiver;
2628
- var toContract = _typeof(accept.receiver) == 'object' ? accept.receiver : undefined;
2629
- return _objectSpread(_objectSpread({}, accept), {}, {
2630
- toAddress: toAddress,
2631
- toContract: toContract,
2632
- fromAddress: account
2633
- });
2666
+ var onRoutesUpdate = function onRoutesUpdate(routes) {
2667
+ if (routes.length == 0) {
2668
+ setAllRoutes([]);
2669
+
2670
+ if (props.setMaxRoute) {
2671
+ props.setMaxRoute(null);
2672
+ }
2673
+ } else {
2674
+ roundAmounts(routes).then(function (roundedRoutes) {
2675
+ var selected;
2676
+
2677
+ if (selectedRoute) {
2678
+ selected = roundedRoutes[allRoutes.findIndex(function (route) {
2679
+ return route.fromToken == selectedRoute.fromToken && route.blockchain == selectedRoute.blockchain;
2680
+ })];
2681
+ }
2682
+
2683
+ if (selected == undefined) {
2684
+ selected = roundedRoutes[0];
2685
+ }
2686
+
2687
+ setSelectedRoute(selected);
2688
+ setAllRoutes(roundedRoutes);
2689
+
2690
+ if (props.setMaxRoute) {
2691
+ props.setMaxRoute(findMaxRoute(roundedRoutes));
2692
+ }
2693
+ });
2694
+ }
2634
2695
  };
2635
2696
 
2636
2697
  var getPaymentRoutes = function getPaymentRoutes(_ref) {
2637
- var allRoutes = _ref.allRoutes,
2638
- selectedRoute = _ref.selectedRoute,
2639
- updatable = _ref.updatable;
2698
+ _ref.allRoutes;
2699
+ _ref.selectedRoute;
2700
+ var updatable = _ref.updatable;
2640
2701
 
2641
2702
  if (updatable == false || !props.accept || !account) {
2642
2703
  return;
2643
2704
  }
2644
2705
 
2645
- route$1({
2646
- accept: props.accept.map(prepareAcceptedPayments),
2647
- whitelist: props.whitelist,
2648
- blacklist: props.blacklist,
2649
- event: props.event,
2650
- fee: props.fee
2651
- }).then(function (routes) {
2652
- if (routes.length == 0) {
2653
- setAllRoutes([]);
2654
-
2655
- if (props.setMaxRoute) {
2656
- props.setMaxRoute(null);
2657
- }
2658
- } else {
2659
- roundAmounts(routes).then(function (roundedRoutes) {
2660
- var selected = selectedRoute ? roundedRoutes[allRoutes.indexOf(selectedRoute)] || roundedRoutes[0] : roundedRoutes[0];
2661
- setSelectedRoute(selected);
2662
- setAllRoutes(roundedRoutes);
2663
-
2664
- if (props.setMaxRoute) {
2665
- props.setMaxRoute(findMaxRoute(roundedRoutes));
2666
- }
2667
- });
2668
- }
2706
+ var slowRoutingTimeout = setTimeout(function () {
2707
+ setSlowRouting(true);
2708
+ }, 4000);
2709
+ routePayments(Object.assign({}, props, {
2710
+ account: account
2711
+ })).then(function (routes) {
2712
+ clearInterval(slowRoutingTimeout);
2713
+ onRoutesUpdate(routes);
2669
2714
  });
2670
2715
  };
2671
2716
 
@@ -2764,7 +2809,8 @@ var PaymentRoutingProvider = (function (props) {
2764
2809
  setSelectedRoute: setSelectedRoute,
2765
2810
  getPaymentRoutes: getPaymentRoutes,
2766
2811
  allRoutes: allRoutes,
2767
- setAllRoutes: setAllRoutes
2812
+ setAllRoutes: setAllRoutes,
2813
+ slowRouting: slowRouting
2768
2814
  }
2769
2815
  }, props.children);
2770
2816
  });
@@ -3781,11 +3827,11 @@ var PaymentTrackingProvider = (function (props) {
3781
3827
  paymentRoute = _useState6[0],
3782
3828
  setPaymentRoute = _useState6[1];
3783
3829
 
3784
- var _useState7 = useState(!!(track && (track.endpoint || typeof track.method == 'function'))),
3830
+ var _useState7 = useState(!!(track && (track.endpoint || typeof track.method == 'function') && track.async != true)),
3785
3831
  _useState8 = _slicedToArray(_useState7, 1),
3786
3832
  tracking = _useState8[0];
3787
3833
 
3788
- var _useState9 = useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function'))),
3834
+ var _useState9 = useState(!!(track && track.poll && (track.poll.endpoint || typeof track.poll.method == 'function') && track.async != true)),
3789
3835
  _useState10 = _slicedToArray(_useState9, 1),
3790
3836
  polling = _useState10[0];
3791
3837
 
@@ -3951,6 +3997,10 @@ var PaymentTrackingProvider = (function (props) {
3951
3997
  return;
3952
3998
  }
3953
3999
 
4000
+ if (!tracking) {
4001
+ return;
4002
+ }
4003
+
3954
4004
  var pollingInterval = setInterval(function () {
3955
4005
  return pollStatus(polling, transaction, afterBlock, paymentRoute, pollingInterval);
3956
4006
  }, 5000);
@@ -4006,6 +4056,10 @@ var PaymentTrackingProvider = (function (props) {
4006
4056
  var initializeTracking = function initializeTracking(transaction, afterBlock, paymentRoute) {
4007
4057
  storePayment(transaction, afterBlock, paymentRoute, 1);
4008
4058
 
4059
+ if (tracking || track && track.async == true) {
4060
+ startTracking(transaction, afterBlock, paymentRoute);
4061
+ }
4062
+
4009
4063
  if (tracking == false) {
4010
4064
  return;
4011
4065
  }
@@ -4014,7 +4068,6 @@ var PaymentTrackingProvider = (function (props) {
4014
4068
  setAfterBlock(afterBlock);
4015
4069
  setPaymentRoute(paymentRoute);
4016
4070
  openSocket(transaction);
4017
- startTracking(transaction, afterBlock, paymentRoute);
4018
4071
  };
4019
4072
 
4020
4073
  return /*#__PURE__*/React.createElement(PaymentTrackingContext.Provider, {
@@ -4205,7 +4258,7 @@ var WalletProvider = (function (props) {
4205
4258
  setWalletState('connected');
4206
4259
 
4207
4260
  if (props.connected) {
4208
- props.connected(accounts[0]);
4261
+ props.connected(account);
4209
4262
  }
4210
4263
  };
4211
4264
 
@@ -4573,6 +4626,10 @@ var PaymentOverviewSkeleton = (function (props) {
4573
4626
  var _useContext = useContext(ChangableAmountContext),
4574
4627
  amountsMissing = _useContext.amountsMissing;
4575
4628
 
4629
+ var _useContext2 = useContext(PaymentRoutingContext),
4630
+ slowRouting = _useContext2.slowRouting,
4631
+ selectedRoute = _useContext2.selectedRoute;
4632
+
4576
4633
  return /*#__PURE__*/React.createElement(Dialog$1, {
4577
4634
  header: /*#__PURE__*/React.createElement("div", {
4578
4635
  className: "PaddingTopS PaddingLeftM PaddingRightM TextLeft"
@@ -4598,7 +4655,9 @@ var PaymentOverviewSkeleton = (function (props) {
4598
4655
  className: "ButtonPrimary Skeleton"
4599
4656
  }, /*#__PURE__*/React.createElement("div", {
4600
4657
  className: "SkeletonBackground"
4601
- }))))
4658
+ }))), selectedRoute == undefined && slowRouting && /*#__PURE__*/React.createElement("div", {
4659
+ className: "TextCenter Opacity05 PaddingTopS"
4660
+ }, /*#__PURE__*/React.createElement("strong", null, "Still loading your wallet balances...")))
4602
4661
  });
4603
4662
  });
4604
4663
 
@@ -4872,6 +4931,23 @@ var Payment = /*#__PURE__*/function () {
4872
4931
  };
4873
4932
  }();
4874
4933
 
4934
+ Payment.preload = function (_ref5) {
4935
+ var account = _ref5.account,
4936
+ accept = _ref5.accept,
4937
+ whitelist = _ref5.whitelist,
4938
+ blacklist = _ref5.blacklist,
4939
+ event = _ref5.event,
4940
+ fee = _ref5.fee;
4941
+ routePayments({
4942
+ account: account,
4943
+ accept: accept,
4944
+ whitelist: whitelist,
4945
+ blacklist: blacklist,
4946
+ event: event,
4947
+ fee: fee
4948
+ });
4949
+ };
4950
+
4875
4951
  var SaleRoutingContext = /*#__PURE__*/React.createContext();
4876
4952
 
4877
4953
  var ToTokenContext = /*#__PURE__*/React.createContext();