@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
|
@@ -512,18 +512,6 @@
|
|
|
512
512
|
};
|
|
513
513
|
return _extends.apply(this, arguments);
|
|
514
514
|
}
|
|
515
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
516
|
-
if (source == null) return {};
|
|
517
|
-
var target = {};
|
|
518
|
-
var sourceKeys = Object.keys(source);
|
|
519
|
-
var key, i;
|
|
520
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
521
|
-
key = sourceKeys[i];
|
|
522
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
523
|
-
target[key] = source[key];
|
|
524
|
-
}
|
|
525
|
-
return target;
|
|
526
|
-
}
|
|
527
515
|
function _unsupportedIterableToArray(o, minLen) {
|
|
528
516
|
if (!o) return;
|
|
529
517
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
@@ -4729,7 +4717,6 @@
|
|
|
4729
4717
|
};
|
|
4730
4718
|
}();
|
|
4731
4719
|
|
|
4732
|
-
var _excluded = ["slippageTolerance", "refreshTrigger", "onSwap", "AccountId", "poolFetchingState", "referralId"];
|
|
4733
4720
|
var ThemeContext = /*#__PURE__*/React.createContext(defaultTheme);
|
|
4734
4721
|
var ThemeContextProvider = function ThemeContextProvider(_ref) {
|
|
4735
4722
|
var customTheme = _ref.customTheme,
|
|
@@ -4908,7 +4895,7 @@
|
|
|
4908
4895
|
AccountId = params.AccountId,
|
|
4909
4896
|
poolFetchingState = params.poolFetchingState,
|
|
4910
4897
|
referralId = params.referralId,
|
|
4911
|
-
|
|
4898
|
+
tokens = params.tokens;
|
|
4912
4899
|
var tokenIn = params.tokenIn,
|
|
4913
4900
|
tokenOut = params.tokenOut,
|
|
4914
4901
|
amountIn = params.amountIn;
|
|
@@ -4930,6 +4917,15 @@
|
|
|
4930
4917
|
var _useState14 = React.useState(false),
|
|
4931
4918
|
forceEstimate = _useState14[0],
|
|
4932
4919
|
setForceEstimate = _useState14[1];
|
|
4920
|
+
var _useTokenBalances = useTokenBalances(tokens, AccountId),
|
|
4921
|
+
balances = _useTokenBalances.balances,
|
|
4922
|
+
updateTokenBalance = _useTokenBalances.updateTokenBalance;
|
|
4923
|
+
var tokenInBalance = React.useMemo(function () {
|
|
4924
|
+
return balances[tokenIn == null ? void 0 : tokenIn.id];
|
|
4925
|
+
}, [tokenIn, balances]);
|
|
4926
|
+
var tokenOutBalance = React.useMemo(function () {
|
|
4927
|
+
return balances[tokenOut == null ? void 0 : tokenOut.id] || '';
|
|
4928
|
+
}, [tokenOut, balances]);
|
|
4933
4929
|
var minAmountOut = amountOut ? percentLess(slippageTolerance, amountOut) : '';
|
|
4934
4930
|
var fee = !params.tokenOut || !params.tokenIn ? 0 : getAvgFee(estimates, params.tokenOut.id, toNonDivisibleNumber(params.tokenIn.decimals, params.amountIn));
|
|
4935
4931
|
var rate = calculateExchangeRate(ONLY_ZEROS.test(params.amountIn) ? '1' : params.amountIn, amountOut || '1');
|
|
@@ -4971,8 +4967,16 @@
|
|
|
4971
4967
|
_minAmountOut = percentLess(slippageTolerance, scientificNotationToString(bigEstimate.toString()));
|
|
4972
4968
|
transactionsRef.push(nearWithdrawTransaction(_minAmountOut));
|
|
4973
4969
|
}
|
|
4974
|
-
|
|
4975
|
-
|
|
4970
|
+
_context3.next = 9;
|
|
4971
|
+
return onSwap(transactionsRef);
|
|
4972
|
+
case 9:
|
|
4973
|
+
setTimeout(function () {
|
|
4974
|
+
var tokensToUpdate = [];
|
|
4975
|
+
if (tokenIn) tokensToUpdate.push(tokenIn.id);
|
|
4976
|
+
if (tokenOut) tokensToUpdate.push(tokenOut.id);
|
|
4977
|
+
if (tokensToUpdate.length > 0 && AccountId) updateTokenBalance(tokensToUpdate, AccountId);
|
|
4978
|
+
}, 3000);
|
|
4979
|
+
case 10:
|
|
4976
4980
|
case "end":
|
|
4977
4981
|
return _context3.stop();
|
|
4978
4982
|
}
|
|
@@ -5034,6 +5038,9 @@
|
|
|
5034
5038
|
return {
|
|
5035
5039
|
amountOut: amountOut,
|
|
5036
5040
|
minAmountOut: minAmountOut,
|
|
5041
|
+
balances: balances,
|
|
5042
|
+
tokenInBalance: tokenInBalance,
|
|
5043
|
+
tokenOutBalance: tokenOutBalance,
|
|
5037
5044
|
fee: fee,
|
|
5038
5045
|
rate: rate,
|
|
5039
5046
|
estimates: estimates,
|
|
@@ -5061,30 +5068,108 @@
|
|
|
5061
5068
|
value: tokenPriceList
|
|
5062
5069
|
}, children);
|
|
5063
5070
|
};
|
|
5064
|
-
var
|
|
5071
|
+
var useTokenBalances = function useTokenBalances(tokens, AccountId) {
|
|
5065
5072
|
var _useState16 = React.useState({}),
|
|
5066
5073
|
balances = _useState16[0],
|
|
5067
5074
|
setBalances = _useState16[1];
|
|
5075
|
+
var updateTokenBalance = React.useCallback( /*#__PURE__*/function () {
|
|
5076
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(tokenIds, AccountId) {
|
|
5077
|
+
var updatedTokensBalancesMap;
|
|
5078
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5079
|
+
while (1) {
|
|
5080
|
+
switch (_context5.prev = _context5.next) {
|
|
5081
|
+
case 0:
|
|
5082
|
+
updatedTokensBalancesMap = {};
|
|
5083
|
+
_context5.next = 3;
|
|
5084
|
+
return Promise.all(tokenIds.map( /*#__PURE__*/function () {
|
|
5085
|
+
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(tokenId) {
|
|
5086
|
+
var _tokens$find;
|
|
5087
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
5088
|
+
while (1) {
|
|
5089
|
+
switch (_context4.prev = _context4.next) {
|
|
5090
|
+
case 0:
|
|
5091
|
+
_context4.t0 = toReadableNumber;
|
|
5092
|
+
_context4.t1 = ((_tokens$find = tokens.find(function (t) {
|
|
5093
|
+
return t.id === tokenId;
|
|
5094
|
+
})) == null ? void 0 : _tokens$find.decimals) || 0;
|
|
5095
|
+
_context4.next = 4;
|
|
5096
|
+
return ftGetBalance(tokenId === exports.WRAP_NEAR_CONTRACT_ID ? 'NEAR' : tokenId, AccountId);
|
|
5097
|
+
case 4:
|
|
5098
|
+
_context4.t2 = _context4.sent;
|
|
5099
|
+
updatedTokensBalancesMap[tokenId] = (0, _context4.t0)(_context4.t1, _context4.t2);
|
|
5100
|
+
case 6:
|
|
5101
|
+
case "end":
|
|
5102
|
+
return _context4.stop();
|
|
5103
|
+
}
|
|
5104
|
+
}
|
|
5105
|
+
}, _callee4);
|
|
5106
|
+
}));
|
|
5107
|
+
return function (_x3) {
|
|
5108
|
+
return _ref9.apply(this, arguments);
|
|
5109
|
+
};
|
|
5110
|
+
}()));
|
|
5111
|
+
case 3:
|
|
5112
|
+
setBalances(function (prevState) {
|
|
5113
|
+
return _extends({}, prevState, updatedTokensBalancesMap);
|
|
5114
|
+
});
|
|
5115
|
+
case 4:
|
|
5116
|
+
case "end":
|
|
5117
|
+
return _context5.stop();
|
|
5118
|
+
}
|
|
5119
|
+
}
|
|
5120
|
+
}, _callee5);
|
|
5121
|
+
}));
|
|
5122
|
+
return function (_x, _x2) {
|
|
5123
|
+
return _ref8.apply(this, arguments);
|
|
5124
|
+
};
|
|
5125
|
+
}(), [tokens]);
|
|
5068
5126
|
React.useEffect(function () {
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5127
|
+
// Initializes token balances
|
|
5128
|
+
// Called in 1 minute intervals
|
|
5129
|
+
var initTokenBalances = /*#__PURE__*/function () {
|
|
5130
|
+
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
5131
|
+
var validTokens, ids;
|
|
5132
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
5133
|
+
while (1) {
|
|
5134
|
+
switch (_context6.prev = _context6.next) {
|
|
5135
|
+
case 0:
|
|
5136
|
+
if (AccountId) {
|
|
5137
|
+
_context6.next = 3;
|
|
5138
|
+
break;
|
|
5139
|
+
}
|
|
5140
|
+
setBalances({});
|
|
5141
|
+
return _context6.abrupt("return");
|
|
5142
|
+
case 3:
|
|
5143
|
+
validTokens = tokens.filter(function (t) {
|
|
5144
|
+
return !!(t != null && t.id);
|
|
5145
|
+
});
|
|
5146
|
+
ids = validTokens.map(function (token) {
|
|
5147
|
+
return token.id;
|
|
5148
|
+
});
|
|
5149
|
+
updateTokenBalance(ids, AccountId);
|
|
5150
|
+
case 6:
|
|
5151
|
+
case "end":
|
|
5152
|
+
return _context6.stop();
|
|
5153
|
+
}
|
|
5154
|
+
}
|
|
5155
|
+
}, _callee6);
|
|
5156
|
+
}));
|
|
5157
|
+
return function initTokenBalances() {
|
|
5158
|
+
return _ref10.apply(this, arguments);
|
|
5159
|
+
};
|
|
5160
|
+
}();
|
|
5161
|
+
initTokenBalances();
|
|
5162
|
+
var interval = setInterval(initTokenBalances, 60000);
|
|
5163
|
+
return function () {
|
|
5164
|
+
return clearInterval(interval);
|
|
5165
|
+
};
|
|
5166
|
+
}, [AccountId, tokens.map(function (t) {
|
|
5085
5167
|
return t == null ? void 0 : t.id;
|
|
5086
5168
|
}).join('-')]);
|
|
5087
|
-
return
|
|
5169
|
+
return {
|
|
5170
|
+
balances: balances,
|
|
5171
|
+
updateTokenBalance: updateTokenBalance
|
|
5172
|
+
};
|
|
5088
5173
|
};
|
|
5089
5174
|
|
|
5090
5175
|
function styleInject(css, ref) {
|
|
@@ -5114,7 +5199,7 @@
|
|
|
5114
5199
|
}
|
|
5115
5200
|
}
|
|
5116
5201
|
|
|
5117
|
-
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";
|
|
5202
|
+
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";
|
|
5118
5203
|
styleInject(css_248z);
|
|
5119
5204
|
|
|
5120
5205
|
var getPriceImpact$1 = function getPriceImpact(value, tokenIn, tokenInAmount) {
|
|
@@ -5427,6 +5512,8 @@
|
|
|
5427
5512
|
}
|
|
5428
5513
|
}, "Max"));
|
|
5429
5514
|
};
|
|
5515
|
+
var DECIMAL_POINT = '.';
|
|
5516
|
+
var ALLOWED_KEYS = ['Backspace', 'Tab', 'ArrowLeft', 'ArrowRight', 'Delete', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', DECIMAL_POINT];
|
|
5430
5517
|
var TokenAmount = function TokenAmount(props) {
|
|
5431
5518
|
var _ref$current2;
|
|
5432
5519
|
var balance = props.balance,
|
|
@@ -5447,6 +5534,28 @@
|
|
|
5447
5534
|
var _useState5 = React.useState(false),
|
|
5448
5535
|
hoverSelect = _useState5[0],
|
|
5449
5536
|
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
|
+
};
|
|
5450
5559
|
var handleChange = function handleChange(amount) {
|
|
5451
5560
|
if (onChangeAmount) {
|
|
5452
5561
|
onChangeAmount(amount);
|
|
@@ -5492,7 +5601,8 @@
|
|
|
5492
5601
|
}, !token ? React__default.createElement(React__default.Fragment, null, React__default.createElement("span", {
|
|
5493
5602
|
style: {
|
|
5494
5603
|
whiteSpace: 'nowrap',
|
|
5495
|
-
height: '26px'
|
|
5604
|
+
height: '26px',
|
|
5605
|
+
userSelect: 'none'
|
|
5496
5606
|
},
|
|
5497
5607
|
className: "__ref-swap-widget-row-flex-center"
|
|
5498
5608
|
}, "Select Token")) : React__default.createElement(React__default.Fragment, null, React__default.createElement("img", {
|
|
@@ -5527,16 +5637,16 @@
|
|
|
5527
5637
|
}, React__default.createElement("input", {
|
|
5528
5638
|
ref: ref,
|
|
5529
5639
|
max: !!onChangeAmount ? curMax : undefined,
|
|
5530
|
-
min: "0",
|
|
5531
5640
|
onWheel: function onWheel() {
|
|
5532
5641
|
if (ref.current) {
|
|
5533
5642
|
ref.current.blur();
|
|
5534
5643
|
}
|
|
5535
5644
|
},
|
|
5536
5645
|
className: "__ref-swap-widget-input-class",
|
|
5537
|
-
step: "any",
|
|
5538
5646
|
value: amount,
|
|
5539
|
-
type: "
|
|
5647
|
+
type: "text",
|
|
5648
|
+
onKeyDown: handleKeyDown,
|
|
5649
|
+
onPaste: handlePaste,
|
|
5540
5650
|
placeholder: !onChangeAmount ? '-' : '0.0',
|
|
5541
5651
|
onChange: function onChange(_ref7) {
|
|
5542
5652
|
var target = _ref7.target;
|
|
@@ -5544,9 +5654,6 @@
|
|
|
5544
5654
|
handleChange(target.value);
|
|
5545
5655
|
},
|
|
5546
5656
|
disabled: !onChangeAmount,
|
|
5547
|
-
onKeyDown: function onKeyDown(e) {
|
|
5548
|
-
return symbolsArr.includes(e.key) && e.preventDefault();
|
|
5549
|
-
},
|
|
5550
5657
|
style: {
|
|
5551
5658
|
color: primary,
|
|
5552
5659
|
marginBottom: '8px',
|
|
@@ -6394,15 +6501,9 @@
|
|
|
6394
6501
|
var _useState2 = React.useState(),
|
|
6395
6502
|
tokenOut = _useState2[0],
|
|
6396
6503
|
setTokenOut = _useState2[1];
|
|
6397
|
-
var _useState3 = React.useState(
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
var _useState4 = React.useState(''),
|
|
6401
|
-
tokenOutBalance = _useState4[0],
|
|
6402
|
-
setTokenOutBalance = _useState4[1];
|
|
6403
|
-
var _useState5 = React.useState(false),
|
|
6404
|
-
notOpen = _useState5[0],
|
|
6405
|
-
setNotOpen = _useState5[1];
|
|
6504
|
+
var _useState3 = React.useState(false),
|
|
6505
|
+
notOpen = _useState3[0],
|
|
6506
|
+
setNotOpen = _useState3[1];
|
|
6406
6507
|
React.useEffect(function () {
|
|
6407
6508
|
if (!transactionState) return;
|
|
6408
6509
|
if (transactionState && transactionState.state !== null) {
|
|
@@ -6410,18 +6511,18 @@
|
|
|
6410
6511
|
}
|
|
6411
6512
|
transactionState == null ? void 0 : transactionState.setState((transactionState == null ? void 0 : transactionState.state) || null);
|
|
6412
6513
|
}, [transactionState]);
|
|
6413
|
-
var
|
|
6414
|
-
widgetRoute =
|
|
6415
|
-
setWidgetRoute =
|
|
6416
|
-
var
|
|
6417
|
-
amountIn =
|
|
6418
|
-
setAmountIn =
|
|
6419
|
-
var
|
|
6420
|
-
showSlip =
|
|
6421
|
-
setShowSlip =
|
|
6422
|
-
var
|
|
6423
|
-
slippageTolerance =
|
|
6424
|
-
setSlippageTolerance =
|
|
6514
|
+
var _useState4 = React.useState('swap'),
|
|
6515
|
+
widgetRoute = _useState4[0],
|
|
6516
|
+
setWidgetRoute = _useState4[1];
|
|
6517
|
+
var _useState5 = React.useState('1'),
|
|
6518
|
+
amountIn = _useState5[0],
|
|
6519
|
+
setAmountIn = _useState5[1];
|
|
6520
|
+
var _useState6 = React.useState(false),
|
|
6521
|
+
showSlip = _useState6[0],
|
|
6522
|
+
setShowSlip = _useState6[1];
|
|
6523
|
+
var _useState7 = React.useState(0.5),
|
|
6524
|
+
slippageTolerance = _useState7[0],
|
|
6525
|
+
setSlippageTolerance = _useState7[1];
|
|
6425
6526
|
var _useTokensIndexer = useTokensIndexer({
|
|
6426
6527
|
defaultTokenList: defaultTokenList,
|
|
6427
6528
|
AccountId: AccountId
|
|
@@ -6432,10 +6533,9 @@
|
|
|
6432
6533
|
useAllTokens({
|
|
6433
6534
|
reload: true
|
|
6434
6535
|
});
|
|
6435
|
-
var
|
|
6436
|
-
|
|
6437
|
-
|
|
6438
|
-
setRreshTrigger = _useState10[1];
|
|
6536
|
+
var _useState8 = React.useState(false),
|
|
6537
|
+
refreshTrigger = _useState8[0],
|
|
6538
|
+
setRreshTrigger = _useState8[1];
|
|
6439
6539
|
var tokenPriceList = useTokenPriceList();
|
|
6440
6540
|
var _useRefPools = useRefPools(refreshTrigger),
|
|
6441
6541
|
allPools = _useRefPools.allPools,
|
|
@@ -6477,28 +6577,6 @@
|
|
|
6477
6577
|
handleSetTokenOut(exports.REF_META_DATA);
|
|
6478
6578
|
}
|
|
6479
6579
|
}, [tokens, tokenLoading]);
|
|
6480
|
-
React.useEffect(function () {
|
|
6481
|
-
if (!tokenIn) return;
|
|
6482
|
-
var wrapedId = tokenIn.id === exports.WRAP_NEAR_CONTRACT_ID ? 'NEAR' : tokenIn.id;
|
|
6483
|
-
if (balances[wrapedId]) {
|
|
6484
|
-
setTokenInBalance(balances[wrapedId]);
|
|
6485
|
-
return;
|
|
6486
|
-
}
|
|
6487
|
-
ftGetBalance(wrapedId, AccountId).then(function (available) {
|
|
6488
|
-
setTokenInBalance(toReadableNumber(tokenIn.decimals, available));
|
|
6489
|
-
});
|
|
6490
|
-
}, [tokenIn, AccountId, balances]);
|
|
6491
|
-
React.useEffect(function () {
|
|
6492
|
-
if (!tokenOut) return;
|
|
6493
|
-
var wrapedId = tokenOut.id === exports.WRAP_NEAR_CONTRACT_ID ? 'NEAR' : tokenOut.id;
|
|
6494
|
-
if (balances[wrapedId]) {
|
|
6495
|
-
setTokenOutBalance(balances[wrapedId]);
|
|
6496
|
-
return;
|
|
6497
|
-
}
|
|
6498
|
-
ftGetBalance(wrapedId, AccountId).then(function (available) {
|
|
6499
|
-
setTokenOutBalance(toReadableNumber(tokenOut.decimals, available));
|
|
6500
|
-
});
|
|
6501
|
-
}, [tokenOut, AccountId, balances]);
|
|
6502
6580
|
var _useSwap = useSwap({
|
|
6503
6581
|
tokenIn: tokenIn,
|
|
6504
6582
|
tokenOut: tokenOut,
|
|
@@ -6520,10 +6598,14 @@
|
|
|
6520
6598
|
AccountId: AccountId,
|
|
6521
6599
|
refreshTrigger: refreshTrigger,
|
|
6522
6600
|
poolFetchingState: poolFetchingState,
|
|
6523
|
-
referralId: referralId
|
|
6601
|
+
referralId: referralId,
|
|
6602
|
+
tokens: tokens
|
|
6524
6603
|
}),
|
|
6525
6604
|
amountOut = _useSwap.amountOut,
|
|
6526
6605
|
minAmountOut = _useSwap.minAmountOut,
|
|
6606
|
+
balances = _useSwap.balances,
|
|
6607
|
+
tokenInBalance = _useSwap.tokenInBalance,
|
|
6608
|
+
tokenOutBalance = _useSwap.tokenOutBalance,
|
|
6527
6609
|
rate = _useSwap.rate,
|
|
6528
6610
|
fee = _useSwap.fee,
|
|
6529
6611
|
estimates = _useSwap.estimates,
|
|
@@ -6548,6 +6630,9 @@
|
|
|
6548
6630
|
makeSwap();
|
|
6549
6631
|
};
|
|
6550
6632
|
var canSubmit = tokenIn && tokenOut && canSwap && !swapError && isSignedIn && new Big(tokenInBalance || '0').gte(amountIn || '0') && slippageTolerance > 0 && slippageTolerance < 100 && !ONLY_ZEROS.test(tokenInBalance);
|
|
6633
|
+
var tokensLoaded = React.useMemo(function () {
|
|
6634
|
+
return tokens.length > 0;
|
|
6635
|
+
}, [tokens]);
|
|
6551
6636
|
return React__default.createElement(ThemeContextProvider, {
|
|
6552
6637
|
customTheme: curTheme
|
|
6553
6638
|
}, React__default.createElement(TokenPriceContextProvider, null, widgetRoute === 'swap' && React__default.createElement("form", {
|
|
@@ -6589,6 +6674,7 @@
|
|
|
6589
6674
|
price: !tokenIn ? null : tokenPriceList == null ? void 0 : (_tokenPriceList$token = tokenPriceList[tokenIn.id]) == null ? void 0 : _tokenPriceList$token.price,
|
|
6590
6675
|
onChangeAmount: setAmountIn,
|
|
6591
6676
|
onSelectToken: function onSelectToken() {
|
|
6677
|
+
if (!tokensLoaded) return;
|
|
6592
6678
|
setWidgetRoute('token-selector-in');
|
|
6593
6679
|
}
|
|
6594
6680
|
}), React__default.createElement("div", {
|
|
@@ -6614,6 +6700,7 @@
|
|
|
6614
6700
|
token: tokenOut,
|
|
6615
6701
|
price: !tokenOut ? null : tokenPriceList == null ? void 0 : (_tokenPriceList$token2 = tokenPriceList[tokenOut.id]) == null ? void 0 : _tokenPriceList$token2.price,
|
|
6616
6702
|
onSelectToken: function onSelectToken() {
|
|
6703
|
+
if (!tokensLoaded) return;
|
|
6617
6704
|
setWidgetRoute('token-selector-out');
|
|
6618
6705
|
},
|
|
6619
6706
|
onForceUpdate: function onForceUpdate() {
|
|
@@ -6650,7 +6737,9 @@
|
|
|
6650
6737
|
cursor: !canSubmit ? 'not-allowed' : 'pointer'
|
|
6651
6738
|
},
|
|
6652
6739
|
disabled: !canSubmit
|
|
6653
|
-
}, 'Swap'
|
|
6740
|
+
}, tokensLoaded ? 'Swap' : React__default.createElement("div", {
|
|
6741
|
+
className: "__ref-swap-widget-submit-button-loader"
|
|
6742
|
+
})) : React__default.createElement("button", {
|
|
6654
6743
|
type: "button",
|
|
6655
6744
|
className: "__ref-swap-widget-submit-button __ref-swap-widget-button",
|
|
6656
6745
|
onClick: onConnect,
|