@huma-finance/widgets 0.0.11 → 0.0.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.
@@ -2731,6 +2731,10 @@ function ChooseAmountModal(_ref) {
2731
2731
  var theme = material.useTheme();
2732
2732
  var _useMQ = shared.useMQ(),
2733
2733
  isXsSize = _useMQ.isXsSize;
2734
+ var _useState = React.useState(false),
2735
+ _useState2 = _slicedToArray(_useState, 2),
2736
+ inputTouched = _useState2[0],
2737
+ setInputTouched = _useState2[1];
2734
2738
  var styles = {
2735
2739
  subTitle: material.css(_templateObject$c || (_templateObject$c = _taggedTemplateLiteral(["\n font-family: 'Uni-Neue-Regular';\n "]))),
2736
2740
  description2: material.css(_templateObject2$9 || (_templateObject2$9 = _taggedTemplateLiteral(["\n ", ";\n font-family: 'Uni-Neue-Regular';\n font-size: 16px;\n color: #a8a1b2;\n margin-top: 16px;\n "])), theme.cssMixins.rowCentered),
@@ -2758,6 +2762,7 @@ function ChooseAmountModal(_ref) {
2758
2762
  handleChangeAmount(newValue);
2759
2763
  };
2760
2764
  var handleInputChange = function handleInputChange(event) {
2765
+ setInputTouched(true);
2761
2766
  // @ts-ignore
2762
2767
  handleChangeAmount(event.target.value);
2763
2768
  };
@@ -2822,7 +2827,7 @@ function ChooseAmountModal(_ref) {
2822
2827
  })]
2823
2828
  })
2824
2829
  }), jsxRuntime.jsx(material.Slider, {
2825
- max: sliderMax,
2830
+ max: Number(sliderMax),
2826
2831
  min: 0,
2827
2832
  css: styles.slider,
2828
2833
  "aria-label": "Amount",
@@ -2836,8 +2841,9 @@ function ChooseAmountModal(_ref) {
2836
2841
  children: [jsxRuntime.jsx(material.Input, {
2837
2842
  css: styles.inputField,
2838
2843
  type: "number",
2839
- value: currentAmount,
2840
- onChange: handleInputChange
2844
+ value: !inputTouched && currentAmount === 0 ? '' : currentAmount,
2845
+ onChange: handleInputChange,
2846
+ placeholder: "0"
2841
2847
  }), jsxRuntime.jsx(material.Button, {
2842
2848
  variant: "contained",
2843
2849
  css: styles.maxButton,
@@ -2874,7 +2880,7 @@ function ChooseAmountModal(_ref) {
2874
2880
  variant: "contained",
2875
2881
  css: styles.okButton,
2876
2882
  onClick: handleAction,
2877
- disabled: currentAmount === 0 || currentAmount > sliderMax,
2883
+ disabled: !currentAmount || Number(currentAmount) <= 0 || Number(currentAmount) > Number(sliderMax),
2878
2884
  children: actionText.toUpperCase()
2879
2885
  }), !hideTerms && jsxRuntime.jsxs(material.Box, {
2880
2886
  css: styles.terms,
@@ -2887,13 +2893,9 @@ function ChooseAmount$6(_ref) {
2887
2893
  var poolInfo = _ref.poolInfo,
2888
2894
  accountStats = _ref.accountStats;
2889
2895
  var dispatch = useAppDispatch();
2890
- var _useWeb3React = core.useWeb3React(),
2891
- account = _useWeb3React.account;
2892
2896
  var poolUnderlyingToken = poolInfo.poolUnderlyingToken;
2893
2897
  var symbol = poolUnderlyingToken.symbol,
2894
2898
  decimals = poolUnderlyingToken.decimals;
2895
- var _useCLPoolAllowance = shared.useCLPoolAllowance(poolInfo.poolName, account),
2896
- approved = _useCLPoolAllowance.approved;
2897
2899
  var _useCLFeeManager = shared.useCLFeeManager(poolInfo.poolName),
2898
2900
  getFeesCharged = _useCLFeeManager.getFeesCharged;
2899
2901
  var _useState = React.useState(0),
@@ -2912,14 +2914,14 @@ function ChooseAmount$6(_ref) {
2912
2914
  setChargedFees(newChargedFees);
2913
2915
  }, [getFeesCharged]);
2914
2916
  var handleAction = React.useCallback(function () {
2915
- var nextStep = approved ? WIDGET_STEP.Transfer : WIDGET_STEP.ApproveAllowance;
2917
+ var nextStep = WIDGET_STEP.Transfer;
2916
2918
  dispatch(setBorrowInfo({
2917
2919
  borrowAmount: currentAmount,
2918
2920
  borrowAmountBN: shared.upScale(currentAmount, decimals),
2919
2921
  chargedFees: chargedFees,
2920
2922
  nextStep: nextStep
2921
2923
  }));
2922
- }, [approved, chargedFees, currentAmount, decimals, dispatch]);
2924
+ }, [chargedFees, currentAmount, decimals, dispatch]);
2923
2925
  return jsxRuntime.jsx(ChooseAmountModal, {
2924
2926
  title: "Borrow",
2925
2927
  description1: "Choose Amount",
@@ -3046,7 +3048,7 @@ function ApproveAllowance$4(_ref) {
3046
3048
  var poolInfo = _ref.poolInfo;
3047
3049
  var dispatch = useAppDispatch();
3048
3050
  var handleSuccess = React.useCallback(function () {
3049
- dispatch(setStep(WIDGET_STEP.Transfer));
3051
+ dispatch(setStep(WIDGET_STEP.Done));
3050
3052
  }, [dispatch]);
3051
3053
  return jsxRuntime.jsx(ApproveAllowanceModal, {
3052
3054
  poolInfo: poolInfo,
@@ -3099,11 +3101,18 @@ function TxSendModal(_ref) {
3099
3101
  function Transfer$6(_ref) {
3100
3102
  var poolInfo = _ref.poolInfo;
3101
3103
  var dispatch = useAppDispatch();
3104
+ var reset = utils.useResetAtom(shared.txAtom);
3105
+ var _useWeb3React = core.useWeb3React(),
3106
+ account = _useWeb3React.account;
3102
3107
  var _useAppSelector = useAppSelector(selectWidgetState),
3103
3108
  borrowAmountBN = _useAppSelector.borrowAmountBN;
3109
+ var _useCLPoolAllowance = shared.useCLPoolAllowance(poolInfo.poolName, account),
3110
+ allowance = _useCLPoolAllowance.allowance;
3104
3111
  var handleSuccess = React.useCallback(function () {
3105
- dispatch(setStep(WIDGET_STEP.Done));
3106
- }, [dispatch]);
3112
+ reset();
3113
+ var nextStep = allowance.gte(shared.toBigNumber(borrowAmountBN)) ? WIDGET_STEP.Done : WIDGET_STEP.ApproveAllowance;
3114
+ dispatch(setStep(nextStep));
3115
+ }, [allowance, borrowAmountBN, dispatch, reset]);
3107
3116
  return jsxRuntime.jsx(TxSendModal, {
3108
3117
  poolInfo: poolInfo,
3109
3118
  method: "drawdown",