@ref-finance/ref-sdk 1.3.9 → 1.3.11

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.
@@ -168,6 +168,8 @@
168
168
 
169
169
  .__ref-swap-widget-submit-button {
170
170
  width: 100%;
171
+ display: flex;
172
+ align-items: center;
171
173
  justify-content: center;
172
174
  font-size: 18px;
173
175
  font-weight: 700;
@@ -176,6 +178,28 @@
176
178
  margin-top: 14px;
177
179
  cursor: pointer;
178
180
  }
181
+
182
+ .__ref-swap-widget-submit-button-loader {
183
+ width: 20px;
184
+ height: 20px;
185
+ border: 2px solid #fff;
186
+ border-bottom-color: rgb(255, 255, 255);
187
+ border-bottom-color: transparent;
188
+ border-radius: 50%;
189
+ display: inline-block;
190
+ box-sizing: border-box;
191
+ animation: rotation 1s linear infinite;
192
+ }
193
+
194
+ @keyframes rotation {
195
+ 0% {
196
+ transform: rotate(0deg);
197
+ }
198
+ 100% {
199
+ transform: rotate(360deg);
200
+ }
201
+ }
202
+
179
203
  .__ref-widget-swap-detail-view {
180
204
  justify-content: space-between;
181
205
  width: 100%;
@@ -5191,6 +5191,7 @@ var useTokenBalances = function useTokenBalances(tokens, AccountId) {
5191
5191
  };
5192
5192
  };
5193
5193
 
5194
+ var _ALLOWED_KEYS;
5194
5195
  var getPriceImpact$1 = function getPriceImpact(value, tokenIn, tokenInAmount) {
5195
5196
  var textColor = Number(value) <= 1 ? 'text-greenLight' : 1 < Number(value) && Number(value) <= 2 ? 'text-warn' : 'text-error';
5196
5197
  var displayValue = scientificNotationToString(multiply(tokenInAmount || '0', divide(value, '100')));
@@ -5501,6 +5502,34 @@ var HalfAndMaxAmount = function HalfAndMaxAmount(_ref6) {
5501
5502
  }
5502
5503
  }, "Max"));
5503
5504
  };
5505
+ var DECIMAL_POINT = '.';
5506
+ var ALLOWED_KEYS = (_ALLOWED_KEYS = {
5507
+ '0': true,
5508
+ '1': true,
5509
+ '2': true,
5510
+ '3': true,
5511
+ '4': true,
5512
+ '5': true,
5513
+ '6': true,
5514
+ '7': true,
5515
+ '8': true,
5516
+ '9': true
5517
+ }, _ALLOWED_KEYS[DECIMAL_POINT] = true, _ALLOWED_KEYS);
5518
+ var isValidInput = function isValidInput(value) {
5519
+ var decimalPointsAmount = 0;
5520
+ if (value === DECIMAL_POINT) return false;
5521
+ for (var i = 0; i < value.length; i++) {
5522
+ var _char = value[i];
5523
+ if (!ALLOWED_KEYS[_char]) return false;
5524
+ if (_char === DECIMAL_POINT) {
5525
+ decimalPointsAmount++;
5526
+ if (decimalPointsAmount === 2) {
5527
+ return false;
5528
+ }
5529
+ }
5530
+ }
5531
+ return true;
5532
+ };
5504
5533
  var TokenAmount = function TokenAmount(props) {
5505
5534
  var _ref$current2;
5506
5535
  var balance = props.balance,
@@ -5566,7 +5595,8 @@ var TokenAmount = function TokenAmount(props) {
5566
5595
  }, !token ? React__default.createElement(React__default.Fragment, null, React__default.createElement("span", {
5567
5596
  style: {
5568
5597
  whiteSpace: 'nowrap',
5569
- height: '26px'
5598
+ height: '26px',
5599
+ userSelect: 'none'
5570
5600
  },
5571
5601
  className: "__ref-swap-widget-row-flex-center"
5572
5602
  }, "Select Token")) : React__default.createElement(React__default.Fragment, null, React__default.createElement("img", {
@@ -5601,26 +5631,22 @@ var TokenAmount = function TokenAmount(props) {
5601
5631
  }, React__default.createElement("input", {
5602
5632
  ref: ref,
5603
5633
  max: !!onChangeAmount ? curMax : undefined,
5604
- min: "0",
5605
5634
  onWheel: function onWheel() {
5606
5635
  if (ref.current) {
5607
5636
  ref.current.blur();
5608
5637
  }
5609
5638
  },
5610
5639
  className: "__ref-swap-widget-input-class",
5611
- step: "any",
5612
5640
  value: amount,
5613
- type: "number",
5641
+ type: "text",
5614
5642
  placeholder: !onChangeAmount ? '-' : '0.0',
5615
5643
  onChange: function onChange(_ref7) {
5616
5644
  var target = _ref7.target;
5645
+ if (!isValidInput(target.value)) return;
5617
5646
  target.setCustomValidity('');
5618
5647
  handleChange(target.value);
5619
5648
  },
5620
5649
  disabled: !onChangeAmount,
5621
- onKeyDown: function onKeyDown(e) {
5622
- return symbolsArr.includes(e.key) && e.preventDefault();
5623
- },
5624
5650
  style: {
5625
5651
  color: primary,
5626
5652
  marginBottom: '8px',
@@ -6597,6 +6623,9 @@ var SwapWidget = function SwapWidget(props) {
6597
6623
  makeSwap();
6598
6624
  };
6599
6625
  var canSubmit = tokenIn && tokenOut && canSwap && !swapError && isSignedIn && new Big(tokenInBalance || '0').gte(amountIn || '0') && slippageTolerance > 0 && slippageTolerance < 100 && !ONLY_ZEROS.test(tokenInBalance);
6626
+ var tokensLoaded = React.useMemo(function () {
6627
+ return tokens.length > 0;
6628
+ }, [tokens]);
6600
6629
  return React__default.createElement(ThemeContextProvider, {
6601
6630
  customTheme: curTheme
6602
6631
  }, React__default.createElement(TokenPriceContextProvider, null, widgetRoute === 'swap' && React__default.createElement("form", {
@@ -6638,6 +6667,7 @@ var SwapWidget = function SwapWidget(props) {
6638
6667
  price: !tokenIn ? null : tokenPriceList == null ? void 0 : (_tokenPriceList$token = tokenPriceList[tokenIn.id]) == null ? void 0 : _tokenPriceList$token.price,
6639
6668
  onChangeAmount: setAmountIn,
6640
6669
  onSelectToken: function onSelectToken() {
6670
+ if (!tokensLoaded) return;
6641
6671
  setWidgetRoute('token-selector-in');
6642
6672
  }
6643
6673
  }), React__default.createElement("div", {
@@ -6663,6 +6693,7 @@ var SwapWidget = function SwapWidget(props) {
6663
6693
  token: tokenOut,
6664
6694
  price: !tokenOut ? null : tokenPriceList == null ? void 0 : (_tokenPriceList$token2 = tokenPriceList[tokenOut.id]) == null ? void 0 : _tokenPriceList$token2.price,
6665
6695
  onSelectToken: function onSelectToken() {
6696
+ if (!tokensLoaded) return;
6666
6697
  setWidgetRoute('token-selector-out');
6667
6698
  },
6668
6699
  onForceUpdate: function onForceUpdate() {
@@ -6699,7 +6730,9 @@ var SwapWidget = function SwapWidget(props) {
6699
6730
  cursor: !canSubmit ? 'not-allowed' : 'pointer'
6700
6731
  },
6701
6732
  disabled: !canSubmit
6702
- }, 'Swap') : React__default.createElement("button", {
6733
+ }, tokensLoaded ? 'Swap' : React__default.createElement("div", {
6734
+ className: "__ref-swap-widget-submit-button-loader"
6735
+ })) : React__default.createElement("button", {
6703
6736
  type: "button",
6704
6737
  className: "__ref-swap-widget-submit-button __ref-swap-widget-button",
6705
6738
  onClick: onConnect,