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
4517af39
Unverified
Commit
4517af39
authored
May 13, 2021
by
Noah Zinsmeister
Committed by
GitHub
May 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't jump on mouse exit (#1565)
parent
b40163ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
20 deletions
+35
-20
PositionPage.tsx
src/pages/Pool/PositionPage.tsx
+35
-20
No files found.
src/pages/Pool/PositionPage.tsx
View file @
4517af39
import
React
,
{
SyntheticEvent
,
useCallback
,
useMemo
,
useRef
,
useState
}
from
'
react
'
import
React
,
{
useCallback
,
useMemo
,
useRef
,
useState
}
from
'
react
'
import
{
NonfungiblePositionManager
,
Pool
,
Position
}
from
'
@uniswap/v3-sdk
'
import
{
PoolState
,
usePool
}
from
'
hooks/usePools
'
...
...
@@ -201,20 +201,11 @@ function getRatio(
}
}
function
NFT
({
image
,
height
:
targetHeight
}:
{
image
:
string
;
height
:
number
})
{
const
[
animate
,
setAnimate
]
=
useState
(
false
)
const
canvasRef
=
useRef
<
HTMLCanvasElement
>
()
const
imageRef
=
useRef
<
HTMLImageElement
>
()
const
getSnapshot
=
(
src
:
HTMLImageElement
)
=>
{
if
(
!
canvasRef
.
current
)
return
const
{
current
:
canvas
}
=
canvasRef
const
context
=
canvas
.
getContext
(
'
2d
'
)
if
(
!
context
)
return
// snapshots a src img into a canvas
function
getSnapshot
(
src
:
HTMLImageElement
,
canvas
:
HTMLCanvasElement
,
targetHeight
:
number
)
{
const
context
=
canvas
.
getContext
(
'
2d
'
)
if
(
context
)
{
let
{
width
,
height
}
=
src
// src may be hidden and not have the target dimensions
...
...
@@ -232,15 +223,39 @@ function NFT({ image, height: targetHeight }: { image: string; height: number })
context
.
clearRect
(
0
,
0
,
width
,
height
)
context
.
drawImage
(
src
,
0
,
0
,
width
,
height
)
}
}
const
onLoad
=
(
e
:
SyntheticEvent
<
HTMLImageElement
>
)
=>
{
getSnapshot
(
e
.
target
as
HTMLImageElement
)
}
function
NFT
({
image
,
height
:
targetHeight
}:
{
image
:
string
;
height
:
number
})
{
const
[
animate
,
setAnimate
]
=
useState
(
false
)
const
canvasRef
=
useRef
<
HTMLCanvasElement
>
(
null
)
const
imageRef
=
useRef
<
HTMLImageElement
>
(
null
)
return
(
<
NFTGrid
onMouseEnter=
{
()
=>
setAnimate
(
true
)
}
onMouseLeave=
{
()
=>
setAnimate
(
false
)
}
>
<
NFTCanvas
ref=
{
canvasRef
as
any
}
/>
<
NFTImage
src=
{
image
}
hidden=
{
!
animate
}
onLoad=
{
onLoad
}
ref=
{
imageRef
as
any
}
/>
<
NFTGrid
onMouseEnter=
{
()
=>
{
setAnimate
(
true
)
}
}
onMouseLeave=
{
()
=>
{
// snapshot the current frame so the transition to the canvas is smooth
if
(
imageRef
.
current
&&
canvasRef
.
current
)
{
getSnapshot
(
imageRef
.
current
,
canvasRef
.
current
,
targetHeight
)
}
setAnimate
(
false
)
}
}
>
<
NFTCanvas
ref=
{
canvasRef
}
/>
<
NFTImage
ref=
{
imageRef
}
src=
{
image
}
hidden=
{
!
animate
}
onLoad=
{
()
=>
{
// snapshot for the canvas
if
(
imageRef
.
current
&&
canvasRef
.
current
)
{
getSnapshot
(
imageRef
.
current
,
canvasRef
.
current
,
targetHeight
)
}
}
}
/>
</
NFTGrid
>
)
}
...
...
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