@ref-finance/ref-sdk 1.3.7 → 1.3.9
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.js +161 -89
- 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 +162 -90
- package/dist/ref-sdk.esm.js.map +1 -1
- package/dist/ref-sdk.umd.development.js +161 -89
- 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/dist/v1-swap/pool.d.ts +1 -5
- 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);
|
|
@@ -4675,24 +4663,36 @@
|
|
|
4675
4663
|
}();
|
|
4676
4664
|
var fetchAllPools = /*#__PURE__*/function () {
|
|
4677
4665
|
var _ref9 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(perPage) {
|
|
4678
|
-
var totalPools, pages, pools;
|
|
4666
|
+
var _pools, totalPools, pages, pools;
|
|
4679
4667
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
4680
4668
|
while (1) {
|
|
4681
4669
|
switch (_context7.prev = _context7.next) {
|
|
4682
4670
|
case 0:
|
|
4671
|
+
_context7.prev = 0;
|
|
4672
|
+
_context7.next = 3;
|
|
4673
|
+
return fetch(exports.config.indexerUrl + "/fetchAllPools").then(function (res) {
|
|
4674
|
+
return res.json();
|
|
4675
|
+
});
|
|
4676
|
+
case 3:
|
|
4677
|
+
_pools = _context7.sent;
|
|
4678
|
+
return _context7.abrupt("return", _pools);
|
|
4679
|
+
case 7:
|
|
4680
|
+
_context7.prev = 7;
|
|
4681
|
+
_context7.t0 = _context7["catch"](0);
|
|
4682
|
+
case 9:
|
|
4683
4683
|
if (perPage) {
|
|
4684
4684
|
DEFAULT_PAGE_LIMIT = Math.min(perPage, 500);
|
|
4685
4685
|
}
|
|
4686
|
-
_context7.next =
|
|
4686
|
+
_context7.next = 12;
|
|
4687
4687
|
return getTotalPools();
|
|
4688
|
-
case
|
|
4688
|
+
case 12:
|
|
4689
4689
|
totalPools = _context7.sent;
|
|
4690
4690
|
pages = Math.ceil(totalPools / DEFAULT_PAGE_LIMIT);
|
|
4691
|
-
_context7.next =
|
|
4691
|
+
_context7.next = 16;
|
|
4692
4692
|
return Promise.all([].concat(Array(pages)).fill(0).map(function (_, i) {
|
|
4693
4693
|
return getRefPools(i + 1);
|
|
4694
4694
|
}));
|
|
4695
|
-
case
|
|
4695
|
+
case 16:
|
|
4696
4696
|
pools = _context7.sent.flat();
|
|
4697
4697
|
return _context7.abrupt("return", {
|
|
4698
4698
|
simplePools: pools.filter(function (p) {
|
|
@@ -4705,19 +4705,18 @@
|
|
|
4705
4705
|
return p.pool_kind && p.pool_kind === 'RATED_SWAP';
|
|
4706
4706
|
})
|
|
4707
4707
|
});
|
|
4708
|
-
case
|
|
4708
|
+
case 18:
|
|
4709
4709
|
case "end":
|
|
4710
4710
|
return _context7.stop();
|
|
4711
4711
|
}
|
|
4712
4712
|
}
|
|
4713
|
-
}, _callee7);
|
|
4713
|
+
}, _callee7, null, [[0, 7]]);
|
|
4714
4714
|
}));
|
|
4715
4715
|
return function fetchAllPools(_x8) {
|
|
4716
4716
|
return _ref9.apply(this, arguments);
|
|
4717
4717
|
};
|
|
4718
4718
|
}();
|
|
4719
4719
|
|
|
4720
|
-
var _excluded = ["slippageTolerance", "refreshTrigger", "onSwap", "AccountId", "poolFetchingState", "referralId"];
|
|
4721
4720
|
var ThemeContext = /*#__PURE__*/React.createContext(defaultTheme);
|
|
4722
4721
|
var ThemeContextProvider = function ThemeContextProvider(_ref) {
|
|
4723
4722
|
var customTheme = _ref.customTheme,
|
|
@@ -4896,7 +4895,7 @@
|
|
|
4896
4895
|
AccountId = params.AccountId,
|
|
4897
4896
|
poolFetchingState = params.poolFetchingState,
|
|
4898
4897
|
referralId = params.referralId,
|
|
4899
|
-
|
|
4898
|
+
tokens = params.tokens;
|
|
4900
4899
|
var tokenIn = params.tokenIn,
|
|
4901
4900
|
tokenOut = params.tokenOut,
|
|
4902
4901
|
amountIn = params.amountIn;
|
|
@@ -4918,6 +4917,15 @@
|
|
|
4918
4917
|
var _useState14 = React.useState(false),
|
|
4919
4918
|
forceEstimate = _useState14[0],
|
|
4920
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]);
|
|
4921
4929
|
var minAmountOut = amountOut ? percentLess(slippageTolerance, amountOut) : '';
|
|
4922
4930
|
var fee = !params.tokenOut || !params.tokenIn ? 0 : getAvgFee(estimates, params.tokenOut.id, toNonDivisibleNumber(params.tokenIn.decimals, params.amountIn));
|
|
4923
4931
|
var rate = calculateExchangeRate(ONLY_ZEROS.test(params.amountIn) ? '1' : params.amountIn, amountOut || '1');
|
|
@@ -4959,8 +4967,16 @@
|
|
|
4959
4967
|
_minAmountOut = percentLess(slippageTolerance, scientificNotationToString(bigEstimate.toString()));
|
|
4960
4968
|
transactionsRef.push(nearWithdrawTransaction(_minAmountOut));
|
|
4961
4969
|
}
|
|
4962
|
-
|
|
4963
|
-
|
|
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:
|
|
4964
4980
|
case "end":
|
|
4965
4981
|
return _context3.stop();
|
|
4966
4982
|
}
|
|
@@ -5022,6 +5038,9 @@
|
|
|
5022
5038
|
return {
|
|
5023
5039
|
amountOut: amountOut,
|
|
5024
5040
|
minAmountOut: minAmountOut,
|
|
5041
|
+
balances: balances,
|
|
5042
|
+
tokenInBalance: tokenInBalance,
|
|
5043
|
+
tokenOutBalance: tokenOutBalance,
|
|
5025
5044
|
fee: fee,
|
|
5026
5045
|
rate: rate,
|
|
5027
5046
|
estimates: estimates,
|
|
@@ -5049,30 +5068,108 @@
|
|
|
5049
5068
|
value: tokenPriceList
|
|
5050
5069
|
}, children);
|
|
5051
5070
|
};
|
|
5052
|
-
var
|
|
5071
|
+
var useTokenBalances = function useTokenBalances(tokens, AccountId) {
|
|
5053
5072
|
var _useState16 = React.useState({}),
|
|
5054
5073
|
balances = _useState16[0],
|
|
5055
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]);
|
|
5056
5126
|
React.useEffect(function () {
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
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) {
|
|
5073
5167
|
return t == null ? void 0 : t.id;
|
|
5074
5168
|
}).join('-')]);
|
|
5075
|
-
return
|
|
5169
|
+
return {
|
|
5170
|
+
balances: balances,
|
|
5171
|
+
updateTokenBalance: updateTokenBalance
|
|
5172
|
+
};
|
|
5076
5173
|
};
|
|
5077
5174
|
|
|
5078
5175
|
function styleInject(css, ref) {
|
|
@@ -6382,15 +6479,9 @@
|
|
|
6382
6479
|
var _useState2 = React.useState(),
|
|
6383
6480
|
tokenOut = _useState2[0],
|
|
6384
6481
|
setTokenOut = _useState2[1];
|
|
6385
|
-
var _useState3 = React.useState(
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
var _useState4 = React.useState(''),
|
|
6389
|
-
tokenOutBalance = _useState4[0],
|
|
6390
|
-
setTokenOutBalance = _useState4[1];
|
|
6391
|
-
var _useState5 = React.useState(false),
|
|
6392
|
-
notOpen = _useState5[0],
|
|
6393
|
-
setNotOpen = _useState5[1];
|
|
6482
|
+
var _useState3 = React.useState(false),
|
|
6483
|
+
notOpen = _useState3[0],
|
|
6484
|
+
setNotOpen = _useState3[1];
|
|
6394
6485
|
React.useEffect(function () {
|
|
6395
6486
|
if (!transactionState) return;
|
|
6396
6487
|
if (transactionState && transactionState.state !== null) {
|
|
@@ -6398,18 +6489,18 @@
|
|
|
6398
6489
|
}
|
|
6399
6490
|
transactionState == null ? void 0 : transactionState.setState((transactionState == null ? void 0 : transactionState.state) || null);
|
|
6400
6491
|
}, [transactionState]);
|
|
6401
|
-
var
|
|
6402
|
-
widgetRoute =
|
|
6403
|
-
setWidgetRoute =
|
|
6404
|
-
var
|
|
6405
|
-
amountIn =
|
|
6406
|
-
setAmountIn =
|
|
6407
|
-
var
|
|
6408
|
-
showSlip =
|
|
6409
|
-
setShowSlip =
|
|
6410
|
-
var
|
|
6411
|
-
slippageTolerance =
|
|
6412
|
-
setSlippageTolerance =
|
|
6492
|
+
var _useState4 = React.useState('swap'),
|
|
6493
|
+
widgetRoute = _useState4[0],
|
|
6494
|
+
setWidgetRoute = _useState4[1];
|
|
6495
|
+
var _useState5 = React.useState('1'),
|
|
6496
|
+
amountIn = _useState5[0],
|
|
6497
|
+
setAmountIn = _useState5[1];
|
|
6498
|
+
var _useState6 = React.useState(false),
|
|
6499
|
+
showSlip = _useState6[0],
|
|
6500
|
+
setShowSlip = _useState6[1];
|
|
6501
|
+
var _useState7 = React.useState(0.5),
|
|
6502
|
+
slippageTolerance = _useState7[0],
|
|
6503
|
+
setSlippageTolerance = _useState7[1];
|
|
6413
6504
|
var _useTokensIndexer = useTokensIndexer({
|
|
6414
6505
|
defaultTokenList: defaultTokenList,
|
|
6415
6506
|
AccountId: AccountId
|
|
@@ -6420,10 +6511,9 @@
|
|
|
6420
6511
|
useAllTokens({
|
|
6421
6512
|
reload: true
|
|
6422
6513
|
});
|
|
6423
|
-
var
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
setRreshTrigger = _useState10[1];
|
|
6514
|
+
var _useState8 = React.useState(false),
|
|
6515
|
+
refreshTrigger = _useState8[0],
|
|
6516
|
+
setRreshTrigger = _useState8[1];
|
|
6427
6517
|
var tokenPriceList = useTokenPriceList();
|
|
6428
6518
|
var _useRefPools = useRefPools(refreshTrigger),
|
|
6429
6519
|
allPools = _useRefPools.allPools,
|
|
@@ -6465,28 +6555,6 @@
|
|
|
6465
6555
|
handleSetTokenOut(exports.REF_META_DATA);
|
|
6466
6556
|
}
|
|
6467
6557
|
}, [tokens, tokenLoading]);
|
|
6468
|
-
React.useEffect(function () {
|
|
6469
|
-
if (!tokenIn) return;
|
|
6470
|
-
var wrapedId = tokenIn.id === exports.WRAP_NEAR_CONTRACT_ID ? 'NEAR' : tokenIn.id;
|
|
6471
|
-
if (balances[wrapedId]) {
|
|
6472
|
-
setTokenInBalance(balances[wrapedId]);
|
|
6473
|
-
return;
|
|
6474
|
-
}
|
|
6475
|
-
ftGetBalance(wrapedId, AccountId).then(function (available) {
|
|
6476
|
-
setTokenInBalance(toReadableNumber(tokenIn.decimals, available));
|
|
6477
|
-
});
|
|
6478
|
-
}, [tokenIn, AccountId, balances]);
|
|
6479
|
-
React.useEffect(function () {
|
|
6480
|
-
if (!tokenOut) return;
|
|
6481
|
-
var wrapedId = tokenOut.id === exports.WRAP_NEAR_CONTRACT_ID ? 'NEAR' : tokenOut.id;
|
|
6482
|
-
if (balances[wrapedId]) {
|
|
6483
|
-
setTokenOutBalance(balances[wrapedId]);
|
|
6484
|
-
return;
|
|
6485
|
-
}
|
|
6486
|
-
ftGetBalance(wrapedId, AccountId).then(function (available) {
|
|
6487
|
-
setTokenOutBalance(toReadableNumber(tokenOut.decimals, available));
|
|
6488
|
-
});
|
|
6489
|
-
}, [tokenOut, AccountId, balances]);
|
|
6490
6558
|
var _useSwap = useSwap({
|
|
6491
6559
|
tokenIn: tokenIn,
|
|
6492
6560
|
tokenOut: tokenOut,
|
|
@@ -6508,10 +6576,14 @@
|
|
|
6508
6576
|
AccountId: AccountId,
|
|
6509
6577
|
refreshTrigger: refreshTrigger,
|
|
6510
6578
|
poolFetchingState: poolFetchingState,
|
|
6511
|
-
referralId: referralId
|
|
6579
|
+
referralId: referralId,
|
|
6580
|
+
tokens: tokens
|
|
6512
6581
|
}),
|
|
6513
6582
|
amountOut = _useSwap.amountOut,
|
|
6514
6583
|
minAmountOut = _useSwap.minAmountOut,
|
|
6584
|
+
balances = _useSwap.balances,
|
|
6585
|
+
tokenInBalance = _useSwap.tokenInBalance,
|
|
6586
|
+
tokenOutBalance = _useSwap.tokenOutBalance,
|
|
6515
6587
|
rate = _useSwap.rate,
|
|
6516
6588
|
fee = _useSwap.fee,
|
|
6517
6589
|
estimates = _useSwap.estimates,
|