@ref-finance/ref-sdk 1.4.1 → 1.4.3

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.
@@ -31,6 +31,7 @@ var TiWarning = require('@react-icons/all-files/ti/TiWarning');
31
31
  var CgArrowsExchangeAltV = require('@react-icons/all-files/cg/CgArrowsExchangeAltV');
32
32
 
33
33
  var FEE_DIVISOR = 10000;
34
+ var DEFAULT_SLIPPAGE_TOLERANCE = "0.5";
34
35
  var STABLE_LP_TOKEN_DECIMALS = 18;
35
36
  var RATED_POOL_LP_TOKEN_DECIMALS = 24;
36
37
  var STORAGE_TO_REGISTER_WITH_MFT = '0.1';
@@ -3648,8 +3649,11 @@ function divide(numerator, denominator) {
3648
3649
  notation: 'fixed'
3649
3650
  });
3650
3651
  }
3651
- var getMax = function getMax(id, amount) {
3652
- return id !== exports.WRAP_NEAR_CONTRACT_ID ? amount : Number(amount) <= 0.5 ? '0' : String(Number(amount) - 0.5);
3652
+ var getMax = function getMax(id, amount, minNearAmountLeftForGasFees) {
3653
+ return id !== exports.WRAP_NEAR_CONTRACT_ID ? amount : Number(amount) <= minNearAmountLeftForGasFees ? '0' : String(Number(amount) - minNearAmountLeftForGasFees);
3654
+ };
3655
+ var isValidSlippageTolerance = function isValidSlippageTolerance(value) {
3656
+ return value > 0 && value < 100;
3653
3657
  };
3654
3658
  function getPointByPrice(pointDelta, price, decimalRate, noNeedSlot) {
3655
3659
  var point = Math.log(+price * decimalRate) / Math.log(CONSTANT_D);
@@ -4400,7 +4404,7 @@ var OrderNoRemainedAmount = /*#__PURE__*/formatError('No remained amount on this
4400
4404
  var instantSwap = /*#__PURE__*/function () {
4401
4405
  var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
4402
4406
  var _swapTodos;
4403
- var tokenIn, tokenOut, amountIn, slippageTolerance, swapTodos, AccountId, referralId, transactions, registerToken, registered, actionsList, allSwapsTokens, i, swapTokens;
4407
+ var tokenIn, tokenOut, amountIn, slippageTolerance, swapTodos, AccountId, referralId, transactions, registerToken, actionsList, allSwapsTokens, i, swapTokens;
4404
4408
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4405
4409
  while (1) {
4406
4410
  switch (_context2.prev = _context2.next) {
@@ -4465,24 +4469,9 @@ var instantSwap = /*#__PURE__*/function () {
4465
4469
  return _ref3.apply(this, arguments);
4466
4470
  };
4467
4471
  }();
4468
- if (!(tokenIn.id === exports.config.WRAP_NEAR_CONTRACT_ID)) {
4469
- _context2.next = 12;
4470
- break;
4471
- }
4472
- _context2.next = 8;
4473
- return ftGetStorageBalance(exports.config.WRAP_NEAR_CONTRACT_ID, AccountId);
4474
- case 8:
4475
- registered = _context2.sent;
4476
- if (!(registered === null)) {
4477
- _context2.next = 12;
4478
- break;
4479
- }
4480
- _context2.next = 12;
4481
- return registerToken(tokenIn);
4482
- case 12:
4483
- _context2.next = 14;
4472
+ _context2.next = 7;
4484
4473
  return registerToken(tokenOut);
4485
- case 14:
4474
+ case 7:
4486
4475
  actionsList = [];
4487
4476
  allSwapsTokens = swapTodos.map(function (s) {
4488
4477
  return [s.inputToken, s.outputToken];
@@ -4540,7 +4529,7 @@ var instantSwap = /*#__PURE__*/function () {
4540
4529
  }]
4541
4530
  });
4542
4531
  return _context2.abrupt("return", transactions);
4543
- case 19:
4532
+ case 12:
4544
4533
  case "end":
4545
4534
  return _context2.stop();
4546
4535
  }
@@ -4756,7 +4745,7 @@ var fetchAllPools = /*#__PURE__*/function () {
4756
4745
  });
4757
4746
  case 3:
4758
4747
  _pools = _context7.sent;
4759
- if (!(_pools.code !== 0 || !_pools.simplePools)) {
4748
+ if (_pools.simplePools) {
4760
4749
  _context7.next = 6;
4761
4750
  break;
4762
4751
  }
@@ -5018,12 +5007,12 @@ var useSwap = function useSwap(params) {
5018
5007
  var rate = calculateExchangeRate(ONLY_ZEROS.test(params.amountIn) ? '1' : params.amountIn, amountOut || '1');
5019
5008
  var makeSwap = /*#__PURE__*/function () {
5020
5009
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
5021
- var transactionsRef, outEstimate, routes, bigEstimate, _minAmountOut;
5010
+ var transactionsRef, tokenRegistered, nearDepositAmount, minStorageBalance, outEstimate, routes, bigEstimate, _minAmountOut;
5022
5011
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
5023
5012
  while (1) {
5024
5013
  switch (_context3.prev = _context3.next) {
5025
5014
  case 0:
5026
- if (!(!params.tokenIn || !params.tokenOut)) {
5015
+ if (!(!params.tokenIn || !params.tokenOut || !AccountId)) {
5027
5016
  _context3.next = 2;
5028
5017
  break;
5029
5018
  }
@@ -5036,14 +5025,32 @@ var useSwap = function useSwap(params) {
5036
5025
  amountIn: params.amountIn,
5037
5026
  swapTodos: estimates,
5038
5027
  slippageTolerance: slippageTolerance,
5039
- AccountId: AccountId || '',
5028
+ AccountId: AccountId,
5040
5029
  referralId: referralId
5041
5030
  });
5042
5031
  case 4:
5043
5032
  transactionsRef = _context3.sent;
5044
- if (tokenIn && tokenIn.id === exports.WRAP_NEAR_CONTRACT_ID) {
5045
- transactionsRef.splice(-1, 0, nearDepositTransaction(amountIn));
5033
+ if (!(tokenIn && tokenIn.id === exports.WRAP_NEAR_CONTRACT_ID)) {
5034
+ _context3.next = 16;
5035
+ break;
5046
5036
  }
5037
+ _context3.next = 8;
5038
+ return ftGetStorageBalance(tokenIn.id, AccountId);
5039
+ case 8:
5040
+ tokenRegistered = _context3.sent;
5041
+ nearDepositAmount = amountIn;
5042
+ if (!(tokenRegistered === null)) {
5043
+ _context3.next = 15;
5044
+ break;
5045
+ }
5046
+ _context3.next = 13;
5047
+ return getMinStorageBalance(tokenIn.id);
5048
+ case 13:
5049
+ minStorageBalance = _context3.sent;
5050
+ nearDepositAmount = format.formatNearAmount(String(BigInt(format.parseNearAmount(nearDepositAmount)) + BigInt(minStorageBalance)));
5051
+ case 15:
5052
+ transactionsRef.splice(-1, 0, nearDepositTransaction(nearDepositAmount));
5053
+ case 16:
5047
5054
  if (tokenOut && tokenOut.id === exports.WRAP_NEAR_CONTRACT_ID) {
5048
5055
  outEstimate = new Big(0);
5049
5056
  routes = separateRoutes(estimates, tokenOut.id);
@@ -5054,16 +5061,16 @@ var useSwap = function useSwap(params) {
5054
5061
  _minAmountOut = percentLess(slippageTolerance, scientificNotationToString(bigEstimate.toString()));
5055
5062
  transactionsRef.push(nearWithdrawTransaction(_minAmountOut));
5056
5063
  }
5057
- _context3.next = 9;
5064
+ _context3.next = 19;
5058
5065
  return onSwap(transactionsRef);
5059
- case 9:
5066
+ case 19:
5060
5067
  setTimeout(function () {
5061
5068
  var tokensToUpdate = [];
5062
5069
  if (tokenIn) tokensToUpdate.push(tokenIn.id);
5063
5070
  if (tokenOut) tokensToUpdate.push(tokenOut.id);
5064
5071
  if (tokensToUpdate.length > 0 && AccountId) updateTokenBalance(tokensToUpdate, AccountId);
5065
5072
  }, 3000);
5066
- case 10:
5073
+ case 20:
5067
5074
  case "end":
5068
5075
  return _context3.stop();
5069
5076
  }
@@ -5607,7 +5614,8 @@ var TokenAmount = function TokenAmount(props) {
5607
5614
  onChangeAmount = props.onChangeAmount,
5608
5615
  price = props.price,
5609
5616
  onForceUpdate = props.onForceUpdate,
5610
- poolFetchingState = props.poolFetchingState;
5617
+ poolFetchingState = props.poolFetchingState,
5618
+ minNearAmountLeftForGasFees = props.minNearAmountLeftForGasFees;
5611
5619
  var theme = React.useContext(ThemeContext);
5612
5620
  var primary = theme.primary,
5613
5621
  secondary = theme.secondary,
@@ -5627,14 +5635,14 @@ var TokenAmount = function TokenAmount(props) {
5627
5635
  }
5628
5636
  };
5629
5637
  React.useEffect(function () {
5630
- if (ref.current && onChangeAmount && token && balance && token.id === exports.WRAP_NEAR_CONTRACT_ID && Number(balance) - Number(ref.current.value) < 0.5) {
5631
- ref.current.setCustomValidity('Must have 0.5N or more left in wallet for gas fee.');
5638
+ if (ref.current && onChangeAmount && token && balance && token.id === exports.WRAP_NEAR_CONTRACT_ID && Number(balance) - Number(ref.current.value) < minNearAmountLeftForGasFees) {
5639
+ ref.current.setCustomValidity("Must have " + minNearAmountLeftForGasFees + "N or more left in wallet for gas fee.");
5632
5640
  } else {
5633
5641
  var _ref$current;
5634
5642
  (_ref$current = ref.current) == null ? void 0 : _ref$current.setCustomValidity('');
5635
5643
  }
5636
5644
  }, [ref, balance, ref.current, (_ref$current2 = ref.current) == null ? void 0 : _ref$current2.value, token, amount]);
5637
- var curMax = token ? getMax(token.id, balance || '0') : '0';
5645
+ var curMax = token ? getMax(token.id, balance || '0', minNearAmountLeftForGasFees) : '0';
5638
5646
  return React__default.createElement(React__default.Fragment, null, React__default.createElement("div", {
5639
5647
  className: "__ref-swap-widger-token-amount ",
5640
5648
  style: {
@@ -5736,7 +5744,7 @@ var TokenAmount = function TokenAmount(props) {
5736
5744
  }
5737
5745
  }, React__default.createElement("span", null, "Balance:\xA0", toPrecision(balance, 2)), token && React__default.createElement(HalfAndMaxAmount, {
5738
5746
  token: token,
5739
- max: getMax(token.id, balance),
5747
+ max: getMax(token.id, balance, minNearAmountLeftForGasFees),
5740
5748
  onChangeAmount: handleChange,
5741
5749
  amount: amount
5742
5750
  })));
@@ -5744,7 +5752,6 @@ var TokenAmount = function TokenAmount(props) {
5744
5752
  var SlippageSelector = function SlippageSelector(_ref8) {
5745
5753
  var slippageTolerance = _ref8.slippageTolerance,
5746
5754
  onChangeSlippageTolerance = _ref8.onChangeSlippageTolerance,
5747
- showSlip = _ref8.showSlip,
5748
5755
  setShowSlip = _ref8.setShowSlip;
5749
5756
  var _useState6 = React.useState(false),
5750
5757
  invalid = _useState6[0],
@@ -5755,30 +5762,26 @@ var SlippageSelector = function SlippageSelector(_ref8) {
5755
5762
  primary = theme.primary,
5756
5763
  borderRadius = theme.borderRadius,
5757
5764
  borderColor = theme.borderColor;
5758
- var ref = React.useRef(null);
5759
5765
  var handleChange = function handleChange(amount) {
5760
- onChangeSlippageTolerance(Number(amount));
5761
- if (Number(amount) > 0 && Number(amount) < 100) {
5762
- setInValid(false);
5763
- } else {
5764
- setInValid(true);
5765
- }
5766
- if (ref.current) {
5767
- ref.current.value = amount;
5768
- }
5766
+ onChangeSlippageTolerance(amount);
5767
+ setInValid(!isValidSlippageTolerance(Number(amount)));
5769
5768
  };
5770
5769
  React.useEffect(function () {
5771
- if (!showSlip) return;
5772
- document.onclick = function () {
5773
- return setShowSlip(false);
5770
+ var onClick = function onClick(event) {
5771
+ if (!event.target) return;
5772
+ if (event.target.closest('#__ref-slippage-container') === null) {
5773
+ setShowSlip(false);
5774
+ if (invalid) onChangeSlippageTolerance(DEFAULT_SLIPPAGE_TOLERANCE);
5775
+ }
5774
5776
  };
5777
+ document.addEventListener('click', onClick);
5775
5778
  return function () {
5776
- document.onclick = null;
5779
+ document.removeEventListener('click', onClick);
5777
5780
  };
5778
- }, [showSlip, setShowSlip]);
5779
- if (!showSlip) return null;
5781
+ }, [invalid]);
5780
5782
  return React__default.createElement("div", {
5781
5783
  className: "__ref-swap-widget_slippage_selector __ref-swap-widget-col-flex-start",
5784
+ id: "__ref-slippage-container",
5782
5785
  onClick: function onClick(e) {
5783
5786
  return e.stopPropagation();
5784
5787
  },
@@ -5797,33 +5800,21 @@ var SlippageSelector = function SlippageSelector(_ref8) {
5797
5800
  className: "__ref-swap-widget-row-flex-center\n __ref-swap-widget_slippage_selector_input_container",
5798
5801
  style: {
5799
5802
  border: "1px solid " + (invalid ? '#FF7575' : borderColor),
5800
- borderRadius: borderRadius
5803
+ borderRadius: borderRadius,
5804
+ color: invalid ? '#FF7575' : primary
5801
5805
  }
5802
5806
  }, React__default.createElement("input", {
5803
- ref: ref,
5804
- max: 99.99999,
5805
- min: 0.000001,
5806
- defaultValue: slippageTolerance ? slippageTolerance : 0.5,
5807
- onWheel: function onWheel() {
5808
- if (ref.current) {
5809
- ref.current.blur();
5810
- }
5811
- },
5812
5807
  value: slippageTolerance,
5813
- step: "any",
5814
- type: "number",
5808
+ type: "text",
5815
5809
  required: true,
5816
5810
  placeholder: "",
5817
- onChange: function onChange(_ref9) {
5818
- var target = _ref9.target;
5819
- return handleChange(target.value);
5820
- },
5821
- onKeyDown: function onKeyDown(e) {
5822
- return symbolsArr.includes(e.key) && e.preventDefault();
5811
+ onChange: function onChange(event) {
5812
+ if (isValidInput(event.target.value)) {
5813
+ handleChange(event.target.value);
5814
+ }
5823
5815
  },
5824
5816
  style: {
5825
- width: '100%',
5826
- color: invalid ? '#FF7575' : primary
5817
+ width: '100%'
5827
5818
  },
5828
5819
  className: "__ref-swap-widget-input-class"
5829
5820
  }), React__default.createElement("span", {
@@ -5838,7 +5829,7 @@ var SlippageSelector = function SlippageSelector(_ref8) {
5838
5829
  onClick: function onClick(e) {
5839
5830
  e.stopPropagation();
5840
5831
  e.preventDefault();
5841
- onChangeSlippageTolerance(0.5);
5832
+ onChangeSlippageTolerance(DEFAULT_SLIPPAGE_TOLERANCE);
5842
5833
  setInValid(false);
5843
5834
  }
5844
5835
  }, "Auto")), invalid && React__default.createElement("div", {
@@ -5846,7 +5837,7 @@ var SlippageSelector = function SlippageSelector(_ref8) {
5846
5837
  style: {
5847
5838
  color: '#FF7575',
5848
5839
  fontSize: '12px',
5849
- padding: '10px 0px',
5840
+ padding: '10px 0px 0px 0px',
5850
5841
  alignItems: 'start'
5851
5842
  }
5852
5843
  }, React__default.createElement(IoWarning.IoWarning, {
@@ -5857,11 +5848,11 @@ var SlippageSelector = function SlippageSelector(_ref8) {
5857
5848
  size: 20
5858
5849
  }), React__default.createElement("div", null, 'The slippage tolerance is invalid.')));
5859
5850
  };
5860
- var StarToken = function StarToken(_ref10) {
5861
- var price = _ref10.price,
5862
- token = _ref10.token,
5863
- onDelete = _ref10.onDelete,
5864
- _onClick = _ref10.onClick;
5851
+ var StarToken = function StarToken(_ref9) {
5852
+ var price = _ref9.price,
5853
+ token = _ref9.token,
5854
+ onDelete = _ref9.onDelete,
5855
+ _onClick = _ref9.onClick;
5865
5856
  var theme = React.useContext(ThemeContext);
5866
5857
  var primary = theme.primary,
5867
5858
  secondary = theme.secondary,
@@ -5938,16 +5929,16 @@ var StarToken = function StarToken(_ref10) {
5938
5929
  }
5939
5930
  }, !price ? '$-' : '$' + toInternationalCurrencySystemLongString(price, 2))));
5940
5931
  };
5941
- var Token = function Token(_ref11) {
5942
- var token = _ref11.token,
5943
- _onClick2 = _ref11.onClick,
5944
- price = _ref11.price,
5945
- balance = _ref11.balance,
5946
- isSticky = _ref11.isSticky,
5947
- onClickPin = _ref11.onClickPin,
5948
- index = _ref11.index,
5949
- setHoverIndex = _ref11.setHoverIndex,
5950
- hoverIndex = _ref11.hoverIndex;
5932
+ var Token = function Token(_ref10) {
5933
+ var token = _ref10.token,
5934
+ _onClick2 = _ref10.onClick,
5935
+ price = _ref10.price,
5936
+ balance = _ref10.balance,
5937
+ isSticky = _ref10.isSticky,
5938
+ onClickPin = _ref10.onClickPin,
5939
+ index = _ref10.index,
5940
+ setHoverIndex = _ref10.setHoverIndex,
5941
+ hoverIndex = _ref10.hoverIndex;
5951
5942
  var theme = React.useContext(ThemeContext);
5952
5943
  var primary = theme.primary,
5953
5944
  secondary = theme.secondary,
@@ -6063,14 +6054,14 @@ var Token = function Token(_ref11) {
6063
6054
  }
6064
6055
  })));
6065
6056
  };
6066
- var TokenListTable = function TokenListTable(_ref12) {
6067
- var tokens = _ref12.tokens,
6068
- onClick = _ref12.onClick,
6069
- balances = _ref12.balances,
6070
- tokenPriceList = _ref12.tokenPriceList,
6071
- starList = _ref12.starList,
6072
- setStarList = _ref12.setStarList,
6073
- onDelete = _ref12.onDelete;
6057
+ var TokenListTable = function TokenListTable(_ref11) {
6058
+ var tokens = _ref11.tokens,
6059
+ onClick = _ref11.onClick,
6060
+ balances = _ref11.balances,
6061
+ tokenPriceList = _ref11.tokenPriceList,
6062
+ starList = _ref11.starList,
6063
+ setStarList = _ref11.setStarList,
6064
+ onDelete = _ref11.onDelete;
6074
6065
  var _useState11 = React.useState('down'),
6075
6066
  currentSort = _useState11[0],
6076
6067
  setCurrentSort = _useState11[1];
@@ -6133,13 +6124,13 @@ var TokenListTable = function TokenListTable(_ref12) {
6133
6124
  });
6134
6125
  })));
6135
6126
  };
6136
- var TokenSelector = function TokenSelector(_ref13) {
6137
- var onSelect = _ref13.onSelect,
6138
- width = _ref13.width,
6139
- tokens = _ref13.tokens,
6140
- onClose = _ref13.onClose,
6141
- balances = _ref13.balances,
6142
- className = _ref13.className;
6127
+ var TokenSelector = function TokenSelector(_ref12) {
6128
+ var onSelect = _ref12.onSelect,
6129
+ width = _ref12.width,
6130
+ tokens = _ref12.tokens,
6131
+ onClose = _ref12.onClose,
6132
+ balances = _ref12.balances,
6133
+ className = _ref12.className;
6143
6134
  var theme = React.useContext(ThemeContext);
6144
6135
  var container = theme.container,
6145
6136
  buttonBg = theme.buttonBg,
@@ -6241,9 +6232,9 @@ var TokenSelector = function TokenSelector(_ref13) {
6241
6232
  onDelete: onDelete
6242
6233
  }));
6243
6234
  };
6244
- var Slider = function Slider(_ref14) {
6245
- var showSlip = _ref14.showSlip,
6246
- setShowSlip = _ref14.setShowSlip;
6235
+ var Slider = function Slider(_ref13) {
6236
+ var showSlip = _ref13.showSlip,
6237
+ setShowSlip = _ref13.setShowSlip;
6247
6238
  var _useState15 = React.useState(false),
6248
6239
  hover = _useState15[0],
6249
6240
  setHover = _useState15[1];
@@ -6261,7 +6252,8 @@ var Slider = function Slider(_ref14) {
6261
6252
  },
6262
6253
  onClick: function onClick() {
6263
6254
  return setShowSlip(true);
6264
- }
6255
+ },
6256
+ className: "cursor-pointer"
6265
6257
  }, React__default.createElement("path", {
6266
6258
  fillRule: "evenodd",
6267
6259
  clipRule: "evenodd",
@@ -6416,18 +6408,23 @@ var RouterIcon = function RouterIcon() {
6416
6408
  stopColor: "#8C78FF"
6417
6409
  }))));
6418
6410
  };
6419
- var Notification = function Notification(_ref15) {
6420
- var state = _ref15.state,
6421
- tx = _ref15.tx,
6422
- detail = _ref15.detail,
6423
- open = _ref15.open,
6424
- setOpen = _ref15.setOpen,
6425
- setState = _ref15.setState;
6411
+ var Notification = function Notification(_ref14) {
6412
+ var state = _ref14.state,
6413
+ tx = _ref14.tx,
6414
+ detail = _ref14.detail,
6415
+ setSwapState = _ref14.setSwapState;
6426
6416
  var theme = React.useContext(ThemeContext);
6427
6417
  var container = theme.container,
6428
6418
  buttonBg = theme.buttonBg,
6429
6419
  primary = theme.primary;
6430
- if (!open) return null;
6420
+ var notificationStatus = React.useMemo(function () {
6421
+ return {
6422
+ isClosed: false,
6423
+ isWaitingForConfirmation: state === 'waitingForConfirmation',
6424
+ isFailure: state === 'fail',
6425
+ isSuccess: state === 'success'
6426
+ };
6427
+ }, [state]);
6431
6428
  return React__default.createElement("div", {
6432
6429
  className: "__ref-swap-widget-notification",
6433
6430
  style: {
@@ -6436,18 +6433,18 @@ var Notification = function Notification(_ref15) {
6436
6433
  }
6437
6434
  }, React__default.createElement("div", {
6438
6435
  className: "__ref-swap-widget-notification__icon"
6439
- }, state === null && React__default.createElement(Loading, null), state === 'fail' && React__default.createElement(Warning, null), state === 'success' && React__default.createElement(Success, null)), React__default.createElement("div", {
6436
+ }, notificationStatus.isWaitingForConfirmation && React__default.createElement(Loading, null), notificationStatus.isFailure && React__default.createElement(Warning, null), notificationStatus.isSuccess && React__default.createElement(Success, null)), React__default.createElement("div", {
6440
6437
  style: {
6441
6438
  fontSize: '16px',
6442
6439
  marginTop: '10px',
6443
6440
  marginBottom: '6px'
6444
6441
  }
6445
- }, state === 'success' && React__default.createElement("p", null, "Success!"), state === 'fail' && React__default.createElement("p", null, "Swap Failed!")), React__default.createElement("div", {
6446
- className: "__ref-swap-widget-notification__text",
6442
+ }, notificationStatus.isSuccess && React__default.createElement("p", null, "Success!"), notificationStatus.isFailure && React__default.createElement("p", null, "Swap Failed!")), React__default.createElement("div", {
6443
+ className: "text-center",
6447
6444
  style: {
6448
6445
  color: primary
6449
6446
  }
6450
- }, (state === null || state === undefined) && React__default.createElement("p", null, "Waiting for confirmation"), state === 'success' && tx && React__default.createElement("a", {
6447
+ }, notificationStatus.isWaitingForConfirmation && React__default.createElement("p", null, "Waiting for confirmation"), notificationStatus.isSuccess && tx && React__default.createElement("a", {
6451
6448
  className: "text-primary font-semibold",
6452
6449
  href: exports.config.explorerUrl + "/txns/" + tx,
6453
6450
  target: "_blank",
@@ -6457,7 +6454,7 @@ var Notification = function Notification(_ref15) {
6457
6454
  color: primary
6458
6455
  },
6459
6456
  rel: "noreferrer"
6460
- }, "Click to view."), state === 'success' && detail), state !== null && React__default.createElement("button", {
6457
+ }, "Click to view."), notificationStatus.isSuccess && detail), state !== null && React__default.createElement("button", {
6461
6458
  className: "__ref-swap-widget-notification__button __ref-swap-widget-button",
6462
6459
  style: {
6463
6460
  background: buttonBg,
@@ -6467,8 +6464,7 @@ var Notification = function Notification(_ref15) {
6467
6464
  onClick: function onClick(e) {
6468
6465
  e.preventDefault();
6469
6466
  e.stopPropagation();
6470
- setOpen(false);
6471
- setState && setState(null);
6467
+ setSwapState(null);
6472
6468
  }
6473
6469
  }, "Close"));
6474
6470
  };
@@ -6486,9 +6482,9 @@ var ArrowRight = function ArrowRight() {
6486
6482
  fill: "#7E8A93"
6487
6483
  })));
6488
6484
  };
6489
- var AccountButton = function AccountButton(_ref16) {
6490
- var AccountId = _ref16.AccountId,
6491
- onDisConnect = _ref16.onDisConnect;
6485
+ var AccountButton = function AccountButton(_ref15) {
6486
+ var AccountId = _ref15.AccountId,
6487
+ onDisConnect = _ref15.onDisConnect;
6492
6488
  var _useState16 = React.useState(false),
6493
6489
  hoverAccount = _useState16[0],
6494
6490
  setHoverAccount = _useState16[1];
@@ -6534,7 +6530,9 @@ var SwapWidget = function SwapWidget(props) {
6534
6530
  defaultTokenOut = props.defaultTokenOut,
6535
6531
  onDisConnect = props.onDisConnect,
6536
6532
  darkMode = props.darkMode,
6537
- referralId = props.referralId;
6533
+ referralId = props.referralId,
6534
+ _props$minNearAmountL = props.minNearAmountLeftForGasFees,
6535
+ minNearAmountLeftForGasFees = _props$minNearAmountL === void 0 ? 0.5 : _props$minNearAmountL;
6538
6536
  var curTheme = theme || (darkMode ? defaultDarkModeTheme : defaultTheme);
6539
6537
  var STORAGED_TOKEN_IN = localStorage.getItem(REF_WIDGET_SWAP_IN_KEY);
6540
6538
  var STORAGED_TOKEN_OUT = localStorage.getItem(REF_WIDGET_SWAP_OUT_KEY);
@@ -6562,28 +6560,27 @@ var SwapWidget = function SwapWidget(props) {
6562
6560
  var _useState2 = React.useState(),
6563
6561
  tokenOut = _useState2[0],
6564
6562
  setTokenOut = _useState2[1];
6565
- var _useState3 = React.useState(false),
6566
- notOpen = _useState3[0],
6567
- setNotOpen = _useState3[1];
6568
- React.useEffect(function () {
6569
- if (!transactionState) return;
6570
- if (transactionState && transactionState.state !== null) {
6571
- setNotOpen(true);
6563
+ var _useState3 = React.useState('swap'),
6564
+ widgetRoute = _useState3[0],
6565
+ setWidgetRoute = _useState3[1];
6566
+ var _useState4 = React.useState('1'),
6567
+ amountIn = _useState4[0],
6568
+ setAmountIn = _useState4[1];
6569
+ var _useState5 = React.useState(false),
6570
+ showSlip = _useState5[0],
6571
+ setShowSlip = _useState5[1];
6572
+ var _useState6 = React.useState(DEFAULT_SLIPPAGE_TOLERANCE),
6573
+ slippageTolerance = _useState6[0],
6574
+ setSlippageTolerance = _useState6[1];
6575
+ var formattedSlippageTolerance = React.useMemo(function () {
6576
+ try {
6577
+ var formatted = Number(slippageTolerance);
6578
+ if (Number.isNaN(formatted) || !isValidSlippageTolerance(formatted)) return +DEFAULT_SLIPPAGE_TOLERANCE;
6579
+ return formatted;
6580
+ } catch (_unused) {
6581
+ return +DEFAULT_SLIPPAGE_TOLERANCE;
6572
6582
  }
6573
- transactionState == null ? void 0 : transactionState.setState((transactionState == null ? void 0 : transactionState.state) || null);
6574
- }, [transactionState]);
6575
- var _useState4 = React.useState('swap'),
6576
- widgetRoute = _useState4[0],
6577
- setWidgetRoute = _useState4[1];
6578
- var _useState5 = React.useState('1'),
6579
- amountIn = _useState5[0],
6580
- setAmountIn = _useState5[1];
6581
- var _useState6 = React.useState(false),
6582
- showSlip = _useState6[0],
6583
- setShowSlip = _useState6[1];
6584
- var _useState7 = React.useState(0.5),
6585
- slippageTolerance = _useState7[0],
6586
- setSlippageTolerance = _useState7[1];
6583
+ }, [slippageTolerance]);
6587
6584
  var _useTokensIndexer = useTokensIndexer({
6588
6585
  defaultTokenList: defaultTokenList,
6589
6586
  AccountId: AccountId
@@ -6594,9 +6591,9 @@ var SwapWidget = function SwapWidget(props) {
6594
6591
  useAllTokens({
6595
6592
  reload: true
6596
6593
  });
6597
- var _useState8 = React.useState(false),
6598
- refreshTrigger = _useState8[0],
6599
- setRreshTrigger = _useState8[1];
6594
+ var _useState7 = React.useState(false),
6595
+ refreshTrigger = _useState7[0],
6596
+ setRreshTrigger = _useState7[1];
6600
6597
  var tokenPriceList = useTokenPriceList();
6601
6598
  var _useRefPools = useRefPools(refreshTrigger),
6602
6599
  allPools = _useRefPools.allPools,
@@ -6654,7 +6651,7 @@ var SwapWidget = function SwapWidget(props) {
6654
6651
  return Number(p.shares_total_supply) > 0;
6655
6652
  })
6656
6653
  },
6657
- slippageTolerance: slippageTolerance,
6654
+ slippageTolerance: formattedSlippageTolerance,
6658
6655
  onSwap: onSwap,
6659
6656
  AccountId: AccountId,
6660
6657
  refreshTrigger: refreshTrigger,
@@ -6687,10 +6684,10 @@ var SwapWidget = function SwapWidget(props) {
6687
6684
  }, [estimates, tokenIn, tokenOut, amountIn, amountOut, allStablePools]);
6688
6685
  var handleSubmit = function handleSubmit(e) {
6689
6686
  e.preventDefault();
6690
- setNotOpen(true);
6687
+ transactionState.setState('waitingForConfirmation');
6691
6688
  makeSwap();
6692
6689
  };
6693
- var canSubmit = tokenIn && tokenOut && canSwap && !swapError && isSignedIn && new Big(tokenInBalance || '0').gte(amountIn || '0') && slippageTolerance > 0 && slippageTolerance < 100 && !ONLY_ZEROS.test(tokenInBalance);
6690
+ var canSubmit = tokenIn && tokenOut && canSwap && !swapError && isSignedIn && new Big(tokenInBalance || '0').gte(amountIn || '0') && isValidSlippageTolerance(formattedSlippageTolerance) && !ONLY_ZEROS.test(tokenInBalance);
6694
6691
  var tokensLoaded = React.useMemo(function () {
6695
6692
  return tokens.length > 0;
6696
6693
  }, [tokens]);
@@ -6723,10 +6720,9 @@ var SwapWidget = function SwapWidget(props) {
6723
6720
  }), React__default.createElement(Slider, {
6724
6721
  showSlip: showSlip,
6725
6722
  setShowSlip: setShowSlip
6726
- }), React__default.createElement(SlippageSelector, {
6723
+ }), showSlip && React__default.createElement(SlippageSelector, {
6727
6724
  slippageTolerance: slippageTolerance,
6728
6725
  onChangeSlippageTolerance: setSlippageTolerance,
6729
- showSlip: showSlip,
6730
6726
  setShowSlip: setShowSlip
6731
6727
  }))), React__default.createElement(TokenAmount, {
6732
6728
  amount: amountIn,
@@ -6737,7 +6733,8 @@ var SwapWidget = function SwapWidget(props) {
6737
6733
  onSelectToken: function onSelectToken() {
6738
6734
  if (!tokensLoaded) return;
6739
6735
  setWidgetRoute('token-selector-in');
6740
- }
6736
+ },
6737
+ minNearAmountLeftForGasFees: minNearAmountLeftForGasFees
6741
6738
  }), React__default.createElement("div", {
6742
6739
  className: "__ref-swap-widget-exchange-button __ref-swap-widget-row-flex-center ",
6743
6740
  style: {
@@ -6767,7 +6764,8 @@ var SwapWidget = function SwapWidget(props) {
6767
6764
  onForceUpdate: function onForceUpdate() {
6768
6765
  setRreshTrigger(!refreshTrigger);
6769
6766
  },
6770
- poolFetchingState: poolFetchingState
6767
+ poolFetchingState: poolFetchingState,
6768
+ minNearAmountLeftForGasFees: minNearAmountLeftForGasFees
6771
6769
  }), !swapError && amountIn && amountOut && React__default.createElement(DetailView, {
6772
6770
  fee: fee,
6773
6771
  rate: rate,
@@ -6830,11 +6828,9 @@ var SwapWidget = function SwapWidget(props) {
6830
6828
  style: {
6831
6829
  color: refIcon || 'black'
6832
6830
  }
6833
- }), "\xA0 Powered by Ref.finance")), React__default.createElement(Notification, {
6834
- state: transactionState == null ? void 0 : transactionState.state,
6835
- setState: transactionState == null ? void 0 : transactionState.setState,
6836
- open: notOpen,
6837
- setOpen: setNotOpen,
6831
+ }), "\xA0 Powered by Ref.finance")), transactionState.state !== null && React__default.createElement(Notification, {
6832
+ state: transactionState.state,
6833
+ setSwapState: transactionState.setState,
6838
6834
  tx: transactionState == null ? void 0 : transactionState.tx,
6839
6835
  detail: transactionState == null ? void 0 : transactionState.detail
6840
6836
  })), widgetRoute === 'token-selector-in' && React__default.createElement(TokenSelector, {
@@ -8284,6 +8280,7 @@ exports.DCLSwapByInputOnBestPool = DCLSwapByInputOnBestPool;
8284
8280
  exports.DCLSwapGetStorageBalance = DCLSwapGetStorageBalance;
8285
8281
  exports.DCL_POOL_FEE_LIST = DCL_POOL_FEE_LIST;
8286
8282
  exports.DCL_POOL_SPLITER = DCL_POOL_SPLITER;
8283
+ exports.DEFAULT_SLIPPAGE_TOLERANCE = DEFAULT_SLIPPAGE_TOLERANCE;
8287
8284
  exports.DefaultMainnetTokenList = DefaultMainnetTokenList;
8288
8285
  exports.DefaultTestnetTokenList = DefaultTestnetTokenList;
8289
8286
  exports.FEE_DIVISOR = FEE_DIVISOR;
@@ -8385,6 +8382,7 @@ exports.instantSwap = instantSwap;
8385
8382
  exports.isMobile = isMobile;
8386
8383
  exports.isStablePool = isStablePool;
8387
8384
  exports.isStablePoolToken = isStablePoolToken;
8385
+ exports.isValidSlippageTolerance = isValidSlippageTolerance;
8388
8386
  exports.listDCLPools = listDCLPools;
8389
8387
  exports.list_active_orders = list_active_orders;
8390
8388
  exports.list_history_orders = list_history_orders;