@ref-finance/ref-sdk 1.3.8 → 1.3.10
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/ref-sdk.cjs.development.css +24 -0
- package/dist/ref-sdk.cjs.development.js +179 -90
- package/dist/ref-sdk.cjs.development.js.map +1 -1
- package/dist/ref-sdk.cjs.production.min.js +1 -1
- package/dist/ref-sdk.cjs.production.min.js.map +1 -1
- package/dist/ref-sdk.esm.js +181 -92
- package/dist/ref-sdk.esm.js.map +1 -1
- package/dist/ref-sdk.umd.development.js +180 -91
- package/dist/ref-sdk.umd.development.js.map +1 -1
- package/dist/ref-sdk.umd.production.min.js +1 -1
- package/dist/ref-sdk.umd.production.min.js.map +1 -1
- package/dist/swap-widget/state.d.ts +6 -2
- package/dist/swap-widget/types.d.ts +4 -1
- package/package.json +1 -1
package/dist/ref-sdk.esm.js
CHANGED
|
@@ -5,7 +5,7 @@ import _, { sortBy } from 'lodash-es';
|
|
|
5
5
|
import * as math from 'mathjs';
|
|
6
6
|
import { divide as divide$1, evaluate, format, floor, bignumber, sum, round as round$1 } from 'mathjs';
|
|
7
7
|
import Big from 'big.js';
|
|
8
|
-
import React, { useState, useEffect, createContext, useContext,
|
|
8
|
+
import React, { useState, useEffect, useMemo, useCallback, createContext, useContext, useRef } from 'react';
|
|
9
9
|
import { FiChevronDown } from '@react-icons/all-files/fi/FiChevronDown';
|
|
10
10
|
import { FiChevronLeft } from '@react-icons/all-files/fi/FiChevronLeft';
|
|
11
11
|
import { FiChevronUp } from '@react-icons/all-files/fi/FiChevronUp';
|
|
@@ -524,18 +524,6 @@ function _extends() {
|
|
|
524
524
|
};
|
|
525
525
|
return _extends.apply(this, arguments);
|
|
526
526
|
}
|
|
527
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
528
|
-
if (source == null) return {};
|
|
529
|
-
var target = {};
|
|
530
|
-
var sourceKeys = Object.keys(source);
|
|
531
|
-
var key, i;
|
|
532
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
533
|
-
key = sourceKeys[i];
|
|
534
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
535
|
-
target[key] = source[key];
|
|
536
|
-
}
|
|
537
|
-
return target;
|
|
538
|
-
}
|
|
539
527
|
function _unsupportedIterableToArray(o, minLen) {
|
|
540
528
|
if (!o) return;
|
|
541
529
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
@@ -4742,7 +4730,6 @@ var fetchAllPools = /*#__PURE__*/function () {
|
|
|
4742
4730
|
};
|
|
4743
4731
|
}();
|
|
4744
4732
|
|
|
4745
|
-
var _excluded = ["slippageTolerance", "refreshTrigger", "onSwap", "AccountId", "poolFetchingState", "referralId"];
|
|
4746
4733
|
var ThemeContext = /*#__PURE__*/createContext(defaultTheme);
|
|
4747
4734
|
var ThemeContextProvider = function ThemeContextProvider(_ref) {
|
|
4748
4735
|
var customTheme = _ref.customTheme,
|
|
@@ -4921,7 +4908,7 @@ var useSwap = function useSwap(params) {
|
|
|
4921
4908
|
AccountId = params.AccountId,
|
|
4922
4909
|
poolFetchingState = params.poolFetchingState,
|
|
4923
4910
|
referralId = params.referralId,
|
|
4924
|
-
|
|
4911
|
+
tokens = params.tokens;
|
|
4925
4912
|
var tokenIn = params.tokenIn,
|
|
4926
4913
|
tokenOut = params.tokenOut,
|
|
4927
4914
|
amountIn = params.amountIn;
|
|
@@ -4943,6 +4930,15 @@ var useSwap = function useSwap(params) {
|
|
|
4943
4930
|
var _useState14 = useState(false),
|
|
4944
4931
|
forceEstimate = _useState14[0],
|
|
4945
4932
|
setForceEstimate = _useState14[1];
|
|
4933
|
+
var _useTokenBalances = useTokenBalances(tokens, AccountId),
|
|
4934
|
+
balances = _useTokenBalances.balances,
|
|
4935
|
+
updateTokenBalance = _useTokenBalances.updateTokenBalance;
|
|
4936
|
+
var tokenInBalance = useMemo(function () {
|
|
4937
|
+
return balances[tokenIn == null ? void 0 : tokenIn.id];
|
|
4938
|
+
}, [tokenIn, balances]);
|
|
4939
|
+
var tokenOutBalance = useMemo(function () {
|
|
4940
|
+
return balances[tokenOut == null ? void 0 : tokenOut.id] || '';
|
|
4941
|
+
}, [tokenOut, balances]);
|
|
4946
4942
|
var minAmountOut = amountOut ? percentLess(slippageTolerance, amountOut) : '';
|
|
4947
4943
|
var fee = !params.tokenOut || !params.tokenIn ? 0 : getAvgFee(estimates, params.tokenOut.id, toNonDivisibleNumber(params.tokenIn.decimals, params.amountIn));
|
|
4948
4944
|
var rate = calculateExchangeRate(ONLY_ZEROS.test(params.amountIn) ? '1' : params.amountIn, amountOut || '1');
|
|
@@ -4984,8 +4980,16 @@ var useSwap = function useSwap(params) {
|
|
|
4984
4980
|
_minAmountOut = percentLess(slippageTolerance, scientificNotationToString(bigEstimate.toString()));
|
|
4985
4981
|
transactionsRef.push(nearWithdrawTransaction(_minAmountOut));
|
|
4986
4982
|
}
|
|
4987
|
-
|
|
4988
|
-
|
|
4983
|
+
_context3.next = 9;
|
|
4984
|
+
return onSwap(transactionsRef);
|
|
4985
|
+
case 9:
|
|
4986
|
+
setTimeout(function () {
|
|
4987
|
+
var tokensToUpdate = [];
|
|
4988
|
+
if (tokenIn) tokensToUpdate.push(tokenIn.id);
|
|
4989
|
+
if (tokenOut) tokensToUpdate.push(tokenOut.id);
|
|
4990
|
+
if (tokensToUpdate.length > 0 && AccountId) updateTokenBalance(tokensToUpdate, AccountId);
|
|
4991
|
+
}, 3000);
|
|
4992
|
+
case 10:
|
|
4989
4993
|
case "end":
|
|
4990
4994
|
return _context3.stop();
|
|
4991
4995
|
}
|
|
@@ -5047,6 +5051,9 @@ var useSwap = function useSwap(params) {
|
|
|
5047
5051
|
return {
|
|
5048
5052
|
amountOut: amountOut,
|
|
5049
5053
|
minAmountOut: minAmountOut,
|
|
5054
|
+
balances: balances,
|
|
5055
|
+
tokenInBalance: tokenInBalance,
|
|
5056
|
+
tokenOutBalance: tokenOutBalance,
|
|
5050
5057
|
fee: fee,
|
|
5051
5058
|
rate: rate,
|
|
5052
5059
|
estimates: estimates,
|
|
@@ -5074,30 +5081,108 @@ var TokenPriceContextProvider = function TokenPriceContextProvider(_ref7) {
|
|
|
5074
5081
|
value: tokenPriceList
|
|
5075
5082
|
}, children);
|
|
5076
5083
|
};
|
|
5077
|
-
var
|
|
5084
|
+
var useTokenBalances = function useTokenBalances(tokens, AccountId) {
|
|
5078
5085
|
var _useState16 = useState({}),
|
|
5079
5086
|
balances = _useState16[0],
|
|
5080
5087
|
setBalances = _useState16[1];
|
|
5088
|
+
var updateTokenBalance = useCallback( /*#__PURE__*/function () {
|
|
5089
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(tokenIds, AccountId) {
|
|
5090
|
+
var updatedTokensBalancesMap;
|
|
5091
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5092
|
+
while (1) {
|
|
5093
|
+
switch (_context5.prev = _context5.next) {
|
|
5094
|
+
case 0:
|
|
5095
|
+
updatedTokensBalancesMap = {};
|
|
5096
|
+
_context5.next = 3;
|
|
5097
|
+
return Promise.all(tokenIds.map( /*#__PURE__*/function () {
|
|
5098
|
+
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(tokenId) {
|
|
5099
|
+
var _tokens$find;
|
|
5100
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
5101
|
+
while (1) {
|
|
5102
|
+
switch (_context4.prev = _context4.next) {
|
|
5103
|
+
case 0:
|
|
5104
|
+
_context4.t0 = toReadableNumber;
|
|
5105
|
+
_context4.t1 = ((_tokens$find = tokens.find(function (t) {
|
|
5106
|
+
return t.id === tokenId;
|
|
5107
|
+
})) == null ? void 0 : _tokens$find.decimals) || 0;
|
|
5108
|
+
_context4.next = 4;
|
|
5109
|
+
return ftGetBalance(tokenId === WRAP_NEAR_CONTRACT_ID ? 'NEAR' : tokenId, AccountId);
|
|
5110
|
+
case 4:
|
|
5111
|
+
_context4.t2 = _context4.sent;
|
|
5112
|
+
updatedTokensBalancesMap[tokenId] = (0, _context4.t0)(_context4.t1, _context4.t2);
|
|
5113
|
+
case 6:
|
|
5114
|
+
case "end":
|
|
5115
|
+
return _context4.stop();
|
|
5116
|
+
}
|
|
5117
|
+
}
|
|
5118
|
+
}, _callee4);
|
|
5119
|
+
}));
|
|
5120
|
+
return function (_x3) {
|
|
5121
|
+
return _ref9.apply(this, arguments);
|
|
5122
|
+
};
|
|
5123
|
+
}()));
|
|
5124
|
+
case 3:
|
|
5125
|
+
setBalances(function (prevState) {
|
|
5126
|
+
return _extends({}, prevState, updatedTokensBalancesMap);
|
|
5127
|
+
});
|
|
5128
|
+
case 4:
|
|
5129
|
+
case "end":
|
|
5130
|
+
return _context5.stop();
|
|
5131
|
+
}
|
|
5132
|
+
}
|
|
5133
|
+
}, _callee5);
|
|
5134
|
+
}));
|
|
5135
|
+
return function (_x, _x2) {
|
|
5136
|
+
return _ref8.apply(this, arguments);
|
|
5137
|
+
};
|
|
5138
|
+
}(), [tokens]);
|
|
5081
5139
|
useEffect(function () {
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5140
|
+
// Initializes token balances
|
|
5141
|
+
// Called in 1 minute intervals
|
|
5142
|
+
var initTokenBalances = /*#__PURE__*/function () {
|
|
5143
|
+
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
5144
|
+
var validTokens, ids;
|
|
5145
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
5146
|
+
while (1) {
|
|
5147
|
+
switch (_context6.prev = _context6.next) {
|
|
5148
|
+
case 0:
|
|
5149
|
+
if (AccountId) {
|
|
5150
|
+
_context6.next = 3;
|
|
5151
|
+
break;
|
|
5152
|
+
}
|
|
5153
|
+
setBalances({});
|
|
5154
|
+
return _context6.abrupt("return");
|
|
5155
|
+
case 3:
|
|
5156
|
+
validTokens = tokens.filter(function (t) {
|
|
5157
|
+
return !!(t != null && t.id);
|
|
5158
|
+
});
|
|
5159
|
+
ids = validTokens.map(function (token) {
|
|
5160
|
+
return token.id;
|
|
5161
|
+
});
|
|
5162
|
+
updateTokenBalance(ids, AccountId);
|
|
5163
|
+
case 6:
|
|
5164
|
+
case "end":
|
|
5165
|
+
return _context6.stop();
|
|
5166
|
+
}
|
|
5167
|
+
}
|
|
5168
|
+
}, _callee6);
|
|
5169
|
+
}));
|
|
5170
|
+
return function initTokenBalances() {
|
|
5171
|
+
return _ref10.apply(this, arguments);
|
|
5172
|
+
};
|
|
5173
|
+
}();
|
|
5174
|
+
initTokenBalances();
|
|
5175
|
+
var interval = setInterval(initTokenBalances, 60000);
|
|
5176
|
+
return function () {
|
|
5177
|
+
return clearInterval(interval);
|
|
5178
|
+
};
|
|
5179
|
+
}, [AccountId, tokens.map(function (t) {
|
|
5098
5180
|
return t == null ? void 0 : t.id;
|
|
5099
5181
|
}).join('-')]);
|
|
5100
|
-
return
|
|
5182
|
+
return {
|
|
5183
|
+
balances: balances,
|
|
5184
|
+
updateTokenBalance: updateTokenBalance
|
|
5185
|
+
};
|
|
5101
5186
|
};
|
|
5102
5187
|
|
|
5103
5188
|
function styleInject(css, ref) {
|
|
@@ -5127,7 +5212,7 @@ function styleInject(css, ref) {
|
|
|
5127
5212
|
}
|
|
5128
5213
|
}
|
|
5129
5214
|
|
|
5130
|
-
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 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.__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";
|
|
5215
|
+
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";
|
|
5131
5216
|
styleInject(css_248z);
|
|
5132
5217
|
|
|
5133
5218
|
var getPriceImpact$1 = function getPriceImpact(value, tokenIn, tokenInAmount) {
|
|
@@ -5440,6 +5525,8 @@ var HalfAndMaxAmount = function HalfAndMaxAmount(_ref6) {
|
|
|
5440
5525
|
}
|
|
5441
5526
|
}, "Max"));
|
|
5442
5527
|
};
|
|
5528
|
+
var DECIMAL_POINT = '.';
|
|
5529
|
+
var ALLOWED_KEYS = ['Backspace', 'Tab', 'ArrowLeft', 'ArrowRight', 'Delete', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', DECIMAL_POINT];
|
|
5443
5530
|
var TokenAmount = function TokenAmount(props) {
|
|
5444
5531
|
var _ref$current2;
|
|
5445
5532
|
var balance = props.balance,
|
|
@@ -5460,6 +5547,28 @@ var TokenAmount = function TokenAmount(props) {
|
|
|
5460
5547
|
var _useState5 = useState(false),
|
|
5461
5548
|
hoverSelect = _useState5[0],
|
|
5462
5549
|
setHoverSelect = _useState5[1];
|
|
5550
|
+
var handleKeyDown = function handleKeyDown(event) {
|
|
5551
|
+
if (!ALLOWED_KEYS.includes(event.key) && !event.ctrlKey) {
|
|
5552
|
+
event.preventDefault();
|
|
5553
|
+
}
|
|
5554
|
+
var isDecimalPoint = event.key === DECIMAL_POINT;
|
|
5555
|
+
if (!isDecimalPoint) return;
|
|
5556
|
+
// Ensure only one dot is allowed
|
|
5557
|
+
var inputValue = event.target.value;
|
|
5558
|
+
if (inputValue.includes(DECIMAL_POINT)) {
|
|
5559
|
+
event.preventDefault();
|
|
5560
|
+
}
|
|
5561
|
+
// prohibit only one dot
|
|
5562
|
+
if (inputValue.length === 0) {
|
|
5563
|
+
event.preventDefault();
|
|
5564
|
+
}
|
|
5565
|
+
};
|
|
5566
|
+
var handlePaste = function handlePaste(event) {
|
|
5567
|
+
var paste = event.clipboardData.getData('text');
|
|
5568
|
+
if (!/^[0-9.]+$/.test(paste)) {
|
|
5569
|
+
event.preventDefault();
|
|
5570
|
+
}
|
|
5571
|
+
};
|
|
5463
5572
|
var handleChange = function handleChange(amount) {
|
|
5464
5573
|
if (onChangeAmount) {
|
|
5465
5574
|
onChangeAmount(amount);
|
|
@@ -5505,7 +5614,8 @@ var TokenAmount = function TokenAmount(props) {
|
|
|
5505
5614
|
}, !token ? React.createElement(React.Fragment, null, React.createElement("span", {
|
|
5506
5615
|
style: {
|
|
5507
5616
|
whiteSpace: 'nowrap',
|
|
5508
|
-
height: '26px'
|
|
5617
|
+
height: '26px',
|
|
5618
|
+
userSelect: 'none'
|
|
5509
5619
|
},
|
|
5510
5620
|
className: "__ref-swap-widget-row-flex-center"
|
|
5511
5621
|
}, "Select Token")) : React.createElement(React.Fragment, null, React.createElement("img", {
|
|
@@ -5540,16 +5650,16 @@ var TokenAmount = function TokenAmount(props) {
|
|
|
5540
5650
|
}, React.createElement("input", {
|
|
5541
5651
|
ref: ref,
|
|
5542
5652
|
max: !!onChangeAmount ? curMax : undefined,
|
|
5543
|
-
min: "0",
|
|
5544
5653
|
onWheel: function onWheel() {
|
|
5545
5654
|
if (ref.current) {
|
|
5546
5655
|
ref.current.blur();
|
|
5547
5656
|
}
|
|
5548
5657
|
},
|
|
5549
5658
|
className: "__ref-swap-widget-input-class",
|
|
5550
|
-
step: "any",
|
|
5551
5659
|
value: amount,
|
|
5552
|
-
type: "
|
|
5660
|
+
type: "text",
|
|
5661
|
+
onKeyDown: handleKeyDown,
|
|
5662
|
+
onPaste: handlePaste,
|
|
5553
5663
|
placeholder: !onChangeAmount ? '-' : '0.0',
|
|
5554
5664
|
onChange: function onChange(_ref7) {
|
|
5555
5665
|
var target = _ref7.target;
|
|
@@ -5557,9 +5667,6 @@ var TokenAmount = function TokenAmount(props) {
|
|
|
5557
5667
|
handleChange(target.value);
|
|
5558
5668
|
},
|
|
5559
5669
|
disabled: !onChangeAmount,
|
|
5560
|
-
onKeyDown: function onKeyDown(e) {
|
|
5561
|
-
return symbolsArr.includes(e.key) && e.preventDefault();
|
|
5562
|
-
},
|
|
5563
5670
|
style: {
|
|
5564
5671
|
color: primary,
|
|
5565
5672
|
marginBottom: '8px',
|
|
@@ -6407,15 +6514,9 @@ var SwapWidget = function SwapWidget(props) {
|
|
|
6407
6514
|
var _useState2 = useState(),
|
|
6408
6515
|
tokenOut = _useState2[0],
|
|
6409
6516
|
setTokenOut = _useState2[1];
|
|
6410
|
-
var _useState3 = useState(
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
var _useState4 = useState(''),
|
|
6414
|
-
tokenOutBalance = _useState4[0],
|
|
6415
|
-
setTokenOutBalance = _useState4[1];
|
|
6416
|
-
var _useState5 = useState(false),
|
|
6417
|
-
notOpen = _useState5[0],
|
|
6418
|
-
setNotOpen = _useState5[1];
|
|
6517
|
+
var _useState3 = useState(false),
|
|
6518
|
+
notOpen = _useState3[0],
|
|
6519
|
+
setNotOpen = _useState3[1];
|
|
6419
6520
|
useEffect(function () {
|
|
6420
6521
|
if (!transactionState) return;
|
|
6421
6522
|
if (transactionState && transactionState.state !== null) {
|
|
@@ -6423,18 +6524,18 @@ var SwapWidget = function SwapWidget(props) {
|
|
|
6423
6524
|
}
|
|
6424
6525
|
transactionState == null ? void 0 : transactionState.setState((transactionState == null ? void 0 : transactionState.state) || null);
|
|
6425
6526
|
}, [transactionState]);
|
|
6426
|
-
var
|
|
6427
|
-
widgetRoute =
|
|
6428
|
-
setWidgetRoute =
|
|
6429
|
-
var
|
|
6430
|
-
amountIn =
|
|
6431
|
-
setAmountIn =
|
|
6432
|
-
var
|
|
6433
|
-
showSlip =
|
|
6434
|
-
setShowSlip =
|
|
6435
|
-
var
|
|
6436
|
-
slippageTolerance =
|
|
6437
|
-
setSlippageTolerance =
|
|
6527
|
+
var _useState4 = useState('swap'),
|
|
6528
|
+
widgetRoute = _useState4[0],
|
|
6529
|
+
setWidgetRoute = _useState4[1];
|
|
6530
|
+
var _useState5 = useState('1'),
|
|
6531
|
+
amountIn = _useState5[0],
|
|
6532
|
+
setAmountIn = _useState5[1];
|
|
6533
|
+
var _useState6 = useState(false),
|
|
6534
|
+
showSlip = _useState6[0],
|
|
6535
|
+
setShowSlip = _useState6[1];
|
|
6536
|
+
var _useState7 = useState(0.5),
|
|
6537
|
+
slippageTolerance = _useState7[0],
|
|
6538
|
+
setSlippageTolerance = _useState7[1];
|
|
6438
6539
|
var _useTokensIndexer = useTokensIndexer({
|
|
6439
6540
|
defaultTokenList: defaultTokenList,
|
|
6440
6541
|
AccountId: AccountId
|
|
@@ -6445,10 +6546,9 @@ var SwapWidget = function SwapWidget(props) {
|
|
|
6445
6546
|
useAllTokens({
|
|
6446
6547
|
reload: true
|
|
6447
6548
|
});
|
|
6448
|
-
var
|
|
6449
|
-
|
|
6450
|
-
|
|
6451
|
-
setRreshTrigger = _useState10[1];
|
|
6549
|
+
var _useState8 = useState(false),
|
|
6550
|
+
refreshTrigger = _useState8[0],
|
|
6551
|
+
setRreshTrigger = _useState8[1];
|
|
6452
6552
|
var tokenPriceList = useTokenPriceList();
|
|
6453
6553
|
var _useRefPools = useRefPools(refreshTrigger),
|
|
6454
6554
|
allPools = _useRefPools.allPools,
|
|
@@ -6490,28 +6590,6 @@ var SwapWidget = function SwapWidget(props) {
|
|
|
6490
6590
|
handleSetTokenOut(REF_META_DATA);
|
|
6491
6591
|
}
|
|
6492
6592
|
}, [tokens, tokenLoading]);
|
|
6493
|
-
useEffect(function () {
|
|
6494
|
-
if (!tokenIn) return;
|
|
6495
|
-
var wrapedId = tokenIn.id === WRAP_NEAR_CONTRACT_ID ? 'NEAR' : tokenIn.id;
|
|
6496
|
-
if (balances[wrapedId]) {
|
|
6497
|
-
setTokenInBalance(balances[wrapedId]);
|
|
6498
|
-
return;
|
|
6499
|
-
}
|
|
6500
|
-
ftGetBalance(wrapedId, AccountId).then(function (available) {
|
|
6501
|
-
setTokenInBalance(toReadableNumber(tokenIn.decimals, available));
|
|
6502
|
-
});
|
|
6503
|
-
}, [tokenIn, AccountId, balances]);
|
|
6504
|
-
useEffect(function () {
|
|
6505
|
-
if (!tokenOut) return;
|
|
6506
|
-
var wrapedId = tokenOut.id === WRAP_NEAR_CONTRACT_ID ? 'NEAR' : tokenOut.id;
|
|
6507
|
-
if (balances[wrapedId]) {
|
|
6508
|
-
setTokenOutBalance(balances[wrapedId]);
|
|
6509
|
-
return;
|
|
6510
|
-
}
|
|
6511
|
-
ftGetBalance(wrapedId, AccountId).then(function (available) {
|
|
6512
|
-
setTokenOutBalance(toReadableNumber(tokenOut.decimals, available));
|
|
6513
|
-
});
|
|
6514
|
-
}, [tokenOut, AccountId, balances]);
|
|
6515
6593
|
var _useSwap = useSwap({
|
|
6516
6594
|
tokenIn: tokenIn,
|
|
6517
6595
|
tokenOut: tokenOut,
|
|
@@ -6533,10 +6611,14 @@ var SwapWidget = function SwapWidget(props) {
|
|
|
6533
6611
|
AccountId: AccountId,
|
|
6534
6612
|
refreshTrigger: refreshTrigger,
|
|
6535
6613
|
poolFetchingState: poolFetchingState,
|
|
6536
|
-
referralId: referralId
|
|
6614
|
+
referralId: referralId,
|
|
6615
|
+
tokens: tokens
|
|
6537
6616
|
}),
|
|
6538
6617
|
amountOut = _useSwap.amountOut,
|
|
6539
6618
|
minAmountOut = _useSwap.minAmountOut,
|
|
6619
|
+
balances = _useSwap.balances,
|
|
6620
|
+
tokenInBalance = _useSwap.tokenInBalance,
|
|
6621
|
+
tokenOutBalance = _useSwap.tokenOutBalance,
|
|
6540
6622
|
rate = _useSwap.rate,
|
|
6541
6623
|
fee = _useSwap.fee,
|
|
6542
6624
|
estimates = _useSwap.estimates,
|
|
@@ -6561,6 +6643,9 @@ var SwapWidget = function SwapWidget(props) {
|
|
|
6561
6643
|
makeSwap();
|
|
6562
6644
|
};
|
|
6563
6645
|
var canSubmit = tokenIn && tokenOut && canSwap && !swapError && isSignedIn && new Big(tokenInBalance || '0').gte(amountIn || '0') && slippageTolerance > 0 && slippageTolerance < 100 && !ONLY_ZEROS.test(tokenInBalance);
|
|
6646
|
+
var tokensLoaded = useMemo(function () {
|
|
6647
|
+
return tokens.length > 0;
|
|
6648
|
+
}, [tokens]);
|
|
6564
6649
|
return React.createElement(ThemeContextProvider, {
|
|
6565
6650
|
customTheme: curTheme
|
|
6566
6651
|
}, React.createElement(TokenPriceContextProvider, null, widgetRoute === 'swap' && React.createElement("form", {
|
|
@@ -6602,6 +6687,7 @@ var SwapWidget = function SwapWidget(props) {
|
|
|
6602
6687
|
price: !tokenIn ? null : tokenPriceList == null ? void 0 : (_tokenPriceList$token = tokenPriceList[tokenIn.id]) == null ? void 0 : _tokenPriceList$token.price,
|
|
6603
6688
|
onChangeAmount: setAmountIn,
|
|
6604
6689
|
onSelectToken: function onSelectToken() {
|
|
6690
|
+
if (!tokensLoaded) return;
|
|
6605
6691
|
setWidgetRoute('token-selector-in');
|
|
6606
6692
|
}
|
|
6607
6693
|
}), React.createElement("div", {
|
|
@@ -6627,6 +6713,7 @@ var SwapWidget = function SwapWidget(props) {
|
|
|
6627
6713
|
token: tokenOut,
|
|
6628
6714
|
price: !tokenOut ? null : tokenPriceList == null ? void 0 : (_tokenPriceList$token2 = tokenPriceList[tokenOut.id]) == null ? void 0 : _tokenPriceList$token2.price,
|
|
6629
6715
|
onSelectToken: function onSelectToken() {
|
|
6716
|
+
if (!tokensLoaded) return;
|
|
6630
6717
|
setWidgetRoute('token-selector-out');
|
|
6631
6718
|
},
|
|
6632
6719
|
onForceUpdate: function onForceUpdate() {
|
|
@@ -6663,7 +6750,9 @@ var SwapWidget = function SwapWidget(props) {
|
|
|
6663
6750
|
cursor: !canSubmit ? 'not-allowed' : 'pointer'
|
|
6664
6751
|
},
|
|
6665
6752
|
disabled: !canSubmit
|
|
6666
|
-
}, 'Swap'
|
|
6753
|
+
}, tokensLoaded ? 'Swap' : React.createElement("div", {
|
|
6754
|
+
className: "__ref-swap-widget-submit-button-loader"
|
|
6755
|
+
})) : React.createElement("button", {
|
|
6667
6756
|
type: "button",
|
|
6668
6757
|
className: "__ref-swap-widget-submit-button __ref-swap-widget-button",
|
|
6669
6758
|
onClick: onConnect,
|