Skip to content

Commit

Permalink
fixed infinite channel reconnect (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
smelnikov authored May 18, 2022
1 parent 39e6aba commit b1ef18a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ui/components/pages/swap/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ export function SwapForm({
>(null);

const maxTokens = new Money(BigNumber.MAX_VALUE, fromAsset).getTokens();
const maxTokensRef = React.useRef(maxTokens);

React.useEffect(() => {
maxTokensRef.current = maxTokens;
}, [maxTokens]);

const maxAmountExceededErrorMessage = fromAmountTokens.gt(maxTokens)
? t('swap.maxAmountExceeded', {
maxAmount: maxTokens.toFixed(),
Expand All @@ -232,7 +238,7 @@ export function SwapForm({
const watchExchange = React.useCallback(() => {
let fromTokens = new BigNumber(latestFromAmountValueRef.current || '0');

if (fromTokens.gt(maxTokens)) {
if (fromTokens.gt(maxTokensRef.current)) {
setExchangeInfo(exchangeInfoErrorState);
channelClient?.close();
return;
Expand Down Expand Up @@ -296,8 +302,8 @@ export function SwapForm({
channelClient,
fromAsset,
toAsset,
maxTokens,
latestFromAmountValueRef,
maxTokensRef,
t,
]);

Expand Down

0 comments on commit b1ef18a

Please sign in to comment.