Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
dbbffd17
Unverified
Commit
dbbffd17
authored
May 25, 2021
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: improve cancel/retry detection
parent
85d8b1e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
4 deletions
+7
-4
updater.tsx
src/state/multicall/updater.tsx
+2
-2
retry.ts
src/utils/retry.ts
+5
-2
No files found.
src/state/multicall/updater.tsx
View file @
dbbffd17
...
@@ -5,7 +5,7 @@ import { useActiveWeb3React } from '../../hooks/web3'
...
@@ -5,7 +5,7 @@ import { useActiveWeb3React } from '../../hooks/web3'
import
{
useMulticall2Contract
}
from
'
../../hooks/useContract
'
import
{
useMulticall2Contract
}
from
'
../../hooks/useContract
'
import
useDebounce
from
'
../../hooks/useDebounce
'
import
useDebounce
from
'
../../hooks/useDebounce
'
import
chunkArray
from
'
../../utils/chunkArray
'
import
chunkArray
from
'
../../utils/chunkArray
'
import
{
CancelledError
,
retry
,
RetryableError
}
from
'
../../utils/retry
'
import
{
retry
,
RetryableError
}
from
'
../../utils/retry
'
import
{
useBlockNumber
}
from
'
../application/hooks
'
import
{
useBlockNumber
}
from
'
../application/hooks
'
import
{
AppDispatch
,
AppState
}
from
'
../index
'
import
{
AppDispatch
,
AppState
}
from
'
../index
'
import
{
import
{
...
@@ -217,7 +217,7 @@ export default function Updater(): null {
...
@@ -217,7 +217,7 @@ export default function Updater(): null {
}
}
})
})
.
catch
((
error
:
any
)
=>
{
.
catch
((
error
:
any
)
=>
{
if
(
error
instanceof
CancelledError
)
{
if
(
error
.
is
CancelledError
)
{
console
.
debug
(
'
Cancelled fetch for blockNumber
'
,
latestBlockNumber
)
console
.
debug
(
'
Cancelled fetch for blockNumber
'
,
latestBlockNumber
)
return
return
}
}
...
...
src/utils/retry.ts
View file @
dbbffd17
...
@@ -10,6 +10,7 @@ function waitRandom(min: number, max: number): Promise<void> {
...
@@ -10,6 +10,7 @@ function waitRandom(min: number, max: number): Promise<void> {
* This error is thrown if the function is cancelled before completing
* This error is thrown if the function is cancelled before completing
*/
*/
export
class
CancelledError
extends
Error
{
export
class
CancelledError
extends
Error
{
public
isCancelledError
:
true
=
true
constructor
()
{
constructor
()
{
super
(
'
Cancelled
'
)
super
(
'
Cancelled
'
)
}
}
...
@@ -18,7 +19,9 @@ export class CancelledError extends Error {
...
@@ -18,7 +19,9 @@ export class CancelledError extends Error {
/**
/**
* Throw this error if the function should retry
* Throw this error if the function should retry
*/
*/
export
class
RetryableError
extends
Error
{}
export
class
RetryableError
extends
Error
{
public
isRetryableError
:
true
=
true
}
/**
/**
* Retries the function that returns the promise until the promise successfully resolves up to n retries
* Retries the function that returns the promise until the promise successfully resolves up to n retries
...
@@ -48,7 +51,7 @@ export function retry<T>(
...
@@ -48,7 +51,7 @@ export function retry<T>(
if
(
completed
)
{
if
(
completed
)
{
break
break
}
}
if
(
n
<=
0
||
!
(
error
instanceof
RetryableError
)
)
{
if
(
n
<=
0
||
!
error
.
isRetryableError
)
{
reject
(
error
)
reject
(
error
)
completed
=
true
completed
=
true
break
break
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment