@ref-finance/ref-sdk 1.3.10 → 1.3.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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('near-api-js'), require('bn.js'), require('fs'), require('lodash-es'), require('mathjs'), require('big.js'), require('react'), require('@react-icons/all-files/fi/FiChevronDown'), require('@react-icons/all-files/fi/FiChevronLeft'), require('@react-icons/all-files/fi/FiChevronUp'), require('@react-icons/all-files/fa/FaSearch'), require('@react-icons/all-files/ri/RiRefreshLine'), require('@react-icons/all-files/ti/TiArrowSortedUp'), require('@react-icons/all-files/ti/TiArrowSortedDown'), require('@react-icons/all-files/hi/HiOutlineExternalLink'), require('@react-icons/all-files/ai/AiFillPushpin'), require('@react-icons/all-files/ai/AiOutlinePushpin'), require('@react-icons/all-files/ri/RiExchangeFill'), require('@react-icons/all-files/io5/IoWarning'), require('@react-icons/all-files/io5/IoCloseOutline'), require('@react-icons/all-files/ti/TiWarning'), require('@react-icons/all-files/cg/CgArrowsExchangeAltV')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'near-api-js', 'bn.js', 'fs', 'lodash-es', 'mathjs', 'big.js', 'react', '@react-icons/all-files/fi/FiChevronDown', '@react-icons/all-files/fi/FiChevronLeft', '@react-icons/all-files/fi/FiChevronUp', '@react-icons/all-files/fa/FaSearch', '@react-icons/all-files/ri/RiRefreshLine', '@react-icons/all-files/ti/TiArrowSortedUp', '@react-icons/all-files/ti/TiArrowSortedDown', '@react-icons/all-files/hi/HiOutlineExternalLink', '@react-icons/all-files/ai/AiFillPushpin', '@react-icons/all-files/ai/AiOutlinePushpin', '@react-icons/all-files/ri/RiExchangeFill', '@react-icons/all-files/io5/IoWarning', '@react-icons/all-files/io5/IoCloseOutline', '@react-icons/all-files/ti/TiWarning', '@react-icons/all-files/cg/CgArrowsExchangeAltV'], factory) :
4
- (global = global || self, factory(global['@ref-finance/ref-sdk'] = {}, global.nearApiJs, global.BN, global.fs, global._, global.math, global.Big, global.React, global.FiChevronDown, global.FiChevronLeft, global.FiChevronUp, global.FaSearch, global.RiRefreshLine, global.TiArrowSortedUp, global.TiArrowSortedDown, global.HiOutlineExternalLink, global.AiFillPushpin, global.AiOutlinePushpin, global.RiExchangeFill, global.IoWarning, global.IoCloseOutline, global.TiWarning, global.CgArrowsExchangeAltV));
5
- }(this, (function (exports, nearApiJs, BN, fs, _, math, Big, React, FiChevronDown, FiChevronLeft, FiChevronUp, FaSearch, RiRefreshLine, TiArrowSortedUp, TiArrowSortedDown, HiOutlineExternalLink, AiFillPushpin, AiOutlinePushpin, RiExchangeFill, IoWarning, IoCloseOutline, TiWarning, CgArrowsExchangeAltV) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('near-api-js'), require('bn.js'), require('fs'), require('lodash-es'), require('mathjs'), require('big.js'), require('near-api-js/lib/utils/format'), require('react'), require('@react-icons/all-files/fi/FiChevronDown'), require('@react-icons/all-files/fi/FiChevronLeft'), require('@react-icons/all-files/fi/FiChevronUp'), require('@react-icons/all-files/fa/FaSearch'), require('@react-icons/all-files/ri/RiRefreshLine'), require('@react-icons/all-files/ti/TiArrowSortedUp'), require('@react-icons/all-files/ti/TiArrowSortedDown'), require('@react-icons/all-files/hi/HiOutlineExternalLink'), require('@react-icons/all-files/ai/AiFillPushpin'), require('@react-icons/all-files/ai/AiOutlinePushpin'), require('@react-icons/all-files/ri/RiExchangeFill'), require('@react-icons/all-files/io5/IoWarning'), require('@react-icons/all-files/io5/IoCloseOutline'), require('@react-icons/all-files/ti/TiWarning'), require('@react-icons/all-files/cg/CgArrowsExchangeAltV')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'near-api-js', 'bn.js', 'fs', 'lodash-es', 'mathjs', 'big.js', 'near-api-js/lib/utils/format', 'react', '@react-icons/all-files/fi/FiChevronDown', '@react-icons/all-files/fi/FiChevronLeft', '@react-icons/all-files/fi/FiChevronUp', '@react-icons/all-files/fa/FaSearch', '@react-icons/all-files/ri/RiRefreshLine', '@react-icons/all-files/ti/TiArrowSortedUp', '@react-icons/all-files/ti/TiArrowSortedDown', '@react-icons/all-files/hi/HiOutlineExternalLink', '@react-icons/all-files/ai/AiFillPushpin', '@react-icons/all-files/ai/AiOutlinePushpin', '@react-icons/all-files/ri/RiExchangeFill', '@react-icons/all-files/io5/IoWarning', '@react-icons/all-files/io5/IoCloseOutline', '@react-icons/all-files/ti/TiWarning', '@react-icons/all-files/cg/CgArrowsExchangeAltV'], factory) :
4
+ (global = global || self, factory(global['@ref-finance/ref-sdk'] = {}, global.nearApiJs, global.BN, global.fs, global._, global.math, global.Big, global.format, global.React, global.FiChevronDown, global.FiChevronLeft, global.FiChevronUp, global.FaSearch, global.RiRefreshLine, global.TiArrowSortedUp, global.TiArrowSortedDown, global.HiOutlineExternalLink, global.AiFillPushpin, global.AiOutlinePushpin, global.RiExchangeFill, global.IoWarning, global.IoCloseOutline, global.TiWarning, global.CgArrowsExchangeAltV));
5
+ }(this, (function (exports, nearApiJs, BN, fs, _, math, Big, format, React, FiChevronDown, FiChevronLeft, FiChevronUp, FaSearch, RiRefreshLine, TiArrowSortedUp, TiArrowSortedDown, HiOutlineExternalLink, AiFillPushpin, AiOutlinePushpin, RiExchangeFill, IoWarning, IoCloseOutline, TiWarning, CgArrowsExchangeAltV) { 'use strict';
6
6
 
7
7
  BN = BN && Object.prototype.hasOwnProperty.call(BN, 'default') ? BN['default'] : BN;
8
8
  fs = fs && Object.prototype.hasOwnProperty.call(fs, 'default') ? fs['default'] : fs;
@@ -14,6 +14,8 @@
14
14
  var STABLE_LP_TOKEN_DECIMALS = 18;
15
15
  var RATED_POOL_LP_TOKEN_DECIMALS = 24;
16
16
  var STORAGE_TO_REGISTER_WITH_MFT = '0.1';
17
+ //0.0125 NEAR
18
+ var FT_MINIMUM_STORAGE_BALANCE_LARGE = "12500000000000000000000";
17
19
  var ONE_YOCTO_NEAR = '0.000000000000000000000001';
18
20
  var ENV = '';
19
21
  var INDEXER_URL = '';
@@ -4259,6 +4261,51 @@
4259
4261
  }
4260
4262
  });
4261
4263
  };
4264
+ var getMinStorageBalance = /*#__PURE__*/function () {
4265
+ var _ref14 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(nep141Address) {
4266
+ var provider, result, balance;
4267
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
4268
+ while (1) {
4269
+ switch (_context11.prev = _context11.next) {
4270
+ case 0:
4271
+ _context11.prev = 0;
4272
+ provider = new nearApiJs.providers.JsonRpcProvider({
4273
+ url: getConfig().nodeUrl
4274
+ });
4275
+ _context11.next = 4;
4276
+ return provider.query({
4277
+ request_type: 'call_function',
4278
+ account_id: nep141Address,
4279
+ method_name: 'storage_balance_bounds',
4280
+ args_base64: '',
4281
+ finality: 'optimistic'
4282
+ });
4283
+ case 4:
4284
+ result = _context11.sent;
4285
+ balance = JSON.parse(Buffer.from(result.result).toString());
4286
+ if (!(!balance || !balance.min)) {
4287
+ _context11.next = 8;
4288
+ break;
4289
+ }
4290
+ return _context11.abrupt("return", FT_MINIMUM_STORAGE_BALANCE_LARGE);
4291
+ case 8:
4292
+ return _context11.abrupt("return", balance.min);
4293
+ case 11:
4294
+ _context11.prev = 11;
4295
+ _context11.t0 = _context11["catch"](0);
4296
+ console.error(_context11.t0, nep141Address);
4297
+ return _context11.abrupt("return", FT_MINIMUM_STORAGE_BALANCE_LARGE);
4298
+ case 15:
4299
+ case "end":
4300
+ return _context11.stop();
4301
+ }
4302
+ }
4303
+ }, _callee11, null, [[0, 11]]);
4304
+ }));
4305
+ return function getMinStorageBalance(_x13) {
4306
+ return _ref14.apply(this, arguments);
4307
+ };
4308
+ }();
4262
4309
 
4263
4310
  var DCL_POOL_FEE_LIST = [100, 400, 2000, 10000];
4264
4311
  var getDCLPoolId = function getDCLPoolId(tokenA, tokenB, fee) {
@@ -4359,21 +4406,35 @@
4359
4406
  });
4360
4407
  case 2:
4361
4408
  tokenRegistered = _context.sent;
4362
- if (tokenRegistered === null) {
4363
- transactions.push({
4364
- receiverId: token.id,
4365
- functionCalls: [{
4366
- methodName: 'storage_deposit',
4367
- args: {
4368
- registration_only: true,
4369
- account_id: AccountId
4370
- },
4371
- gas: '30000000000000',
4372
- amount: STORAGE_TO_REGISTER_WITH_MFT
4373
- }]
4374
- });
4409
+ if (!(tokenRegistered === null)) {
4410
+ _context.next = 16;
4411
+ break;
4375
4412
  }
4376
- case 4:
4413
+ _context.t0 = transactions;
4414
+ _context.t1 = token.id;
4415
+ _context.t2 = {
4416
+ registration_only: true,
4417
+ account_id: AccountId
4418
+ };
4419
+ _context.t3 = format.formatNearAmount;
4420
+ _context.next = 10;
4421
+ return getMinStorageBalance(token.id);
4422
+ case 10:
4423
+ _context.t4 = _context.sent;
4424
+ _context.t5 = (0, _context.t3)(_context.t4, 24);
4425
+ _context.t6 = {
4426
+ methodName: 'storage_deposit',
4427
+ args: _context.t2,
4428
+ gas: '30000000000000',
4429
+ amount: _context.t5
4430
+ };
4431
+ _context.t7 = [_context.t6];
4432
+ _context.t8 = {
4433
+ receiverId: _context.t1,
4434
+ functionCalls: _context.t7
4435
+ };
4436
+ _context.t0.push.call(_context.t0, _context.t8);
4437
+ case 16:
4377
4438
  case "end":
4378
4439
  return _context.stop();
4379
4440
  }
@@ -5202,6 +5263,7 @@
5202
5263
  var css_248z = ".__ref-swap-widget-container {\n border-radius: 16px;\n padding: 28px;\n padding-bottom: 16px;\n position: relative;\n max-width: 90%;\n}\n\n.__ref-swap-widget-row-flex-center {\n display: flex;\n align-items: center;\n}\n\n.__ref-swap-widget-col-flex-start {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n}\n\n.__ref-swap-widget-header {\n justify-content: space-between;\n margin-bottom: 25px;\n}\n\n.__ref-swap-widget-header-title {\n font-weight: 700;\n font-size: 20px;\n}\n.__ref-swap-widget-header-button-account {\n font-size: 14px;\n margin-right: 8px;\n padding: 4px 13px;\n border-radius: 25px;\n min-width: 120px;\n justify-content: center;\n}\n\n.__ref-swap-widget-header-button-account:hover {\n background: rgba(255, 104, 158, 0.2) !important;\n}\n\n.__ref-swap-widget_slippage_selector {\n box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.25);\n border-radius: 12px;\n position: absolute;\n top: 30px;\n right: 0px;\n padding: 16px;\n padding-right: 20px;\n padding-left: 20px;\n z-index: 100;\n width: 230px;\n font-size: 14px;\n}\n\n.__ref-swap-widget_slippage_selector_input_container {\n width: 100%;\n height: 26px;\n margin-right: 4px;\n padding: 2px 10px;\n}\n.__ref-swap-widget_slippage_selector_button {\n font-size: 14px;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 6px 16px;\n}\n\n.__ref-swap-widget-opacity-hover:hover {\n opacity: 0.5;\n}\n\n.__ref-swap-widget-opacity-active:active {\n opacity: 0.5;\n}\n\n.__ref-swap-widger-token-amount {\n padding: 14px;\n padding-bottom: 8px;\n border-radius: 8px;\n display: flex;\n align-items: flex-start;\n}\n\n.__ref-swap-widger-token-amount_input {\n width: 100%;\n display: flex;\n flex-direction: column;\n align-items: flex-end;\n}\n\n.__ref-swap-widget-token-amount_quick_selector {\n}\n\n.__ref-swap-widger-token-amount_balance {\n margin-top: 7px;\n justify-content: space-between;\n}\n\n.__ref-swap-widget-token-amount_quick_selector_item {\n font-size: 12px;\n padding: 6px;\n padding-top: 3px;\n padding-bottom: 3px;\n cursor: pointer;\n}\n.__ref-swap-widget-select-token_input {\n padding: 14px;\n border-radius: 8px;\n}\n\n.__ref-swap-widget_star_token {\n padding: 8px 10px 8px 8px;\n margin: 0px 6px 10px 0px;\n position: relative;\n cursor: pointer;\n border-radius: 8px;\n}\n\n.__ref-swap-widget_token_icon {\n border-radius: 100%;\n flex-shrink: 0;\n}\n\n.__ref-swap-widget_token_list_table {\n table-layout: auto;\n width: 100%;\n font-size: 14px;\n}\n\n.__ref-swap-widget_token_list_table_header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 6px 12px;\n margin: 0px 6px;\n}\n\n.__ref-swap-widget_token-selector-star-tokens {\n margin-top: 20px;\n flex-wrap: wrap;\n}\n.__ref-swap-widget_token_list_table_content {\n display: flex;\n flex-direction: column;\n max-height: 50vh;\n min-height: 30vh;\n overflow-y: auto;\n}\n\n.__ref-swap-widget_token-selector-token-list-item {\n justify-content: space-between;\n padding: 9px 20px;\n}\n.__ref-swap-widget-token-amount_token-select-button {\n font-size: 16px;\n border-radius: 18px;\n padding: 6px 8px;\n cursor: pointer;\n}\n\n.__ref-swap-widget-exchange-button {\n width: 100%;\n justify-content: center;\n padding: 20px 0;\n}\n\n.__ref-swap-widget-submit-button {\n width: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 18px;\n font-weight: 700;\n border-radius: 8px;\n padding: 14px 0 14px 0;\n margin-top: 14px;\n cursor: pointer;\n}\n\n.__ref-swap-widget-submit-button-loader {\n width: 20px;\n height: 20px;\n border: 2px solid #fff;\n border-bottom-color: rgb(255, 255, 255);\n border-bottom-color: transparent;\n border-radius: 50%;\n display: inline-block;\n box-sizing: border-box;\n animation: rotation 1s linear infinite;\n}\n\n@keyframes rotation {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n\n.__ref-widget-swap-detail-view {\n justify-content: space-between;\n width: 100%;\n font-size: 14px;\n margin-top: 16px;\n}\n\n.__ref-swap-widget-swap-detail-view-item {\n justify-content: space-between;\n margin-bottom: 12px;\n width: 100%;\n}\n\n.__ref-swap-widget-loading {\n animation: spin 2s linear infinite;\n}\n\n.__ref-swap-widget-notification {\n position: absolute;\n top: 50%;\n left: 50%;\n width: 50%;\n transform: translate(-50%, -50%);\n background: rgba(0, 0, 0, 0.5);\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n z-index: 100;\n box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.25);\n border-radius: 12px;\n padding: 32px 20px;\n}\n\n.__ref-swap-widget-notification__button {\n border-radius: 8px;\n padding: 8px 20px;\n margin-top: 14px;\n}\n@keyframes spin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n}\n\ninput.__ref-swap-widget-input-class {\n margin: 0;\n background-color: transparent;\n display: block;\n width: 100%;\n padding: 0;\n border-width: 0;\n}\n\ninput.__ref-swap-widget-input-class:focus {\n outline: none;\n border-width: 0;\n}\n\ninput.__ref-swap-widget-input-class::-webkit-outer-spin-button,\ninput.__ref-swap-widget-input-class::-webkit-inner-spin-button {\n -webkit-appearance: none;\n margin: 0;\n}\n\ninput.__ref-swap-widget-input-class[type='number'] {\n -moz-appearance: textfield; /* Firefox */\n}\n\nbutton.__ref-swap-widget-button {\n border: none;\n}\n\n.__ref-swap-widget-submit-button:hover {\n opacity: 0.5;\n}\n\n.__ref-swap-widget-active:active {\n color: #00c6a2;\n}\n\n.__ref-swap-widget-hover:hover {\n color: #00c6a2;\n}\n\n.__ref-swap-widget_token_list_table_content::-webkit-scrollbar {\n width: 4px;\n height: 4px;\n border-radius: 3px;\n}\n\n.__ref-swap-widget_token_list_table_content::-webkit-scrollbar-track {\n box-shadow: inset 0 0 6px rgba(0, 0, 0, 0);\n}\n.__ref-swap-widget_token_list_table_content::-webkit-scrollbar-thumb {\n background: #00c6a2;\n border-radius: 8px;\n}\n\n.__ref-swap-widget-swap_routes {\n border-radius: 12px;\n padding: 8px 12px 8px 12px;\n width: 100%;\n}\n\n.__ref-swap-widget-valueStyle {\n background-image: -webkit-linear-gradient(left, #00ffd1, #00ffd1, #8c78ff);\n -webkit-background-clip: text;\n -webkit-text-fill-color: transparent;\n}\n\n.__ref-swap-widget-swap_route_row {\n justify-content: space-between;\n margin-bottom: 4px;\n}\n";
5203
5264
  styleInject(css_248z);
5204
5265
 
5266
+ var _ALLOWED_KEYS;
5205
5267
  var getPriceImpact$1 = function getPriceImpact(value, tokenIn, tokenInAmount) {
5206
5268
  var textColor = Number(value) <= 1 ? 'text-greenLight' : 1 < Number(value) && Number(value) <= 2 ? 'text-warn' : 'text-error';
5207
5269
  var displayValue = scientificNotationToString(multiply(tokenInAmount || '0', divide(value, '100')));
@@ -5513,7 +5575,33 @@
5513
5575
  }, "Max"));
5514
5576
  };
5515
5577
  var DECIMAL_POINT = '.';
5516
- var ALLOWED_KEYS = ['Backspace', 'Tab', 'ArrowLeft', 'ArrowRight', 'Delete', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', DECIMAL_POINT];
5578
+ var ALLOWED_KEYS = (_ALLOWED_KEYS = {
5579
+ '0': true,
5580
+ '1': true,
5581
+ '2': true,
5582
+ '3': true,
5583
+ '4': true,
5584
+ '5': true,
5585
+ '6': true,
5586
+ '7': true,
5587
+ '8': true,
5588
+ '9': true
5589
+ }, _ALLOWED_KEYS[DECIMAL_POINT] = true, _ALLOWED_KEYS);
5590
+ var isValidInput = function isValidInput(value) {
5591
+ var decimalPointsAmount = 0;
5592
+ if (value === DECIMAL_POINT) return false;
5593
+ for (var i = 0; i < value.length; i++) {
5594
+ var _char = value[i];
5595
+ if (!ALLOWED_KEYS[_char]) return false;
5596
+ if (_char === DECIMAL_POINT) {
5597
+ decimalPointsAmount++;
5598
+ if (decimalPointsAmount === 2) {
5599
+ return false;
5600
+ }
5601
+ }
5602
+ }
5603
+ return true;
5604
+ };
5517
5605
  var TokenAmount = function TokenAmount(props) {
5518
5606
  var _ref$current2;
5519
5607
  var balance = props.balance,
@@ -5534,28 +5622,6 @@
5534
5622
  var _useState5 = React.useState(false),
5535
5623
  hoverSelect = _useState5[0],
5536
5624
  setHoverSelect = _useState5[1];
5537
- var handleKeyDown = function handleKeyDown(event) {
5538
- if (!ALLOWED_KEYS.includes(event.key) && !event.ctrlKey) {
5539
- event.preventDefault();
5540
- }
5541
- var isDecimalPoint = event.key === DECIMAL_POINT;
5542
- if (!isDecimalPoint) return;
5543
- // Ensure only one dot is allowed
5544
- var inputValue = event.target.value;
5545
- if (inputValue.includes(DECIMAL_POINT)) {
5546
- event.preventDefault();
5547
- }
5548
- // prohibit only one dot
5549
- if (inputValue.length === 0) {
5550
- event.preventDefault();
5551
- }
5552
- };
5553
- var handlePaste = function handlePaste(event) {
5554
- var paste = event.clipboardData.getData('text');
5555
- if (!/^[0-9.]+$/.test(paste)) {
5556
- event.preventDefault();
5557
- }
5558
- };
5559
5625
  var handleChange = function handleChange(amount) {
5560
5626
  if (onChangeAmount) {
5561
5627
  onChangeAmount(amount);
@@ -5645,11 +5711,10 @@
5645
5711
  className: "__ref-swap-widget-input-class",
5646
5712
  value: amount,
5647
5713
  type: "text",
5648
- onKeyDown: handleKeyDown,
5649
- onPaste: handlePaste,
5650
5714
  placeholder: !onChangeAmount ? '-' : '0.0',
5651
5715
  onChange: function onChange(_ref7) {
5652
5716
  var target = _ref7.target;
5717
+ if (!isValidInput(target.value)) return;
5653
5718
  target.setCustomValidity('');
5654
5719
  handleChange(target.value);
5655
5720
  },
@@ -8226,6 +8291,7 @@
8226
8291
  exports.DefaultMainnetTokenList = DefaultMainnetTokenList;
8227
8292
  exports.DefaultTestnetTokenList = DefaultTestnetTokenList;
8228
8293
  exports.FEE_DIVISOR = FEE_DIVISOR;
8294
+ exports.FT_MINIMUM_STORAGE_BALANCE_LARGE = FT_MINIMUM_STORAGE_BALANCE_LARGE;
8229
8295
  exports.InValidAccessKeyError = InValidAccessKeyError;
8230
8296
  exports.NEAR_META_DATA = NEAR_META_DATA;
8231
8297
  exports.NoAccountIdFound = NoAccountIdFound;
@@ -8296,6 +8362,7 @@
8296
8362
  exports.getKeyStore = getKeyStore;
8297
8363
  exports.getMax = getMax;
8298
8364
  exports.getMemorySigner = getMemorySigner;
8365
+ exports.getMinStorageBalance = getMinStorageBalance;
8299
8366
  exports.getPointByPrice = getPointByPrice;
8300
8367
  exports.getPool = getPool;
8301
8368
  exports.getPoolAllocationPercents = getPoolAllocationPercents;