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
566da074
Unverified
Commit
566da074
authored
Jun 24, 2022
by
Jordan Frankfurt
Committed by
GitHub
Jun 24, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(risk): cache risk check with ttl (#3965)
parent
31a3840b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
19 deletions
+28
-19
useAccountRiskCheck.ts
src/hooks/useAccountRiskCheck.ts
+28
-19
No files found.
src/hooks/useAccountRiskCheck.ts
View file @
566da074
import
{
sendEvent
}
from
'
components/analytics
'
import
{
sendEvent
}
from
'
components/analytics
'
import
ms
from
'
ms.macro
'
import
{
useEffect
}
from
'
react
'
import
{
useEffect
}
from
'
react
'
import
{
ApplicationModal
,
setOpenModal
}
from
'
state/application/reducer
'
import
{
ApplicationModal
,
setOpenModal
}
from
'
state/application/reducer
'
import
{
useAppDispatch
}
from
'
state/hooks
'
import
{
useAppDispatch
}
from
'
state/hooks
'
...
@@ -8,6 +9,12 @@ export default function useAccountRiskCheck(account: string | null | undefined)
...
@@ -8,6 +9,12 @@ export default function useAccountRiskCheck(account: string | null | undefined)
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
account
)
{
if
(
account
)
{
const
riskCheckLocalStorageKey
=
`risk-check-
${
account
}
`
const
now
=
Date
.
now
()
try
{
const
storedTime
=
localStorage
.
getItem
(
riskCheckLocalStorageKey
)
const
checkExpirationTime
=
storedTime
?
parseInt
(
storedTime
)
:
now
-
1
if
(
checkExpirationTime
<
Date
.
now
())
{
const
headers
=
new
Headers
({
'
Content-Type
'
:
'
application/json
'
})
const
headers
=
new
Headers
({
'
Content-Type
'
:
'
application/json
'
})
fetch
(
'
https://screening-worker.uniswap.workers.dev
'
,
{
fetch
(
'
https://screening-worker.uniswap.workers.dev
'
,
{
method
:
'
POST
'
,
method
:
'
POST
'
,
...
@@ -25,9 +32,11 @@ export default function useAccountRiskCheck(account: string | null | undefined)
...
@@ -25,9 +32,11 @@ export default function useAccountRiskCheck(account: string | null | undefined)
})
})
}
}
})
})
.
catch
(()
=>
{
.
catch
(()
=>
dispatch
(
setOpenModal
(
null
)))
dispatch
(
setOpenModal
(
null
))
}
})
}
finally
{
localStorage
.
setItem
(
riskCheckLocalStorageKey
,
(
now
+
ms
`7 days`
).
toString
())
}
}
}
},
[
account
,
dispatch
])
},
[
account
,
dispatch
])
}
}
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